btDebugDraw.cpp 3.1 KB

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