forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeedTreeNode.I
More file actions
207 lines (186 loc) · 5.05 KB
/
speedTreeNode.I
File metadata and controls
207 lines (186 loc) · 5.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file speedTreeNode.I
* @author drose
* @date 2010-09-30
*/
/**
* Returns true if the node is valid and ready to render, false otherwise.
* Note that this might not become false until after the first time the node
* is rendered.
*/
INLINE bool SpeedTreeNode::
is_valid() const {
return _is_valid;
}
/**
* Returns the number of unique tree objects that have been added to the node.
* This count does not include multiple instances of the same tree that appear
* in different transforms.
*/
INLINE int SpeedTreeNode::
get_num_trees() const {
return (int)_trees.size();
}
/**
* Returns the STTree pointer for the nth tree. See get_num_trees().
*/
INLINE const STTree *SpeedTreeNode::
get_tree(int n) const {
nassertr(n >= 0 && n < (int)_trees.size(), nullptr);
InstanceList *instance_list = _trees[n];
return instance_list->get_tree();
}
/**
* Returns a list of transforms that corresponds to the instances at which the
* nth tree appears.
*/
INLINE const SpeedTreeNode::InstanceList &SpeedTreeNode::
get_instance_list(int n) const {
// TODO: This should be nassertr instead of assert, but there's nothing we
// can really return when the assert fails.
assert(n >= 0 && n < (int)_trees.size());
InstanceList *instance_list = _trees[n];
return *instance_list;
}
/**
* Returns a modifiable STTree pointer for the nth tree instance.
*/
INLINE STTree *SpeedTreeNode::
modify_tree(int n) {
nassertr(n >= 0 && n < (int)_trees.size(), nullptr);
InstanceList *instance_list = _trees[n];
_needs_repopulate = true;
return (STTree *)instance_list->get_tree();
}
/**
* Removes the terrain associated with the node.
*/
INLINE void SpeedTreeNode::
clear_terrain() {
set_terrain(nullptr);
}
/**
* Returns true if a valid terrain has been associated with the node, false
* otherwise.
*/
INLINE bool SpeedTreeNode::
has_terrain() const {
return _terrain != nullptr;
}
/**
* Returns the terrain associated with the node, or NULL if there is no
* terrain.
*/
INLINE STTerrain *SpeedTreeNode::
get_terrain() const {
return _terrain;
}
/**
* Specifies an offset that is to be added each frame to the global clock's
* frame_time for the purpose of animating the trees in this particular node.
* Also see set_global_time_delta().
*/
INLINE void SpeedTreeNode::
set_time_delta(double delta) {
_time_delta = delta;
}
/**
* Returns an offset that is to be added each frame to the global clock's
* frame_time for the purpose of animating the trees in this particular node.
* Also see get_global_time_delta().
*/
INLINE double SpeedTreeNode::
get_time_delta() const {
return _time_delta;
}
/**
* Specifies an offset that is to be added each frame to the global clock's
* frame_time for the purpose of animating the trees in all SpeedTreeNodes.
* Also see set_time_delta().
*/
INLINE void SpeedTreeNode::
set_global_time_delta(double delta) {
_global_time_delta = delta;
}
/**
* Returns an offset that is to be added each frame to the global clock's
* frame_time for the purpose of animating the trees in all SpeedTreeNodes.
* Also see get_time_delta().
*/
INLINE double SpeedTreeNode::
get_global_time_delta() {
return _global_time_delta;
}
/**
*
*/
INLINE SpeedTreeNode::InstanceList::
InstanceList(const STTree *tree) : _tree((STTree *)tree) {
}
/**
* Used for comparison for ov_set.
*/
INLINE bool SpeedTreeNode::InstanceList::
operator < (const InstanceList &other) const {
return _tree < other._tree;
}
/**
* Returns the particular tree this list refers to.
*/
INLINE const STTree *SpeedTreeNode::InstanceList::
get_tree() const {
return _tree;
}
/**
* Returns the number of instances of this tree.
*/
INLINE int SpeedTreeNode::InstanceList::
get_num_instances() const {
return (int)_instances.size();
}
/**
* Returns the transform of the nth instance of this tree.
*/
INLINE STTransform SpeedTreeNode::InstanceList::
get_instance(int n) const {
nassertr(n >= 0 && n < (int)_instances.size(), STTransform::ident_mat());
return _instances[n];
}
/**
* Replaces the transform of the nth instance of this tree.
*/
INLINE void SpeedTreeNode::InstanceList::
set_instance(int n, const STTransform &transform) {
nassertv(n >= 0 && n < (int)_instances.size());
_instances[n] = transform;
}
/**
* Adds a new instance of this tree at the indicated transform. Returns the
* index number of the new instance.
*/
INLINE int SpeedTreeNode::InstanceList::
add_instance(const STTransform &transform) {
_instances.push_back(transform);
return ((int)_instances.size() - 1);
}
/**
* Removes the nth instance of this tree.
*/
INLINE void SpeedTreeNode::InstanceList::
remove_instance(int n) {
nassertv(n >= 0 && n < (int)_instances.size());
_instances.erase(_instances.begin() + n);
}
/**
*
*/
INLINE SpeedTreeNode::DrawCallback::
DrawCallback(SpeedTreeNode *node) : _node(node) {
}