Panda3D
|
00001 // Filename: eggNurbsCurve.I 00002 // Created by: drose (15Feb00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 //////////////////////////////////////////////////////////////////// 00016 // Function: EggNurbsCurve::Constructor 00017 // Access: Public 00018 // Description: 00019 //////////////////////////////////////////////////////////////////// 00020 INLINE EggNurbsCurve:: 00021 EggNurbsCurve(const string &name) : EggCurve(name) { 00022 _order = 0; 00023 } 00024 00025 //////////////////////////////////////////////////////////////////// 00026 // Function: EggNurbsCurve::Copy constructor 00027 // Access: Public 00028 // Description: 00029 //////////////////////////////////////////////////////////////////// 00030 INLINE EggNurbsCurve:: 00031 EggNurbsCurve(const EggNurbsCurve ©) : 00032 EggCurve(copy), 00033 _knots(copy._knots), 00034 _order(copy._order) 00035 { 00036 } 00037 00038 //////////////////////////////////////////////////////////////////// 00039 // Function: EggNurbsCurve::Copy assignment operator 00040 // Access: Public 00041 // Description: 00042 //////////////////////////////////////////////////////////////////// 00043 INLINE EggNurbsCurve &EggNurbsCurve:: 00044 operator = (const EggNurbsCurve ©) { 00045 EggCurve::operator = (copy); 00046 _knots = copy._knots; 00047 _order = copy._order; 00048 return *this; 00049 } 00050 00051 //////////////////////////////////////////////////////////////////// 00052 // Function: EggNurbsCurve::set_order 00053 // Access: Public 00054 // Description: Directly changes the order to the indicated value 00055 // (which must be an integer in the range 1 <= order <= 00056 // 4). If possible, it is preferable to use the setup() 00057 // method instead of this method, since changing the 00058 // order directly may result in an invalid curve. 00059 //////////////////////////////////////////////////////////////////// 00060 INLINE void EggNurbsCurve:: 00061 set_order(int order) { 00062 nassertv(order >= 1 && order <= 4); 00063 _order = order; 00064 } 00065 00066 //////////////////////////////////////////////////////////////////// 00067 // Function: EggNurbsCurve::set_knot 00068 // Access: Public 00069 // Description: Resets the value of the indicated knot as indicated. 00070 // k must be in the range 0 <= k < get_num_knots(), 00071 // and the value must be in the range get_knot(k - 1) 00072 // <= value <= get_knot(k + 1). 00073 //////////////////////////////////////////////////////////////////// 00074 INLINE void EggNurbsCurve:: 00075 set_knot(int k, double value) { 00076 nassertv(k >= 0 && k < (int)_knots.size()); 00077 _knots[k] = value; 00078 } 00079 00080 //////////////////////////////////////////////////////////////////// 00081 // Function: EggNurbsCurve::get_order 00082 // Access: Public 00083 // Description: Returns the order of the curve. The order is the 00084 // degree of the NURBS equation plus 1; for a typical 00085 // NURBS, the order is 4. With this implementation of 00086 // NURBS, the order must be in the range [1, 4]. 00087 //////////////////////////////////////////////////////////////////// 00088 INLINE int EggNurbsCurve:: 00089 get_order() const { 00090 return _order; 00091 } 00092 00093 //////////////////////////////////////////////////////////////////// 00094 // Function: EggNurbsCurve::get_degree 00095 // Access: Public 00096 // Description: Returns the degree of the curve. For a typical 00097 // NURBS, the degree is 3. 00098 //////////////////////////////////////////////////////////////////// 00099 INLINE int EggNurbsCurve:: 00100 get_degree() const { 00101 return _order - 1; 00102 } 00103 00104 //////////////////////////////////////////////////////////////////// 00105 // Function: EggNurbsCurve::get_num_knots 00106 // Access: Public 00107 // Description: Returns the number of knots. 00108 //////////////////////////////////////////////////////////////////// 00109 INLINE int EggNurbsCurve:: 00110 get_num_knots() const { 00111 return _knots.size(); 00112 } 00113 00114 //////////////////////////////////////////////////////////////////// 00115 // Function: EggNurbsCurve::get_num_cvs 00116 // Access: Public 00117 // Description: Returns the total number of control vertices that 00118 // *should* be defined for the curve. This is 00119 // determined by the number of knots and the order, in 00120 // each direction; it does not necessarily reflect the 00121 // number of vertices that have actually been added to 00122 // the curve. (However, if the number of vertices in 00123 // the curve are wrong, the curve is invalid.) 00124 //////////////////////////////////////////////////////////////////// 00125 INLINE int EggNurbsCurve:: 00126 get_num_cvs() const { 00127 return get_num_knots() - get_order(); 00128 } 00129 00130 //////////////////////////////////////////////////////////////////// 00131 // Function: EggNurbsCurve::get_knot 00132 // Access: Public 00133 // Description: Returns the nth knot value defined. 00134 //////////////////////////////////////////////////////////////////// 00135 INLINE double EggNurbsCurve:: 00136 get_knot(int k) const { 00137 nassertr(k >= 0 && k < (int)_knots.size(), 0.0); 00138 return _knots[k]; 00139 } 00140