1 | #include "ObjectPlacer.h"
|
---|
2 | #include "Matrix4x4.h"
|
---|
3 | #include "SceneGraph.h"
|
---|
4 |
|
---|
5 |
|
---|
6 |
|
---|
7 | namespace GtpVisibilityPreprocessor
|
---|
8 | {
|
---|
9 |
|
---|
10 | // ---------------------------------------------------------------------------
|
---|
11 | // ObjectPlacer implementation
|
---|
12 | // ---------------------------------------------------------------------------
|
---|
13 |
|
---|
14 | ObjectPlacer::ObjectPlacer()
|
---|
15 | : mCurrentObject(0)
|
---|
16 | {
|
---|
17 | }
|
---|
18 |
|
---|
19 |
|
---|
20 | void ObjectPlacer::AddObject(SceneGraphLeaf *obj)
|
---|
21 | {
|
---|
22 | mLibraryObjects.push_back(obj);
|
---|
23 | }
|
---|
24 |
|
---|
25 |
|
---|
26 | void ObjectPlacer::NextObject()
|
---|
27 | {
|
---|
28 | mCurrentObject = (mCurrentObject + 1) % (int)mLibraryObjects.size();
|
---|
29 | }
|
---|
30 |
|
---|
31 |
|
---|
32 | void ObjectPlacer::PreviousObject()
|
---|
33 | {
|
---|
34 | mCurrentObject = (mCurrentObject - 1) % (int)mLibraryObjects.size();
|
---|
35 | }
|
---|
36 |
|
---|
37 |
|
---|
38 | SceneGraphLeaf *ObjectPlacer::GetCurrentObject()
|
---|
39 | {
|
---|
40 | if (mCurrentObject >= mLibraryObjects.size())
|
---|
41 | return NULL;
|
---|
42 |
|
---|
43 | return mLibraryObjects[mCurrentObject];
|
---|
44 | }
|
---|
45 |
|
---|
46 |
|
---|
47 | void ObjectPlacer::PlaceObject(const Vector3 &pt)
|
---|
48 | {
|
---|
49 | Vector3 p = pt;
|
---|
50 |
|
---|
51 | SceneGraphLeaf *obj = mLibraryObjects[mCurrentObject];
|
---|
52 |
|
---|
53 | // set pivot to ground of object
|
---|
54 | p.y -= obj->GetOriginalBox().Min().y;
|
---|
55 | Matrix4x4 trafo = TranslationMatrix(p);
|
---|
56 |
|
---|
57 | obj->LoadTransform(trafo);
|
---|
58 | }
|
---|
59 |
|
---|
60 |
|
---|
61 | void ObjectPlacer::PlaceObject(SceneGraphLeaf *leaf, const Vector3 &pt)
|
---|
62 | {
|
---|
63 | AxisAlignedBox3 box = leaf->GetBox();
|
---|
64 |
|
---|
65 | Vector3 p = box.Center() - pt;;
|
---|
66 |
|
---|
67 | // set pivot to ground of object
|
---|
68 | //p.y -= obj->GetOriginalBox().Min().y;
|
---|
69 | Matrix4x4 trafo = TranslationMatrix(p);
|
---|
70 |
|
---|
71 | leaf->ApplyTransform(trafo);
|
---|
72 | }
|
---|
73 |
|
---|
74 | } |
---|