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