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