pxUtils.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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/physx/pxUtils.h"
  24. #include "gfx/gfxTransformSaver.h"
  25. #include "gfx/gfxDrawUtil.h"
  26. #include "math/mMatrix.h"
  27. #include "math/mPoint3.h"
  28. #include "T3D/physics/physX/px.h"
  29. #include "T3D/physics/physX/pxCasts.h"
  30. namespace PxUtils {
  31. void drawActor( NxActor *inActor )
  32. {
  33. GFXDrawUtil *drawer = GFX->getDrawUtil();
  34. //drawer->setZRead( false );
  35. // Determine alpha we render shapes with.
  36. const U8 enabledAlpha = 255;
  37. const U8 disabledAlpha = 100;
  38. U8 renderAlpha = inActor->readActorFlag( NX_AF_DISABLE_COLLISION ) ? disabledAlpha : enabledAlpha;
  39. // Determine color we render actors and shapes with.
  40. ColorI actorColor( 0, 0, 255, 200 );
  41. ColorI shapeColor = ( inActor->isSleeping() ? ColorI( 0, 0, 255, renderAlpha ) : ColorI( 255, 0, 255, renderAlpha ) );
  42. MatrixF actorMat(true);
  43. inActor->getGlobalPose().getRowMajor44( actorMat );
  44. GFXStateBlockDesc desc;
  45. desc.setBlend( true );
  46. desc.setZReadWrite( true, false );
  47. desc.setCullMode( GFXCullNone );
  48. // Draw an xfm gizmo for the actor's globalPose...
  49. //drawer->drawTransform( desc, actorMat, Point3F::One, actorColor );
  50. // Loop through and render all the actor's shapes....
  51. NxShape *const*pShapeArray = inActor->getShapes();
  52. U32 numShapes = inActor->getNbShapes();
  53. for ( U32 i = 0; i < numShapes; i++ )
  54. {
  55. const NxShape *shape = pShapeArray[i];
  56. Point3F shapePos = pxCast<Point3F>( shape->getGlobalPosition() );
  57. MatrixF shapeMat(true);
  58. shape->getGlobalPose().getRowMajor44(shapeMat);
  59. shapeMat.setPosition( Point3F::Zero );
  60. switch ( shape->getType() )
  61. {
  62. case NX_SHAPE_SPHERE:
  63. {
  64. NxSphereShape *sphere = (NxSphereShape*)shape;
  65. drawer->drawSphere( desc, sphere->getRadius(), shapePos, shapeColor );
  66. break;
  67. }
  68. case NX_SHAPE_BOX:
  69. {
  70. NxBoxShape *box = (NxBoxShape*)shape;
  71. Point3F size = pxCast<Point3F>( box->getDimensions() );
  72. drawer->drawCube( desc, size*2, shapePos, shapeColor, &shapeMat );
  73. break;
  74. }
  75. case NX_SHAPE_CAPSULE:
  76. {
  77. shapeMat.mul( MatrixF( EulerF( mDegToRad(90.0f), mDegToRad(90.0f), 0 ) ) );
  78. NxCapsuleShape *capsule = (NxCapsuleShape*)shape;
  79. drawer->drawCapsule( desc, shapePos, capsule->getRadius(), capsule->getHeight(), shapeColor, &shapeMat );
  80. break;
  81. }
  82. default:
  83. {
  84. break;
  85. }
  86. }
  87. }
  88. //drawer->clearZDefined();
  89. }
  90. } // namespace PxUtils