Panda3D
 All Classes Functions Variables Enumerations
eggNode.I
1 // Filename: eggNode.I
2 // Created by: drose (10Feb99)
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: EggNode::Constructor
18 // Access: Public
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE EggNode::
22 EggNode(const string &name) : EggNamedObject(name) {
23  _parent = NULL;
24  _depth = 0;
25  _under_flags = 0;
26 }
27 
28 ////////////////////////////////////////////////////////////////////
29 // Function: EggNode::Copy constructor
30 // Access: Public
31 // Description:
32 ////////////////////////////////////////////////////////////////////
33 INLINE EggNode::
34 EggNode(const EggNode &copy) : EggNamedObject(copy) {
35  _parent = NULL;
36  _depth = 0;
37  _under_flags = 0;
38 }
39 
40 
41 ////////////////////////////////////////////////////////////////////
42 // Function: EggNode::Copy assignment operator
43 // Access: Public
44 // Description:
45 ////////////////////////////////////////////////////////////////////
46 INLINE EggNode &EggNode::
47 operator = (const EggNode &copy) {
48  EggNamedObject::operator = (copy);
49  update_under(0);
50  return *this;
51 }
52 
53 
54 ////////////////////////////////////////////////////////////////////
55 // Function: EggNode::get_parent
56 // Access: Public
57 // Description:
58 ////////////////////////////////////////////////////////////////////
59 INLINE EggGroupNode *EggNode::
60 get_parent() const {
61  return _parent;
62 }
63 
64 ////////////////////////////////////////////////////////////////////
65 // Function: EggNode::get_depth
66 // Access: Public
67 // Description: Returns the number of nodes above this node in the
68 // egg hierarchy.
69 ////////////////////////////////////////////////////////////////////
70 INLINE int EggNode::
71 get_depth() const {
72  return _depth;
73 }
74 
75 
76 ////////////////////////////////////////////////////////////////////
77 // Function: EggNode::is_under_instance
78 // Access: Public
79 // Description: Returns true if there is an <Instance> node somewhere
80 // in the egg tree at or above this node, false
81 // otherwise.
82 ////////////////////////////////////////////////////////////////////
83 INLINE bool EggNode::
85  return (_under_flags & UF_under_instance) != 0;
86 }
87 
88 ////////////////////////////////////////////////////////////////////
89 // Function: EggNode::is_under_transform
90 // Access: Public
91 // Description: Returns true if there is a <Transform> entry somewhere
92 // in the egg tree at or above this node, false
93 // otherwise.
94 ////////////////////////////////////////////////////////////////////
95 INLINE bool EggNode::
97  return (_under_flags & UF_under_transform) != 0;
98 }
99 
100 ////////////////////////////////////////////////////////////////////
101 // Function: EggNode::is_local_coord
102 // Access: Public
103 // Description: Returns true if this node's vertices are not in the
104 // global coordinate space. This will be the case if
105 // there was an <Instance> node under a transform at or
106 // above this node.
107 ////////////////////////////////////////////////////////////////////
108 INLINE bool EggNode::
109 is_local_coord() const {
110  return (_under_flags & UF_local_coord) != 0;
111 }
112 
113 
114 ////////////////////////////////////////////////////////////////////
115 // Function: EggNode::get_vertex_frame
116 // Access: Public
117 // Description: Returns the coordinate frame of the vertices
118 // referenced by primitives at or under this node. This
119 // is not the same as get_node_frame().
120 //
121 // Generally, vertices in an egg file are stored in the
122 // global coordinate space, regardless of the transforms
123 // defined at each node. Thus, get_vertex_frame() will
124 // usually return the identity transform (global
125 // coordinate space). However, primitives under an
126 // <Instance> entry reference their vertices in the
127 // coordinate system under effect at the time of the
128 // <Instance>. Thus, nodes under an <Instance> entry
129 // may return this non-identity matrix.
130 //
131 // Specifically, this may return a non-identity matrix
132 // only if is_local_coord() is true.
133 ////////////////////////////////////////////////////////////////////
134 INLINE const LMatrix4d &EggNode::
136  if (_vertex_frame == (LMatrix4d *)NULL) {
137  return LMatrix4d::ident_mat();
138  } else {
139  return *_vertex_frame;
140  }
141 }
142 
143 
144 ////////////////////////////////////////////////////////////////////
145 // Function: EggNode::get_node_frame
146 // Access: Public
147 // Description: Returns the coordinate frame of the node itself.
148 // This is simply the net product of all transformations
149 // up to the root.
150 ////////////////////////////////////////////////////////////////////
151 INLINE const LMatrix4d &EggNode::
152 get_node_frame() const {
153  if (_node_frame == (LMatrix4d *)NULL) {
154  return LMatrix4d::ident_mat();
155  } else {
156  return *_node_frame;
157  }
158 }
159 
160 ////////////////////////////////////////////////////////////////////
161 // Function: EggNode::get_vertex_frame_inv
162 // Access: Public
163 // Description: Returns the inverse of the matrix returned by
164 // get_vertex_frame(). See get_vertex_frame().
165 ////////////////////////////////////////////////////////////////////
166 INLINE const LMatrix4d &EggNode::
168  if (_vertex_frame_inv == (LMatrix4d *)NULL) {
169  return LMatrix4d::ident_mat();
170  } else {
171  return *_vertex_frame_inv;
172  }
173 }
174 
175 
176 ////////////////////////////////////////////////////////////////////
177 // Function: EggNode::get_node_frame_inv
178 // Access: Public
179 // Description: Returns the inverse of the matrix returned by
180 // get_node_frame(). See get_node_frame().
181 ////////////////////////////////////////////////////////////////////
182 INLINE const LMatrix4d &EggNode::
184  if (_node_frame_inv == (LMatrix4d *)NULL) {
185  return LMatrix4d::ident_mat();
186  } else {
187  return *_node_frame_inv;
188  }
189 }
190 
191 ////////////////////////////////////////////////////////////////////
192 // Function: EggNode::get_vertex_to_node
193 // Access: Public
194 // Description: Returns the transformation matrix suitable for
195 // converting the vertices as read from the egg file
196 // into the coordinate space of the node. This is the
197 // same thing as:
198 //
199 // get_vertex_frame() * get_node_frame_inv()
200 //
201 ////////////////////////////////////////////////////////////////////
202 INLINE const LMatrix4d &EggNode::
204  if (_vertex_to_node == (LMatrix4d *)NULL) {
205  return LMatrix4d::ident_mat();
206  } else {
207  return *_vertex_to_node;
208  }
209 }
210 
211 ////////////////////////////////////////////////////////////////////
212 // Function: EggNode::get_node_to_vertex
213 // Access: Public
214 // Description: Returns the transformation matrix suitable for
215 // converting vertices in the coordinate space of the
216 // node to the appropriate coordinate space for storing
217 // in the egg file. This is the same thing as:
218 //
219 // get_node_frame() * get_vertex_frame_inv()
220 //
221 ////////////////////////////////////////////////////////////////////
222 INLINE const LMatrix4d &EggNode::
224  if (_node_to_vertex == (LMatrix4d *)NULL) {
225  return LMatrix4d::ident_mat();
226  } else {
227  return *_node_to_vertex;
228  }
229 }
230 
231 ////////////////////////////////////////////////////////////////////
232 // Function: EggNode::get_vertex_frame_ptr
233 // Access: Public
234 // Description: Returns either a NULL pointer or a unique pointer
235 // shared by nodes with the same get_vertex_frame()
236 // matrix.
237 ////////////////////////////////////////////////////////////////////
238 INLINE const LMatrix4d *EggNode::
240  return _vertex_frame;
241 }
242 
243 
244 ////////////////////////////////////////////////////////////////////
245 // Function: EggNode::get_node_frame_ptr
246 // Access: Public
247 // Description: Returns either a NULL pointer or a unique pointer
248 // shared by nodes with the same get_node_frame()
249 // matrix.
250 ////////////////////////////////////////////////////////////////////
251 INLINE const LMatrix4d *EggNode::
253  return _node_frame;
254 }
255 
256 ////////////////////////////////////////////////////////////////////
257 // Function: EggNode::get_vertex_frame_inv_ptr
258 // Access: Public
259 // Description: Returns either a NULL pointer or a unique pointer
260 // shared by nodes with the same get_vertex_frame_inv()
261 // matrix.
262 ////////////////////////////////////////////////////////////////////
263 INLINE const LMatrix4d *EggNode::
265  return _vertex_frame_inv;
266 }
267 
268 
269 ////////////////////////////////////////////////////////////////////
270 // Function: EggNode::get_node_frame_inv_ptr
271 // Access: Public
272 // Description: Returns either a NULL pointer or a unique pointer
273 // shared by nodes with the same get_node_frame_inv()
274 // matrix.
275 ////////////////////////////////////////////////////////////////////
276 INLINE const LMatrix4d *EggNode::
278  return _node_frame_inv;
279 }
280 
281 ////////////////////////////////////////////////////////////////////
282 // Function: EggNode::get_vertex_to_node_ptr
283 // Access: Public
284 // Description: Returns either a NULL pointer or a unique pointer
285 // shared by nodes with the same get_vertex_to_node()
286 // matrix.
287 ////////////////////////////////////////////////////////////////////
288 INLINE const LMatrix4d *EggNode::
290  return _vertex_to_node;
291 }
292 
293 ////////////////////////////////////////////////////////////////////
294 // Function: EggNode::get_node_to_vertex_ptr
295 // Access: Public
296 // Description: Returns either a NULL pointer or a unique pointer
297 // shared by nodes with the same get_node_to_vertex()
298 // matrix.
299 ////////////////////////////////////////////////////////////////////
300 INLINE const LMatrix4d *EggNode::
302  return _node_to_vertex;
303 }
304 
305 
306 ////////////////////////////////////////////////////////////////////
307 // Function: EggNode::transform
308 // Access: Public
309 // Description: Applies the indicated transformation to the node and
310 // all of its descendants.
311 ////////////////////////////////////////////////////////////////////
312 INLINE void EggNode::
313 transform(const LMatrix4d &mat) {
314  LMatrix4d inv = invert(mat);
315 
316  r_transform(mat, inv, CS_default);
317  r_transform_vertices(mat);
318 
319  // Now we have to recompute the under_flags to ensure that all the
320  // cached relative matrices are correct.
321  update_under(0);
322 }
323 
324 ////////////////////////////////////////////////////////////////////
325 // Function: EggNode::transform_vertices_only
326 // Access: Public
327 // Description: Applies the indicated transformation only to vertices
328 // that appear in global space within vertex pools at
329 // this node and below. Joints and other transforms are
330 // not affected, nor are local vertices.
331 ////////////////////////////////////////////////////////////////////
332 INLINE void EggNode::
334  r_transform_vertices(mat);
335 }
336 
337 ////////////////////////////////////////////////////////////////////
338 // Function: EggNode::flatten_transforms
339 // Access: Public
340 // Description: Removes any transform and instance records from this
341 // node in the scene graph and below. If an instance
342 // node is encountered, removes the instance and applies
343 // the transform to its vertices, duplicating vertices
344 // if necessary.
345 //
346 // Since this function may result in duplicated
347 // vertices, it may be a good idea to call
348 // remove_unused_vertices() after calling this.
349 ////////////////////////////////////////////////////////////////////
350 INLINE void EggNode::
352  r_flatten_transforms();
353  update_under(0);
354 }
void transform(const LMatrix4d &mat)
Applies the indicated transformation to the node and all of its descendants.
Definition: eggNode.I:313
const LMatrix4d * get_node_to_vertex_ptr() const
Returns either a NULL pointer or a unique pointer shared by nodes with the same get_node_to_vertex() ...
Definition: eggNode.I:301
int get_depth() const
Returns the number of nodes above this node in the egg hierarchy.
Definition: eggNode.I:71
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:4716
bool is_local_coord() const
Returns true if this node&#39;s vertices are not in the global coordinate space.
Definition: eggNode.I:109
A base class for nodes in the hierarchy that are not leaf nodes.
Definition: eggGroupNode.h:51
bool is_under_instance() const
Returns true if there is an &lt;Instance&gt; node somewhere in the egg tree at or above this node...
Definition: eggNode.I:84
const LMatrix4d & get_vertex_frame_inv() const
Returns the inverse of the matrix returned by get_vertex_frame().
Definition: eggNode.I:167
const LMatrix4d & get_vertex_to_node() const
Returns the transformation matrix suitable for converting the vertices as read from the egg file into...
Definition: eggNode.I:203
const LMatrix4d & get_node_to_vertex() const
Returns the transformation matrix suitable for converting vertices in the coordinate space of the nod...
Definition: eggNode.I:223
const LMatrix4d * get_vertex_frame_ptr() const
Returns either a NULL pointer or a unique pointer shared by nodes with the same get_vertex_frame() ma...
Definition: eggNode.I:239
bool is_under_transform() const
Returns true if there is a &lt;Transform&gt; entry somewhere in the egg tree at or above this node...
Definition: eggNode.I:96
const LMatrix4d & get_node_frame() const
Returns the coordinate frame of the node itself.
Definition: eggNode.I:152
static const LMatrix4d & ident_mat()
Returns an identity matrix.
Definition: lmatrix.h:5168
const LMatrix4d & get_vertex_frame() const
Returns the coordinate frame of the vertices referenced by primitives at or under this node...
Definition: eggNode.I:135
void transform_vertices_only(const LMatrix4d &mat)
Applies the indicated transformation only to vertices that appear in global space within vertex pools...
Definition: eggNode.I:333
const LMatrix4d * get_node_frame_ptr() const
Returns either a NULL pointer or a unique pointer shared by nodes with the same get_node_frame() matr...
Definition: eggNode.I:252
const LMatrix4d * get_vertex_to_node_ptr() const
Returns either a NULL pointer or a unique pointer shared by nodes with the same get_vertex_to_node() ...
Definition: eggNode.I:289
void flatten_transforms()
Removes any transform and instance records from this node in the scene graph and below.
Definition: eggNode.I:351
This is a fairly low-level base class–any egg object that has a name.
const LMatrix4d * get_node_frame_inv_ptr() const
Returns either a NULL pointer or a unique pointer shared by nodes with the same get_node_frame_inv() ...
Definition: eggNode.I:277
A base class for things that may be directly added into the egg hierarchy.
Definition: eggNode.h:38
const LMatrix4d * get_vertex_frame_inv_ptr() const
Returns either a NULL pointer or a unique pointer shared by nodes with the same get_vertex_frame_inv(...
Definition: eggNode.I:264
const LMatrix4d & get_node_frame_inv() const
Returns the inverse of the matrix returned by get_node_frame().
Definition: eggNode.I:183