Panda3D

Loading...
Searching...
No Matches
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 */
19INLINE 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 */
29INLINE 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 */
37INLINE 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 */
48INLINE const SpeedTreeNode::InstanceList &SpeedTreeNode::
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 */
60INLINE 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 */
71INLINE void SpeedTreeNode::
72 clear_terrain() {
73 set_terrain(nullptr);
74}
75
76/**
77 * Returns true if a valid terrain has been associated with the node, false
78 * otherwise.
79 */
80INLINE 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 */
89INLINE STTerrain *SpeedTreeNode::
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 */
99INLINE 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 */
109INLINE 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 */
119INLINE 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 */
129INLINE double SpeedTreeNode::
130 get_global_time_delta() {
131 return _global_time_delta;
132}
133
134/**
135 *
136 */
137INLINE SpeedTreeNode::InstanceList::
138InstanceList(const STTree *tree) : _tree((STTree *)tree) {
139}
140
141/**
142 * Used for comparison for ov_set.
143 */
144INLINE bool SpeedTreeNode::InstanceList::
145 operator < (const InstanceList &other) const {
146 return _tree < other._tree;
147}
148
149/**
150 * Returns the particular tree this list refers to.
151 */
152INLINE const STTree *SpeedTreeNode::InstanceList::
153 get_tree() const {
154 return _tree;
155}
156
157/**
158 * Returns the number of instances of this tree.
159 */
160INLINE 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 */
168INLINE STTransform SpeedTreeNode::InstanceList::
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 */
177INLINE void SpeedTreeNode::InstanceList::
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 */
187INLINE int SpeedTreeNode::InstanceList::
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 */
196INLINE void SpeedTreeNode::InstanceList::
197 remove_instance(int n) {
198 nassertv(n >= 0 && n < (int)_instances.size());
199 _instances.erase(_instances.begin() + n);
200}
201
202/**
203 *
204 */
205INLINE SpeedTreeNode::DrawCallback::
206DrawCallback(SpeedTreeNode *node) : _node(node) {
207}
STTerrain
This is the abstract base class that defines the interface needed to describe a terrain for rendering...
Definition stTerrain.h:34
STTransform
Represents a transform that may be applied to a particular instance of a tree when added to the Speed...
Definition stTransform.h:26
STTransform::ident_mat
static const STTransform & ident_mat()
Returns a global identity transform object.
Definition stTransform.I:108
STTree
Encapsulates a single tree model in the SpeedTree library, as loaded from an SRT file.
Definition stTree.h:28
SpeedTreeNode::InstanceList
Definition speedTreeNode.h:58
SpeedTreeNode::InstanceList::add_instance
int add_instance(const STTransform &transform)
Adds a new instance of this tree at the indicated transform.
Definition speedTreeNode.I:188
SpeedTreeNode::InstanceList::remove_instance
void remove_instance(int n)
Removes the nth instance of this tree.
Definition speedTreeNode.I:197
SpeedTreeNode::InstanceList::set_instance
void set_instance(int n, const STTransform &transform)
Replaces the transform of the nth instance of this tree.
Definition speedTreeNode.I:178
SpeedTreeNode::InstanceList::get_tree
const STTree * get_tree() const
Returns the particular tree this list refers to.
Definition speedTreeNode.I:153
SpeedTreeNode::InstanceList::get_num_instances
get_num_instances
Returns the number of instances of this tree.
Definition speedTreeNode.h:68
SpeedTreeNode::InstanceList::get_instance
get_instance
Returns the transform of the nth instance of this tree.
Definition speedTreeNode.h:68
SpeedTreeNode::InstanceList::operator<
bool operator<(const InstanceList &other) const
Used for comparison for ov_set.
Definition speedTreeNode.I:145
SpeedTreeNode::has_terrain
bool has_terrain() const
Returns true if a valid terrain has been associated with the node, false otherwise.
Definition speedTreeNode.I:81
SpeedTreeNode::modify_tree
STTree * modify_tree(int n)
Returns a modifiable STTree pointer for the nth tree instance.
Definition speedTreeNode.I:61
SpeedTreeNode::get_num_trees
get_num_trees
Returns the number of unique tree objects that have been added to the node.
Definition speedTreeNode.h:95
SpeedTreeNode::is_valid
bool is_valid() const
Returns true if the node is valid and ready to render, false otherwise.
Definition speedTreeNode.I:20
SpeedTreeNode::set_terrain
void set_terrain(STTerrain *terrain)
Associated a terrain with the node.
Definition speedTreeNode.cxx:558
SpeedTreeNode::get_instance_list
get_instance_list
Returns a list of transforms that corresponds to the instances at which the indicated tree appears.
Definition speedTreeNode.h:97
SpeedTreeNode::set_time_delta
set_time_delta
Specifies an offset that is to be added each frame to the global clock's frame_time for the purpose o...
Definition speedTreeNode.h:144
SpeedTreeNode::set_global_time_delta
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...
Definition speedTreeNode.h:146
SpeedTreeNode::get_tree
get_tree
Returns the STTree pointer for the nth tree.
Definition speedTreeNode.h:95
SpeedTreeNode::get_global_time_delta
get_global_time_delta
Returns an offset that is to be added each frame to the global clock's frame_time for the purpose of ...
Definition speedTreeNode.h:146
SpeedTreeNode::clear_terrain
void clear_terrain()
Removes the terrain associated with the node.
Definition speedTreeNode.I:72
SpeedTreeNode::get_time_delta
get_time_delta
Returns an offset that is to be added each frame to the global clock's frame_time for the purpose of ...
Definition speedTreeNode.h:144
SpeedTreeNode::get_terrain
STTerrain * get_terrain() const
Returns the terrain associated with the node, or NULL if there is no terrain.
Definition speedTreeNode.I:90
ordered_vector::size
size_type_0 size() const
Returns the number of elements in the ordered vector.
Definition ordered_vector.I:221