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

Revision 3054, 1.3 KB checked in by mattausch, 16 years ago (diff)

worked on render queue

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)
16{
17        mCenter = GetBoundingBox().Center();
18}
19
20
21Shape::~Shape()
22{}
23
24
25void Shape::Render(RenderState *state)
26{
27        if (mMaterial)
28                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        if (mParent->GetTransform()->IsIdentity())
58                return mGeometry->GetBoundingBox();
59
60        Matrix4x4 mat = mParent->GetTransform()->GetMatrix();
61
62        return Transform(mGeometry->GetBoundingBox(), mat);
63}
64
65
66Vector3 Shape::GetCenter() const
67{
68        if (mParent->GetTransform()->IsIdentity())
69                return mCenter;
70
71        Matrix4x4 mat = mParent->GetTransform()->GetMatrix();
72
73        return mat * mCenter;
74}
75
76
77}
Note: See TracBrowser for help on using the repository browser.