Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/physics/src/ogrebullet/Debug/OgreBulletCollisionsDebugDrawer.cpp @ 1971

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

Added OgreBullet to the repository. The revision was 2493 (ogreaddons), trunk.

  • Property svn:eol-style set to native
File size: 10.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 "Debug/OgreBulletCollisionsDebugDrawer.h"
30#include "Utils/OgreBulletConverter.h"
31
32using namespace OgreBulletCollisions;
33using namespace Ogre;
34
35//------------------------------------------------------------------------------------------------
36DebugDrawer::DebugDrawer() :
37    DebugLines(),
38    btIDebugDraw(),
39    mDebugMode(0)
40{
41}
42//------------------------------------------------------------------------------------------------
43DebugDrawer::~DebugDrawer() 
44{
45}
46//------------------------------------------------------------------------------------------------
47void    DebugDrawer::reportErrorWarning(const char* warningString)
48{
49        Ogre::LogManager::getSingleton().getDefaultLog()->logMessage(warningString);
50}
51//------------------------------------------------------------------------------------------------
52void DebugDrawer::setDrawAabb(bool enable)
53{ 
54    if (enable) 
55        mDebugMode |= btIDebugDraw::DBG_DrawAabb;
56    else
57        mDebugMode &= ~btIDebugDraw::DBG_DrawAabb;
58}
59//------------------------------------------------------------------------------------------------
60void    DebugDrawer::draw3dText(const btVector3& location,const char* textString)
61{
62}
63//------------------------------------------------------------------------------------------------
64bool DebugDrawer::doesDrawAabb () const {return (mDebugMode & btIDebugDraw::DBG_DrawAabb) != 0;};
65//------------------------------------------------------------------------------------------------
66bool DebugDrawer::doesDrawWireframe () const {return (mDebugMode & btIDebugDraw::DBG_DrawWireframe) != 0;};
67//------------------------------------------------------------------------------------------------
68bool DebugDrawer::doesDrawFeaturesText () const {return (mDebugMode & btIDebugDraw::DBG_DrawFeaturesText) != 0;};
69//------------------------------------------------------------------------------------------------
70bool DebugDrawer::doesDrawContactPoints () const {return (mDebugMode & btIDebugDraw::DBG_DrawContactPoints) != 0;};
71//------------------------------------------------------------------------------------------------
72bool DebugDrawer::doesNoDeactivation () const {return (mDebugMode & btIDebugDraw::DBG_NoDeactivation) != 0;};
73//------------------------------------------------------------------------------------------------
74bool DebugDrawer::doesNoHelpText () const {return (mDebugMode & btIDebugDraw::DBG_NoHelpText) != 0;};
75//------------------------------------------------------------------------------------------------
76bool DebugDrawer::doesDrawText () const {return (mDebugMode & btIDebugDraw::DBG_DrawText) != 0;};
77//------------------------------------------------------------------------------------------------
78bool DebugDrawer::doesProfileTimings () const {return (mDebugMode & btIDebugDraw::DBG_ProfileTimings) != 0;};
79//------------------------------------------------------------------------------------------------
80bool DebugDrawer::doesEnableSatComparison () const {return (mDebugMode & btIDebugDraw::DBG_EnableSatComparison) != 0;};
81//------------------------------------------------------------------------------------------------
82bool DebugDrawer::doesDisableBulletLCP () const {return (mDebugMode & btIDebugDraw::DBG_DisableBulletLCP) != 0;};
83//------------------------------------------------------------------------------------------------
84bool DebugDrawer::doesEnableCCD () const {return (mDebugMode & btIDebugDraw::DBG_EnableCCD) != 0;};
85//------------------------------------------------------------------------------------------------
86void DebugDrawer::setDrawWireframe(bool enable)
87{ 
88    if (enable) 
89        mDebugMode |= btIDebugDraw::DBG_DrawWireframe;
90    else
91        mDebugMode &= ~btIDebugDraw::DBG_DrawWireframe;
92}
93//------------------------------------------------------------------------------------------------
94void DebugDrawer::setDrawFeaturesText(bool enable)
95{ 
96    if (enable) 
97        mDebugMode |= btIDebugDraw::DBG_DrawFeaturesText;
98    else
99        mDebugMode &= ~btIDebugDraw::DBG_DrawFeaturesText;
100}
101//------------------------------------------------------------------------------------------------
102void DebugDrawer::setDrawContactPoints(bool enable)
103{ 
104    if (enable) 
105        mDebugMode |= btIDebugDraw::DBG_DrawContactPoints;
106    else
107        mDebugMode &= ~btIDebugDraw::DBG_DrawContactPoints;
108}
109//------------------------------------------------------------------------------------------------
110void DebugDrawer::setNoDeactivation(bool enable)
111{ 
112    if (enable) 
113        mDebugMode |= btIDebugDraw::DBG_NoDeactivation;
114    else
115        mDebugMode &= ~btIDebugDraw::DBG_NoDeactivation;
116}
117//------------------------------------------------------------------------------------------------
118void DebugDrawer::setNoHelpText(bool enable)
119{ 
120    if (enable) 
121        mDebugMode |= btIDebugDraw::DBG_NoHelpText;
122    else
123        mDebugMode &= ~btIDebugDraw::DBG_NoHelpText;
124}
125//------------------------------------------------------------------------------------------------
126void DebugDrawer::setDrawText(bool enable)
127{ 
128    if (enable) 
129        mDebugMode |= btIDebugDraw::DBG_DrawText;
130    else
131        mDebugMode &= ~btIDebugDraw::DBG_DrawText;
132}
133//------------------------------------------------------------------------------------------------
134void DebugDrawer::setProfileTimings(bool enable)
135{ 
136    if (enable) 
137        mDebugMode |= btIDebugDraw::DBG_ProfileTimings;
138    else
139        mDebugMode &= ~btIDebugDraw::DBG_ProfileTimings;
140}
141//------------------------------------------------------------------------------------------------
142void DebugDrawer::setEnableSatComparison(bool enable)
143{ 
144    if (enable) 
145        mDebugMode |= btIDebugDraw::DBG_EnableSatComparison;
146    else
147        mDebugMode &= ~btIDebugDraw::DBG_EnableSatComparison;
148}
149//------------------------------------------------------------------------------------------------
150void DebugDrawer::setDisableBulletLCP (bool enable)
151{ 
152    if (enable) 
153        mDebugMode |= btIDebugDraw::DBG_DisableBulletLCP ;
154    else
155        mDebugMode &= ~btIDebugDraw::DBG_DisableBulletLCP ;
156}
157//------------------------------------------------------------------------------------------------
158void DebugDrawer::setEnableCCD(bool enable)
159{ 
160    if (enable) 
161        mDebugMode |= btIDebugDraw::DBG_EnableCCD;
162    else
163        mDebugMode &= ~btIDebugDraw::DBG_EnableCCD;
164}
165//------------------------------------------------------------------------------------------------
166void 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//------------------------------------------------------------------------------------------------
174void    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//------------------------------------------------------------------------------------------------
182void    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//------------------------------------------------------------------------------------------------
191void 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//------------------------------------------------------------------------------------------------
223void 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//------------------------------------------------------------------------------------------------
231void 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
Note: See TracBrowser for help on using the repository browser.