Panda3D
 All Classes Functions Variables Enumerations
speedTreeNode.I
00001 // Filename: speedTreeNode.I
00002 // Created by:  drose (30Sep10)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 
00016 ////////////////////////////////////////////////////////////////////
00017 //     Function: SpeedTreeNode::is_valid
00018 //       Access: Published
00019 //  Description: Returns true if the node is valid and ready to
00020 //               render, false otherwise.  Note that this might not
00021 //               become false until after the first time the node is
00022 //               rendered.
00023 ////////////////////////////////////////////////////////////////////
00024 INLINE bool SpeedTreeNode::
00025 is_valid() const {
00026   return _is_valid;
00027 }
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 //     Function: SpeedTreeNode::get_num_trees
00031 //       Access: Published
00032 //  Description: Returns the number of unique tree objects that have
00033 //               been added to the node.  This count does not include
00034 //               multiple instances of the same tree that appear in
00035 //               different transforms.
00036 ////////////////////////////////////////////////////////////////////
00037 INLINE int SpeedTreeNode::
00038 get_num_trees() const {
00039   return (int)_trees.size();
00040 }
00041 
00042 ////////////////////////////////////////////////////////////////////
00043 //     Function: SpeedTreeNode::get_tree
00044 //       Access: Published
00045 //  Description: Returns the STTree pointer for the nth tree.
00046 //               See get_num_trees().
00047 ////////////////////////////////////////////////////////////////////
00048 INLINE const STTree *SpeedTreeNode::
00049 get_tree(int n) const {
00050   nassertr(n >= 0 && n < (int)_trees.size(), NULL);
00051   InstanceList *instance_list = _trees[n];
00052   return instance_list->get_tree();
00053 }
00054 
00055 ////////////////////////////////////////////////////////////////////
00056 //     Function: SpeedTreeNode::get_instance_list
00057 //       Access: Published
00058 //  Description: Returns a list of transforms that corresponds to the
00059 //               instances at which the nth tree appears.
00060 ////////////////////////////////////////////////////////////////////
00061 INLINE const SpeedTreeNode::InstanceList &SpeedTreeNode::
00062 get_instance_list(int n) const {
00063   nassertr(n >= 0 && n < (int)_trees.size(), *(InstanceList *)NULL);
00064   InstanceList *instance_list = _trees[n];
00065   return *instance_list;
00066 }
00067 
00068 ////////////////////////////////////////////////////////////////////
00069 //     Function: SpeedTreeNode::modify_tree
00070 //       Access: Published
00071 //  Description: Returns a modifiable STTree pointer for the nth tree
00072 //               instance.
00073 ////////////////////////////////////////////////////////////////////
00074 INLINE STTree *SpeedTreeNode::
00075 modify_tree(int n) {
00076   nassertr(n >= 0 && n < (int)_trees.size(), NULL);
00077   InstanceList *instance_list = _trees[n];
00078   _needs_repopulate = true;
00079   return (STTree *)instance_list->get_tree();
00080 }
00081 
00082 ////////////////////////////////////////////////////////////////////
00083 //     Function: SpeedTreeNode::clear_terrain
00084 //       Access: Published
00085 //  Description: Removes the terrain associated with the node.
00086 ////////////////////////////////////////////////////////////////////
00087 INLINE void SpeedTreeNode::
00088 clear_terrain() {
00089   set_terrain(NULL);
00090 }
00091 
00092 ////////////////////////////////////////////////////////////////////
00093 //     Function: SpeedTreeNode::has_terrain
00094 //       Access: Published
00095 //  Description: Returns true if a valid terrain has been associated
00096 //               with the node, false otherwise.
00097 ////////////////////////////////////////////////////////////////////
00098 INLINE bool SpeedTreeNode::
00099 has_terrain() const {
00100   return _terrain != (STTerrain *)NULL;
00101 }
00102 
00103 ////////////////////////////////////////////////////////////////////
00104 //     Function: SpeedTreeNode::get_terrain
00105 //       Access: Published
00106 //  Description: Returns the terrain associated with the node, or NULL
00107 //               if there is no terrain.
00108 ////////////////////////////////////////////////////////////////////
00109 INLINE STTerrain *SpeedTreeNode::
00110 get_terrain() const {
00111   return _terrain;
00112 }
00113 
00114 ////////////////////////////////////////////////////////////////////
00115 //     Function: SpeedTreeNode::set_time_delta
00116 //       Access: Published
00117 //  Description: Specifies an offset that is to be added each frame to
00118 //               the global clock's frame_time for the purpose of
00119 //               animating the trees in this particular node.  Also
00120 //               see set_global_time_delta().
00121 ////////////////////////////////////////////////////////////////////
00122 INLINE void SpeedTreeNode::
00123 set_time_delta(double delta) {
00124   _time_delta = delta;
00125 }
00126 
00127 ////////////////////////////////////////////////////////////////////
00128 //     Function: SpeedTreeNode::get_time_delta
00129 //       Access: Published
00130 //  Description: Returns an offset that is to be added each frame to
00131 //               the global clock's frame_time for the purpose of
00132 //               animating the trees in this particular node.  Also
00133 //               see get_global_time_delta().
00134 ////////////////////////////////////////////////////////////////////
00135 INLINE double SpeedTreeNode::
00136 get_time_delta() const {
00137   return _time_delta;
00138 }
00139 
00140 ////////////////////////////////////////////////////////////////////
00141 //     Function: SpeedTreeNode::set_global_time_delta
00142 //       Access: Published, Static
00143 //  Description: Specifies an offset that is to be added each frame to
00144 //               the global clock's frame_time for the purpose of
00145 //               animating the trees in all SpeedTreeNodes.  Also
00146 //               see set_time_delta().
00147 ////////////////////////////////////////////////////////////////////
00148 INLINE void SpeedTreeNode::
00149 set_global_time_delta(double delta) {
00150   _global_time_delta = delta;
00151 }
00152 
00153 ////////////////////////////////////////////////////////////////////
00154 //     Function: SpeedTreeNode::get_global_time_delta
00155 //       Access: Published, Static
00156 //  Description: Returns an offset that is to be added each frame to
00157 //               the global clock's frame_time for the purpose of
00158 //               animating the trees in all SpeedTreeNodes.  Also
00159 //               see get_time_delta().
00160 ////////////////////////////////////////////////////////////////////
00161 INLINE double SpeedTreeNode::
00162 get_global_time_delta() {
00163   return _global_time_delta;
00164 }
00165 
00166 ////////////////////////////////////////////////////////////////////
00167 //     Function: SpeedTreeNode::InstanceList::Constructor
00168 //       Access: Public
00169 //  Description:
00170 ////////////////////////////////////////////////////////////////////
00171 INLINE SpeedTreeNode::InstanceList::
00172 InstanceList(const STTree *tree) : _tree((STTree *)tree) {
00173 }
00174 
00175 ////////////////////////////////////////////////////////////////////
00176 //     Function: SpeedTreeNode::InstanceList::operator <
00177 //       Access: Public
00178 //  Description: Used for comparison for ov_set.
00179 ////////////////////////////////////////////////////////////////////
00180 INLINE bool SpeedTreeNode::InstanceList::
00181 operator < (const InstanceList &other) const {
00182   return _tree < other._tree;
00183 }
00184 
00185 ////////////////////////////////////////////////////////////////////
00186 //     Function: SpeedTreeNode::InstanceList::get_tree
00187 //       Access: Published
00188 //  Description: Returns the particular tree this list refers to.
00189 ////////////////////////////////////////////////////////////////////
00190 INLINE const STTree *SpeedTreeNode::InstanceList::
00191 get_tree() const {
00192   return _tree;
00193 }
00194 
00195 ////////////////////////////////////////////////////////////////////
00196 //     Function: SpeedTreeNode::InstanceList::get_num_instances
00197 //       Access: Published
00198 //  Description: Returns the number of instances of this tree.
00199 ////////////////////////////////////////////////////////////////////
00200 INLINE int SpeedTreeNode::InstanceList::
00201 get_num_instances() const {
00202   return (int)_instances.size();
00203 }
00204 
00205 ////////////////////////////////////////////////////////////////////
00206 //     Function: SpeedTreeNode::InstanceList::get_instance
00207 //       Access: Published
00208 //  Description: Returns the transform of the nth instance of this
00209 //               tree.
00210 ////////////////////////////////////////////////////////////////////
00211 INLINE STTransform SpeedTreeNode::InstanceList::
00212 get_instance(int n) const {
00213   nassertr(n >= 0 && n < (int)_instances.size(), STTransform::ident_mat());
00214   return _instances[n];
00215 }
00216 
00217 ////////////////////////////////////////////////////////////////////
00218 //     Function: SpeedTreeNode::InstanceList::set_instance
00219 //       Access: Published
00220 //  Description: Replaces the transform of the nth instance of this
00221 //               tree.
00222 ////////////////////////////////////////////////////////////////////
00223 INLINE void SpeedTreeNode::InstanceList::
00224 set_instance(int n, const STTransform &transform) {
00225   nassertv(n >= 0 && n < (int)_instances.size());
00226   _instances[n] = transform;
00227 }
00228 
00229 ////////////////////////////////////////////////////////////////////
00230 //     Function: SpeedTreeNode::InstanceList::add_instance
00231 //       Access: Published
00232 //  Description: Adds a new instance of this tree at the indicated
00233 //               transform.  Returns the index number of the new
00234 //               instance.
00235 ////////////////////////////////////////////////////////////////////
00236 INLINE int SpeedTreeNode::InstanceList::
00237 add_instance(const STTransform &transform) {
00238   _instances.push_back(transform);
00239   return ((int)_instances.size() - 1);
00240 }
00241 
00242 ////////////////////////////////////////////////////////////////////
00243 //     Function: SpeedTreeNode::InstanceList::remove_instance
00244 //       Access: Published
00245 //  Description: Removes the nth instance of this tree.
00246 ////////////////////////////////////////////////////////////////////
00247 INLINE void SpeedTreeNode::InstanceList::
00248 remove_instance(int n) {
00249   nassertv(n >= 0 && n < (int)_instances.size());
00250   _instances.erase(_instances.begin() + n);
00251 }
00252 
00253 ////////////////////////////////////////////////////////////////////
00254 //     Function: SpeedTreeNode::DrawCallback::Constructor
00255 //       Access: Published
00256 //  Description:
00257 ////////////////////////////////////////////////////////////////////
00258 INLINE SpeedTreeNode::DrawCallback::
00259 DrawCallback(SpeedTreeNode *node) : _node(node) {
00260 }
 All Classes Functions Variables Enumerations