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