Thursday, January 19, 2012

Where I'm at with Havok (I don't know what I'm doing)

So I've been playing around with the Havok 6.0 SDK (very old, but that's what ASS uses) and it comes with a series of demos that shows off the physics and animation engine. The SDK provides the engine itself as a series of static libraries (.lib files) and their associated header files. Since the libraries are static, when I compile the demo it inlines all the functions into the executable. This makes for a very large executable, but luckily it has symbols, so for that I'm grateful.

So I wasn't really sure where to start, except for finding if it even worked with textures. All of the demos are built into a single executable with a menu system for viewing the various examples.

The example menu

The 'Animation/Api/Blending/Additive' example is actually one of the demo's that I found to load textures. Here's, what I assume will be, my next target for modification. 

Just look at her, with her face, I know she secretly wants to be red.

The source for the demo's project is laid out exactly as the menu system, so it's easy to find the code for the above example. The demo does some basic things to render the above. First it loads scene information (background etc). It does this by reading in the hkScene.hkx file and then converts it to it's internal 'scene' representation in it's environment. Next it loads the 'rig' which is another hkx file. I didn't know what a rig was so I asked my friend. He told me that the rig is basically the skeleton of the model for animation. Next it loads the animation information and does something with that (not really sure). Finally, it loads the skin file. Here's that bit of code.

The skin being loaded, and doing stuff.

Yeah, that, makes very little sense to me. I'm not stupid, I realized the engine would encapsulate the rendering, but I was hoping there'd be at least some clear references on rendering or DirectX or something. OK, so I figured that all of the functions and data that I'm concerned with is probably in one of the 300 lib and header files. 

Before that, I decided to load up the executable in IDA Pro to see if I could find any references to DirectX. First, I checked out the imports section of the file and found.... absolutely no references to DirectX. Infact, all I did find was references to OpenGL. But as you can see from the first menu image above, they clearly state that it is using DirectX9 shaders...? So after being stumped for a while I looked at the functions list for any DirectX stuff. All I found was various DirectX matrix and vector functions, but nothing I was familiar with seeing.

The OpenGL imports and limited DirectX functions

So going back to my original idea of looking at the lib files, I go to the lib directory and see if I can find anything related to DirectX, which I did.

The static Havok dx9 library

So I loaded the hkgDx9s.lib file in IDA and was presented with the below screen.

Dx9s's objects

Ok... that's not easy to work with because I can only load one 'obj' per IDA instance. After going through a number of objects I found there was still no references to DirectX functions. So I'm still continuing my search to try to figure out how exactly they wrapped the DirectX stuff. I just need to play a bit more and probably load it in Visual Studio's debugger and shake it to see what falls out. 

I however, will leave that for the weekend.

No comments:

Post a Comment