Jump to content
  • Advertisement
Sign in to follow this  
Kryogenik

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();

Objects->SetPosition(D3DXVECTOR3(TempPos(0),TempPos(1),TempPos(2)));

}

}
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
Advertisement
You're right, it is very easy:

float p[16];
hkTransform transform;
m_chassisRigidBody->approxCurrentTransform(transform);

transform.get4x4ColumnMajor(p);


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).
hkMonitorStream::getInstance().resize(200000);


hkpWorldCinfo info;
info.m_simulationType=hkpWorldCinfo::SIMULATION_TYPE_MULTITHREADED;
info.m_gravity.set(Gravity.x, Gravity.y, Gravity.z);
info.m_collisionTolerance=0.1f;
info.setBroadPhaseWorldSize(1500.0f);
info.setupSolverInfo(hkpWorldCinfo::SOLVER_TYPE_4ITERS_MEDIUM);
HavokWorld=new hkpWorld(info);
HavokWorld->markForWrite();
hkpAgentRegisterUtil::registerAllAgents( HavokWorld->getCollisionDispatcher() );HavokWorld->registerWithJobQueue( jobQueue );
HavokWorld->unmarkForWrite();
}

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);
HavokWorld->markForWrite();
hkpConvexShape* shape = new hkpBoxShape(boxsize);
hkpRigidBodyCinfo info;
if (dynamic)
{
hkpInertiaTensorComputer::computeBoxVolumeMassProperties(boxsize, mass, massProperties);
info.m_mass=mass;
info.m_friction=friction;
info.m_centerOfMass=massProperties.m_centerOfMass;
info.m_inertiaTensor=massProperties.m_inertiaTensor;
info.m_solverDeactivation=info.SOLVER_DEACTIVATION_MEDIUM;
info.m_shape=shape;
info.m_motionType=hkpMotion::MOTION_BOX_INERTIA;
info.m_qualityType=HK_COLLIDABLE_QUALITY_MOVING;
info.m_position=position;
}
else
{
info.m_shape=shape;
info.m_mass=0.0f;
info.m_motionType=hkpMotion::MOTION_FIXED;
info.m_position=position;
info.m_qualityType=HK_COLLIDABLE_QUALITY_FIXED;
}
HavokBody[ID]=new hkpRigidBody(info);
HavokWorld->lock();
HavokWorld->addEntity(HavokBody[ID]);
HavokWorld->unmarkForWrite();
shape->removeReference();
HavokBody[ID]->removeReference();
HavokWorld->unlock();
}

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).

codetag
code here
/codetag

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!