[1985] | 1 | /*************************************************************************** |
---|
| 2 | |
---|
| 3 | This source file is part of OGREBULLET |
---|
| 4 | (Object-oriented Graphics Rendering Engine Bullet Wrapper) |
---|
| 5 | For the latest info, see http://www.ogre3d.org/phpBB2addons/viewforum.php?f=10 |
---|
| 6 | |
---|
| 7 | Copyright (c) 2007 tuan.kuranes@gmail.com (Use it Freely, even Statically, but have to contribute any changes) |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | |
---|
| 11 | This program is free software; you can redistribute it and/or modify it under |
---|
| 12 | the terms of the GPL General Public License with runtime exception as published by the Free Software |
---|
| 13 | Foundation; either version 2 of the License, or (at your option) any later |
---|
| 14 | version. |
---|
| 15 | |
---|
| 16 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
| 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
| 18 | FOR A PARTICULAR PURPOSE. See the GPL General Public License with runtime exception for more details. |
---|
| 19 | |
---|
| 20 | You should have received a copy of the GPL General Public License with runtime exception along with |
---|
| 21 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
| 22 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
| 23 | http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
| 24 | ----------------------------------------------------------------------------- |
---|
| 25 | */ |
---|
| 26 | |
---|
| 27 | #include "OgreBulletCollisions.h" |
---|
| 28 | #include "Utils/OgreBulletConverter.h" |
---|
| 29 | |
---|
| 30 | #include "Shapes/OgreBulletCollisionsCompoundShape.h" |
---|
| 31 | |
---|
| 32 | using namespace Ogre; |
---|
| 33 | using namespace OgreBulletCollisions; |
---|
| 34 | |
---|
| 35 | namespace OgreBulletCollisions |
---|
| 36 | { |
---|
| 37 | // ------------------------------------------------------------------------- |
---|
| 38 | CompoundCollisionShape::CompoundCollisionShape(): |
---|
| 39 | CollisionShape() |
---|
| 40 | { |
---|
| 41 | mShape = new btCompoundShape(); |
---|
| 42 | } |
---|
| 43 | // ------------------------------------------------------------------------- |
---|
| 44 | CompoundCollisionShape::~CompoundCollisionShape() |
---|
| 45 | { |
---|
| 46 | } |
---|
| 47 | // ------------------------------------------------------------------------- |
---|
| 48 | void CompoundCollisionShape::addChildShape(CollisionShape *shape, const Vector3 &pos, const Quaternion &quat) |
---|
| 49 | { |
---|
| 50 | btTransform localTrans; |
---|
| 51 | |
---|
| 52 | //localTrans.setIdentity(); |
---|
| 53 | //localTrans effectively shifts the center of mass with respect to the chassis |
---|
| 54 | localTrans.setOrigin (OgreBtConverter::to(pos)); |
---|
| 55 | localTrans.setRotation (OgreBtConverter::to(quat)); |
---|
| 56 | |
---|
| 57 | static_cast <btCompoundShape *> (mShape)->addChildShape(localTrans, shape->getBulletShape()); |
---|
| 58 | |
---|
| 59 | mShapes.push_back (shape); |
---|
| 60 | } |
---|
| 61 | // ------------------------------------------------------------------------- |
---|
| 62 | bool CompoundCollisionShape::drawWireFrame(DebugLines *wire, |
---|
| 63 | const Ogre::Vector3 &pos, |
---|
| 64 | const Ogre::Quaternion &quat) const |
---|
| 65 | { |
---|
| 66 | bool isVisual = false; |
---|
| 67 | btCompoundShape * const myBtCompoundShape = static_cast <btCompoundShape *> (mShape); |
---|
| 68 | int numChildShapes = myBtCompoundShape->getNumChildShapes (); |
---|
| 69 | |
---|
| 70 | int i; |
---|
| 71 | for (std::vector<CollisionShape *>::const_iterator itShape = mShapes.begin(); |
---|
| 72 | itShape != mShapes.end(); ++itShape) |
---|
| 73 | { |
---|
| 74 | const btCollisionShape * const shape = (*itShape)->getBulletShape(); |
---|
| 75 | for (i = 0; i < numChildShapes; i++) |
---|
| 76 | { |
---|
| 77 | if (myBtCompoundShape->getChildShape (i) == shape) |
---|
| 78 | break; |
---|
| 79 | } |
---|
| 80 | assert (i < numChildShapes); |
---|
| 81 | |
---|
| 82 | const btTransform &localTrans = myBtCompoundShape->getChildTransform (i); |
---|
| 83 | |
---|
| 84 | const Vector3 pos (BtOgreConverter::to(localTrans.getOrigin ())); |
---|
| 85 | const Quaternion quat( BtOgreConverter::to(localTrans.getRotation ())); |
---|
| 86 | |
---|
| 87 | if ((*itShape)->drawWireFrame(wire, pos, quat)) |
---|
| 88 | isVisual = true; |
---|
| 89 | } |
---|
| 90 | return isVisual; |
---|
| 91 | } |
---|
| 92 | } |
---|
| 93 | |
---|