Panda3D
|
00001 // Filename: nurbsBasisVector.I 00002 // Created by: drose (04Dec02) 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 //////////////////////////////////////////////////////////////////// 00017 // Function: NurbsBasisVector::Constructor 00018 // Access: Public 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE NurbsBasisVector:: 00022 NurbsBasisVector() { 00023 _order = 0; 00024 } 00025 00026 //////////////////////////////////////////////////////////////////// 00027 // Function: NurbsBasisVector::Destructor 00028 // Access: Public 00029 // Description: 00030 //////////////////////////////////////////////////////////////////// 00031 INLINE NurbsBasisVector:: 00032 ~NurbsBasisVector() { 00033 } 00034 00035 //////////////////////////////////////////////////////////////////// 00036 // Function: NurbsBasisVector::get_order 00037 // Access: Public 00038 // Description: Returns the order of the segments in the curve. 00039 //////////////////////////////////////////////////////////////////// 00040 INLINE int NurbsBasisVector:: 00041 get_order() const { 00042 return _order; 00043 } 00044 00045 //////////////////////////////////////////////////////////////////// 00046 // Function: NurbsBasisVector::get_num_segments 00047 // Access: Public 00048 // Description: Returns the number of piecewise continuous segments 00049 // in the curve. 00050 //////////////////////////////////////////////////////////////////// 00051 INLINE int NurbsBasisVector:: 00052 get_num_segments() const { 00053 return _segments.size(); 00054 } 00055 00056 //////////////////////////////////////////////////////////////////// 00057 // Function: NurbsBasisVector::get_start_t 00058 // Access: Public 00059 // Description: Returns the first legal value of t on the curve. 00060 // Usually this is 0.0. 00061 //////////////////////////////////////////////////////////////////// 00062 INLINE PN_stdfloat NurbsBasisVector:: 00063 get_start_t() const { 00064 nassertr(!_segments.empty(), 0.0f); 00065 return _segments.front()._from; 00066 } 00067 00068 //////////////////////////////////////////////////////////////////// 00069 // Function: NurbsBasisVector::get_end_t 00070 // Access: Public 00071 // Description: Returns the last legal value of t on the curve. 00072 //////////////////////////////////////////////////////////////////// 00073 INLINE PN_stdfloat NurbsBasisVector:: 00074 get_end_t() const { 00075 nassertr(!_segments.empty(), 0.0f); 00076 return _segments.back()._to; 00077 } 00078 00079 //////////////////////////////////////////////////////////////////// 00080 // Function: NurbsBasisVector::get_vertex_index 00081 // Access: Public 00082 // Description: Returns the vertex index of the nth segment. This is 00083 // the index number of the first associated control 00084 // vertex within the source NurbsCurveEvaluator object. 00085 //////////////////////////////////////////////////////////////////// 00086 INLINE int NurbsBasisVector:: 00087 get_vertex_index(int segment) const { 00088 nassertr(segment >= 0 && segment < (int)_segments.size(), 0); 00089 return _segments[segment]._vertex_index; 00090 } 00091 00092 //////////////////////////////////////////////////////////////////// 00093 // Function: NurbsBasisVector::get_from 00094 // Access: Public 00095 // Description: Returns the t value of the beginning of this segment. 00096 //////////////////////////////////////////////////////////////////// 00097 INLINE PN_stdfloat NurbsBasisVector:: 00098 get_from(int segment) const { 00099 nassertr(segment >= 0 && segment < (int)_segments.size(), 0.0f); 00100 return _segments[segment]._from; 00101 } 00102 00103 //////////////////////////////////////////////////////////////////// 00104 // Function: NurbsBasisVector::get_to 00105 // Access: Public 00106 // Description: Returns the t value of the end of this segment. 00107 //////////////////////////////////////////////////////////////////// 00108 INLINE PN_stdfloat NurbsBasisVector:: 00109 get_to(int segment) const { 00110 nassertr(segment >= 0 && segment < (int)_segments.size(), 0.0f); 00111 return _segments[segment]._to; 00112 } 00113 00114 //////////////////////////////////////////////////////////////////// 00115 // Function: NurbsBasisVector::get_basis 00116 // Access: Public 00117 // Description: Returns the basis matrix associated with the nth 00118 // segment. This is the pure matrix based on the knot 00119 // vector over the segment; it does not depend on the 00120 // control vertices. 00121 //////////////////////////////////////////////////////////////////// 00122 INLINE const LMatrix4 &NurbsBasisVector:: 00123 get_basis(int segment) const { 00124 nassertr(segment >= 0 && segment < (int)_segments.size(), LMatrix4::ident_mat()); 00125 return _segments[segment]._basis; 00126 } 00127 00128 //////////////////////////////////////////////////////////////////// 00129 // Function: NurbsBasisVector::scale_t 00130 // Access: Public 00131 // Description: Scales the value of t into the range [0, 1] 00132 // corresponding to [from, to]. Returns the scaled 00133 // value. 00134 //////////////////////////////////////////////////////////////////// 00135 INLINE PN_stdfloat NurbsBasisVector:: 00136 scale_t(int segment, PN_stdfloat t) const { 00137 nassertr(segment >= 0 && segment < (int)_segments.size(), 0.0f); 00138 PN_stdfloat from = _segments[segment]._from; 00139 PN_stdfloat to = _segments[segment]._to; 00140 t = (t - from) / (to - from); 00141 return min(max(t, (PN_stdfloat)0.0), (PN_stdfloat)1.0); 00142 }