Integration into a DirectX based engine (left vs right handedness)

Integration into a DirectX based engine (left vs right handedness)


I'm attempting to integrate Havok into a DirectX based engine and it's coming along fine. That is, until I tried to map the transforms from RigidBodies to the world matrices of my game objects (these matrices are also used for rendering).

Myrigid bodiesare exported from 3ds Max, currently without any transformations, and I understand that it uses a right handed coordinate system and my engine is left handed. So I read the excellent article "Rotations, Handedness, and all that." from the documentation and it refers to an example that does pretty much exactly what I'm trying to do, but I can't find that example application anywhere in the Demos folder.

So my question is this: Is there any example code in the SDK showing how to convert transforms between right and left handedness?

I've tried to convert from right handed hkTransform to left handed matrix a few different ways (hkConvertCS, hkRotation.transpose(), hkRotation.changeBasis()), but I can't seem to wrap my head around it.

Any replies would greatly appreciated!

9 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hi sylwander,

Just letting you know that the example application reference is a little out of date and that application isn't included in the current version of the SDK. There is an issue logged with the SDK team about that but it's not a major priority right now. I'll have a look to see if I can get that app freed up though. It looks like it might be a useful bit of code for people to see how Havok integrates with DirectX without using the Havok Graphics framework used by the demos.


Hi Daniel,

That would be great! It seems several other posts are related to this so it would probably be useful to a lot of people :-)

If anyone has any code snippets to share regarding handedness conversion, I would be grateful!

/Johan Sylwander

This is always a challenge for people. Any code / examples you can give for integrating with DirectX would help immensely.

Far from the most optimal solution, but works as a manual conversion:

hkTransform trans = rigidBody->getTransform();

D3DXMATRIX physMat(trans(0,0), trans(1,0), trans(2,0), trans(3,0),
trans(0,1), trans(1,1), trans(2,1), trans(3,1),
trans(0,2), trans(1,2), trans(2,2), trans(3,2),
trans(0,3), trans(1,3), trans(2,3), trans(3,3));

Then use physMat to render as a world matrix for your mesh.

I don't have either sdk on this computer for referenceatm but I believe I use something similar to the following for getting the orientation of havok objects. I'm unaware what goes on in the background for this conversion so there is most likely a more efficient way of doing things...

D3DXMATRIX orientation;


And sorry for the poor formatting above, tried to use code blocks...force of habit I guess ;P

D3DXMATRIX orientation;


Thanks for the replies!

It seems to be working now for all object created in runtime and thereby assigned LH values, but there are still some issues with converting from RH to LH when loading a hkx-file containing rigid bodies.

I'll post some example code as soon as I've got it working.


So, I now it's been a while sinceI posted this question, but I thought I'd share some tips now that it's working. As mentioned above the models are created in 3ds Max (RH)and used in a DirectX engine (LH).

When exporting I use the following filters in the Havok Content Tools Filter Manager:

Transform Scene

Create Rigid Bodies

Preview Scene

Write to Platform

In the Transform Scene filter I've set the Preset to CUSTOM and the matrix to:

1 0 0

0 0 1

0 1 0

which has the effect of switching the Y and Z axes. Flip Triangle Winding is not checked. This setup works great together with models exported with the Panda exporter whenenabling the Left Handed Axis option under X file settings.

Another thing that must be right for the visual and physical representations to match is the pivot of themodels. If there is a difference in orientation between the pivot for therender mesh and that of the rigid body, the two will not mirror correctly in-game. This might seem obvious, but is quite easy to forget.

That setup works for me, hope it works for someone else too :-)


Login to leave a comment.