Panda3D
 All Classes Functions Variables Enumerations
speedTreeNode.I
1 // Filename: speedTreeNode.I
2 // Created by: drose (30Sep10)
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: SpeedTreeNode::is_valid
18 // Access: Published
19 // Description: Returns true if the node is valid and ready to
20 // render, false otherwise. Note that this might not
21 // become false until after the first time the node is
22 // rendered.
23 ////////////////////////////////////////////////////////////////////
24 INLINE bool SpeedTreeNode::
25 is_valid() const {
26  return _is_valid;
27 }
28 
29 ////////////////////////////////////////////////////////////////////
30 // Function: SpeedTreeNode::get_num_trees
31 // Access: Published
32 // Description: Returns the number of unique tree objects that have
33 // been added to the node. This count does not include
34 // multiple instances of the same tree that appear in
35 // different transforms.
36 ////////////////////////////////////////////////////////////////////
37 INLINE int SpeedTreeNode::
38 get_num_trees() const {
39  return (int)_trees.size();
40 }
41 
42 ////////////////////////////////////////////////////////////////////
43 // Function: SpeedTreeNode::get_tree
44 // Access: Published
45 // Description: Returns the STTree pointer for the nth tree.
46 // See get_num_trees().
47 ////////////////////////////////////////////////////////////////////
48 INLINE const STTree *SpeedTreeNode::
49 get_tree(int n) const {
50  nassertr(n >= 0 && n < (int)_trees.size(), NULL);
51  InstanceList *instance_list = _trees[n];
52  return instance_list->get_tree();
53 }
54 
55 ////////////////////////////////////////////////////////////////////
56 // Function: SpeedTreeNode::get_instance_list
57 // Access: Published
58 // Description: Returns a list of transforms that corresponds to the
59 // instances at which the nth tree appears.
60 ////////////////////////////////////////////////////////////////////
62 get_instance_list(int n) const {
63  nassertr(n >= 0 && n < (int)_trees.size(), *(InstanceList *)NULL);
64  InstanceList *instance_list = _trees[n];
65  return *instance_list;
66 }
67 
68 ////////////////////////////////////////////////////////////////////
69 // Function: SpeedTreeNode::modify_tree
70 // Access: Published
71 // Description: Returns a modifiable STTree pointer for the nth tree
72 // instance.
73 ////////////////////////////////////////////////////////////////////
74 INLINE STTree *SpeedTreeNode::
75 modify_tree(int n) {
76  nassertr(n >= 0 && n < (int)_trees.size(), NULL);
77  InstanceList *instance_list = _trees[n];
78  _needs_repopulate = true;
79  return (STTree *)instance_list->get_tree();
80 }
81 
82 ////////////////////////////////////////////////////////////////////
83 // Function: SpeedTreeNode::clear_terrain
84 // Access: Published
85 // Description: Removes the terrain associated with the node.
86 ////////////////////////////////////////////////////////////////////
87 INLINE void SpeedTreeNode::
89  set_terrain(NULL);
90 }
91 
92 ////////////////////////////////////////////////////////////////////
93 // Function: SpeedTreeNode::has_terrain
94 // Access: Published
95 // Description: Returns true if a valid terrain has been associated
96 // with the node, false otherwise.
97 ////////////////////////////////////////////////////////////////////
98 INLINE bool SpeedTreeNode::
99 has_terrain() const {
100  return _terrain != (STTerrain *)NULL;
101 }
102 
103 ////////////////////////////////////////////////////////////////////
104 // Function: SpeedTreeNode::get_terrain
105 // Access: Published
106 // Description: Returns the terrain associated with the node, or NULL
107 // if there is no terrain.
108 ////////////////////////////////////////////////////////////////////
110 get_terrain() const {
111  return _terrain;
112 }
113 
114 ////////////////////////////////////////////////////////////////////
115 // Function: SpeedTreeNode::set_time_delta
116 // Access: Published
117 // Description: Specifies an offset that is to be added each frame to
118 // the global clock's frame_time for the purpose of
119 // animating the trees in this particular node. Also
120 // see set_global_time_delta().
121 ////////////////////////////////////////////////////////////////////
122 INLINE void SpeedTreeNode::
123 set_time_delta(double delta) {
124  _time_delta = delta;
125 }
126 
127 ////////////////////////////////////////////////////////////////////
128 // Function: SpeedTreeNode::get_time_delta
129 // Access: Published
130 // Description: Returns an offset that is to be added each frame to
131 // the global clock's frame_time for the purpose of
132 // animating the trees in this particular node. Also
133 // see get_global_time_delta().
134 ////////////////////////////////////////////////////////////////////
135 INLINE double SpeedTreeNode::
136 get_time_delta() const {
137  return _time_delta;
138 }
139 
140 ////////////////////////////////////////////////////////////////////
141 // Function: SpeedTreeNode::set_global_time_delta
142 // Access: Published, Static
143 // Description: Specifies an offset that is to be added each frame to
144 // the global clock's frame_time for the purpose of
145 // animating the trees in all SpeedTreeNodes. Also
146 // see set_time_delta().
147 ////////////////////////////////////////////////////////////////////
148 INLINE void SpeedTreeNode::
149 set_global_time_delta(double delta) {
150  _global_time_delta = delta;
151 }
152 
153 ////////////////////////////////////////////////////////////////////
154 // Function: SpeedTreeNode::get_global_time_delta
155 // Access: Published, Static
156 // Description: Returns an offset that is to be added each frame to
157 // the global clock's frame_time for the purpose of
158 // animating the trees in all SpeedTreeNodes. Also
159 // see get_time_delta().
160 ////////////////////////////////////////////////////////////////////
161 INLINE double SpeedTreeNode::
163  return _global_time_delta;
164 }
165 
166 ////////////////////////////////////////////////////////////////////
167 // Function: SpeedTreeNode::InstanceList::Constructor
168 // Access: Public
169 // Description:
170 ////////////////////////////////////////////////////////////////////
171 INLINE SpeedTreeNode::InstanceList::
172 InstanceList(const STTree *tree) : _tree((STTree *)tree) {
173 }
174 
175 ////////////////////////////////////////////////////////////////////
176 // Function: SpeedTreeNode::InstanceList::operator <
177 // Access: Public
178 // Description: Used for comparison for ov_set.
179 ////////////////////////////////////////////////////////////////////
181 operator < (const InstanceList &other) const {
182  return _tree < other._tree;
183 }
184 
185 ////////////////////////////////////////////////////////////////////
186 // Function: SpeedTreeNode::InstanceList::get_tree
187 // Access: Published
188 // Description: Returns the particular tree this list refers to.
189 ////////////////////////////////////////////////////////////////////
191 get_tree() const {
192  return _tree;
193 }
194 
195 ////////////////////////////////////////////////////////////////////
196 // Function: SpeedTreeNode::InstanceList::get_num_instances
197 // Access: Published
198 // Description: Returns the number of instances of this tree.
199 ////////////////////////////////////////////////////////////////////
202  return (int)_instances.size();
203 }
204 
205 ////////////////////////////////////////////////////////////////////
206 // Function: SpeedTreeNode::InstanceList::get_instance
207 // Access: Published
208 // Description: Returns the transform of the nth instance of this
209 // tree.
210 ////////////////////////////////////////////////////////////////////
212 get_instance(int n) const {
213  nassertr(n >= 0 && n < (int)_instances.size(), STTransform::ident_mat());
214  return _instances[n];
215 }
216 
217 ////////////////////////////////////////////////////////////////////
218 // Function: SpeedTreeNode::InstanceList::set_instance
219 // Access: Published
220 // Description: Replaces the transform of the nth instance of this
221 // tree.
222 ////////////////////////////////////////////////////////////////////
224 set_instance(int n, const STTransform &transform) {
225  nassertv(n >= 0 && n < (int)_instances.size());
226  _instances[n] = transform;
227 }
228 
229 ////////////////////////////////////////////////////////////////////
230 // Function: SpeedTreeNode::InstanceList::add_instance
231 // Access: Published
232 // Description: Adds a new instance of this tree at the indicated
233 // transform. Returns the index number of the new
234 // instance.
235 ////////////////////////////////////////////////////////////////////
237 add_instance(const STTransform &transform) {
238  _instances.push_back(transform);
239  return ((int)_instances.size() - 1);
240 }
241 
242 ////////////////////////////////////////////////////////////////////
243 // Function: SpeedTreeNode::InstanceList::remove_instance
244 // Access: Published
245 // Description: Removes the nth instance of this tree.
246 ////////////////////////////////////////////////////////////////////
249  nassertv(n >= 0 && n < (int)_instances.size());
250  _instances.erase(_instances.begin() + n);
251 }
252 
253 ////////////////////////////////////////////////////////////////////
254 // Function: SpeedTreeNode::DrawCallback::Constructor
255 // Access: Published
256 // Description:
257 ////////////////////////////////////////////////////////////////////
258 INLINE SpeedTreeNode::DrawCallback::
259 DrawCallback(SpeedTreeNode *node) : _node(node) {
260 }
const STTree * get_tree(int n) const
Returns the STTree pointer for the nth tree.
Definition: speedTreeNode.I:49
void clear_terrain()
Removes the terrain associated with the node.
Definition: speedTreeNode.I:88
bool operator<(const InstanceList &other) const
Used for comparison for ov_set.
This is the abstract base class that defines the interface needed to describe a terrain for rendering...
Definition: stTerrain.h:39
static double get_global_time_delta()
Returns an offset that is to be added each frame to the global clock&#39;s frame_time for the purpose of ...
STTree * modify_tree(int n)
Returns a modifiable STTree pointer for the nth tree instance.
Definition: speedTreeNode.I:75
static void set_global_time_delta(double delta)
Specifies an offset that is to be added each frame to the global clock&#39;s frame_time for the purpose o...
void set_time_delta(double delta)
Specifies an offset that is to be added each frame to the global clock&#39;s frame_time for the purpose o...
void set_terrain(STTerrain *terrain)
Associated a terrain with the node.
void set_instance(int n, const STTransform &transform)
Replaces the transform of the nth instance of this tree.
void remove_instance(int n)
Removes the nth instance of this tree.
const STTree * get_tree() const
Returns the particular tree this list refers to.
STTerrain * get_terrain() const
Returns the terrain associated with the node, or NULL if there is no terrain.
Interfaces with the SpeedTree library to render SpeedTree objects, especially trees, within the Panda3D scene graph.
Definition: speedTreeNode.h:54
const InstanceList & get_instance_list(int n) const
Returns a list of transforms that corresponds to the instances at which the nth tree appears...
Definition: speedTreeNode.I:62
int get_num_trees() const
Returns the number of unique tree objects that have been added to the node.
Definition: speedTreeNode.I:38
bool has_terrain() const
Returns true if a valid terrain has been associated with the node, false otherwise.
Definition: speedTreeNode.I:99
double get_time_delta() const
Returns an offset that is to be added each frame to the global clock&#39;s frame_time for the purpose of ...
Represents a transform that may be applied to a particular instance of a tree when added to the Speed...
Definition: stTransform.h:29
bool is_valid() const
Returns true if the node is valid and ready to render, false otherwise.
Definition: speedTreeNode.I:25
static const STTransform & ident_mat()
Returns a global identity transform object.
Definition: stTransform.I:128
size_type_0 size() const
Returns the number of elements in the ordered vector.
int add_instance(const STTransform &transform)
Adds a new instance of this tree at the indicated transform.
STTransform get_instance(int n) const
Returns the transform of the nth instance of this tree.
int get_num_instances() const
Returns the number of instances of this tree.
Encapsulates a single tree model in the SpeedTree library, as loaded from an SRT file.
Definition: stTree.h:30