Panda3D
 All Classes Functions Variables Enumerations
ropeNode.I
1 // Filename: ropeNode.I
2 // Created by: drose (04Dec02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: RopeNode::CData::Constructor
18 // Access: Public
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE RopeNode::CData::
22 CData() {
23  _curve = new NurbsCurveEvaluator;
24  _render_mode = RopeNode::RM_thread;
25  _uv_mode = RopeNode::UV_none;
26  _u_dominant = true;
27  _uv_scale = 1.0f;
28  _normal_mode = RopeNode::NM_none;
29  _tube_up = LVector3::up();
30  _matrix = LMatrix4::ident_mat();
31  _has_matrix = false;
32  _use_vertex_color = false;
33  _num_subdiv = 10;
34  _num_slices = 5;
35  _use_vertex_thickness = false;
36  _thickness = 1.0f;
37 }
38 
39 ////////////////////////////////////////////////////////////////////
40 // Function: RopeNode::CData::Copy Constructor
41 // Access: Public
42 // Description:
43 ////////////////////////////////////////////////////////////////////
44 INLINE RopeNode::CData::
45 CData(const RopeNode::CData &copy) :
46  _curve(copy._curve),
47  _render_mode(copy._render_mode),
48  _uv_mode(copy._uv_mode),
49  _u_dominant(copy._u_dominant),
50  _uv_scale(copy._uv_scale),
51  _normal_mode(copy._normal_mode),
52  _tube_up(copy._tube_up),
53  _matrix(copy._matrix),
54  _has_matrix(copy._has_matrix),
55  _use_vertex_color(copy._use_vertex_color),
56  _num_subdiv(copy._num_subdiv),
57  _num_slices(copy._num_slices),
58  _use_vertex_thickness(copy._use_vertex_thickness),
59  _thickness(copy._thickness)
60 {
61 }
62 
63 ////////////////////////////////////////////////////////////////////
64 // Function: set_curve
65 // Access: Published
66 // Description: Sets the particular curve represented by the
67 // RopeNode.
68 ////////////////////////////////////////////////////////////////////
69 INLINE void RopeNode::
71  CDWriter cdata(_cycler);
72  cdata->_curve = curve;
73 }
74 
75 ////////////////////////////////////////////////////////////////////
76 // Function: get_curve
77 // Access: Published
78 // Description: Returns the curve represented by the RopeNode.
79 ////////////////////////////////////////////////////////////////////
81 get_curve() const {
82  CDReader cdata(_cycler);
83  return cdata->_curve;
84 }
85 
86 ////////////////////////////////////////////////////////////////////
87 // Function: set_render_mode
88 // Access: Published
89 // Description: Specifies the method used to render the rope. The
90 // simplest is RM_thread, which just draws a one-pixel
91 // line segment.
92 ////////////////////////////////////////////////////////////////////
93 INLINE void RopeNode::
94 set_render_mode(RopeNode::RenderMode render_mode) {
95  CDWriter cdata(_cycler);
96  cdata->_render_mode = render_mode;
97 }
98 
99 ////////////////////////////////////////////////////////////////////
100 // Function: get_render_mode
101 // Access: Published
102 // Description: Returns the method used to render the rope. See
103 // set_render_mode().
104 ////////////////////////////////////////////////////////////////////
105 INLINE RopeNode::RenderMode RopeNode::
107  CDReader cdata(_cycler);
108  return cdata->_render_mode;
109 }
110 
111 ////////////////////////////////////////////////////////////////////
112 // Function: set_uv_mode
113 // Access: Published
114 // Description: Specifies the algorithm to use to generate UV's for
115 // the rope.
116 ////////////////////////////////////////////////////////////////////
117 INLINE void RopeNode::
118 set_uv_mode(RopeNode::UVMode uv_mode) {
119  CDWriter cdata(_cycler);
120  cdata->_uv_mode = uv_mode;
121 }
122 
123 ////////////////////////////////////////////////////////////////////
124 // Function: get_uv_mode
125 // Access: Published
126 // Description: Returns the algorithm to use to generate UV's for the
127 // rope.
128 ////////////////////////////////////////////////////////////////////
129 INLINE RopeNode::UVMode RopeNode::
130 get_uv_mode() const {
131  CDReader cdata(_cycler);
132  return cdata->_uv_mode;
133 }
134 
135 ////////////////////////////////////////////////////////////////////
136 // Function: set_uv_direction
137 // Access: Published
138 // Description: Specify true to vary the U coordinate down the length
139 // of the rope, or false to vary the V coordinate.
140 ////////////////////////////////////////////////////////////////////
141 INLINE void RopeNode::
142 set_uv_direction(bool u_dominant) {
143  CDWriter cdata(_cycler);
144  cdata->_u_dominant = u_dominant;
145 }
146 
147 ////////////////////////////////////////////////////////////////////
148 // Function: get_uv_direction
149 // Access: Published
150 // Description: Returns true if the rope runs down the U coordinate
151 // of the texture, or false if it runs down the V
152 // coordinate.
153 ////////////////////////////////////////////////////////////////////
154 INLINE bool RopeNode::
156  CDReader cdata(_cycler);
157  return cdata->_u_dominant;
158 }
159 
160 ////////////////////////////////////////////////////////////////////
161 // Function: set_uv_scale
162 // Access: Published
163 // Description: Specifies an additional scaling factor to apply to
164 // generated UV's along the rope. This scale factor is
165 // applied in whichever direction is along the rope, as
166 // specified by set_uv_direction().
167 ////////////////////////////////////////////////////////////////////
168 INLINE void RopeNode::
169 set_uv_scale(PN_stdfloat uv_scale) {
170  CDWriter cdata(_cycler);
171  cdata->_uv_scale = uv_scale;
172 }
173 
174 ////////////////////////////////////////////////////////////////////
175 // Function: get_uv_scale
176 // Access: Published
177 // Description: Returns the scaling factor to apply to generated UV's
178 // for the rope.
179 ////////////////////////////////////////////////////////////////////
180 INLINE PN_stdfloat RopeNode::
181 get_uv_scale() const {
182  CDReader cdata(_cycler);
183  return cdata->_uv_scale;
184 }
185 
186 ////////////////////////////////////////////////////////////////////
187 // Function: set_normal_mode
188 // Access: Published
189 // Description: Specifies the kind of normals to generate for the
190 // rope. This is only applicable when the RenderMode is
191 // set to RM_tube; in the other render modes, normals
192 // are never generated.
193 ////////////////////////////////////////////////////////////////////
194 INLINE void RopeNode::
195 set_normal_mode(RopeNode::NormalMode normal_mode) {
196  CDWriter cdata(_cycler);
197  cdata->_normal_mode = normal_mode;
198 }
199 
200 ////////////////////////////////////////////////////////////////////
201 // Function: get_normal_mode
202 // Access: Published
203 // Description: Returns the kind of normals to generate for the rope.
204 // This is only applicable when the RenderMode is set to
205 // RM_tube.
206 ////////////////////////////////////////////////////////////////////
207 INLINE RopeNode::NormalMode RopeNode::
209  CDReader cdata(_cycler);
210  return cdata->_normal_mode;
211 }
212 
213 ////////////////////////////////////////////////////////////////////
214 // Function: set_tube_up
215 // Access: Published
216 // Description: Specifies a normal vector, generally perpendicular to
217 // the main axis of the starting point of the curve,
218 // that controls the "top" of the curve, when RenderMode
219 // is RM_tube. This is used to orient the vertices that
220 // make up the tube. If this vector is too nearly
221 // parallel with the starting direction of the curve,
222 // there may be a tendency for the whole tube to
223 // gimble-lock around its primary axis.
224 ////////////////////////////////////////////////////////////////////
225 INLINE void RopeNode::
226 set_tube_up(const LVector3 &tube_up) {
227  CDWriter cdata(_cycler);
228  cdata->_tube_up = tube_up;
229 }
230 
231 ////////////////////////////////////////////////////////////////////
232 // Function: get_tube_up
233 // Access: Published
234 // Description: Returns the normal vector used to control the "top"
235 // of the curve, when RenderMode is RM_tube. See
236 // set_tube_up().
237 ////////////////////////////////////////////////////////////////////
238 INLINE const LVector3 &RopeNode::
239 get_tube_up() const {
240  CDReader cdata(_cycler);
241  return cdata->_tube_up;
242 }
243 
244 ////////////////////////////////////////////////////////////////////
245 // Function: set_use_vertex_color
246 // Access: Published
247 // Description: Sets the "use vertex color" flag. When this is true,
248 // the R, G, B, A vertex color is assumed to be stored
249 // as the dimensions n + 0, n + 1, n + 2, n + 3,
250 // respectively, of the extended vertex values, where n
251 // is the value returned by
252 // get_vertex_color_dimension(). Use
253 // NurbsCurveEvaluator::set_extended_vertex() to set
254 // these values.
255 ////////////////////////////////////////////////////////////////////
256 INLINE void RopeNode::
258  CDWriter cdata(_cycler);
259  cdata->_use_vertex_color = flag;
260 }
261 
262 ////////////////////////////////////////////////////////////////////
263 // Function: get_use_vertex_color
264 // Access: Published
265 // Description: Returns the "use vertex color" flag. See
266 // set_use_vertex_color().
267 ////////////////////////////////////////////////////////////////////
268 INLINE bool RopeNode::
270  CDReader cdata(_cycler);
271  return cdata->_use_vertex_color;
272 }
273 
274 ////////////////////////////////////////////////////////////////////
275 // Function: get_vertex_color_dimension
276 // Access: Published, Static
277 // Description: Returns the numeric extended dimension in which the
278 // color components should be found. See
279 // NurbsCurveEvaluator::set_extended_vertex().
280 //
281 // The color components will be expected at (n, n + 1, n
282 // + 2, n + 3).
283 ////////////////////////////////////////////////////////////////////
284 INLINE int RopeNode::
286  return 0;
287 }
288 
289 ////////////////////////////////////////////////////////////////////
290 // Function: set_num_subdiv
291 // Access: Published
292 // Description: Specifies the number of subdivisions per cubic
293 // segment (that is, per unique knot value) to draw in a
294 // fixed uniform tesselation of the curve.
295 ////////////////////////////////////////////////////////////////////
296 INLINE void RopeNode::
297 set_num_subdiv(int num_subdiv) {
298  nassertv(num_subdiv >= 0);
299  CDWriter cdata(_cycler);
300  cdata->_num_subdiv = num_subdiv;
301 }
302 
303 ////////////////////////////////////////////////////////////////////
304 // Function: get_num_subdiv
305 // Access: Published
306 // Description: Returns the number of subdivisions per cubic segment
307 // to draw. See set_num_subdiv().
308 ////////////////////////////////////////////////////////////////////
309 INLINE int RopeNode::
310 get_num_subdiv() const {
311  CDReader cdata(_cycler);
312  return cdata->_num_subdiv;
313 }
314 
315 ////////////////////////////////////////////////////////////////////
316 // Function: set_num_slices
317 // Access: Published
318 // Description: Specifies the number of radial subdivisions to make
319 // if RenderMode is RM_tube. It is ignored in the other
320 // render modes.
321 //
322 // Increasing this number increases the roundness of a
323 // cross-section of the tube. The minimum value for a
324 // dimensional tube is 3; setting it to 2 will get you a
325 // thin piece of tape (which is similar to RM_billboard,
326 // except it won't rotate to face the camera).
327 ////////////////////////////////////////////////////////////////////
328 INLINE void RopeNode::
329 set_num_slices(int num_slices) {
330  nassertv(num_slices >= 0);
331  CDWriter cdata(_cycler);
332  cdata->_num_slices = num_slices;
333 }
334 
335 ////////////////////////////////////////////////////////////////////
336 // Function: get_num_slices
337 // Access: Published
338 // Description: Returns the number of radial subdivisions to make if
339 // RenderMode is RM_tube. It is ignored in the other
340 // render modes. See set_num_slices().
341 ////////////////////////////////////////////////////////////////////
342 INLINE int RopeNode::
343 get_num_slices() const {
344  CDReader cdata(_cycler);
345  return cdata->_num_slices;
346 }
347 
348 ////////////////////////////////////////////////////////////////////
349 // Function: set_use_vertex_thickness
350 // Access: Published
351 // Description: Sets the "use vertex thickness" flag. When this is true,
352 // the vertex thickness is assumed to be stored as the
353 // dimension get_vertex_thickness_dimension(), of the
354 // extended vertex values. Use
355 // NurbsCurveEvaluator::set_extended_vertex() to set
356 // these values.
357 //
358 // In this mode, the overall thickness is also applied
359 // as a scale to the vertex thickness. Not all render
360 // modes support vertex thickness.
361 ////////////////////////////////////////////////////////////////////
362 INLINE void RopeNode::
364  CDWriter cdata(_cycler);
365  cdata->_use_vertex_thickness = flag;
366 }
367 
368 ////////////////////////////////////////////////////////////////////
369 // Function: get_use_vertex_thickness
370 // Access: Published
371 // Description: Returns the "use vertex thickness" flag. See
372 // set_use_vertex_thickness().
373 ////////////////////////////////////////////////////////////////////
374 INLINE bool RopeNode::
376  CDReader cdata(_cycler);
377  return cdata->_use_vertex_thickness;
378 }
379 
380 ////////////////////////////////////////////////////////////////////
381 // Function: get_vertex_thickness_dimension
382 // Access: Published, Static
383 // Description: Returns the numeric extended dimension in which the
384 // thickness component should be found. See
385 // NurbsCurveEvaluator::set_extended_vertex().
386 ////////////////////////////////////////////////////////////////////
387 INLINE int RopeNode::
389  return 4;
390 }
391 
392 ////////////////////////////////////////////////////////////////////
393 // Function: set_thickness
394 // Access: Published
395 // Description: Specifies the thickness of the rope, in pixels or in
396 // spatial units, depending on the render mode. See
397 // set_render_mode().
398 //
399 // The thickness may also be specified on a per-vertex
400 // basis. See set_use_vertex_thickness().
401 ////////////////////////////////////////////////////////////////////
402 INLINE void RopeNode::
403 set_thickness(PN_stdfloat thickness) {
404  nassertv(thickness >= 0);
405  CDWriter cdata(_cycler);
406  cdata->_thickness = thickness;
407 }
408 
409 ////////////////////////////////////////////////////////////////////
410 // Function: get_thickness
411 // Access: Published
412 // Description: Returns the thickness of the rope. See
413 // set_thickness().
414 ////////////////////////////////////////////////////////////////////
415 INLINE PN_stdfloat RopeNode::
416 get_thickness() const {
417  CDReader cdata(_cycler);
418  return cdata->_thickness;
419 }
420 
421 ////////////////////////////////////////////////////////////////////
422 // Function: set_matrix
423 // Access: Published
424 // Description: Specifies an optional matrix which is used to
425 // transform each control vertex after it has been
426 // transformed into the RopeNode's coordinate space, but
427 // before the polygon vertices are generated.
428 ////////////////////////////////////////////////////////////////////
429 INLINE void RopeNode::
430 set_matrix(const LMatrix4 &matrix) {
431  CDWriter cdata(_cycler);
432  cdata->_matrix = matrix;
433  cdata->_has_matrix = true;
434 }
435 
436 ////////////////////////////////////////////////////////////////////
437 // Function: clear_matrix
438 // Access: Published
439 // Description: Resets the node's matrix to identity. See
440 // set_matrix().
441 ////////////////////////////////////////////////////////////////////
442 INLINE void RopeNode::
444  CDWriter cdata(_cycler);
445  cdata->_matrix = LMatrix4::ident_mat();
446  cdata->_has_matrix = false;
447 }
448 
449 ////////////////////////////////////////////////////////////////////
450 // Function: has_matrix
451 // Access: Published
452 // Description: Returns true if the node has a matrix set, false
453 // otherwise. See set_matrix().
454 ////////////////////////////////////////////////////////////////////
455 INLINE bool RopeNode::
456 has_matrix() const {
457  CDReader cdata(_cycler);
458  return cdata->_has_matrix;
459 }
460 
461 ////////////////////////////////////////////////////////////////////
462 // Function: get_matrix
463 // Access: Published
464 // Description: Returns the optional matrix which is used to
465 // transform each control vertex after it has been
466 // transformed into the RopeNode's coordinate space, but
467 // before the polygon vertices are generated.
468 ////////////////////////////////////////////////////////////////////
469 INLINE const LMatrix4 &RopeNode::
470 get_matrix() const {
471  CDReader cdata(_cycler);
472  return cdata->_matrix;
473 }
void set_normal_mode(NormalMode normal_mode)
Specifies the kind of normals to generate for the rope.
Definition: ropeNode.I:195
static const LMatrix4f & ident_mat()
Returns an identity matrix.
Definition: lmatrix.h:903
PN_stdfloat get_uv_scale() const
Returns the scaling factor to apply to generated UV's for the rope.
Definition: ropeNode.I:181
NormalMode get_normal_mode() const
Returns the kind of normals to generate for the rope.
Definition: ropeNode.I:208
void set_tube_up(const LVector3 &tube_up)
Specifies a normal vector, generally perpendicular to the main axis of the starting point of the curv...
Definition: ropeNode.I:226
RenderMode get_render_mode() const
Returns the method used to render the rope.
Definition: ropeNode.I:106
const LVector3 & get_tube_up() const
Returns the normal vector used to control the "top" of the curve, when RenderMode is RM_tube...
Definition: ropeNode.I:239
This class is an abstraction for evaluating NURBS curves.
bool get_uv_direction() const
Returns true if the rope runs down the U coordinate of the texture, or false if it runs down the V co...
Definition: ropeNode.I:155
int get_num_slices() const
Returns the number of radial subdivisions to make if RenderMode is RM_tube.
Definition: ropeNode.I:343
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
void clear_matrix()
Resets the node's matrix to identity.
Definition: ropeNode.I:443
void set_curve(NurbsCurveEvaluator *curve)
Sets the particular curve represented by the RopeNode.
Definition: ropeNode.I:70
void set_uv_direction(bool u_dominant)
Specify true to vary the U coordinate down the length of the rope, or false to vary the V coordinate...
Definition: ropeNode.I:142
const LMatrix4 & get_matrix() const
Returns the optional matrix which is used to transform each control vertex after it has been transfor...
Definition: ropeNode.I:470
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
void set_use_vertex_thickness(bool flag)
Sets the "use vertex thickness" flag.
Definition: ropeNode.I:363
void set_num_slices(int num_slices)
Specifies the number of radial subdivisions to make if RenderMode is RM_tube.
Definition: ropeNode.I:329
void set_num_subdiv(int num_subdiv)
Specifies the number of subdivisions per cubic segment (that is, per unique knot value) to draw in a ...
Definition: ropeNode.I:297
void set_render_mode(RenderMode render_mode)
Specifies the method used to render the rope.
Definition: ropeNode.I:94
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
NurbsCurveEvaluator * get_curve() const
Returns the curve represented by the RopeNode.
Definition: ropeNode.I:81
UVMode get_uv_mode() const
Returns the algorithm to use to generate UV's for the rope.
Definition: ropeNode.I:130
bool get_use_vertex_color() const
Returns the "use vertex color" flag.
Definition: ropeNode.I:269
void set_thickness(PN_stdfloat thickness)
Specifies the thickness of the rope, in pixels or in spatial units, depending on the render mode...
Definition: ropeNode.I:403
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
void set_uv_mode(UVMode uv_mode)
Specifies the algorithm to use to generate UV's for the rope.
Definition: ropeNode.I:118
void set_use_vertex_color(bool flag)
Sets the "use vertex color" flag.
Definition: ropeNode.I:257
void set_matrix(const LMatrix4 &matrix)
Specifies an optional matrix which is used to transform each control vertex after it has been transfo...
Definition: ropeNode.I:430
bool has_matrix() const
Returns true if the node has a matrix set, false otherwise.
Definition: ropeNode.I:456
void set_uv_scale(PN_stdfloat scale)
Specifies an additional scaling factor to apply to generated UV's along the rope. ...
Definition: ropeNode.I:169
static int get_vertex_thickness_dimension()
Returns the numeric extended dimension in which the thickness component should be found...
Definition: ropeNode.I:388
bool get_use_vertex_thickness() const
Returns the "use vertex thickness" flag.
Definition: ropeNode.I:375
int get_num_subdiv() const
Returns the number of subdivisions per cubic segment to draw.
Definition: ropeNode.I:310
static LVector3f up(CoordinateSystem cs=CS_default)
Returns the up vector for the given coordinate system.
Definition: lvector3.h:527
static int get_vertex_color_dimension()
Returns the numeric extended dimension in which the color components should be found.
Definition: ropeNode.I:285
PN_stdfloat get_thickness() const
Returns the thickness of the rope.
Definition: ropeNode.I:416