btDebugDraw.cpp
Engine/source/T3D/physics/bullet/btDebugDraw.cpp
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#include "platform/platform.h" 25#include "T3D/physics/bullet/btDebugDraw.h" 26 27#include "T3D/physics/bullet/btCasts.h" 28#include "gfx/gfxDevice.h" 29#include "math/util/frustum.h" 30#include "gfx/primBuilder.h" 31 32 33void BtDebugDraw::drawLine( const btVector3 &fromBt, const btVector3 &toBt, const btVector3 &color ) 34{ 35 Point3F from = btCast<Point3F>( fromBt ); 36 Point3F to = btCast<Point3F>( toBt ); 37 38 // Cull first if we have a frustum. 39 //F32 distSquared = ( mCuller->getPosition() - from ).lenSquared(); 40 //if ( mCuller && distSquared > ( 150 * 150 ) ) //!mCuller->clipSegment( from, to ) ) 41 //return; 42 43 // Do we need to flush the builder? 44 if ( mVertexCount + 2 >= 1000 ) 45 flush(); 46 47 // Are we starting a new primitive? 48 if ( mVertexCount == 0 ) 49 PrimBuild::begin( GFXLineList, 1000 ); 50 51 PrimBuild::color3f( color.x(), color.y(), color.z() ); 52 PrimBuild::vertex3f( from.x, from.y, from.z ); 53 PrimBuild::vertex3f( to.x, to.y, to.z ); 54 55 mVertexCount += 2; 56} 57 58void BtDebugDraw::drawTriangle( const btVector3 &v0, 59 const btVector3 &v1, 60 const btVector3 &v2, 61 const btVector3 &color, 62 btScalar /*alpha*/ ) 63{ 64 drawLine(v0,v1,color); 65 drawLine(v1,v2,color); 66 drawLine(v2,v0,color); 67} 68 69void BtDebugDraw::drawContactPoint( const btVector3 &pointOnB, 70 const btVector3 &normalOnB, 71 btScalar distance, 72 int lifeTime, const 73 btVector3 &color ) 74{ 75 drawLine( pointOnB, pointOnB+normalOnB*distance, color ); 76} 77 78void BtDebugDraw::flush() 79{ 80 // Do we have verts to render? 81 if ( mVertexCount == 0 ) 82 return; 83 84 PrimBuild::end(); 85 mVertexCount = 0; 86} 87