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::
20is_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::
30get_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::
38get_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 */
49get_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 */
61modify_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::
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::
81has_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 */
90get_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::
100set_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::
110get_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::
120set_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::
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 */
145operator < (const InstanceList &other) const {
146 return _tree < other._tree;
147}
148
149/**
150 * Returns the particular tree this list refers to.
151 */
153get_tree() const {
154 return _tree;
155}
156
157/**
158 * Returns the number of instances of this tree.
159 */
161get_num_instances() const {
162 return (int)_instances.size();
163}
164
165/**
166 * Returns the transform of the nth instance of this tree.
167 */
169get_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 */
178set_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 */
188add_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 */
197remove_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}
This is the abstract base class that defines the interface needed to describe a terrain for rendering...
Definition stTerrain.h:34
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.
Encapsulates a single tree model in the SpeedTree library, as loaded from an SRT file.
Definition stTree.h:28
int add_instance(const STTransform &transform)
Adds a new instance of this tree at the indicated transform.
void remove_instance(int n)
Removes the nth instance of this tree.
void set_instance(int n, const STTransform &transform)
Replaces the transform of the nth instance of this tree.
const STTree * get_tree() const
Returns the particular tree this list refers to.
get_num_instances
Returns the number of instances of this tree.
get_instance
Returns the transform of the nth instance of this tree.
bool operator<(const InstanceList &other) const
Used for comparison for ov_set.
Interfaces with the SpeedTree library to render SpeedTree objects, especially trees,...
bool has_terrain() const
Returns true if a valid terrain has been associated with the node, false otherwise.
STTree * modify_tree(int n)
Returns a modifiable STTree pointer for the nth tree instance.
get_num_trees
Returns the number of unique tree objects that have been added to the node.
bool is_valid() const
Returns true if the node is valid and ready to render, false otherwise.
void set_terrain(STTerrain *terrain)
Associated a terrain with the node.
get_instance_list
Returns a list of transforms that corresponds to the instances at which the indicated tree appears.
set_time_delta
Specifies an offset that is to be added each frame to the global clock's frame_time for the purpose o...
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...
get_tree
Returns the STTree pointer for the nth tree.
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 ...
void clear_terrain()
Removes the terrain associated with the node.
get_time_delta
Returns an offset that is to be added each frame to the global clock's frame_time for the purpose of ...
STTerrain * get_terrain() const
Returns the terrain associated with the node, or NULL if there is no terrain.
size_type_0 size() const
Returns the number of elements in the ordered vector.