Havok integration for OGRE - HkOgre + 2 & 1/2 Demos

A place to show off your latest screenshots and for people to comment on them. Only start a new thread here if you have some nice images to show off!
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Havok integration for OGRE - HkOgre + 2 & 1/2 Demos

Post by Mind Calamity »

Hello guys! Here's my little side project that I've been working on for the last month or so (spending about 2-3 hours a week).

It's a minimalistic wrapper for using Havok with OGRE (as seen by the lazy name that I ripped-off of btOgre which I loved at the time that I used Bullet).

So, this wrapper is pretty much inspired by btOgre and OgrePhysX, both of which provided only what's needed to synchronize your graphics with the physics simulation.

Without further ado, I hereby present to you HkOgre - the Havok integration for OGRE ! (Read that in an epic voice :D)

[youtube]xYUIr-aHcsI[/youtube]

The code is very minimal and it's basically a collection of functions and a few classes to help you get started with using Havok. (Creating custom collision shapes and synchronizing rigid bodies come to mind.)

The above video showcases the 2 complete working demos that are more or less done, and the last terrain demo which I was working on today. (Special thanks to duststorm for pointing me to and sharing his code for retrieving mesh data from the terrain)

Q: How simple is it to setup rigid body synchronization ?
A: 1 Line of code. What did you expect?

Code: Select all

HkOgre::Renderable* rend = new HkOgre::Renderable(sphereNode, sphereRigidBody, mWorld);
Q: Do I need to do anything else ?
A: Yes, manage your own physical world and simulation using raw Havok code. (The advantage to this is that you can easily implement the demos).

Q: Does HkOgre support Havok animation or ragdolls ?
A: No, sadly not yet, but it is a planned feature.

Q: Can you show me an example of how to setup a collision shape for my level ?
A: If you use 1 mesh for your whole level, like I do for the demos, then it's as easy as this:

Code: Select all

		Ogre::Entity* ground = mSceneMgr->createEntity("ground", "Level.mesh");
		Ogre::StaticGeometry *sg = mSceneMgr->createStaticGeometry("Level");
		const int size = 1300;
		sg->setRegionDimensions(Ogre::Vector3(size));
		sg->setOrigin(Ogre::Vector3(-size/2, 0, -size/2));
		sg->addEntity(ground, Ogre::Vector3::ZERO);
		sg->build();

		// Create the collision shape and rigid body of our level.
		hkpBvTreeShape* groundShape = HkOgre::Cooker::processOgreMesh(ground);
		hkpRigidBodyCinfo ci;
		ci.m_shape = groundShape;
		ci.m_motionType = hkpMotion::MOTION_FIXED;
		ci.m_position = hkVector4( 0.0f, 0.0f, 0.0f );
		ci.m_qualityType = HK_COLLIDABLE_QUALITY_FIXED;
		hkpRigidBody* groundBody = new hkpRigidBody(ci);

		mWorld->markForWrite();
		// Add the ground geometry to the physical world.
		mWorld->addEntity(groundBody)->removeReference();

		// Remove the reference to our physical
		// shape because it's unneeded.
		groundShape->removeReference();
		mWorld->unmarkForWrite();
- For notes on how to use static geometry and what it does, refer to the 5th Intermediate Tutorial on the wiki.

Q: Where can I find the demos and HkOgre itself ?
A: HkOgre is currently hosted on a BitBucket repository. You can grab the code for the demos and HkOgre from there and compile them yourself.
The pre-compiled version of the demo can be downloaded from my MediaFire folder which holds all my contributions for OGRE.

Q: Will you write any tutorials apart from the demos ?
A: Quite possibly, yes. I like using OGRE and Havok, I'll probably write a simple "Getting Started" tutorial very soon.

Q: The source code is not pretty. (Well documented or well-organized). Are you going to prettify it ?
A: Yes, as soon as possible.

Q: Generating collision meshes at runtime is slow - isn't there a tool to make them beforehand ?
A: If you have 3DS Max, Maya, or Softimage XSI available, Havok provides the needed tools to export stuff. But as I don't I'm going to write a .mesh to hkt/hkx converter soon.

Q: What is the license ?
A: HkOgre itself is licensed under the MIT license, like OGRE. So whatever terms apply to OGRE, the same goes for HkOgre too. The demos and resources are an exception. The demos and my original artwork are licensed under the WTFPL, while some of the individual resources, like the Lancer Evolution (vehicle used in the vehicle demo) and some of the textures used in the level are under their own licenses, each of which and the credit they require are included in the distribution.

Q: Which version of Havok do I need to use with HkOgre ?
A: I faced some problems with the regular one, so for now use the noSIMD version.
Update: drwbns found a workaround for this. Just add "HK_CONFIG_SIMD=1" (no quote marks) to your Preprocessor Definitions, and you shouldn't have any problems with the regular, SIMD version.

Q: Where can I find the free version of Havok ?
A: Here: http://www.havok.com/try-havok

Q: I heard Havok isn't open source, what limitations are there ?
A: From Havok's website:
License Requirements:
Havok's Intel® sponsored free binary-only PC download can be used during development to evaluate, prototype, and commercially release any PC game. There are some basic licensing rules to follow:

PC titles sold for a retail value of less than $10.00 USD do not require a Havok distribution license to be executed.
PC titles sold for a retail value of more than $10.00 USD or more do require a Havok license to be executed but at no additional cost.
If you have any more questions that I failed to cover do ask and I'll try to answer them as soon as possible.

I'll most definitely write more demos in the future, as Havok has a whole lot of interesting ones.

Also, the vehicle demo is not perfect, because it currently utilizes a barebones vehicle using Havok's vehicle API (it has no wheels, just raycasts, so accuracy is far from it's best side).

TLDR:
-------------------------------------------------------------
What ?
Havok + OGRE = HkOGRE
License: Wrapper - MIT | Demos and Original Artwork - WTFPL

Where ?
Source Here | Precompiled Demos Here (As soon as they're uploaded)

How ?
Easy! Example (Or scroll up a bit)

-- I wanted to make the Q&A a bit more lighthearted, sorry if I went a bit over the top and made myself sound like a crappy salesman... :D
Last edited by Mind Calamity on Mon Aug 27, 2012 12:16 am, edited 4 times in total.
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
User avatar
Brocan
Orc
Posts: 441
Joined: Tue Aug 01, 2006 1:43 am
Location: Spain!!
x 8

Re: Havok integration for OGRE - HkOgre + 2 & 1/2 Demos

Post by Brocan »

Great!! good work!! :D :D
User avatar
saejox
Goblin
Posts: 260
Joined: Tue Oct 25, 2011 1:07 am
x 36

Re: Havok integration for OGRE - HkOgre + 2 & 1/2 Demos

Post by saejox »

havok is very good.
but free version is essentially a trial.
they supply binaries only for visual studio 2010.

how many games these day target only win32?

last time i filled they sales inquiry form they didnt even respond,
i think they know i am to poor to be interested in their software :)
Nimet - Advanced Ogre3D Mesh/dotScene Viewer
asPEEK - Remote Angelscript debugger with html interface
ogreHTML - HTML5 user interfaces in Ogre
N_K
Greenskin
Posts: 115
Joined: Wed Dec 07, 2011 9:05 pm
x 4

Re: Havok integration for OGRE - HkOgre + 2 & 1/2 Demos

Post by N_K »

Awesome! We certainly need more BtOgre-style thin wrappers for all physics engines! :D

(I wanted to create one for Newton, but after about a week, I realized I fail at coding, so quickly abandoned the idea...)
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: Havok integration for OGRE - HkOgre + 2 & 1/2 Demos

Post by Mind Calamity »

Brocan wrote:Great!! good work!! :D :D
Thanks! :)
saejox wrote:havok is very good.
but free version is essentially a trial.
they supply binaries only for visual studio 2010.
I really don't have a problem with this for my project.
saejox wrote:how many games these day target only win32?
Probably quite a few indie games. ;)

You do know that in order to do console development you need to be (a part of) an established game development studio which has some quality games shipped within their portfolio. This isn't the case for some indies however.

Besides in the making of my engine, I'm trying to make sure that changing physics engines is really easy. (I'll probably include Bullet and Havok, alternatively PhysX and Havok).
saejox wrote:last time i filled they sales inquiry form they didnt even respond,
i think they know i am to poor to be interested in their software
They probably go along with the console requirements - (be a part of) an established game development studio with shipped titles.
N_K wrote:Awesome! We certainly need more BtOgre-style thin wrappers for all physics engines! :D
Thanks! :)
N_K wrote:(I wanted to create one for Newton, but after about a week, I realized I fail at coding, so quickly abandoned the idea...)
Maybe you should try it a few months later. The same thing happened with my work on this thing August 2011, I tried making a wrapper for Havok and failed miserably after a week or so. It's amazing how much you can learn in just a few months. ;)
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
User avatar
areay
Bugbear
Posts: 819
Joined: Wed May 05, 2010 4:59 am
Location: Auckland, NZ
x 69

Re: Havok integration for OGRE - HkOgre + 2 & 1/2 Demos

Post by areay »

Nice work mate
User avatar
rafael2468
Gnoblar
Posts: 10
Joined: Wed Mar 07, 2012 12:03 pm

Re: Havok integration for OGRE - HkOgre + 2 & 1/2 Demos

Post by rafael2468 »

Thanks a lot friend :P . I can't wait to back to home and start messing around with havok and ogre. I'll use it for my project no. 2 so I can pass my exams ;)
User avatar
duststorm
Minaton
Posts: 921
Joined: Sat Jul 31, 2010 6:29 pm
Location: Belgium
x 80

Re: Havok integration for OGRE - HkOgre + 2 & 1/2 Demos

Post by duststorm »

Very nice work :) Shame I didn't notice this any earlier.
It's great to have so many integration examples available for Ogre with other libraries. This makes Ogre a more interesting option for potential users.
Developer @ MakeHuman.org
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: Havok integration for OGRE - HkOgre + 2 & 1/2 Demos

Post by Mind Calamity »

areay wrote:Nice work mate
Thanks! :)
rafael2468 wrote:Thanks a lot friend :P . I can't wait to back to home and start messing around with havok and ogre. I'll use it for my project no. 2 so I can pass my exams ;)
I'm glad it can be of use to someone. :) If you run into any problems, or have any suggestions - post here I'll get on to them as soon as possible.
duststorm wrote:Very nice work :) Shame I didn't notice this any earlier.
It's great to have so many integration examples available for Ogre with other libraries. This makes Ogre a more interesting option for potential users.
Thanks, duststorm. Yeah, since I found Havok I've been drooling over the vast amount of samples it had, and how good they looked, I wanted to use it at the time, but, unfortunately no usable integrations (by my standards at the time) were available, so I decided to roll my own. And I agree, the more options OGRE has, the more attractive it is to potential users.

As soon as I get the time I'm going to add physics to your Detour/Recast demo, and see how good it looks (I expect it to look pretty nice). Also, thanks a lot for the terrain code, I only have it partially working at this point. When I get the time I'll come back to this.
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
drwbns
Orc Shaman
Posts: 788
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California
x 24

Re: Havok integration for OGRE - HkOgre + 2 & 1/2 Demos

Post by drwbns »

I get an error when running the precompiled demo. I'm using Ogre 1.7.3

Code: Select all

---------------------------
hkogrecharacterdemo.exe - Entry Point Not Found
---------------------------
The procedure entry point ?setAutoTracking@Camera@Ogre@@QAEX_NQAVSceneNode@2@ABVVector3@2@@Z could not be located in the dynamic link library OgreMain.dll. 
---------------------------
OK   
---------------------------
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: Havok integration for OGRE - HkOgre + 2 & 1/2 Demos

Post by Mind Calamity »

Did you replace the OgreMain.dll with your own version ? Either that, or you have a location which contains another OgreMain.dll in your PATH environment variable, and the demo is trying to use that one instead.
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
drwbns
Orc Shaman
Posts: 788
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California
x 24

Re: Havok integration for OGRE - HkOgre + 2 & 1/2 Demos

Post by drwbns »

You mean the precompiled demo is supposed to have ogremain.dll? Mine doesn't have it and I'm using the Ogre 1.7.3 SDK and there are no other paths with OgreMain.dll in my PATH variable.
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: Havok integration for OGRE - HkOgre + 2 & 1/2 Demos

Post by Mind Calamity »

I just downloaded it, and tested it out, no problems here. Just unpack and run any of the 3 executables.

Are you sure you're using the precompiled demos from here, and are not compiling them yourself ? (I may have misunderstood, in which case you have a problem with your OGRE setup).
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
drwbns
Orc Shaman
Posts: 788
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California
x 24

Re: Havok integration for OGRE - HkOgre + 2 & 1/2 Demos

Post by drwbns »

Yeah, I downloaded that one, but I'm rebuilding Ogre because I don't see any reason why my OgreMain.dll should be missing that function. I'll post back if I have any problems. Nice work btw. :)
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: Havok integration for OGRE - HkOgre + 2 & 1/2 Demos

Post by Mind Calamity »

Thanks, but still... Why are you rebuilding OGRE ? You shouldn't even need OGRE to try the precompiled demos as I've included my own dll in the archive. Are you perhaps compiling the demos yourself ?
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
drwbns
Orc Shaman
Posts: 788
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California
x 24

Re: Havok integration for OGRE - HkOgre + 2 & 1/2 Demos

Post by drwbns »

Oh ok, Norton was automatically deleting the files because no reputatuion :) lol. Thanks
drwbns
Orc Shaman
Posts: 788
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California
x 24

Re: Havok integration for OGRE - HkOgre + 2 & 1/2 Demos

Post by drwbns »

Ok I demo'd them and wow. Havok is so much better than PhysX. Maybe it's just the feel of it, but it seems much more realistic. Great job!

Edit: I tried the Terrain demo and at first the physics were normal. On the 2nd and third time I ran it, the balls would fall through the terrain. Any idea what happened?
drwbns
Orc Shaman
Posts: 788
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California
x 24

Re: Havok integration for OGRE - HkOgre + 2 & 1/2 Demos

Post by drwbns »

Missing header in vehicleUtils.h-

Code: Select all

#include <Graphics/Raycast.h>
Also, I had to add the preprocessor command "HK_CONFIG_SIMD=1" to get it to link without error
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: Havok integration for OGRE - HkOgre + 2 & 1/2 Demos

Post by Mind Calamity »

drwbns wrote:Missing header in vehicleUtils.h-

Code: Select all

#include <Graphics/Raycast.h>
Sorry about that, I included the file and pushed the changes to the repository. Pull them and it should work.
drwbns wrote:Also, I had to add the preprocessor command "HK_CONFIG_SIMD=1" to get it to link without error
I mentioned that in the FAQ. I didn't manage to fix the linking errors, so I gave up and used the noSIMD version. I'll include your workaround in the FAQ. Thanks a lot. :)
drwbns wrote:Ok I demo'd them and wow. Havok is so much better than PhysX. Maybe it's just the feel of it, but it seems much more realistic. Great job!
Thanks! :)
drwbns wrote:Edit: I tried the Terrain demo and at first the physics were normal. On the 2nd and third time I ran it, the balls would fall through the terrain. Any idea what happened?
Now you know why the title says 2 & 1/2 (two and a half) demos. :D

The terrain collision code is not finished yet. (I haven't had time to get back to this yet.)
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
drwbns
Orc Shaman
Posts: 788
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California
x 24

Re: Havok integration for OGRE - HkOgre + 2 & 1/2 Demos

Post by drwbns »

Oh ok, one more strange bug when running the debug version of the characterdemo built from source - I get an exception after createScene is called -

Code: Select all

Unhandled exception at 0x770e15de in HkOgreCharacterDemo.exe: 0xC0000005: Access violation reading location 0x00000000.
and if I hit continue...

Code: Select all

Unhandled exception at 0x770e15de in HkOgreCharacterDemo.exe: 0x00000000: The operation completed successfully.
Looking at the call stack shows mCharCtrl is 0xCCCCCCCC -

Code: Select all

mCharCtrl = new DemoCharacterController(mCamera, mWorld);
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: Havok integration for OGRE - HkOgre + 2 & 1/2 Demos

Post by Mind Calamity »

I'll check it out, probably some uninitialized pointer in the character demo.

Update: I just tried it, no exception here. Did you modify anything ?
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
drwbns
Orc Shaman
Posts: 788
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California
x 24

Re: Havok integration for OGRE - HkOgre + 2 & 1/2 Demos

Post by drwbns »

Nope, Just tried to build it. It runs fine in release mode though. BaseApplication Object ends up as 0x00000000 too. I think it's something to do with SIMD, I'm going to try the havok without SIMD

UPDATE: Havok without SIMD allows Character demo to run fine in debug mode :)

But I found anouther bug - Hitting ctrl on the keyboard crashes the characterDemo...
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: Havok integration for OGRE - HkOgre + 2 & 1/2 Demos

Post by Mind Calamity »

drwbns wrote:Nope, Just tried to build it. It runs fine in release mode though. BaseApplication Object ends up as 0x00000000 too. I think it's something to do with SIMD, I'm going to try the havok without SIMD

UPDATE: Havok without SIMD allows Character demo to run fine in debug mode :)

But I found anouther bug - Hitting ctrl on the keyboard crashes the characterDemo...
Yeah... That's the code to make the character crouch. It worked at one point. I'll fix it up in the next few days ;)

It's as simple as replacing the collision shape with a smaller capsule. :)
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
drwbns
Orc Shaman
Posts: 788
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California
x 24

Re: Havok integration for OGRE - HkOgre + 2 & 1/2 Demos

Post by drwbns »

Nice :) Where did you read up on how to integrate havok? Is there a guide or did you just read the api?
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: Havok integration for OGRE - HkOgre + 2 & 1/2 Demos

Post by Mind Calamity »

The Havok Forums were helpful a lot, and utilizing a lot of Google Fu I managed to integrate it. The hardest part was the triangle collision shape building (due to the fact that I didn't know what vertex and index buffers were at the time). Also, make sure you read the manual when you get the time, it's essential. :)
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt