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