SuperTuxKart
Loading...
Searching...
No Matches
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
28namespace irr
29{
30 namespace scene { class ISceneManager; class ISceneNode; }
31}
32using namespace irr;
33
34#include <set>
35#include <memory>
36
37namespace irr
38{
39 namespace scene
40 {
41 const int ESNT_LOD_NODE = MAKE_IRR_ID('l','o','d','n');
42 }
43}
44
49class LODNode : public scene::ISceneNode
50{
51private:
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 std::unique_ptr<int> m_current_level;
67
68 // Area of the bounding box (for autoLOD computation)
69 float m_area;
70
71 bool m_update_box_every_frame;
72public:
73
74 LODNode(std::string group_name, scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id=-1);
75 virtual ~LODNode();
76
78 virtual const core::aabbox3d<f32>& getBoundingBox() const { return Box; }
79
80 int getLevel();
81
82 void updateVisibility(bool* shown = NULL);
83
84 /*
88 virtual core::matrix4& getRelativeTransformationMatrix() { return RelativeTransformationMatrix; }
89
91 virtual core::matrix4 getRelativeTransformation() const { return RelativeTransformationMatrix; }
92 */
93
101 void add(int level, scene::ISceneNode* node, bool reparent);
102
106 void autoComputeLevel(float scale);
107
108 void forceLevelOfDetail(int n);
109
111 scene::ISceneNode* getFirstNode()
112 {
113 if (m_nodes.size() > 0) return m_nodes[0];
114 else return NULL;
115 }
116
117 std::vector<scene::ISceneNode*>& getAllNodes() { return m_nodes; }
118
120
122 virtual void OnAnimate(u32 timeMs);
123
124 virtual void OnRegisterSceneNode();
125 virtual void render();
126
127 virtual scene::ESCENE_NODE_TYPE getType() const { return (scene::ESCENE_NODE_TYPE)scene::ESNT_LOD_NODE; }
128
129 const std::string& getGroupName() const { return m_group_name; }
130};
131
132#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:78
int getLevel()
Returns the level to use, or -1 if the object is too far away.
Definition: lod_node.cpp:73
void autoComputeLevel(float scale)
This method can be used to automatically compute LoD level.
Definition: lod_node.cpp:198
scene::ISceneNode * getFirstNode()
Get the highest level of detail node.
Definition: lod_node.hpp:111
int m_forced_lod
The normal level of detail can be overwritten.
Definition: lod_node.hpp:64
virtual void OnAnimate(u32 timeMs)
OnAnimate() is called just before rendering the whole scene.
Definition: lod_node.cpp:109
void add(int level, scene::ISceneNode *node, bool reparent)
Adds a node associated with a level of detail.
Definition: lod_node.cpp:238
void forceLevelOfDetail(int n)
Forces the level of detail to be n.
Definition: lod_node.cpp:103