| 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 "Debug/OgreBulletCollisionsDebugDrawer.h" |
|---|
| 30 | #include "Utils/OgreBulletConverter.h" |
|---|
| 31 | |
|---|
| 32 | using namespace OgreBulletCollisions; |
|---|
| 33 | using namespace Ogre; |
|---|
| 34 | |
|---|
| 35 | //------------------------------------------------------------------------------------------------ |
|---|
| 36 | DebugDrawer::DebugDrawer() : |
|---|
| 37 | DebugLines(), |
|---|
| 38 | btIDebugDraw(), |
|---|
| 39 | mDebugMode(0) |
|---|
| 40 | { |
|---|
| 41 | } |
|---|
| 42 | //------------------------------------------------------------------------------------------------ |
|---|
| 43 | DebugDrawer::~DebugDrawer() |
|---|
| 44 | { |
|---|
| 45 | } |
|---|
| 46 | //------------------------------------------------------------------------------------------------ |
|---|
| 47 | void DebugDrawer::reportErrorWarning(const char* warningString) |
|---|
| 48 | { |
|---|
| 49 | Ogre::LogManager::getSingleton().getDefaultLog()->logMessage(warningString); |
|---|
| 50 | } |
|---|
| 51 | //------------------------------------------------------------------------------------------------ |
|---|
| 52 | void DebugDrawer::setDrawAabb(bool enable) |
|---|
| 53 | { |
|---|
| 54 | if (enable) |
|---|
| 55 | mDebugMode |= btIDebugDraw::DBG_DrawAabb; |
|---|
| 56 | else |
|---|
| 57 | mDebugMode &= ~btIDebugDraw::DBG_DrawAabb; |
|---|
| 58 | } |
|---|
| 59 | //------------------------------------------------------------------------------------------------ |
|---|
| 60 | void DebugDrawer::draw3dText(const btVector3& location,const char* textString) |
|---|
| 61 | { |
|---|
| 62 | } |
|---|
| 63 | //------------------------------------------------------------------------------------------------ |
|---|
| 64 | bool DebugDrawer::doesDrawAabb () const {return (mDebugMode & btIDebugDraw::DBG_DrawAabb) != 0;}; |
|---|
| 65 | //------------------------------------------------------------------------------------------------ |
|---|
| 66 | bool DebugDrawer::doesDrawWireframe () const {return (mDebugMode & btIDebugDraw::DBG_DrawWireframe) != 0;}; |
|---|
| 67 | //------------------------------------------------------------------------------------------------ |
|---|
| 68 | bool DebugDrawer::doesDrawFeaturesText () const {return (mDebugMode & btIDebugDraw::DBG_DrawFeaturesText) != 0;}; |
|---|
| 69 | //------------------------------------------------------------------------------------------------ |
|---|
| 70 | bool DebugDrawer::doesDrawContactPoints () const {return (mDebugMode & btIDebugDraw::DBG_DrawContactPoints) != 0;}; |
|---|
| 71 | //------------------------------------------------------------------------------------------------ |
|---|
| 72 | bool DebugDrawer::doesNoDeactivation () const {return (mDebugMode & btIDebugDraw::DBG_NoDeactivation) != 0;}; |
|---|
| 73 | //------------------------------------------------------------------------------------------------ |
|---|
| 74 | bool DebugDrawer::doesNoHelpText () const {return (mDebugMode & btIDebugDraw::DBG_NoHelpText) != 0;}; |
|---|
| 75 | //------------------------------------------------------------------------------------------------ |
|---|
| 76 | bool DebugDrawer::doesDrawText () const {return (mDebugMode & btIDebugDraw::DBG_DrawText) != 0;}; |
|---|
| 77 | //------------------------------------------------------------------------------------------------ |
|---|
| 78 | bool DebugDrawer::doesProfileTimings () const {return (mDebugMode & btIDebugDraw::DBG_ProfileTimings) != 0;}; |
|---|
| 79 | //------------------------------------------------------------------------------------------------ |
|---|
| 80 | bool DebugDrawer::doesEnableSatComparison () const {return (mDebugMode & btIDebugDraw::DBG_EnableSatComparison) != 0;}; |
|---|
| 81 | //------------------------------------------------------------------------------------------------ |
|---|
| 82 | bool DebugDrawer::doesDisableBulletLCP () const {return (mDebugMode & btIDebugDraw::DBG_DisableBulletLCP) != 0;}; |
|---|
| 83 | //------------------------------------------------------------------------------------------------ |
|---|
| 84 | bool DebugDrawer::doesEnableCCD () const {return (mDebugMode & btIDebugDraw::DBG_EnableCCD) != 0;}; |
|---|
| 85 | //------------------------------------------------------------------------------------------------ |
|---|
| 86 | void DebugDrawer::setDrawWireframe(bool enable) |
|---|
| 87 | { |
|---|
| 88 | if (enable) |
|---|
| 89 | mDebugMode |= btIDebugDraw::DBG_DrawWireframe; |
|---|
| 90 | else |
|---|
| 91 | mDebugMode &= ~btIDebugDraw::DBG_DrawWireframe; |
|---|
| 92 | } |
|---|
| 93 | //------------------------------------------------------------------------------------------------ |
|---|
| 94 | void DebugDrawer::setDrawFeaturesText(bool enable) |
|---|
| 95 | { |
|---|
| 96 | if (enable) |
|---|
| 97 | mDebugMode |= btIDebugDraw::DBG_DrawFeaturesText; |
|---|
| 98 | else |
|---|
| 99 | mDebugMode &= ~btIDebugDraw::DBG_DrawFeaturesText; |
|---|
| 100 | } |
|---|
| 101 | //------------------------------------------------------------------------------------------------ |
|---|
| 102 | void DebugDrawer::setDrawContactPoints(bool enable) |
|---|
| 103 | { |
|---|
| 104 | if (enable) |
|---|
| 105 | mDebugMode |= btIDebugDraw::DBG_DrawContactPoints; |
|---|
| 106 | else |
|---|
| 107 | mDebugMode &= ~btIDebugDraw::DBG_DrawContactPoints; |
|---|
| 108 | } |
|---|
| 109 | //------------------------------------------------------------------------------------------------ |
|---|
| 110 | void DebugDrawer::setNoDeactivation(bool enable) |
|---|
| 111 | { |
|---|
| 112 | if (enable) |
|---|
| 113 | mDebugMode |= btIDebugDraw::DBG_NoDeactivation; |
|---|
| 114 | else |
|---|
| 115 | mDebugMode &= ~btIDebugDraw::DBG_NoDeactivation; |
|---|
| 116 | } |
|---|
| 117 | //------------------------------------------------------------------------------------------------ |
|---|
| 118 | void DebugDrawer::setNoHelpText(bool enable) |
|---|
| 119 | { |
|---|
| 120 | if (enable) |
|---|
| 121 | mDebugMode |= btIDebugDraw::DBG_NoHelpText; |
|---|
| 122 | else |
|---|
| 123 | mDebugMode &= ~btIDebugDraw::DBG_NoHelpText; |
|---|
| 124 | } |
|---|
| 125 | //------------------------------------------------------------------------------------------------ |
|---|
| 126 | void DebugDrawer::setDrawText(bool enable) |
|---|
| 127 | { |
|---|
| 128 | if (enable) |
|---|
| 129 | mDebugMode |= btIDebugDraw::DBG_DrawText; |
|---|
| 130 | else |
|---|
| 131 | mDebugMode &= ~btIDebugDraw::DBG_DrawText; |
|---|
| 132 | } |
|---|
| 133 | //------------------------------------------------------------------------------------------------ |
|---|
| 134 | void DebugDrawer::setProfileTimings(bool enable) |
|---|
| 135 | { |
|---|
| 136 | if (enable) |
|---|
| 137 | mDebugMode |= btIDebugDraw::DBG_ProfileTimings; |
|---|
| 138 | else |
|---|
| 139 | mDebugMode &= ~btIDebugDraw::DBG_ProfileTimings; |
|---|
| 140 | } |
|---|
| 141 | //------------------------------------------------------------------------------------------------ |
|---|
| 142 | void DebugDrawer::setEnableSatComparison(bool enable) |
|---|
| 143 | { |
|---|
| 144 | if (enable) |
|---|
| 145 | mDebugMode |= btIDebugDraw::DBG_EnableSatComparison; |
|---|
| 146 | else |
|---|
| 147 | mDebugMode &= ~btIDebugDraw::DBG_EnableSatComparison; |
|---|
| 148 | } |
|---|
| 149 | //------------------------------------------------------------------------------------------------ |
|---|
| 150 | void DebugDrawer::setDisableBulletLCP (bool enable) |
|---|
| 151 | { |
|---|
| 152 | if (enable) |
|---|
| 153 | mDebugMode |= btIDebugDraw::DBG_DisableBulletLCP ; |
|---|
| 154 | else |
|---|
| 155 | mDebugMode &= ~btIDebugDraw::DBG_DisableBulletLCP ; |
|---|
| 156 | } |
|---|
| 157 | //------------------------------------------------------------------------------------------------ |
|---|
| 158 | void DebugDrawer::setEnableCCD(bool enable) |
|---|
| 159 | { |
|---|
| 160 | if (enable) |
|---|
| 161 | mDebugMode |= btIDebugDraw::DBG_EnableCCD; |
|---|
| 162 | else |
|---|
| 163 | mDebugMode &= ~btIDebugDraw::DBG_EnableCCD; |
|---|
| 164 | } |
|---|
| 165 | //------------------------------------------------------------------------------------------------ |
|---|
| 166 | void DebugDrawer::drawAabb(const btVector3& from,const btVector3& to,const btVector3& color) |
|---|
| 167 | { |
|---|
| 168 | if (mDebugMode & btIDebugDraw::DBG_DrawAabb) |
|---|
| 169 | { |
|---|
| 170 | drawAabb (BtOgreConverter::to(from), BtOgreConverter::to(to), BtOgreConverter::to (color)); |
|---|
| 171 | } |
|---|
| 172 | } |
|---|
| 173 | //------------------------------------------------------------------------------------------------ |
|---|
| 174 | void DebugDrawer::drawLine(const btVector3& from,const btVector3& to,const btVector3& color) |
|---|
| 175 | { |
|---|
| 176 | if (mDebugMode > 0) |
|---|
| 177 | { |
|---|
| 178 | drawLine (BtOgreConverter::to(from), BtOgreConverter::to(to), BtOgreConverter::to (color)); |
|---|
| 179 | } |
|---|
| 180 | } |
|---|
| 181 | //------------------------------------------------------------------------------------------------ |
|---|
| 182 | void DebugDrawer::drawContactPoint(const btVector3& PointOnB,const btVector3& normalOnB, |
|---|
| 183 | btScalar distance,int lifeTime,const btVector3& color) |
|---|
| 184 | { |
|---|
| 185 | if (mDebugMode & btIDebugDraw::DBG_DrawContactPoints) |
|---|
| 186 | { |
|---|
| 187 | // |
|---|
| 188 | } |
|---|
| 189 | } |
|---|
| 190 | //------------------------------------------------------------------------------------------------ |
|---|
| 191 | void DebugDrawer::drawAabb (const Ogre::Vector3& from,const Ogre::Vector3& to,const Ogre::Vector3& color) |
|---|
| 192 | { |
|---|
| 193 | if (mDebugMode & btIDebugDraw::DBG_DrawAabb) |
|---|
| 194 | { |
|---|
| 195 | Vector3 halfExtents = (to-from)* 0.5f; |
|---|
| 196 | Vector3 center = (to+from) *0.5f; |
|---|
| 197 | int i,j; |
|---|
| 198 | |
|---|
| 199 | Vector3 edgecoord(1.f,1.f,1.f),pa,pb; |
|---|
| 200 | for (i=0;i<4;i++) |
|---|
| 201 | { |
|---|
| 202 | for (j=0;j<3;j++) |
|---|
| 203 | { |
|---|
| 204 | pa = Vector3(edgecoord[0]*halfExtents[0], edgecoord[1]*halfExtents[1], |
|---|
| 205 | edgecoord[2]*halfExtents[2]); |
|---|
| 206 | pa+=center; |
|---|
| 207 | |
|---|
| 208 | int othercoord = j%3; |
|---|
| 209 | edgecoord[othercoord]*=-1.f; |
|---|
| 210 | pb = Vector3(edgecoord[0]*halfExtents[0], edgecoord[1]*halfExtents[1], |
|---|
| 211 | edgecoord[2]*halfExtents[2]); |
|---|
| 212 | pb+=center; |
|---|
| 213 | |
|---|
| 214 | drawLine(pa,pb,color); |
|---|
| 215 | } |
|---|
| 216 | edgecoord = Vector3(-1.f,-1.f,-1.f); |
|---|
| 217 | if (i<3) |
|---|
| 218 | edgecoord[i]*=-1.f; |
|---|
| 219 | } |
|---|
| 220 | } |
|---|
| 221 | } |
|---|
| 222 | //------------------------------------------------------------------------------------------------ |
|---|
| 223 | void DebugDrawer::drawLine(const Ogre::Vector3& from,const Ogre::Vector3& to,const Ogre::Vector3& color) |
|---|
| 224 | { |
|---|
| 225 | if (mDebugMode > 0) |
|---|
| 226 | { |
|---|
| 227 | addLine (from, to); |
|---|
| 228 | } |
|---|
| 229 | } |
|---|
| 230 | //------------------------------------------------------------------------------------------------ |
|---|
| 231 | void DebugDrawer::drawContactPoint(const Ogre::Vector3& PointOnB,const Ogre::Vector3& normalOnB, |
|---|
| 232 | Real distance,int lifeTime,const Ogre::Vector3& color) |
|---|
| 233 | { |
|---|
| 234 | if (mDebugMode & btIDebugDraw::DBG_DrawContactPoints) |
|---|
| 235 | { |
|---|
| 236 | |
|---|
| 237 | } |
|---|
| 238 | //... |
|---|
| 239 | } |
|---|
| 240 | //------------------------------------------------------------------------------------------------ |
|---|
| 241 | |
|---|