Line | |
---|
1 | #include "Shape.h"
|
---|
2 | #include "Material.h"
|
---|
3 | #include "RenderState.h"
|
---|
4 | #include "Geometry.h"
|
---|
5 | #include "SceneEntity.h"
|
---|
6 | #include "Transform3.h"
|
---|
7 |
|
---|
8 |
|
---|
9 | namespace CHCDemoEngine
|
---|
10 | {
|
---|
11 |
|
---|
12 | Shape::Shape(Geometry *geometry, Material *mat, SceneEntity *parent):
|
---|
13 | mGeometry(geometry),
|
---|
14 | mMaterial(mat),
|
---|
15 | mParent(parent),
|
---|
16 | mRenderQueueBucket(NULL)
|
---|
17 | {
|
---|
18 | mCenter = GetBoundingBox().Center();
|
---|
19 | }
|
---|
20 |
|
---|
21 |
|
---|
22 | Shape::~Shape()
|
---|
23 | {}
|
---|
24 |
|
---|
25 |
|
---|
26 | void Shape::Render(RenderState *state)
|
---|
27 | {
|
---|
28 | if (mMaterial) mMaterial->Render(state);
|
---|
29 |
|
---|
30 | mParent->GetTransform()->Load(state);
|
---|
31 | mGeometry->Render(state);
|
---|
32 | mParent->GetTransform()->Unload(state);
|
---|
33 | }
|
---|
34 |
|
---|
35 |
|
---|
36 | void Shape::SetGeometry(Geometry *geom)
|
---|
37 | {
|
---|
38 | mGeometry = geom;
|
---|
39 | }
|
---|
40 |
|
---|
41 |
|
---|
42 | void Shape::SetMaterial(Material *mat)
|
---|
43 | {
|
---|
44 | mMaterial = mat;
|
---|
45 | }
|
---|
46 |
|
---|
47 |
|
---|
48 |
|
---|
49 | AxisAlignedBox3 Shape::GetBoundingBox() const
|
---|
50 | {
|
---|
51 | return mGeometry->GetBoundingBox();
|
---|
52 | }
|
---|
53 |
|
---|
54 |
|
---|
55 | AxisAlignedBox3 Shape::GetTransformedBoundingBox() const
|
---|
56 | {
|
---|
57 | Matrix4x4 *mat = mParent->GetTransform()->GetMatrix();
|
---|
58 |
|
---|
59 | if (!mat)
|
---|
60 | return mGeometry->GetBoundingBox();
|
---|
61 |
|
---|
62 | return Transform(mGeometry->GetBoundingBox(), *mat);
|
---|
63 | }
|
---|
64 |
|
---|
65 |
|
---|
66 | Vector3 Shape::GetCenter() const
|
---|
67 | {
|
---|
68 | Matrix4x4 *mat = mParent->GetTransform()->GetMatrix();
|
---|
69 |
|
---|
70 | if (!mat) return mCenter;
|
---|
71 |
|
---|
72 | return (*mat) * mCenter;
|
---|
73 | }
|
---|
74 |
|
---|
75 |
|
---|
76 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.