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 
36 namespace irr
37 {
38  namespace scene
39  {
40  const int ESNT_LOD_NODE = MAKE_IRR_ID('l','o','d','n');
41  }
42 }
43 
48 class LODNode : public scene::ISceneNode
49 {
50 private:
51  core::matrix4 RelativeTransformationMatrix;
52  core::aabbox3d<f32> Box;
53 
54  std::vector<int> m_detail;
55  std::vector<irr::scene::ISceneNode*> m_nodes;
56 
57  std::set<scene::ISceneNode*> m_nodes_set;
58 
59  std::string m_group_name;
60 
64 
65  // Area of the bounding box (for autoLOD computation)
66  float m_area;
67 
68  enum PreviousVisibility
69  {
70  FIRST_PASS,
71  WAS_SHOWN,
72  WAS_HIDDEN
73  };
74 
75  PreviousVisibility m_previous_visibility;
76 
77  u32 m_last_tick;
78 
79 public:
80 
81  LODNode(std::string group_name, scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id=-1);
82  virtual ~LODNode();
83 
85  virtual const core::aabbox3d<f32>& getBoundingBox() const { return Box; }
86 
87  int getLevel();
88 
89  void updateVisibility(bool* shown = NULL);
90 
91  /*
95  virtual core::matrix4& getRelativeTransformationMatrix() { return RelativeTransformationMatrix; }
96 
98  virtual core::matrix4 getRelativeTransformation() const { return RelativeTransformationMatrix; }
99  */
100 
108  void add(int level, scene::ISceneNode* node, bool reparent);
109 
113  void autoComputeLevel(float scale);
114 
115  void forceLevelOfDetail(int n);
116 
118  scene::ISceneNode* getFirstNode()
119  {
120  if (m_nodes.size() > 0) return m_nodes[0];
121  else return NULL;
122  }
123 
124  std::vector<scene::ISceneNode*>& getAllNodes() { return m_nodes; }
125 
127 
129  virtual void OnAnimate(u32 timeMs);
130 
131  virtual void OnRegisterSceneNode();
132  virtual void render();
133 
134  virtual scene::ESCENE_NODE_TYPE getType() const { return (scene::ESCENE_NODE_TYPE)scene::ESNT_LOD_NODE; }
135 
136  const std::string& getGroupName() const { return m_group_name; }
137 };
138 
139 #endif
Definition: three_d_animation.hpp:32
int m_forced_lod
The normal level of detail can be overwritten.
Definition: lod_node.hpp:63
manages level-of-detail
Definition: lod_node.hpp:48
virtual const core::aabbox3d< f32 > & getBoundingBox() const
returns the axis aligned bounding box of this node
Definition: lod_node.hpp:85
scene::ISceneNode * getFirstNode()
Get the highest level of detail node.
Definition: lod_node.hpp:118