Ogre-Havok integration problem

Ogre-Havok integration problem

Hello !I have a big problem with integrating havok and ogre3d, to be more specific with collision. Position of my ogre mesh is not synchronized with my rigidbody's position.This is my function to synchronize position and orientation(conversion of vectors and quaternions i found on this forum):void Ship::update(){ hkVector4 p=rigidBody->getPosition(); node->setPosition(OgreHavokObj::hkVector4ToOgre(p)); hkQuaternion q =rigidBody->getRotation(); node->setOrientation(OgreHavokObj::hkQuatToOgre(q));}This is my function which updates world:
void Renderer::update(double& dt){ if(m_world!=HK_NULL){ if(dt>0.5)dt=0.5; //if(lastD/dt>=4.0f)dt=(2*lastD)/3; m_world->stepMultithreaded(m_pJobQueue,m_pThreadPool,dt); m_world->lock(); if(objArray.size()!=0){ for(int i=0;i if(objArray[i]!=NULL){ objArray[i]->applyForces(); objArray[i]->update(dt); } } } m_world->unlock(); if(m_bVisualDebuggerActive){ m_pPhysicsContext->syncTimers( m_pThreadPool ); m_pVisualDebugger->step(); } hkMonitorStream::getInstance().reset(); m_pThreadPool->clearTimerData(); } }and this the usual result of collision:http://imageshack.us/photo/my-images/543/failmm.png/
Could somebody point out what i am doing worng?Thanks for the help.

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

Hello maxiebp

The first step here is to make sure the
physics world is indeed updating correctly. As it appears you have the VDB set
up in your code I would verify that the rigid bodies representing your ogre
meshes are behaving the way you want them to.If the rigid bodies are
behaving correctly, then the issue is in your conversion from physics world to
graphics world.

Something that immediately strikes me
as odd is the following:

m_world->stepMultithreaded(m_pJobQueue,m_pThreadPool,dt);

m_world->lock();

if(objArray.size()!=0){

	for(int i=0;iapplyForces();

			objArray[i]->update(dt);

		}

	}

}

It looks like you are updating the
physics world and then updating your graphics world using forces? All position,
velocity, and orientation calculations should be handled by the physics world. Otherwise you will more than likely run into synchronization issues.

You shouldn't have to perform any
additional calculations to determine the position and orientation of your
graphics objects in your graphics world. After updating the physics world, call
your update functions (like Ship::update()) on each object,
synchronizing the positions of the object's rigid body with its ogre mesh.

If I am misunderstanding that update
loop please let me know, otherwise, hope that helps!

Cheers,

Nick

Nick S. Developer Support Engineer Havok www.havok.com

I too think that it's easier/more preciseto set the translation instead of applying a force to it.this is the update function snippet of my ogHkBody class

sn->setPosition( hkVecToOgVec( hkbody->getPosition() ) );

sn->setOrientation( hkQuatToOgQuat( hkbody->getRotation() ) );
pretty straight forward:)

Applyforce just applys forces to the ship according to user inputHere is the code:

void Ship::applyForces(){ hkVector4 v=OgreHavokObj::OgreTohkVector4(node->getOrientation()*force); hkVector4 t=OgreHavokObj::OgreTohkVector4(node->getOrientation()*torque); rigidBody->applyLinearImpulse(v); rigidBody->applyAngularImpulse(t); }

force and torque have value diffrent than (0,0,0) only if user holds proper key. Vectors are rotated to affect ships sites.

Hey maxiebp,

Were you able to verify the rigid
bodies representing your Ogre meshes were behaving correctly in the VDB? The
first step is to determine if the issue is in your updating of the Havok
physics world or in the actual conversion from rigid bodies to graphic meshes.

-Nick

Nick S. Developer Support Engineer Havok www.havok.com

Leave a Comment

Please sign in to add a comment. Not a member? Join today