Panda3D
|
00001 // Filename: ropeNode.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: RopeNode::CData::Constructor 00018 // Access: Public 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE RopeNode::CData:: 00022 CData() { 00023 _curve = new NurbsCurveEvaluator; 00024 _render_mode = RopeNode::RM_thread; 00025 _uv_mode = RopeNode::UV_none; 00026 _u_dominant = true; 00027 _uv_scale = 1.0f; 00028 _normal_mode = RopeNode::NM_none; 00029 _tube_up = LVector3::up(); 00030 _matrix = LMatrix4::ident_mat(); 00031 _has_matrix = false; 00032 _use_vertex_color = false; 00033 _num_subdiv = 10; 00034 _num_slices = 5; 00035 _use_vertex_thickness = false; 00036 _thickness = 1.0f; 00037 } 00038 00039 //////////////////////////////////////////////////////////////////// 00040 // Function: RopeNode::CData::Copy Constructor 00041 // Access: Public 00042 // Description: 00043 //////////////////////////////////////////////////////////////////// 00044 INLINE RopeNode::CData:: 00045 CData(const RopeNode::CData ©) : 00046 _curve(copy._curve), 00047 _render_mode(copy._render_mode), 00048 _uv_mode(copy._uv_mode), 00049 _u_dominant(copy._u_dominant), 00050 _uv_scale(copy._uv_scale), 00051 _normal_mode(copy._normal_mode), 00052 _tube_up(copy._tube_up), 00053 _matrix(copy._matrix), 00054 _has_matrix(copy._has_matrix), 00055 _use_vertex_color(copy._use_vertex_color), 00056 _num_subdiv(copy._num_subdiv), 00057 _num_slices(copy._num_slices), 00058 _use_vertex_thickness(copy._use_vertex_thickness), 00059 _thickness(copy._thickness) 00060 { 00061 } 00062 00063 //////////////////////////////////////////////////////////////////// 00064 // Function: set_curve 00065 // Access: Published 00066 // Description: Sets the particular curve represented by the 00067 // RopeNode. 00068 //////////////////////////////////////////////////////////////////// 00069 INLINE void RopeNode:: 00070 set_curve(NurbsCurveEvaluator *curve) { 00071 CDWriter cdata(_cycler); 00072 cdata->_curve = curve; 00073 } 00074 00075 //////////////////////////////////////////////////////////////////// 00076 // Function: get_curve 00077 // Access: Published 00078 // Description: Returns the curve represented by the RopeNode. 00079 //////////////////////////////////////////////////////////////////// 00080 INLINE NurbsCurveEvaluator *RopeNode:: 00081 get_curve() const { 00082 CDReader cdata(_cycler); 00083 return cdata->_curve; 00084 } 00085 00086 //////////////////////////////////////////////////////////////////// 00087 // Function: set_render_mode 00088 // Access: Published 00089 // Description: Specifies the method used to render the rope. The 00090 // simplest is RM_thread, which just draws a one-pixel 00091 // line segment. 00092 //////////////////////////////////////////////////////////////////// 00093 INLINE void RopeNode:: 00094 set_render_mode(RopeNode::RenderMode render_mode) { 00095 CDWriter cdata(_cycler); 00096 cdata->_render_mode = render_mode; 00097 } 00098 00099 //////////////////////////////////////////////////////////////////// 00100 // Function: get_render_mode 00101 // Access: Published 00102 // Description: Returns the method used to render the rope. See 00103 // set_render_mode(). 00104 //////////////////////////////////////////////////////////////////// 00105 INLINE RopeNode::RenderMode RopeNode:: 00106 get_render_mode() const { 00107 CDReader cdata(_cycler); 00108 return cdata->_render_mode; 00109 } 00110 00111 //////////////////////////////////////////////////////////////////// 00112 // Function: set_uv_mode 00113 // Access: Published 00114 // Description: Specifies the algorithm to use to generate UV's for 00115 // the rope. 00116 //////////////////////////////////////////////////////////////////// 00117 INLINE void RopeNode:: 00118 set_uv_mode(RopeNode::UVMode uv_mode) { 00119 CDWriter cdata(_cycler); 00120 cdata->_uv_mode = uv_mode; 00121 } 00122 00123 //////////////////////////////////////////////////////////////////// 00124 // Function: get_uv_mode 00125 // Access: Published 00126 // Description: Returns the algorithm to use to generate UV's for the 00127 // rope. 00128 //////////////////////////////////////////////////////////////////// 00129 INLINE RopeNode::UVMode RopeNode:: 00130 get_uv_mode() const { 00131 CDReader cdata(_cycler); 00132 return cdata->_uv_mode; 00133 } 00134 00135 //////////////////////////////////////////////////////////////////// 00136 // Function: set_uv_direction 00137 // Access: Published 00138 // Description: Specify true to vary the U coordinate down the length 00139 // of the rope, or false to vary the V coordinate. 00140 //////////////////////////////////////////////////////////////////// 00141 INLINE void RopeNode:: 00142 set_uv_direction(bool u_dominant) { 00143 CDWriter cdata(_cycler); 00144 cdata->_u_dominant = u_dominant; 00145 } 00146 00147 //////////////////////////////////////////////////////////////////// 00148 // Function: get_uv_direction 00149 // Access: Published 00150 // Description: Returns true if the rope runs down the U coordinate 00151 // of the texture, or false if it runs down the V 00152 // coordinate. 00153 //////////////////////////////////////////////////////////////////// 00154 INLINE bool RopeNode:: 00155 get_uv_direction() const { 00156 CDReader cdata(_cycler); 00157 return cdata->_u_dominant; 00158 } 00159 00160 //////////////////////////////////////////////////////////////////// 00161 // Function: set_uv_scale 00162 // Access: Published 00163 // Description: Specifies an additional scaling factor to apply to 00164 // generated UV's along the rope. This scale factor is 00165 // applied in whichever direction is along the rope, as 00166 // specified by set_uv_direction(). 00167 //////////////////////////////////////////////////////////////////// 00168 INLINE void RopeNode:: 00169 set_uv_scale(PN_stdfloat uv_scale) { 00170 CDWriter cdata(_cycler); 00171 cdata->_uv_scale = uv_scale; 00172 } 00173 00174 //////////////////////////////////////////////////////////////////// 00175 // Function: get_uv_scale 00176 // Access: Published 00177 // Description: Returns the scaling factor to apply to generated UV's 00178 // for the rope. 00179 //////////////////////////////////////////////////////////////////// 00180 INLINE PN_stdfloat RopeNode:: 00181 get_uv_scale() const { 00182 CDReader cdata(_cycler); 00183 return cdata->_uv_scale; 00184 } 00185 00186 //////////////////////////////////////////////////////////////////// 00187 // Function: set_normal_mode 00188 // Access: Published 00189 // Description: Specifies the kind of normals to generate for the 00190 // rope. This is only applicable when the RenderMode is 00191 // set to RM_tube; in the other render modes, normals 00192 // are never generated. 00193 //////////////////////////////////////////////////////////////////// 00194 INLINE void RopeNode:: 00195 set_normal_mode(RopeNode::NormalMode normal_mode) { 00196 CDWriter cdata(_cycler); 00197 cdata->_normal_mode = normal_mode; 00198 } 00199 00200 //////////////////////////////////////////////////////////////////// 00201 // Function: get_normal_mode 00202 // Access: Published 00203 // Description: Returns the kind of normals to generate for the rope. 00204 // This is only applicable when the RenderMode is set to 00205 // RM_tube. 00206 //////////////////////////////////////////////////////////////////// 00207 INLINE RopeNode::NormalMode RopeNode:: 00208 get_normal_mode() const { 00209 CDReader cdata(_cycler); 00210 return cdata->_normal_mode; 00211 } 00212 00213 //////////////////////////////////////////////////////////////////// 00214 // Function: set_tube_up 00215 // Access: Published 00216 // Description: Specifies a normal vector, generally perpendicular to 00217 // the main axis of the starting point of the curve, 00218 // that controls the "top" of the curve, when RenderMode 00219 // is RM_tube. This is used to orient the vertices that 00220 // make up the tube. If this vector is too nearly 00221 // parallel with the starting direction of the curve, 00222 // there may be a tendency for the whole tube to 00223 // gimble-lock around its primary axis. 00224 //////////////////////////////////////////////////////////////////// 00225 INLINE void RopeNode:: 00226 set_tube_up(const LVector3 &tube_up) { 00227 CDWriter cdata(_cycler); 00228 cdata->_tube_up = tube_up; 00229 } 00230 00231 //////////////////////////////////////////////////////////////////// 00232 // Function: get_tube_up 00233 // Access: Published 00234 // Description: Returns the normal vector used to control the "top" 00235 // of the curve, when RenderMode is RM_tube. See 00236 // set_tube_up(). 00237 //////////////////////////////////////////////////////////////////// 00238 INLINE const LVector3 &RopeNode:: 00239 get_tube_up() const { 00240 CDReader cdata(_cycler); 00241 return cdata->_tube_up; 00242 } 00243 00244 //////////////////////////////////////////////////////////////////// 00245 // Function: set_use_vertex_color 00246 // Access: Published 00247 // Description: Sets the "use vertex color" flag. When this is true, 00248 // the R, G, B, A vertex color is assumed to be stored 00249 // as the dimensions n + 0, n + 1, n + 2, n + 3, 00250 // respectively, of the extended vertex values, where n 00251 // is the value returned by 00252 // get_vertex_color_dimension(). Use 00253 // NurbsCurveEvaluator::set_extended_vertex() to set 00254 // these values. 00255 //////////////////////////////////////////////////////////////////// 00256 INLINE void RopeNode:: 00257 set_use_vertex_color(bool flag) { 00258 CDWriter cdata(_cycler); 00259 cdata->_use_vertex_color = flag; 00260 } 00261 00262 //////////////////////////////////////////////////////////////////// 00263 // Function: get_use_vertex_color 00264 // Access: Published 00265 // Description: Returns the "use vertex color" flag. See 00266 // set_use_vertex_color(). 00267 //////////////////////////////////////////////////////////////////// 00268 INLINE bool RopeNode:: 00269 get_use_vertex_color() const { 00270 CDReader cdata(_cycler); 00271 return cdata->_use_vertex_color; 00272 } 00273 00274 //////////////////////////////////////////////////////////////////// 00275 // Function: get_vertex_color_dimension 00276 // Access: Published, Static 00277 // Description: Returns the numeric extended dimension in which the 00278 // color components should be found. See 00279 // NurbsCurveEvaluator::set_extended_vertex(). 00280 // 00281 // The color components will be expected at (n, n + 1, n 00282 // + 2, n + 3). 00283 //////////////////////////////////////////////////////////////////// 00284 INLINE int RopeNode:: 00285 get_vertex_color_dimension() { 00286 return 0; 00287 } 00288 00289 //////////////////////////////////////////////////////////////////// 00290 // Function: set_num_subdiv 00291 // Access: Published 00292 // Description: Specifies the number of subdivisions per cubic 00293 // segment (that is, per unique knot value) to draw in a 00294 // fixed uniform tesselation of the curve. 00295 //////////////////////////////////////////////////////////////////// 00296 INLINE void RopeNode:: 00297 set_num_subdiv(int num_subdiv) { 00298 nassertv(num_subdiv >= 0); 00299 CDWriter cdata(_cycler); 00300 cdata->_num_subdiv = num_subdiv; 00301 } 00302 00303 //////////////////////////////////////////////////////////////////// 00304 // Function: get_num_subdiv 00305 // Access: Published 00306 // Description: Returns the number of subdivisions per cubic segment 00307 // to draw. See set_num_subdiv(). 00308 //////////////////////////////////////////////////////////////////// 00309 INLINE int RopeNode:: 00310 get_num_subdiv() const { 00311 CDReader cdata(_cycler); 00312 return cdata->_num_subdiv; 00313 } 00314 00315 //////////////////////////////////////////////////////////////////// 00316 // Function: set_num_slices 00317 // Access: Published 00318 // Description: Specifies the number of radial subdivisions to make 00319 // if RenderMode is RM_tube. It is ignored in the other 00320 // render modes. 00321 // 00322 // Increasing this number increases the roundness of a 00323 // cross-section of the tube. The minimum value for a 00324 // dimensional tube is 3; setting it to 2 will get you a 00325 // thin piece of tape (which is similar to RM_billboard, 00326 // except it won't rotate to face the camera). 00327 //////////////////////////////////////////////////////////////////// 00328 INLINE void RopeNode:: 00329 set_num_slices(int num_slices) { 00330 nassertv(num_slices >= 0); 00331 CDWriter cdata(_cycler); 00332 cdata->_num_slices = num_slices; 00333 } 00334 00335 //////////////////////////////////////////////////////////////////// 00336 // Function: get_num_slices 00337 // Access: Published 00338 // Description: Returns the number of radial subdivisions to make if 00339 // RenderMode is RM_tube. It is ignored in the other 00340 // render modes. See set_num_slices(). 00341 //////////////////////////////////////////////////////////////////// 00342 INLINE int RopeNode:: 00343 get_num_slices() const { 00344 CDReader cdata(_cycler); 00345 return cdata->_num_slices; 00346 } 00347 00348 //////////////////////////////////////////////////////////////////// 00349 // Function: set_use_vertex_thickness 00350 // Access: Published 00351 // Description: Sets the "use vertex thickness" flag. When this is true, 00352 // the vertex thickness is assumed to be stored as the 00353 // dimension get_vertex_thickness_dimension(), of the 00354 // extended vertex values. Use 00355 // NurbsCurveEvaluator::set_extended_vertex() to set 00356 // these values. 00357 // 00358 // In this mode, the overall thickness is also applied 00359 // as a scale to the vertex thickness. Not all render 00360 // modes support vertex thickness. 00361 //////////////////////////////////////////////////////////////////// 00362 INLINE void RopeNode:: 00363 set_use_vertex_thickness(bool flag) { 00364 CDWriter cdata(_cycler); 00365 cdata->_use_vertex_thickness = flag; 00366 } 00367 00368 //////////////////////////////////////////////////////////////////// 00369 // Function: get_use_vertex_thickness 00370 // Access: Published 00371 // Description: Returns the "use vertex thickness" flag. See 00372 // set_use_vertex_thickness(). 00373 //////////////////////////////////////////////////////////////////// 00374 INLINE bool RopeNode:: 00375 get_use_vertex_thickness() const { 00376 CDReader cdata(_cycler); 00377 return cdata->_use_vertex_thickness; 00378 } 00379 00380 //////////////////////////////////////////////////////////////////// 00381 // Function: get_vertex_thickness_dimension 00382 // Access: Published, Static 00383 // Description: Returns the numeric extended dimension in which the 00384 // thickness component should be found. See 00385 // NurbsCurveEvaluator::set_extended_vertex(). 00386 //////////////////////////////////////////////////////////////////// 00387 INLINE int RopeNode:: 00388 get_vertex_thickness_dimension() { 00389 return 4; 00390 } 00391 00392 //////////////////////////////////////////////////////////////////// 00393 // Function: set_thickness 00394 // Access: Published 00395 // Description: Specifies the thickness of the rope, in pixels or in 00396 // spatial units, depending on the render mode. See 00397 // set_render_mode(). 00398 // 00399 // The thickness may also be specified on a per-vertex 00400 // basis. See set_use_vertex_thickness(). 00401 //////////////////////////////////////////////////////////////////// 00402 INLINE void RopeNode:: 00403 set_thickness(PN_stdfloat thickness) { 00404 nassertv(thickness >= 0); 00405 CDWriter cdata(_cycler); 00406 cdata->_thickness = thickness; 00407 } 00408 00409 //////////////////////////////////////////////////////////////////// 00410 // Function: get_thickness 00411 // Access: Published 00412 // Description: Returns the thickness of the rope. See 00413 // set_thickness(). 00414 //////////////////////////////////////////////////////////////////// 00415 INLINE PN_stdfloat RopeNode:: 00416 get_thickness() const { 00417 CDReader cdata(_cycler); 00418 return cdata->_thickness; 00419 } 00420 00421 //////////////////////////////////////////////////////////////////// 00422 // Function: set_matrix 00423 // Access: Published 00424 // Description: Specifies an optional matrix which is used to 00425 // transform each control vertex after it has been 00426 // transformed into the RopeNode's coordinate space, but 00427 // before the polygon vertices are generated. 00428 //////////////////////////////////////////////////////////////////// 00429 INLINE void RopeNode:: 00430 set_matrix(const LMatrix4 &matrix) { 00431 CDWriter cdata(_cycler); 00432 cdata->_matrix = matrix; 00433 cdata->_has_matrix = true; 00434 } 00435 00436 //////////////////////////////////////////////////////////////////// 00437 // Function: clear_matrix 00438 // Access: Published 00439 // Description: Resets the node's matrix to identity. See 00440 // set_matrix(). 00441 //////////////////////////////////////////////////////////////////// 00442 INLINE void RopeNode:: 00443 clear_matrix() { 00444 CDWriter cdata(_cycler); 00445 cdata->_matrix = LMatrix4::ident_mat(); 00446 cdata->_has_matrix = false; 00447 } 00448 00449 //////////////////////////////////////////////////////////////////// 00450 // Function: has_matrix 00451 // Access: Published 00452 // Description: Returns true if the node has a matrix set, false 00453 // otherwise. See set_matrix(). 00454 //////////////////////////////////////////////////////////////////// 00455 INLINE bool RopeNode:: 00456 has_matrix() const { 00457 CDReader cdata(_cycler); 00458 return cdata->_has_matrix; 00459 } 00460 00461 //////////////////////////////////////////////////////////////////// 00462 // Function: get_matrix 00463 // Access: Published 00464 // Description: Returns the optional matrix which is used to 00465 // transform each control vertex after it has been 00466 // transformed into the RopeNode's coordinate space, but 00467 // before the polygon vertices are generated. 00468 //////////////////////////////////////////////////////////////////// 00469 INLINE const LMatrix4 &RopeNode:: 00470 get_matrix() const { 00471 CDReader cdata(_cycler); 00472 return cdata->_matrix; 00473 }