Jump to content
  • Advertisement
Sign in to follow this  

Simple Havok Question

This topic is 2856 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I put this on the Havok forum, didn't get a response. It's a pretty simple question.

I can't figure out how to get the positions and rotations from havok and position/rotate my directx objects with them. I tried this:

for (int i=0;i<ObjectNum;i++)


if (HavokBody)


hkVector4 TempPos=HavokBody->getPosition();



But that doesn't work. I didn't even try setting the rotation because I don't understand quaternions (I'm using Euler angles). I don't really understand hkVector4s. From what I understand, you can't just get the x, y, z (and w if I ever need it) values like this:

float xcoord = examplehkVector4.x;

How would I position and rotate my direct x objects to match the ones in the simulation? How would I convert a quaternion to Euler angles (or a matrix)? Thanks for any help.

Share this post

Link to post
Share on other sites
You're right, it is very easy:

float p[16];
hkTransform transform;


This returns a column major 4x4 matrix; the last column contains your 1x4 vector. You might want to use a row major matrix instead (which is what I think d3d defaults to) but the principle is the same.

Share this post

Link to post
Share on other sites
Thanks for the response, I get an error though (I think its something wrong with the way I make the rigid body)
I get my error at the approxCurrentTransform function, the next line of code to be run is this:

HK_ASSERT2(0x3dd87047, m_world, "This function requires the body to be in an hkpWorld, in order to retrieve the current time.");

I assume this is my problem, but I'm pretty sure I added the rigid body, here's my code, for initializing the havok world, and adding rigid bodies.

void DXClass::InitHavok(D3DXVECTOR3 Gravity)
// Initialize the base system including our memory system
m_pMemoryRouter = hkMemoryInitUtil::initDefault(hkMallocAllocator::m_defaultMallocAllocator, hkMemorySystem::FrameInfo(500000));
hkBaseSystem::init( m_pMemoryRouter, errorReport );

// Initialize the multi-threading classes, hkJobQueue, and hkJobThreadPool
// Get the number of physical threads available on the system
hkHardwareInfo hardwareInfo;
hkGetHardwareInfo( hardwareInfo );
totalNumThreadsUsed = hardwareInfo.m_numThreads;

// We use one less than this for our thread pool, because we must also use this thread for our simulation
hkCpuJobThreadPoolCinfo threadPoolInfo;
threadPoolInfo.m_numThreads = totalNumThreadsUsed - 1;
// This line enables timers collection, by allocating 200 Kb per thread. If you leave this at its default (0),
// timer collection will not be enabled.
threadPoolInfo.m_timerBufferPerThreadAllocation = 200000;
threadPool = new hkCpuJobThreadPool( threadPoolInfo );
// We also need to create a Job queue. This job queue will be used by all Havok modules to run multithreaded work.
hkJobQueueCinfo jobQueueInfo;
jobQueueInfo.m_jobQueueHwSetup.m_numCpuThreads = totalNumThreadsUsed;
jobQueue = new hkJobQueue( jobQueueInfo );

// Enable monitors for this thread.
// Monitors have been enabled for thread pool threads already (see above comment).

hkpWorldCinfo info;
info.m_gravity.set(Gravity.x, Gravity.y, Gravity.z);
HavokWorld=new hkpWorld(info);
hkpAgentRegisterUtil::registerAllAgents( HavokWorld->getCollisionDispatcher() );HavokWorld->registerWithJobQueue( jobQueue );

void DXClass::MakeHavokBox(int ID, float x, float y, float z, float sizex, float sizey, float sizez, float mass, float friction, bool dynamic)
hkpMassProperties massProperties;
hkVector4 boxsize(sizex, sizey, sizez);
hkVector4 position(x, y, z);
hkpConvexShape* shape = new hkpBoxShape(boxsize);
hkpRigidBodyCinfo info;
if (dynamic)
hkpInertiaTensorComputer::computeBoxVolumeMassProperties(boxsize, mass, massProperties);
HavokBody[ID]=new hkpRigidBody(info);

Sorry about the long code, I don't understand the code tags on this forum. I tried just doing this (I know the word "codetag" isn't the actual codetag, its just there to show where I would put it).

code here

But it doesn't work. Anyway.

What's in the matrix? Does it have the same stuff as a D3DXMATRIX just in column major form? Does that mean that p[0] would be the first row, first column, and that p[1] would be second row, first column, and so on? Thanks for any help.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!