SuperTuxKart
lod_node.hpp
1 // SuperTuxKart - a fun racing game with go-kart
2 // Copyright (C) 2011-2015 Marianne Gagnon
3 // based on code Copyright 2002-2010 Nikolaus Gebhardt
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 3
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 #ifndef HEADER_LOD_NODE_HPP
20 #define HEADER_LOD_NODE_HPP
21 
22 #include <aabbox3d.h>
23 #include <matrix4.h>
24 #include <ISceneNode.h>
25 #include <vector>
26 #include <string>
27 
28 namespace irr
29 {
30  namespace scene { class ISceneManager; class ISceneNode; }
31 }
32 using namespace irr;
33 
34 #include <set>
35 #include <memory>
36 
37 namespace irr
38 {
39  namespace scene
40  {
41  const int ESNT_LOD_NODE = MAKE_IRR_ID('l','o','d','n');
42  }
43 }
44 
49 class LODNode : public scene::ISceneNode
50 {
51 private:
52  core::matrix4 RelativeTransformationMatrix;
53  core::aabbox3d<f32> Box;
54 
55  std::vector<int> m_detail;
56  std::vector<irr::scene::ISceneNode*> m_nodes;
57 
58  std::set<scene::ISceneNode*> m_nodes_set;
59 
60  std::string m_group_name;
61 
65 
66  int m_current_level;
67  bool m_current_level_dirty;
68 
69  // Distance below which switching between two levels of detail is avoided
70  int m_min_switch_distance;
71 
72  // Area of the bounding box (for autoLOD computation)
73  float m_area;
74 
75  bool m_update_box_every_frame;
76  bool m_lod_distances_updated;
77 public:
78 
79  LODNode(std::string group_name, scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id=-1);
80  virtual ~LODNode();
81 
83  virtual const core::aabbox3d<f32>& getBoundingBox() const { return Box; }
84 
85  int getLevel();
86 
87  void updateVisibility();
88 
89  /*
93  virtual core::matrix4& getRelativeTransformationMatrix() { return RelativeTransformationMatrix; }
94 
96  virtual core::matrix4 getRelativeTransformation() const { return RelativeTransformationMatrix; }
97  */
98 
106  void add(int level, scene::ISceneNode* node, bool reparent);
107 
111  void autoComputeLevel(float scale);
112 
113  void forceLevelOfDetail(int n);
114 
116  scene::ISceneNode* getFirstNode()
117  {
118  if (m_nodes.size() > 0) return m_nodes[0];
119  else return NULL;
120  }
121 
122  std::vector<scene::ISceneNode*>& getAllNodes() { return m_nodes; }
123  std::set<scene::ISceneNode*>& getNodesSet() { return m_nodes_set; }
124 
126 
128  virtual void OnAnimate(u32 timeMs);
129 
130  virtual void OnRegisterSceneNode();
131  virtual void render();
132 
133  virtual scene::ESCENE_NODE_TYPE getType() const { return (scene::ESCENE_NODE_TYPE)scene::ESNT_LOD_NODE; }
134 
135  const std::string& getGroupName() const { return m_group_name; }
136 };
137 
138 #endif
manages level-of-detail
Definition: lod_node.hpp:50
virtual const core::aabbox3d< f32 > & getBoundingBox() const
returns the axis aligned bounding box of this node
Definition: lod_node.hpp:83
int m_forced_lod
The normal level of detail can be overwritten.
Definition: lod_node.hpp:64
scene::ISceneNode * getFirstNode()
Get the highest level of detail node.
Definition: lod_node.hpp:116
void render(float elapsed_time, bool is_loading)
called on every frame to trigger the rendering of the GUI.
Definition: engine.cpp:1265