source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.cpp @ 2847

Revision 2847, 1.2 KB checked in by mattausch, 16 years ago (diff)
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
9namespace CHCDemoEngine
10{
11
12Shape::Shape(Geometry *geometry, Material *mat, SceneEntity *parent):
13mGeometry(geometry),
14mMaterial(mat),
15mParent(parent),
16mRenderQueueBucket(NULL)
17{
18        mCenter = GetBoundingBox().Center();
19}
20
21
22Shape::~Shape()
23{}
24
25
26void 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
36void Shape::SetGeometry(Geometry *geom)
37{
38        mGeometry = geom;
39}
40
41
42void Shape::SetMaterial(Material *mat)
43{
44        mMaterial = mat;
45}
46
47
48
49AxisAlignedBox3 Shape::GetBoundingBox() const
50{
51        return mGeometry->GetBoundingBox();
52}
53
54
55AxisAlignedBox3 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
66Vector3 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.