[snippet] Ogre3d update node position from physics update

[snippet] Ogre3d update node position from physics update

hkQuaternion newRotation = mSphereRigidBody->getRotation();
Ogre::Radian angleRot(newRotation.getAngle());
hkVector4 axis(0,0,0);
newRotation.getAxis (axis);

Ogre::Vector3 axisRot(axis(0),axis(1),axis(2));
Ogre::Quaternion newOgRot(angleRot,axisRot);
hkVector4 newPos = mSphereRigidBody->getPosition();
Ogre::Vector3 newPosO(newPos(0),newPos(1),newPos(2));

those are the codes to update your node position, like mesh(attach your mesh into a node first)
it just only updating rotation and position and not scaling.

please reply if you found anything that can be optimized

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

hkQuaternion::getAngle() requires a call to acos (which is fairly expensive) and hkQuaternion:hasValidAxis() has to compute the vector length (which is also not cheap). It would be better to access the values of the quaternion directly. I think this would work.

hkQuaternion newRotation = mSphereRigidBody->getRotation();
hkVector4 vec = newRotation.m_vec;
Ogre::Quaternion newOgRot( vec(3), vec(0), vec(1), vec(2) );

I don't use Ogre, but judging from the Ogre::Quaternion reference, that's the right order for the constructor args.

Taking another step back, if Ogre uses matrices to represent its rotations, then it might be faster to use hkpRigidBody::getTransform(). This returns an hkTransform&, which is a 3x4 matrix (three hkVector4's) representing the rotation, and one hkVector4 for the translation. If you worked with that instead, you might avoid a quaternion -> matrix conversion inside Ogre side. But again, that all depends on how Ogre "prefers" its rotations.

Hope that helps. Let me know if you need more info.


I'm using Ogre for some time now and I've managed to write my own wrapper for Havok and I have to agree with havokchris that the best way is to convert quaternions between these engines. It is working very well.
But be careful, because some times if you'll export wrong data from 3DS MAX to havok you'll have to add some additional rotation or correct your data during export.

Hope this helps :)

hi. do you mind to post the check list to export from 3dsmax to ogre. i use OgreMax.
it work well i think. like when i have 2 meters radius of ball, it would become also 2.0f in the boundingbox

but when i create the sphereRigidBody in havok, then i supply 2.0f as the radius, it would become like 2cm or 2 in what unit, obviously not in meters.

this is the movie file. i put 20.0f as the radius for the small ball.
and the 2 meter radius big ball I exported with havok content filter,


my conclusion is,
1. havok content filter exactly exported to meters. i loaded with havokLoader in my ogre app,and it displays correctly on vdb.
2. ogremax exported correct things to ogre. it displays correctly in ogre.
3. but this "20.0f" value I supplied to havok from my code is not interpreted as 20 meter in havok

hkReal radius = mCharacter->getBoundingBox().getMaximum().y*10 ;
hkpSphereShape* sphere = new hkpSphereShape(radius);
hkpRigidBodyCinfo sphereInfo;
    sphereInfo.m_mass = (hkReal)CConfig::get()->keyFloat("ball_mass");
    hkpMassProperties massProperties;
    hkpInertiaTensorComputer::computeSphereVolumeMassProperties(radius, sphereInfo.m_mass, massProperties);
    sphereInfo.m_inertiaTensor = massProperties.m_inertiaTensor;
    sphereInfo.m_motionType = hkpMotion::MOTION_SPHERE_INERTIA;
sphereInfo.m_shape = sphere;    

the variable radius gives me 20.0f. but it displays as a small ball in that hkm movie on the link above

Login to leave a comment.