Line | |
---|
1 | #include "SceneEntity.h"
|
---|
2 | #include "glInterface.h"
|
---|
3 | #include "Geometry.h"
|
---|
4 | #include "Material.h"
|
---|
5 | #include "RenderState.h"
|
---|
6 |
|
---|
7 |
|
---|
8 | namespace CHCDemoEngine
|
---|
9 | {
|
---|
10 |
|
---|
11 |
|
---|
12 | SceneEntity::SceneEntity(Geometry *geometry,
|
---|
13 | Material *mat,
|
---|
14 | Matrix4x4 *trafo):
|
---|
15 | mGeometry(geometry), mMaterial(mat), mTransform(trafo)
|
---|
16 | {
|
---|
17 | }
|
---|
18 |
|
---|
19 |
|
---|
20 | SceneEntity::~SceneEntity()
|
---|
21 | {
|
---|
22 | // delete only trafo here, the other members could be shared
|
---|
23 | // among several entities and are therefore handled separately
|
---|
24 | DEL_PTR(mTransform);
|
---|
25 | }
|
---|
26 |
|
---|
27 |
|
---|
28 | void SceneEntity::Render(RenderState *state)
|
---|
29 | {
|
---|
30 | if (mMaterial) mMaterial->Render(state);
|
---|
31 |
|
---|
32 | if (mTransform)
|
---|
33 | {
|
---|
34 | glPushMatrix();
|
---|
35 | glMultMatrixf((float *)mTransform->x);
|
---|
36 | mGeometry->Render(state);
|
---|
37 |
|
---|
38 | glPopMatrix();
|
---|
39 | }
|
---|
40 | else
|
---|
41 | {
|
---|
42 | mGeometry->Render(state);
|
---|
43 | }
|
---|
44 | }
|
---|
45 |
|
---|
46 |
|
---|
47 | void SceneEntity::SetGeometry(Geometry *geom)
|
---|
48 | {
|
---|
49 | mGeometry = geom;
|
---|
50 | }
|
---|
51 |
|
---|
52 |
|
---|
53 | void SceneEntity::SetTransformation(Matrix4x4 *trafo)
|
---|
54 | {
|
---|
55 | mTransform = trafo;
|
---|
56 | }
|
---|
57 |
|
---|
58 |
|
---|
59 | void SceneEntity::SetMaterial(Material *mat)
|
---|
60 | {
|
---|
61 | mMaterial = mat;
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 | void SceneEntity::SetLastRendered(int lastRendered)
|
---|
66 | {
|
---|
67 | mLastRendered = lastRendered;
|
---|
68 | }
|
---|
69 |
|
---|
70 |
|
---|
71 | int SceneEntity::GetLastRendered() const
|
---|
72 | {
|
---|
73 | return mLastRendered;
|
---|
74 | }
|
---|
75 |
|
---|
76 |
|
---|
77 | AxisAlignedBox3 SceneEntity::GetBoundingBox() const
|
---|
78 | {
|
---|
79 | AxisAlignedBox3 box = mGeometry->GetBoundingBox();
|
---|
80 | if (mTransform) Transform(box, *mTransform);
|
---|
81 |
|
---|
82 | return box;
|
---|
83 | }
|
---|
84 |
|
---|
85 |
|
---|
86 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.