bool BoxController::setExtents(const NxVec3& e) { extents = e; if(kineActor) { NxShape* S = *kineActor->getShapes(); NX_ASSERT(S && static_cast<NxBoxShape*>(S)); NxBoxShape* BS = static_cast<NxBoxShape*>(S); BS->setDimensions(e * 0.8f); } return true; }
void CPhysicsActor::SetScale( Vec3& scale ) { // do not scale if scale is currently 1:1 or if the scale // has not changed if( scale.x == 1 && scale.y == 1 && scale.z == 1 || scale == m_CurrentScale ) { return; } // make sure the scale is valid // No 0 scales or negative scales! if( scale.x <= 0 && scale.y <= 0 && scale.z <= 0 ) { m_ToolBox->Log( LOGWARNING, _T("CPhysicsActor::SetScale() Invalid scale!\n" ) ); return; } NxVec3 newScale( scale.x, scale.y, scale.z ); // unscale the old scale // Loop through shapes in the actor unsigned int numShapes = m_Actor->getNbShapes(); NxShape*const* shapes = m_Actor->getShapes(); NxShape* currentShape; NxVec3 shapeLocalPosition; // for each shape type scale its dimensions while( numShapes-- >= 1 ) { currentShape = shapes[numShapes]; // get the shape's type NxShapeType type = currentShape->getType(); switch( type ) { case NX_SHAPE_BOX: { // do something NxBoxShape* shape = (NxBoxShape*)currentShape; // rescale box dimensions NxVec3 dimensions = shape->getDimensions(); Vec3 newDimensions(dimensions.x, dimensions.y, dimensions.z); RescaleVector( newDimensions, scale ); // set the shape data with the newly rescaled dimensions shape->setDimensions( NxVec3(newDimensions.x, newDimensions.y, newDimensions.z) ); break; } case NX_SHAPE_SPHERE: { // do something NxSphereShape* shape = (NxSphereShape*)currentShape; float radius = shape->getRadius(); radius /= m_CurrentScale.x; radius *= newScale.x; // set the shape data with the newly rescaled dimensions shape->setRadius( radius ); break; } case NX_SHAPE_CAPSULE: { // do something NxCapsuleShape* shape; shape = (NxCapsuleShape*)currentShape; // rescale radius float radius = shape->getRadius(); radius /= m_CurrentScale.x; radius *= newScale.x; // rescale height float height = shape->getHeight(); height /= m_CurrentScale.z; height *= newScale.z; // set the shape data with the newly rescaled dimensions shape->setRadius( radius ); shape->setHeight( height ); break; } default: m_ToolBox->Log( LOGWARNING, _T("CPhysicsObject::SetScale() Attempting to scale on unsupported shape!\n" ) ); return; } // get the shape's local position and rescale it shapeLocalPosition = currentShape->getLocalPosition(); Vec3 newShapeLocalPosition(shapeLocalPosition.x, shapeLocalPosition.y, shapeLocalPosition.z); RescaleVector( newShapeLocalPosition, scale ); currentShape->setLocalPosition( NxVec3(newShapeLocalPosition.x, newShapeLocalPosition.y, newShapeLocalPosition.z) ); } // Set the current scale to the new scale so we can unscale the scale m_CurrentScale = scale; }