Havok and OpenGL

Havok and OpenGL

I am trying to make a scene with openGL + glut. Maybe make just a plain floor and some boxes or spheres falling with physics or something to see that it is working. I don't know how to get started. All havok demoes are strange, or working with directx. I want simple openGL glut and only add physics to objects created with glut or know how to create object with havok and add them to the scene drawn by openGL. 

Any help would be apprechiated.

8 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

Hi Krisboss,

It may be best to understand getting just Havok and some physics setup in an applcation before rendering it with OpenGL.

The Quickstart Guide in the Docs folder (where you unzipped the Havok package) would be a good place to start to make sure you can get the Havok Demos building & running.

The "MemoryUtilInit" project (Demo/StandAloneDemos/StepByStep/MemoryUtilInit) shows you how to get Havok set up and then the "ConsoleExampleMt" project (Demo/StandAloneDemos/ConsoleExampleMt) introduces an actual physics world with physics objects (and the visual debugger).

Once your happy that Havok is working in your application, the function hkpGeometryConverter::appendGeometryFromRigidBody(...) is a utility which creates geometry from a single rigid body. This function will give you a hkGeometry structure which should contain the triangle/vertex data (see hkGeometry.h) you need to pass to OpenGL.

If you have any more questions just let me know.

Amy Developer Support Engineer Havok www.havok.com

I tried many demoes. Yes I can compile them with visual studio 2010 and all looks like working fine. I try to render something from the ConsoleExampleMt. It works in visual debugger but I want to see it in glut openGL window. I tried copying main to new function and then calling it in display function of openGL but it has a loop that stops my openGL window in place, but if I remove the loop it crashes the application and causes me to brake. 

I wanted to draw maybe a sphere with glutSolidSphere and get the position and rotation from the g_ball in ConsoleExampleMt but I don't know how.

I don't know how to update and display something that is in havok to the openGL window.

Hi Krisboss,

Firstly, you must keep in mind that the physical world that Havok simulates and the graphical world that OpenGL renders are two distinct things. You cannot conceptually draw the physical objects in Havok, instead you use the positions and rotations calculated by Havok for rigid bodies to position the corresponding graphical objects in the world seen by OpenGL. Then each time you update the application, you "step" the physics world so you can get the new positions for your graphical objects in the next frame.
If this still isn't clear, have a look at this post: http://software.intel.com/en-us/forums/topic/278673 It walks you through creating a very simple game using Havok physics and will hopefully help you understand how the physics and graphics talk to each other.

1) What exactly is the crash you are getting?

2) Are you talking about the for loop at line 297? The main() function in ConsoleExampleMt sets up Havok with some physics then uses that for loop (at line 297) to simulate a game's update loop for 60sec, then Havok is shut down and the application exited.
So everything before that for loop should be done when you initialise OpenGL and everything after it should be done when you shut down OpenGL. The contents of that for loop can then be placed in your OpenGL update loop (the function passed to glutIdleFunc if I remember OpenGL correctly).

3) To answer your question about getting the position of g_ball, you can get the position/rotation (as well as many other properties) of a rigid body by calling getPosition()/getRotation() on that body. Have a look at hkpRigidBody.h and Section "2.2.1.2 Rigid Bodies" of the User Guide in the Docs to see what other properties you might want to access.
Note: getRotation will return a hkQuaternion, but you should be able to use the getAngle() and getAxis() functions to get something (in radians) you can use with glRotate.

Amy Developer Support Engineer Havok www.havok.com

I found this tutorial: http://software.intel.com/en-us/forums/topic/278673 and it's great to start with. I still need to figure out many things but it helps a lot.

Hi Krisboss,

Glad to hear that tutorial is helping. Let me know if you have anymore questions.

Amy Developer Support Engineer Havok www.havok.com

Ok now as I know how to render something with OpenGL I would like to make a car that I can control and drive on some simple terrain.

I know how to make the terrain but how to make the vehicle in havok world? After creating that car there I probably need only to transfer position and rotation of chassis and wheels but I don't know how to make it in the havok world. The VehicleAPI demo probably is the simplest but I don't get it. What I need in my code from it to work?

Hi Krisboss,

The code you'll need is mixed up with the DemoFramework code in VehicleApiDemo.cpp, so it's difficult to say exactly which sections of code from you'll need from it. Hopefully this will help though.

1a)The hkpVehicleInstance which the VehicleApiDemo uses to simulate a vehicle is just a type of hkpAction (like wind or a motor, but more complicated), which has a rigid body chassis associated with it. However it doesn't have rigid bodies for wheels, see "Wheel collision detection" in the User Guide for why it doesn't.

1b)The section titled "Integrating Havok Vehicles into your game" in the User Guide gives a list of the steps required to set up a vehicle in your game & you should be able to find where each of these steps are done in VehicleApiDemo.cpp. (Some of the helper functions used in that file can be found in Demo\Demos\DemoCommon\Utilities\VehicleApi).

2)Once the hkpVehicleInstance is added to the physics world it'll be updated automatically but you'll need to decide what input to give it in order to drive it (the VehicleApiDemo uses a helper function VehicleApiUtils::steer(...) if you need an example of this).

3)When it comes to drawing, the chassis of the vehicle should be a simple rigidbody & can be accessed using hkpVehicleInstance::getChassis(). For the wheel positions, hkpVehicleInstance::calcCurrentPositionAndRotation(...) should be what you're looking for (see syncDisplayWheels(...) in VehicleApiUtils.cpp for an example of it being used).

Glad to hear you got Havok with OpenGl up and running. If you have anymore questions let me know (but maybe in a new post with a new title so other users can search the forum a bit easier) :)

Amy Developer Support Engineer Havok www.havok.com

Laisser un commentaire

Veuillez ouvrir une session pour ajouter un commentaire. Pas encore membre ? Rejoignez-nous dès aujourd’hui