source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp @ 2842

Revision 2842, 2.0 KB checked in by mattausch, 16 years ago (diff)
Line 
1#include "SceneEntity.h"
2#include "glInterface.h"
3#include "Geometry.h"
4#include "Material.h"
5#include "RenderState.h"
6#include "Shape.h"
7#include <Cg/cg.h>
8#include <Cg/cgGL.h>
9
10
11using namespace std;
12
13
14namespace CHCDemoEngine
15{
16
17
18SceneEntity::SceneEntity(Transform3 *trafo): mTransform(trafo)
19{
20}
21
22
23SceneEntity::~SceneEntity()
24{
25}
26
27
28void SceneEntity::GetCurrentLODLevel(ShapeContainer &shapes)
29{
30        ShapeContainer::const_iterator sit, sit_end;
31
32        if (mLODInfos.empty())
33        {
34                sit = mShapes.begin(); sit_end = mShapes.end();
35        }
36
37        float mDistance = 0.0f;
38
39        int i = 0;
40
41        LODInfoContainer::const_iterator lid, lid_end = mLODInfos.end();
42
43        for (lid = mLODInfos.begin(); lid != lid_end; ++ lid)
44        {
45                LODInfo *lodInfo = *lid;
46
47                if (lodInfo->mSquaredDistance > mDistance)
48                {
49                        sit = lodInfo->mShapes.begin();
50                        sit_end = lodInfo->mShapes.end();
51                        break;
52                }
53        }
54
55        for (; sit != sit_end; ++ sit)
56        {
57                shapes.push_back(*sit);
58        }
59}
60
61
62void SceneEntity::Render(RenderState *state)
63{
64        //if (mMaterial) mMaterial->Render(state);
65        float mDistance = 0.0f;
66
67        static ShapeContainer shapes;
68        shapes.clear();
69
70        GetCurrentLODLevel(shapes);
71
72        ShapeContainer::const_iterator sit, sit_end = shapes.end();
73
74        for (sit = shapes.begin(); sit != sit_end; ++ sit)
75        {
76                (*sit)->Render(state);
77        }
78}
79
80
81void SceneEntity::AddShape(Shape *shape)
82{
83        mShapes.push_back(shape);
84}
85
86
87void SceneEntity::SetTransform(Transform3 *trafo)
88{
89        mTransform = trafo;
90}
91
92
93void SceneEntity::SetLastRendered(int lastRendered)
94{
95        mLastRendered = lastRendered;
96}
97
98
99int SceneEntity::GetLastRendered() const
100{
101        return mLastRendered;
102}
103
104
105int SceneEntity::CountNumTriangles()
106{
107        int numTriangles = 0;
108        static ShapeContainer shapes;
109        shapes.clear();
110
111        GetCurrentLODLevel(shapes);
112
113        ShapeContainer::const_iterator sit, sit_end = shapes.end();
114
115        for (sit = shapes.begin(); sit != sit_end; ++ sit)
116        {
117                numTriangles += (*sit)->GetGeometry()->GetNumTriangles();
118        }
119
120        return numTriangles;
121}
122
123
124}
Note: See TracBrowser for help on using the repository browser.