Panda3D
speedTreeNode.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 speedTreeNode.I
10  * @author drose
11  * @date 2010-09-30
12  */
13 
14 /**
15  * Returns true if the node is valid and ready to render, false otherwise.
16  * Note that this might not become false until after the first time the node
17  * is rendered.
18  */
19 INLINE bool SpeedTreeNode::
20 is_valid() const {
21  return _is_valid;
22 }
23 
24 /**
25  * Returns the number of unique tree objects that have been added to the node.
26  * This count does not include multiple instances of the same tree that appear
27  * in different transforms.
28  */
29 INLINE int SpeedTreeNode::
30 get_num_trees() const {
31  return (int)_trees.size();
32 }
33 
34 /**
35  * Returns the STTree pointer for the nth tree. See get_num_trees().
36  */
37 INLINE const STTree *SpeedTreeNode::
38 get_tree(int n) const {
39  nassertr(n >= 0 && n < (int)_trees.size(), nullptr);
40  InstanceList *instance_list = _trees[n];
41  return instance_list->get_tree();
42 }
43 
44 /**
45  * Returns a list of transforms that corresponds to the instances at which the
46  * nth tree appears.
47  */
49 get_instance_list(int n) const {
50  // TODO: This should be nassertr instead of assert, but there's nothing we
51  // can really return when the assert fails.
52  assert(n >= 0 && n < (int)_trees.size());
53  InstanceList *instance_list = _trees[n];
54  return *instance_list;
55 }
56 
57 /**
58  * Returns a modifiable STTree pointer for the nth tree instance.
59  */
60 INLINE STTree *SpeedTreeNode::
61 modify_tree(int n) {
62  nassertr(n >= 0 && n < (int)_trees.size(), nullptr);
63  InstanceList *instance_list = _trees[n];
64  _needs_repopulate = true;
65  return (STTree *)instance_list->get_tree();
66 }
67 
68 /**
69  * Removes the terrain associated with the node.
70  */
71 INLINE void SpeedTreeNode::
73  set_terrain(nullptr);
74 }
75 
76 /**
77  * Returns true if a valid terrain has been associated with the node, false
78  * otherwise.
79  */
80 INLINE bool SpeedTreeNode::
81 has_terrain() const {
82  return _terrain != nullptr;
83 }
84 
85 /**
86  * Returns the terrain associated with the node, or NULL if there is no
87  * terrain.
88  */
90 get_terrain() const {
91  return _terrain;
92 }
93 
94 /**
95  * Specifies an offset that is to be added each frame to the global clock's
96  * frame_time for the purpose of animating the trees in this particular node.
97  * Also see set_global_time_delta().
98  */
99 INLINE void SpeedTreeNode::
100 set_time_delta(double delta) {
101  _time_delta = delta;
102 }
103 
104 /**
105  * Returns an offset that is to be added each frame to the global clock's
106  * frame_time for the purpose of animating the trees in this particular node.
107  * Also see get_global_time_delta().
108  */
109 INLINE double SpeedTreeNode::
110 get_time_delta() const {
111  return _time_delta;
112 }
113 
114 /**
115  * Specifies an offset that is to be added each frame to the global clock's
116  * frame_time for the purpose of animating the trees in all SpeedTreeNodes.
117  * Also see set_time_delta().
118  */
119 INLINE void SpeedTreeNode::
120 set_global_time_delta(double delta) {
121  _global_time_delta = delta;
122 }
123 
124 /**
125  * Returns an offset that is to be added each frame to the global clock's
126  * frame_time for the purpose of animating the trees in all SpeedTreeNodes.
127  * Also see get_time_delta().
128  */
129 INLINE double SpeedTreeNode::
130 get_global_time_delta() {
131  return _global_time_delta;
132 }
133 
134 /**
135  *
136  */
137 INLINE SpeedTreeNode::InstanceList::
138 InstanceList(const STTree *tree) : _tree((STTree *)tree) {
139 }
140 
141 /**
142  * Used for comparison for ov_set.
143  */
145 operator < (const InstanceList &other) const {
146  return _tree < other._tree;
147 }
148 
149 /**
150  * Returns the particular tree this list refers to.
151  */
153 get_tree() const {
154  return _tree;
155 }
156 
157 /**
158  * Returns the number of instances of this tree.
159  */
160 INLINE int SpeedTreeNode::InstanceList::
161 get_num_instances() const {
162  return (int)_instances.size();
163 }
164 
165 /**
166  * Returns the transform of the nth instance of this tree.
167  */
169 get_instance(int n) const {
170  nassertr(n >= 0 && n < (int)_instances.size(), STTransform::ident_mat());
171  return _instances[n];
172 }
173 
174 /**
175  * Replaces the transform of the nth instance of this tree.
176  */
178 set_instance(int n, const STTransform &transform) {
179  nassertv(n >= 0 && n < (int)_instances.size());
180  _instances[n] = transform;
181 }
182 
183 /**
184  * Adds a new instance of this tree at the indicated transform. Returns the
185  * index number of the new instance.
186  */
188 add_instance(const STTransform &transform) {
189  _instances.push_back(transform);
190  return ((int)_instances.size() - 1);
191 }
192 
193 /**
194  * Removes the nth instance of this tree.
195  */
198  nassertv(n >= 0 && n < (int)_instances.size());
199  _instances.erase(_instances.begin() + n);
200 }
201 
202 /**
203  *
204  */
205 INLINE SpeedTreeNode::DrawCallback::
206 DrawCallback(SpeedTreeNode *node) : _node(node) {
207 }
STTerrain * get_terrain() const
Returns the terrain associated with the node, or NULL if there is no terrain.
Definition: speedTreeNode.I:90
bool has_terrain() const
Returns true if a valid terrain has been associated with the node, false otherwise.
Definition: speedTreeNode.I:81
size_type_0 size() const
Returns the number of elements in the ordered vector.
void clear_terrain()
Removes the terrain associated with the node.
Definition: speedTreeNode.I:72
bool is_valid() const
Returns true if the node is valid and ready to render, false otherwise.
Definition: speedTreeNode.I:20
This is the abstract base class that defines the interface needed to describe a terrain for rendering...
Definition: stTerrain.h:34
bool operator<(const InstanceList &other) const
Used for comparison for ov_set.
STTree * modify_tree(int n)
Returns a modifiable STTree pointer for the nth tree instance.
Definition: speedTreeNode.I:61
void set_terrain(STTerrain *terrain)
Associated a terrain with the node.
const STTree * get_tree() const
Returns the particular tree this list refers to.
get_instance_list
Returns a list of transforms that corresponds to the instances at which the indicated tree appears.
Definition: speedTreeNode.h:97
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.
Interfaces with the SpeedTree library to render SpeedTree objects, especially trees,...
Definition: speedTreeNode.h:50
get_instance
Returns the transform of the nth instance of this tree.
Definition: speedTreeNode.h:68
set_global_time_delta
Specifies an offset that is to be added each frame to the global clock's frame_time for the purpose o...
Represents a transform that may be applied to a particular instance of a tree when added to the Speed...
Definition: stTransform.h:26
static const STTransform & ident_mat()
Returns a global identity transform object.
Definition: stTransform.I:108
get_tree
Returns the STTree pointer for the nth tree.
Definition: speedTreeNode.h:95
int add_instance(const STTransform &transform)
Adds a new instance of this tree at the indicated transform.
Encapsulates a single tree model in the SpeedTree library, as loaded from an SRT file.
Definition: stTree.h:28
set_time_delta
Specifies an offset that is to be added each frame to the global clock's frame_time for the purpose o...