[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 | |
---|
| 29 | #include "OgreBulletCollisionsShape.h" |
---|
| 30 | #include "Utils/OgreBulletConverter.h" |
---|
| 31 | #include "Debug/OgreBulletCollisionsDebugLines.h" |
---|
| 32 | |
---|
| 33 | using namespace Ogre; |
---|
| 34 | using namespace OgreBulletCollisions; |
---|
| 35 | |
---|
| 36 | namespace OgreBulletCollisions |
---|
| 37 | { |
---|
| 38 | // ------------------------------------------------------------------------- |
---|
| 39 | CollisionShape::CollisionShape() |
---|
| 40 | : |
---|
| 41 | mShape(0) |
---|
| 42 | { |
---|
| 43 | } |
---|
| 44 | // ------------------------------------------------------------------------- |
---|
| 45 | CollisionShape::~CollisionShape() |
---|
| 46 | { |
---|
| 47 | delete mShape; |
---|
| 48 | } |
---|
| 49 | // ------------------------------------------------------------------------- |
---|
| 50 | bool CollisionShape::drawWireFrame(DebugLines *wire, const Vector3 &pos, const Quaternion &quat) const |
---|
| 51 | { |
---|
| 52 | if (mShape->isConvex ()) |
---|
| 53 | return drawConvexWireFrame (wire, pos, quat); |
---|
| 54 | |
---|
| 55 | return false; |
---|
| 56 | } |
---|
| 57 | // ------------------------------------------------------------------------- |
---|
| 58 | bool CollisionShape::drawConvexWireFrame(DebugLines *wire, const Vector3 &pos, const Quaternion &quat) const |
---|
| 59 | { |
---|
| 60 | assert (mShape->isConvex ()); |
---|
| 61 | |
---|
| 62 | const btConvexShape * const s = static_cast <btConvexShape *> (mShape); |
---|
| 63 | |
---|
| 64 | Vector3 lastVec; |
---|
| 65 | bool sideBeginning; |
---|
| 66 | |
---|
| 67 | #define getVertex(X,Y,Z) BtOgreConverter::to(s->localGetSupportingVertex (btVector3(X,Y,Z))) |
---|
| 68 | |
---|
| 69 | const bool hasVecTransform = (pos != Vector3::ZERO); |
---|
| 70 | const bool hasQuatTransform = (quat != Quaternion::IDENTITY); |
---|
| 71 | const bool hasTransform = (hasVecTransform) || (hasQuatTransform); |
---|
| 72 | |
---|
| 73 | Vector3 curVec; |
---|
| 74 | size_t i = 0; |
---|
| 75 | const int subDivisionCount = 1; |
---|
| 76 | const float subDivide = 1.0f / subDivisionCount; |
---|
| 77 | for (int x = -subDivisionCount; x <= subDivisionCount; x++) |
---|
| 78 | { |
---|
| 79 | for (int y = -subDivisionCount; y <= subDivisionCount; y++) |
---|
| 80 | { |
---|
| 81 | sideBeginning = true; |
---|
| 82 | for (int z = -subDivisionCount; z <= subDivisionCount; z++) |
---|
| 83 | { |
---|
| 84 | curVec = getVertex(x*subDivide, y*subDivide, z*subDivide); |
---|
| 85 | if (hasTransform) |
---|
| 86 | { |
---|
| 87 | // apply transformation |
---|
| 88 | if (hasQuatTransform) |
---|
| 89 | curVec = quat * curVec; |
---|
| 90 | if (hasVecTransform) |
---|
| 91 | curVec += pos; |
---|
| 92 | // if (hasVecTransform) |
---|
| 93 | // curVec -= pos; |
---|
| 94 | // if (hasQuatTransform) |
---|
| 95 | // curVec = quat * curVec; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | if (sideBeginning) |
---|
| 99 | sideBeginning = false; |
---|
| 100 | else |
---|
| 101 | wire->addLine (lastVec, curVec); |
---|
| 102 | lastVec = curVec; |
---|
| 103 | |
---|
| 104 | i++; |
---|
| 105 | } |
---|
| 106 | } |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | for (int x = -subDivisionCount; x <= subDivisionCount; x++) |
---|
| 111 | { |
---|
| 112 | for (int z = -subDivisionCount; z <= subDivisionCount; z++) |
---|
| 113 | { |
---|
| 114 | sideBeginning = true; |
---|
| 115 | for (int y = -subDivisionCount; y <= subDivisionCount; y++) |
---|
| 116 | { |
---|
| 117 | curVec = getVertex(x*subDivide, y*subDivide, z*subDivide); |
---|
| 118 | if (hasTransform) |
---|
| 119 | { |
---|
| 120 | // apply transformation |
---|
| 121 | if (hasVecTransform) |
---|
| 122 | curVec -= pos; |
---|
| 123 | if (hasQuatTransform) |
---|
| 124 | curVec = quat * curVec; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | if (sideBeginning) |
---|
| 128 | sideBeginning = false; |
---|
| 129 | else |
---|
| 130 | wire->addLine (lastVec, curVec); |
---|
| 131 | lastVec = curVec; |
---|
| 132 | |
---|
| 133 | i++; |
---|
| 134 | } |
---|
| 135 | } |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | for (int z = -subDivisionCount; z <= subDivisionCount; z++) |
---|
| 141 | { |
---|
| 142 | for (int y = -subDivisionCount; y <= subDivisionCount; y++) |
---|
| 143 | { |
---|
| 144 | sideBeginning = true; |
---|
| 145 | for (int x = -subDivisionCount; x <= subDivisionCount; x++) |
---|
| 146 | { |
---|
| 147 | curVec = getVertex(x*subDivide, y*subDivide, z*subDivide); |
---|
| 148 | if (hasTransform) |
---|
| 149 | { |
---|
| 150 | // apply transformation |
---|
| 151 | if (hasVecTransform) |
---|
| 152 | curVec -= pos; |
---|
| 153 | if (hasQuatTransform) |
---|
| 154 | curVec = quat * curVec; |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | if (sideBeginning) |
---|
| 158 | sideBeginning = false; |
---|
| 159 | else |
---|
| 160 | wire->addLine (lastVec, curVec); |
---|
| 161 | lastVec = curVec; |
---|
| 162 | |
---|
| 163 | i++; |
---|
| 164 | } |
---|
| 165 | } |
---|
| 166 | } |
---|
| 167 | #undef getVertex |
---|
| 168 | |
---|
| 169 | return true; |
---|
| 170 | } |
---|
| 171 | } |
---|
| 172 | |
---|