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