1 | #include "SceneEntity.h"
|
---|
2 | #include "glInterface.h"
|
---|
3 | #include "Geometry.h"
|
---|
4 | #include "Material.h"
|
---|
5 | #include "RenderState.h"
|
---|
6 | #include <Cg/cg.h>
|
---|
7 | #include <Cg/cgGL.h>
|
---|
8 |
|
---|
9 |
|
---|
10 | namespace CHCDemoEngine
|
---|
11 | {
|
---|
12 |
|
---|
13 | CGparameter SceneEntity::sModelMatrixParam;
|
---|
14 |
|
---|
15 | SceneEntity::SceneEntity(Geometry *geometry,
|
---|
16 | Material *mat,
|
---|
17 | Matrix4x4 *trafo):
|
---|
18 | mGeometry(geometry), mMaterial(mat), mTransform(trafo), mRenderQueueBucket(NULL)
|
---|
19 | {
|
---|
20 | }
|
---|
21 |
|
---|
22 |
|
---|
23 | SceneEntity::~SceneEntity()
|
---|
24 | {
|
---|
25 | }
|
---|
26 |
|
---|
27 |
|
---|
28 | void SceneEntity::Render(RenderState *state)
|
---|
29 | {
|
---|
30 | if (mMaterial) mMaterial->Render(state);
|
---|
31 |
|
---|
32 | if (mTransform)
|
---|
33 | {
|
---|
34 | if (state->GetRenderType() == RenderState::DEFERRED)
|
---|
35 | {
|
---|
36 | cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)mTransform->x);
|
---|
37 |
|
---|
38 | mGeometry->Render(state);
|
---|
39 |
|
---|
40 | static Matrix4x4 identity = IdentityMatrix();
|
---|
41 | cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)identity.x);
|
---|
42 | }
|
---|
43 | else
|
---|
44 | {
|
---|
45 | glPushMatrix();
|
---|
46 | glMultMatrixf((float *)mTransform->x);
|
---|
47 |
|
---|
48 | mGeometry->Render(state);
|
---|
49 |
|
---|
50 | glPopMatrix();
|
---|
51 | }
|
---|
52 | }
|
---|
53 | else
|
---|
54 | {
|
---|
55 | mGeometry->Render(state);
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 |
|
---|
60 | void SceneEntity::SetGeometry(Geometry *geom)
|
---|
61 | {
|
---|
62 | mGeometry = geom;
|
---|
63 | }
|
---|
64 |
|
---|
65 |
|
---|
66 | void SceneEntity::SetTransformation(Matrix4x4 *trafo)
|
---|
67 | {
|
---|
68 | mTransform = trafo;
|
---|
69 | }
|
---|
70 |
|
---|
71 |
|
---|
72 | void SceneEntity::SetMaterial(Material *mat)
|
---|
73 | {
|
---|
74 | mMaterial = mat;
|
---|
75 | }
|
---|
76 |
|
---|
77 |
|
---|
78 | void SceneEntity::SetLastRendered(int lastRendered)
|
---|
79 | {
|
---|
80 | mLastRendered = lastRendered;
|
---|
81 | }
|
---|
82 |
|
---|
83 |
|
---|
84 | int SceneEntity::GetLastRendered() const
|
---|
85 | {
|
---|
86 | return mLastRendered;
|
---|
87 | }
|
---|
88 |
|
---|
89 |
|
---|
90 | AxisAlignedBox3 SceneEntity::GetBoundingBox() const
|
---|
91 | {
|
---|
92 | AxisAlignedBox3 box = mGeometry->GetBoundingBox();
|
---|
93 | if (mTransform) Transform(box, *mTransform);
|
---|
94 |
|
---|
95 | return box;
|
---|
96 | }
|
---|
97 |
|
---|
98 |
|
---|
99 | } |
---|