Thursday, 7 November 2013

Havok in Aeolus

So we finally got Havok working in our game!

In this blog I will be going over Havok in more detail starting with not Havok, kind of. What I mean by this is I will be starting with Maya. The reason why I'm starting with Maya is because it will be our source of Havok files. After the Havok plugin is installed to your Maya software, we can start adding physics to our maya scene. The most important tool in Maya that you will use is the rigid body component.  This is what applies the physics properties of an object in your scene. By default it makes your object a static rigid body which means it is collidable but will not move. Once a mass is applied to the model it can have gravity applied to it as well as forces. This makes it a dynamic rigid body.

Once your scene has been set up in Maya and you've applied your rigid bodies properties to your objects within your scene and you're happy with what you have, we will open up our Havok content tools. This is what it looks like.
So there are 7 different available filters there that allow you to modify the configuration set. So when we create our scenes for Aeolus, we try to have the configuration set circled above. It's a very simple base level config set where we transform our scene, then we create the rigid bodies and the world. After that we have a write to platform config. This is used to save the hkx file. Circled on the right hand side of the image we have the format for this file. We need it to be binary and packfile and has to be written to windows 32 for our game to be able to read the files correctly. Up above that we give it a filename and the location of where we want to store the file. At the bottom of this config set we have our preview tool. This is what we use to preview our scene after we have run the configuration.

Now we have this hkx file, but what is an hkx file? This is taken directly from Val, who is a Havok Software Engineer who focuses on the physics, she answers one of my peers when he asked this question on their forum, "hkx is usually the default extension for Havok asset files,  so they are used to export data from the modellers (e.g. Maya) with the Havok content tools, and to load them into a game at run-time." Thanks Val!

On to our game. So we set up a small test scene in Maya, exported it, and loaded it up. Here is our model, well just the top since the camera is parented to the player in the third person mode. I know the scene is boring but we plan to by November 13 to have a polished demo with gameplay and lots of particles and scenery plus 3D sounds. So in terms of physics in this scene, we have our player who is a dynamic rigid body that has gravity being applied to it. When I use the standard wasd i can move the player around with forces. Since we are flying a helicopter we need to be able to elevate and rotate so those controls are integrated near the wasd. These controls are also simple forces being applied.


So here is our very poorly done very hard coded planning on fixing soon code for moving the helicopter around. This is just for the forward, but the rest of the control keys code is pretty much the same aside from some vector changes. As you will read from the code, the forces being applied are not applied locally to the player so once the player rotates the vectors inaccurately move the player. This will be fixed soon. The goal is that date stated earlier. 

switch (arg.key)

{
case OIS::KC_W://move forward
{
if (_RigidBody)
{
int lSpeed = 10;
hkVector4 lNewVel = TOOLS_HAVOK::ToHKVector(Ogre::Vector3(1,0,0) * Ogre::Real(lSpeed));
hkVector4 lNewPos = TOOLS_HAVOK::ToHKVector(Ogre::Vector3(0,0,0));
hkWorld->markForWrite();
{
_RigidBody->GetRB()->applyForce(Ogre::Real(lSpeed), lNewVel,lNewPos);
_RigidBody->GetRB()->setAngularVelocity(TOOLS_HAVOK::ToHKVector(Ogre::Vector3(0,0,0)));
_RigidBody->GetRB()->setLinearVelocity(lNewVel);
}
hkWorld->unmarkForWrite();
}
break;
}
case OIS::KC_Z://rotate left
if (_RigidBody)
{
hkWorld->markForWrite();
{
_RigidBody->GetRB()->setAngularVelocity(TOOLS_HAVOK::ToHKVector(Ogre::Vector3(0,1,0)));

_RigidBody->GetRB()->setLinearVelocity(_RigidBody->GetRB()->getLinearVelocity());
}
hkWorld->unmarkForWrite();
}
break;

I also put the rotate code in here since that's kinda different since it's a setVelocity function rather than an applyForce function.

For my next blog I'm not sure what I plan on doing but it will be something cool.

No comments:

Post a Comment