本文整理汇总了C++中NxShape::setLocalPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ NxShape::setLocalPosition方法的具体用法?C++ NxShape::setLocalPosition怎么用?C++ NxShape::setLocalPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NxShape
的用法示例。
在下文中一共展示了NxShape::setLocalPosition方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetScale
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;
}