Merge pull request #2104 from OTHGMars/ScaleCollision

Sets scale for collision primitives created in the shape editor.
This commit is contained in:
Areloch 2018-04-30 23:39:33 -05:00 committed by GitHub
commit de67b30edc

View file

@ -1044,6 +1044,9 @@ PhysicsCollision* TSShape::_buildColShapes( bool useVisibleMesh, const Point3F &
// We need the default mesh transform. // We need the default mesh transform.
MatrixF localXfm; MatrixF localXfm;
getNodeWorldTransform( object.nodeIndex, &localXfm ); getNodeWorldTransform( object.nodeIndex, &localXfm );
Point3F t = localXfm.getPosition();
t.convolve(scale);
localXfm.setPosition(t);
// We have some sort of collision shape... so allocate it. // We have some sort of collision shape... so allocate it.
if ( !colShape ) if ( !colShape )
@ -1053,12 +1056,14 @@ PhysicsCollision* TSShape::_buildColShapes( bool useVisibleMesh, const Point3F &
if ( dStrStartsWith( meshName, "Colbox" ) ) if ( dStrStartsWith( meshName, "Colbox" ) )
{ {
// The bounds define the box extents directly. // The bounds define the box extents directly.
Point3F halfWidth = mesh->getBounds().getExtents() * 0.5f; Point3F halfWidth = mesh->getBounds().getExtents() * scale * 0.5f;
// Add the offset to the center of the bounds // Add the offset to the center of the bounds
// into the local space transform. // into the local space transform.
MatrixF centerXfm( true ); MatrixF centerXfm( true );
centerXfm.setPosition( mesh->getBounds().getCenter() ); Point3F t = mesh->getBounds().getCenter();
t.convolve(scale);
centerXfm.setPosition(t);
localXfm.mul( centerXfm ); localXfm.mul( centerXfm );
colShape->addBox( halfWidth, localXfm ); colShape->addBox( halfWidth, localXfm );
@ -1066,12 +1071,15 @@ PhysicsCollision* TSShape::_buildColShapes( bool useVisibleMesh, const Point3F &
else if ( dStrStartsWith( meshName, "Colsphere" ) ) else if ( dStrStartsWith( meshName, "Colsphere" ) )
{ {
// Get a sphere inscribed to the bounds. // Get a sphere inscribed to the bounds.
F32 radius = mesh->getBounds().len_min() * 0.5f; Point3F extents = mesh->getBounds().getExtents() * scale;
F32 radius = extents.least() * 0.5f;
// Add the offset to the center of the bounds // Add the offset to the center of the bounds
// into the local space transform. // into the local space transform.
MatrixF primXfm( true ); MatrixF primXfm( true );
primXfm.setPosition( mesh->getBounds().getCenter() ); Point3F t = mesh->getBounds().getCenter();
t.convolve(scale);
primXfm.setPosition(t);
localXfm.mul( primXfm ); localXfm.mul( primXfm );
colShape->addSphere( radius, localXfm ); colShape->addSphere( radius, localXfm );
@ -1079,12 +1087,14 @@ PhysicsCollision* TSShape::_buildColShapes( bool useVisibleMesh, const Point3F &
else if ( dStrStartsWith( meshName, "Colcapsule" ) ) else if ( dStrStartsWith( meshName, "Colcapsule" ) )
{ {
// Use the smallest extent as the radius for the capsule. // Use the smallest extent as the radius for the capsule.
Point3F extents = mesh->getBounds().getExtents(); Point3F extents = mesh->getBounds().getExtents() * scale;
F32 radius = extents.least() * 0.5f; F32 radius = extents.least() * 0.5f;
// We need to center the capsule and align it to the Y axis. // We need to center the capsule and align it to the Y axis.
MatrixF primXfm( true ); MatrixF primXfm( true );
primXfm.setPosition( mesh->getBounds().getCenter() ); Point3F t = mesh->getBounds().getCenter();
t.convolve(scale);
primXfm.setPosition(t);
// Use the longest axis as the capsule height. // Use the longest axis as the capsule height.
F32 height = -radius * 2.0f; F32 height = -radius * 2.0f;
@ -1139,10 +1149,6 @@ PhysicsCollision* TSShape::_buildColShapes( bool useVisibleMesh, const Point3F &
VertexPolyList polyList; VertexPolyList polyList;
MatrixF meshMat( localXfm ); MatrixF meshMat( localXfm );
Point3F t = meshMat.getPosition();
t.convolve( scale );
meshMat.setPosition( t );
polyList.setTransform( &MatrixF::Identity, scale ); polyList.setTransform( &MatrixF::Identity, scale );
mesh->buildPolyList( 0, &polyList, surfaceKey, NULL ); mesh->buildPolyList( 0, &polyList, surfaceKey, NULL );
colShape->addConvex( polyList.getVertexList().address(), colShape->addConvex( polyList.getVertexList().address(),