scaling a rigid body

scaling a rigid body

siodmak's picture

when creating my rigid body I assign an initial matrix to it, which has scaling data like so:
matrix_t matr;
D3DXMatrixScaling( &matr, 10, 1, 10 );
hkTransform tr; tr.setIdentity();
tr.setRows4( hkVector4(matr(0,0),matr(0,1),matr(0,2),matr(0,3)),
hkVector4(matr(3,0),matr(3,1),matr(3,2),matr(3,3)) );
ent->m_pPhysBody->setTransform( tr );
why the body with scaling does not collide? everything flies through it, when I comment out just the setRows call, the body is unscaled and collides (it's a static floor)

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
havokchris's picture

Hi siodmak,
Havok doesn't support scale on it's transforms. Internally, they get converted to quaternions in some places, which have to be unit length. It fact, you ought to be hitting asserts about this if you run in the Debug configuration.

Instead of applying scale through the transform, you have to do it through the hkpShape. For a mesh, you can do this with hkpExtendedMeshShape::setScaling(). For simple shapes like boxes and spheres, you can just make multiple copies for each scale that you need.

Changing the shape of a rigid body once it's in the world is generally frowned upon, but it can be done if you're careful. Is that something that you need to do?

As an aside, I always try to avoid creating temporary hkVector4's like you're doing there. On some platforms (I can't remember if Win32 is one of them), the tempory vector doesn't get aligned correctly and it can cause really hard-to-diagnose bugs. Something like this would be ok:

hkVector4 row0;
row0.set( matr(0,0),matr(0,1),matr(0,2),matr(0,3) );

tr.setRows4(row0, ... );

but since hkTransform::setRows4 essentially does a transpose when you call it, actually setting the columns should be more efficient:

tr.getColumn(0).set( matr(0,0), matr(1,0), ... );
tr.getColumn(1).set( matr(0,1), matr(1,1), ... );


Hope that helps...


siodmak's picture

I just tried to be a wise-guy and use [1,1,1] sized boxes as all entities and just scale the floor by [10,1,10] to avoid playing with meshes until I write an ID3DXBaseMesh to hkShape converter, but it seems that it's a "no go"


Login to leave a comment.