Panda3D
|
00001 // Filename: nurbsSurfaceResult.I 00002 // Created by: drose (10Oct03) 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: NurbsSurfaceResult::Destructor 00018 // Access: Published 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE NurbsSurfaceResult:: 00022 ~NurbsSurfaceResult() { 00023 } 00024 00025 //////////////////////////////////////////////////////////////////// 00026 // Function: NurbsSurfaceResult::get_start_u 00027 // Access: Public 00028 // Description: Returns the first legal value of u on the surface. 00029 // Usually this is 0.0. 00030 //////////////////////////////////////////////////////////////////// 00031 INLINE PN_stdfloat NurbsSurfaceResult:: 00032 get_start_u() const { 00033 return _u_basis.get_start_t(); 00034 } 00035 00036 //////////////////////////////////////////////////////////////////// 00037 // Function: NurbsSurfaceResult::get_end_u 00038 // Access: Public 00039 // Description: Returns the last legal value of u on the surface. 00040 //////////////////////////////////////////////////////////////////// 00041 INLINE PN_stdfloat NurbsSurfaceResult:: 00042 get_end_u() const { 00043 return _u_basis.get_end_t(); 00044 } 00045 00046 //////////////////////////////////////////////////////////////////// 00047 // Function: NurbsSurfaceResult::get_start_v 00048 // Access: Public 00049 // Description: Returns the first legal value of v on the surface. 00050 // Usually this is 0.0. 00051 //////////////////////////////////////////////////////////////////// 00052 INLINE PN_stdfloat NurbsSurfaceResult:: 00053 get_start_v() const { 00054 return _v_basis.get_start_t(); 00055 } 00056 00057 //////////////////////////////////////////////////////////////////// 00058 // Function: NurbsSurfaceResult::get_end_v 00059 // Access: Public 00060 // Description: Returns the last legal value of v on the surface. 00061 //////////////////////////////////////////////////////////////////// 00062 INLINE PN_stdfloat NurbsSurfaceResult:: 00063 get_end_v() const { 00064 return _v_basis.get_end_t(); 00065 } 00066 00067 //////////////////////////////////////////////////////////////////// 00068 // Function: NurbsSurfaceResult::eval_point 00069 // Access: Published 00070 // Description: Computes the point on the surface corresponding to the 00071 // indicated value in parametric time. Returns true if 00072 // the u, v values are valid, false otherwise. 00073 //////////////////////////////////////////////////////////////////// 00074 INLINE bool NurbsSurfaceResult:: 00075 eval_point(PN_stdfloat u, PN_stdfloat v, LVecBase3 &point) { 00076 int ui = find_u_segment(u); 00077 int vi = find_v_segment(v); 00078 if (ui == -1 || vi == -1) { 00079 return false; 00080 } 00081 00082 eval_segment_point(ui, vi, _u_basis.scale_t(ui, u), _v_basis.scale_t(vi, v), 00083 point); 00084 return true; 00085 } 00086 00087 //////////////////////////////////////////////////////////////////// 00088 // Function: NurbsSurfaceResult::eval_normal 00089 // Access: Published 00090 // Description: Computes the normal to the surface at the indicated 00091 // point in parametric time. This normal vector will 00092 // not necessarily be normalized, and could be zero. 00093 // See also eval_point(). 00094 //////////////////////////////////////////////////////////////////// 00095 INLINE bool NurbsSurfaceResult:: 00096 eval_normal(PN_stdfloat u, PN_stdfloat v, LVecBase3 &normal) { 00097 int ui = find_u_segment(u); 00098 int vi = find_v_segment(v); 00099 if (ui == -1 || vi == -1) { 00100 return false; 00101 } 00102 00103 eval_segment_normal(ui, vi, _u_basis.scale_t(ui, u), _v_basis.scale_t(vi, v), 00104 normal); 00105 return true; 00106 } 00107 00108 //////////////////////////////////////////////////////////////////// 00109 // Function: NurbsSurfaceResult::eval_extended_point 00110 // Access: Published 00111 // Description: Evaluates the surface in n-dimensional space according 00112 // to the extended vertices associated with the surface in 00113 // the indicated dimension. 00114 //////////////////////////////////////////////////////////////////// 00115 INLINE PN_stdfloat NurbsSurfaceResult:: 00116 eval_extended_point(PN_stdfloat u, PN_stdfloat v, int d) { 00117 int ui = find_u_segment(u); 00118 int vi = find_v_segment(v); 00119 if (ui == -1 || vi == -1) { 00120 return 0.0f; 00121 } 00122 00123 return eval_segment_extended_point(ui, vi, _u_basis.scale_t(ui, u), 00124 _v_basis.scale_t(vi, v), d); 00125 } 00126 00127 //////////////////////////////////////////////////////////////////// 00128 // Function: NurbsSurfaceResult::eval_extended_points 00129 // Access: Published 00130 // Description: Simultaneously performs eval_extended_point on a 00131 // contiguous sequence of dimensions. The dimensions 00132 // evaluated are d through (d + num_values - 1); the 00133 // results are filled into the num_values elements in 00134 // the indicated result array. 00135 //////////////////////////////////////////////////////////////////// 00136 INLINE bool NurbsSurfaceResult:: 00137 eval_extended_points(PN_stdfloat u, PN_stdfloat v, int d, PN_stdfloat result[], 00138 int num_values) { 00139 int ui = find_u_segment(u); 00140 int vi = find_v_segment(v); 00141 if (ui == -1 || vi == -1) { 00142 return false; 00143 } 00144 00145 eval_segment_extended_points(ui, vi, _u_basis.scale_t(ui, u), 00146 _v_basis.scale_t(vi, v), d, result, 00147 num_values); 00148 return true; 00149 } 00150 00151 //////////////////////////////////////////////////////////////////// 00152 // Function: NurbsSurfaceResult::get_num_u_segments 00153 // Access: Public 00154 // Description: Returns the number of piecewise continuous segments 00155 // within the surface in the U direction. This number 00156 // is usually not important unless you plan to call 00157 // eval_segment_point(). 00158 //////////////////////////////////////////////////////////////////// 00159 INLINE int NurbsSurfaceResult:: 00160 get_num_u_segments() const { 00161 return _u_basis.get_num_segments(); 00162 } 00163 00164 //////////////////////////////////////////////////////////////////// 00165 // Function: NurbsSurfaceResult::get_num_v_segments 00166 // Access: Public 00167 // Description: Returns the number of piecewise continuous segments 00168 // within the surface in the V direction. This number 00169 // is usually not important unless you plan to call 00170 // eval_segment_point(). 00171 //////////////////////////////////////////////////////////////////// 00172 INLINE int NurbsSurfaceResult:: 00173 get_num_v_segments() const { 00174 return _v_basis.get_num_segments(); 00175 } 00176 00177 //////////////////////////////////////////////////////////////////// 00178 // Function: NurbsSurfaceResult::get_segment_u 00179 // Access: Public 00180 // Description: Accepts a u value in the range [0, 1], and assumed to 00181 // be relative to the indicated segment (as in 00182 // eval_segment_point()), and returns the corresponding 00183 // u value in the entire surface (as in eval_point()). 00184 //////////////////////////////////////////////////////////////////// 00185 INLINE PN_stdfloat NurbsSurfaceResult:: 00186 get_segment_u(int ui, PN_stdfloat u) const { 00187 return u * (_u_basis.get_to(ui) - _u_basis.get_from(ui)) + _u_basis.get_from(ui); 00188 } 00189 00190 //////////////////////////////////////////////////////////////////// 00191 // Function: NurbsSurfaceResult::get_segment_v 00192 // Access: Public 00193 // Description: Accepts a v value in the range [0, 1], and assumed to 00194 // be relative to the indicated segment (as in 00195 // eval_segment_point()), and returns the corresponding 00196 // v value in the entire surface (as in eval_point()). 00197 //////////////////////////////////////////////////////////////////// 00198 INLINE PN_stdfloat NurbsSurfaceResult:: 00199 get_segment_v(int vi, PN_stdfloat v) const { 00200 return v * (_v_basis.get_to(vi) - _v_basis.get_from(vi)) + _v_basis.get_from(vi); 00201 } 00202 00203 //////////////////////////////////////////////////////////////////// 00204 // Function: NurbsSurfaceResult::verti 00205 // Access: Private 00206 // Description: An internal function to dereference a 2-d vertex 00207 // coordinate pair into a linear list of vertices. This 00208 // returns the linear index corresponding to the 2-d 00209 // pair. 00210 //////////////////////////////////////////////////////////////////// 00211 INLINE int NurbsSurfaceResult:: 00212 verti(int ui, int vi) const { 00213 return ui * _num_v_vertices + vi; 00214 } 00215 00216 //////////////////////////////////////////////////////////////////// 00217 // Function: NurbsSurfaceResult::segi 00218 // Access: Private 00219 // Description: An internal function to dereference a 2-d segment 00220 // coordinate pair into a linear list of segments. This 00221 // returns the linear index corresponding to the 2-d 00222 // pair. 00223 //////////////////////////////////////////////////////////////////// 00224 INLINE int NurbsSurfaceResult:: 00225 segi(int ui, int vi) const { 00226 return ui * _v_basis.get_num_segments() + vi; 00227 }