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

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

Post by Mind Calamity » Sun Jul 22, 2012 9:26 pm

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.
0 x
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!!

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

Post by Brocan » Sun Jul 22, 2012 10:49 pm

Great!! good work!! :D :D
0 x

User avatar
saejox
Goblin
Posts: 260
Joined: Tue Oct 25, 2011 1:07 am

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

Post by saejox » Mon Jul 23, 2012 12:18 am

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 :)
0 x
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

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

Post by N_K » Mon Jul 23, 2012 1:19 am

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

User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia

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

Post by Mind Calamity » Mon Jul 23, 2012 5:23 am

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. ;)
0 x
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: 814
Joined: Wed May 05, 2010 4:59 am
Location: Auckland, NZ

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

Post by areay » Mon Jul 23, 2012 9:48 am

Nice work mate
0 x

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 » Thu Aug 16, 2012 11:20 am

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 ;)
0 x

User avatar
duststorm
Minaton
Posts: 921
Joined: Sat Jul 31, 2010 6:29 pm
Location: Belgium
Contact:

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

Post by duststorm » Thu Aug 16, 2012 2:42 pm

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.
0 x
Developer @ MakeHuman.org

User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia

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

Post by Mind Calamity » Thu Aug 16, 2012 5:06 pm

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.
0 x
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: 777
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California

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

Post by drwbns » Fri Aug 17, 2012 4:21 pm

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   
---------------------------
0 x

User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia

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

Post by Mind Calamity » Fri Aug 17, 2012 5:06 pm

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.
0 x
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: 777
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California

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

Post by drwbns » Fri Aug 17, 2012 5:46 pm

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.
0 x

User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia

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

Post by Mind Calamity » Fri Aug 17, 2012 7:56 pm

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).
0 x
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: 777
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California

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

Post by drwbns » Sat Aug 18, 2012 4:36 am

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. :)
0 x

User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia

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

Post by Mind Calamity » Sat Aug 18, 2012 7:55 am

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 ?
0 x
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: 777
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California

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

Post by drwbns » Sat Aug 18, 2012 2:23 pm

Oh ok, Norton was automatically deleting the files because no reputatuion :) lol. Thanks
0 x

drwbns
Orc Shaman
Posts: 777
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California

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

Post by drwbns » Sat Aug 18, 2012 2:31 pm

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?
0 x

drwbns
Orc Shaman
Posts: 777
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California

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

Post by drwbns » Sun Aug 26, 2012 11:08 pm

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
0 x

User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia

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

Post by Mind Calamity » Mon Aug 27, 2012 12:13 am

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.)
0 x
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: 777
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California

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

Post by drwbns » Mon Aug 27, 2012 12:21 am

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);
0 x

User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia

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

Post by Mind Calamity » Mon Aug 27, 2012 12:53 am

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 ?
0 x
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: 777
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California

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

Post by drwbns » Mon Aug 27, 2012 2:05 am

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...
0 x

User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia

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

Post by Mind Calamity » Mon Aug 27, 2012 3:01 pm

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. :)
0 x
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: 777
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California

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

Post by drwbns » Mon Aug 27, 2012 6:57 pm

Nice :) Where did you read up on how to integrate havok? Is there a guide or did you just read the api?
0 x

User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia

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

Post by Mind Calamity » Mon Aug 27, 2012 10:56 pm

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. :)
0 x
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

Post Reply