Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/physics/src/ogrebullet/Collisions/OgreBulletCollisionsObject.cpp @ 2259

Last change on this file since 2259 was 2192, checked in by rgrieder, 16 years ago

Reverted all changes of attempt to update physics branch.

  • Property svn:eol-style set to native
File size: 7.3 KB
Line 
1/***************************************************************************
2
3This source file is part of OGREBULLET
4(Object-oriented Graphics Rendering Engine Bullet Wrapper)
5For the latest info, see http://www.ogre3d.org/phpBB2addons/viewforum.php?f=10
6
7Copyright (c) 2007 tuan.kuranes@gmail.com (Use it Freely, even Statically, but have to contribute any changes)
8
9
10
11This program is free software; you can redistribute it and/or modify it under
12the terms of the GPL General Public License with runtime exception as published by the Free Software
13Foundation; either version 2 of the License, or (at your option) any later
14version.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GPL General Public License with runtime exception for more details.
19
20You should have received a copy of the GPL General Public License with runtime exception along with
21this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22Place - Suite 330, Boston, MA 02111-1307, USA, or go to
23http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
24-----------------------------------------------------------------------------
25*/
26
27#include "OgreBulletCollisions.h"
28
29#include "OgreBulletCollisionsObject.h"
30#include "Debug/OgreBulletCollisionsDebugShape.h"
31
32#include "OgreBulletCollisionsObjectState.h"
33#include "OgreBulletCollisionsShape.h"
34#include "OgreBulletCollisionsWorld.h"
35
36using namespace Ogre;
37using namespace OgreBulletCollisions;
38
39namespace OgreBulletCollisions
40{
41    //-----------------------------------------------------------------------
42    const Ogre::String Object::mMovableType = "OgreBullet::Object";
43    // -------------------------------------------------------------------------
44    Object::Object(const String &name, CollisionsWorld *world, bool init)
45        :       
46        MovableObject(name),
47        UserDefinedObject(),
48        mWorld(world),
49        mShape(0),
50        mState(0),
51        mRootNode(0),
52        mBounds(Vector3::ZERO, Vector3::ZERO),
53        mDebugShape(0),
54        mShapeNode(0),
55        mDebugNode(0)
56    {
57        if (init)
58        {
59            mObject = new btCollisionObject();
60            mState = new ObjectState(this);
61        }
62    }
63    // -------------------------------------------------------------------------
64    Object::~Object()
65    {
66        if (mRootNode)
67        {
68            showDebugShape(false);
69            mShapeNode->detachObject (this);
70            mRootNode->removeAndDestroyChild (mShapeNode->getName ());
71            //mRootNode->getParentSceneNode ()->removeAndDestroyChild (mRootNode->getName ());
72        }
73
74        getBulletCollisionWorld()->removeCollisionObject( mObject );
75                getCollisionWorld()->removeObject(this);
76
77        delete mObject;       
78        delete mShape;
79        delete mState;
80        delete mDebugShape;
81    }
82    //-----------------------------------------------------------------------
83    void Object::showDebugShape(bool show)
84    {
85        if (show && mDebugShape == 0 && mShape)
86        {
87            mDebugShape = new DebugCollisionShape(mShape);
88            if (mDebugShape->getIsVisual ())
89            {
90                assert (mDebugNode == 0);
91                mDebugNode = mRootNode->createChildSceneNode(mName + "DebugShape");
92                mDebugNode->attachObject (mDebugShape);
93            }
94        }
95        else if (mDebugShape)
96        {
97            if (mDebugShape->getIsVisual ())
98            {
99                assert (mDebugNode);
100                mDebugNode->detachObject (mDebugShape->getName());
101                mRootNode->removeAndDestroyChild (mDebugNode->getName());
102                mDebugNode = 0;
103            }
104            assert (mDebugNode == 0);
105            delete mDebugShape;
106            mDebugShape = 0;
107        }
108    }
109    // -------------------------------------------------------------------------
110    void Object::setTransform(const btVector3 &pos, const btQuaternion &quat)
111    { 
112        mRootNode->setPosition(pos[0], pos[1], pos[2]);
113        mRootNode->setOrientation(quat.getW(),quat.getX(), quat.getY(), quat.getZ());
114    }
115    // -------------------------------------------------------------------------
116    void Object::setPosition(const btVector3 &pos)
117    {
118        mRootNode->setPosition(pos[0], pos[1], pos[2]);
119    }
120    // -------------------------------------------------------------------------
121    void Object::setOrientation(const btQuaternion &quat)
122    {   
123        mRootNode->setOrientation(quat.getW(),quat.getX(), quat.getY(), quat.getZ());
124    }
125    // -------------------------------------------------------------------------
126    void Object::setTransform(const btTransform& worldTrans)
127    { 
128        mRootNode->setPosition(worldTrans.getOrigin()[0], worldTrans.getOrigin()[1],worldTrans.getOrigin()[2]);
129        mRootNode->setOrientation(worldTrans.getRotation().getW(),worldTrans.getRotation().getX(), worldTrans.getRotation().getY(), worldTrans.getRotation().getZ());
130    }
131    //-----------------------------------------------------------------------
132    void Object::setShape(CollisionShape *shape, 
133        const Vector3 &pos, 
134        const Quaternion &quat)
135    {
136        mShape = shape;
137
138        mRootNode = mWorld->getSceneManager()->getRootSceneNode()->createChildSceneNode(mName, pos, quat);
139        mShapeNode = mRootNode->createChildSceneNode(mName + "Shape");
140        mShapeNode->attachObject(this);
141
142        mObject->setCollisionShape(shape->getBulletShape());
143        showDebugShape(mWorld->getShowDebugShapes());       
144    }
145    // -------------------------------------------------------------------------
146    //-----------------------------------------------------------------------
147    void Object::_notifyAttached(Node* parent, bool isTagPoint)
148    {
149        MovableObject::_notifyAttached(parent,isTagPoint);
150        if (parent)
151        {
152            Object* other_object = mWorld->findObject(static_cast<SceneNode*>(parent));
153            if ((other_object) && (other_object != this))
154            {
155                static_cast<SceneNode*>(parent)->detachObject(other_object);
156
157            }
158            setPosition(parent->getPosition());
159            setOrientation(parent->getOrientation());
160        } 
161    }
162#if (OGRE_VERSION >=  ((1 << 16) | (5 << 8) | 0)) // must have at least shoggoth (1.5.0)
163    //-----------------------------------------------------------------------
164        void Object::visitRenderables(Renderable::Visitor* visitor, 
165                bool debugRenderables)
166        {
167                //visitor->visit(this, 0, false);
168        }
169#endif
170    //-----------------------------------------------------------------------
171    const Ogre::String& Object::getMovableType() const
172    {
173        return mMovableType;
174    }
175
176    //-----------------------------------------------------------------------
177    void Object::_notifyCurrentCamera(Camera* camera)
178    {
179    }
180
181    //-----------------------------------------------------------------------
182    const AxisAlignedBox& Object::getBoundingBox(void) const
183    {
184        return mBounds;
185    }
186    //-----------------------------------------------------------------------
187    Real Object::getBoundingRadius(void) const
188    {
189        return Ogre::Real(0.0);
190    }
191
192    //-----------------------------------------------------------------------
193    void Object::_updateRenderQueue(RenderQueue* queue)
194    {
195    }
196}
197
Note: See TracBrowser for help on using the repository browser.