glut + Havok? how to start with Havok...?

glut + Havok? how to start with Havok...?

1000devilsinthejar's picture

Hi everyone :-)

First of all, thanks for a possibility to play with Havok just for
free, I think this is a great thing for all of computer graphics
enthusiasts :-)

I have been working on kind of academic research, trying to compare
different Physics Engines. I am to write similiar application -
simulating massive number of objects' collisions - under Havok, PhysX
and ODE. Being honest, PhysX (release done by AGEIA, not nVidia) comes
with great "Training Programs" tutorials and with ODE also I had no big
problems. And now.... I am stucked on Havok ;-) This is kind of
different.... But getting to important things: I would like to
integrate it with glut - I would like glut (and OpenGL) to do rendering
and from Hkp only get results from simulation, e.g. rigid bodies'
positions. So first: is this possible? (I suspect that it is.. but who
knows... ;-) ).

The second - more general question - how to actually start? I know, I
know that there is this demo thing, which is kind of confusing at first
glance, besides I guess it is integrated with D3D rather then OGL. So I
started to do things like they say in Documentation, but there also -
problems. I am pretty sure I did like they say there but here are some
problems:

when I try to make a step in simulation:

- Warning: 'Severe performance and stability warning: The stack
size in hkMemory is insufficient to solve the current constraint
system. Allocating from system memory. This can fragment your memory.'
.. and this despite I am allocating stack of size of 512 MB
(setStackArea() method)

- Warning: 'The system has requested a heap allocation on stack
overflow. The requested size is 8208 and the allocated size is
536870912 This can lead to large slowdowns. To fix this, you should
call hkThreadMemory::setStackArea() with larger buffer. [... ] ' ...
and this is printed when m_world->removeReference() is being called.

This is how I initialize Havok:

void InitHkp() {

int stackSize = 512 * STACK_1MB;


hkMemory* memoryManager = new hkPoolMemory();

hkThreadMemory threadMemory(memoryManager);

hkBaseSystem::init(memoryManager, &threadMemory, PrintError);

char* stackBuffer = hkAllocate(stackSize, HK_MEMORY_CLASS_BASE);

threadMemory.setStackArea(stackBuffer, stackSize);


//hkThreadMemory::getInstance().setStackArea(stackBuffer, stackSize);

memoryManager->removeReference();


hkpWorldCinfo info;


#ifdef CONTINUOUS_PHYSICS

info.m_simulationType = hkpWorldCinfo::SIMULATION_TYPE_CONTINUOUS;

#else

info.m_simulationType = hkpWorldCinfo::SIMULATION_TYPE_DISCRETE;

#endif

info.m_gravity = gDefaultGravity;

info.m_collisionTolerance = C_TOLERANCE;

info.setBroadPhaseWorldSize(gWorldSize);

info.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_ASSERT;

info.m_enableDeactivation = false;

info.setupSolverInfo(hkpWorldCinfo::SOLVER_TYPE_4ITERS_MEDIUM);


world = new hkpWorld(info);


&nbsp
; hkpAgentRegisterUtil::registerAllAgents(world->getCollisionDispatcher());

}

this is how I run the simulation: world->stepDeltaTime(gDeltaTime);

and finally release resources:



world->removeReference();

world = HK_NULL;

hkBaseSystem::quit();
I'd be tremendously grateful for all help.
Actually I dream of little stand-alone app, that would do some kind of
simulation and don't argue with graphics engine...

Sorry for such a long post and I hope that I haven't offended anyone
mentioning other technologies. If I did - I'm sorry - just let me know.

Thanks, I'm waiting for reply.


9 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
havokchris's picture

Hi!

1000devilsInTheJar: I would like glut (and OpenGL) to do rendering
and from Hkp only get results from simulation, e.g. rigid bodies'
positions. So first: is this possible? (I suspect that it is.. but who
knows... ;-) ).



Yes, that's definitely possible, and in fact, it's the recommended approach. After you step the world, you can query all the rigid bodies for their positions (and rotations) with hkpRigidBody::getTransform().

1000devilsInTheJar: I know, I
know that there is this demo thing, which is kind of confusing at first
glance, besides I guess it is integrated with D3D rather then OGL.



You should be able to run the demos in OGL mode by adding "-r opengl" to the command line. In the main SDK (anything that's not in the demos folder or starting with hkg) there's no tie to any particular graphics system.

As for your problems, I think it's (at least in part) because of this line:
1000devilsInTheJar: hkThreadMemory threadMemory(memoryManager);


The hkThreadMemory here is a local variable, so as soon as you leave InitHkp, it will be invalid, but the base system keeps a pointer to it. That's bad :) It's OK in our demos, because everything happens in one function.

Instead, you probably want this:
hkThreadMemory* threadMemory = new hkThreadMemory(memoryManager);
But don't forget to keep the pointer so you can delete it later.

Hope that helps...

-Chris
lucearse's picture

i have kind of the same problem, i can't start creating anything even a human.everything i go into is just writing.i need as much help as possible.

1000devilsinthejar's picture



>As for your problems, I think it's (at least in part) because of this line:



>> 1000devilsInTheJar:

>> hkThreadMemory threadMemory(memoryManager);



>The hkThreadMemory here is a local variable, so as soon as you
leave InitHkp, it will be invalid, but the base system >keeps a
pointer to it. That's bad :) It's OK in our demos, because
everything happens in one function.

>Instead, you probably want this:

> hkThreadMemory* threadMemory = new hkThreadMemory(memoryManager);

>But don't forget to keep the pointer so you can delete it later.



Yes, that was exactly wat I needed! Thanks a lot! And sorry for incompetence... :)

Now I have a properly working simulation, integrated with glut and
rendering in OpenGL and I'm on my way to do my collision detection
experiment. Once again, thanks a lot for your help and keep on doing
great job with Havok!

________

Konrad

havokchris's picture

No worries, you're not the first person that I've seen do that :)

Do we get to see any screenshots?

-Chris

1000devilsinthejar's picture

Hi Chris,

Yeah, why not :-) Actually it's nice to hear that you're interested...
So if you are, then maybe you would kinda contribute to it, ha? ;-)
However, I warn, that this post is relatively long and if anybody's
feeling like to read it and even to help, then I would surely
appreciate... And here's what I'm trying to do...

I've decided to "compare" some physics engines based on their ability
to perform Collision Detection. First I came up with an idea of
something more interactive that would include user input. So I wrote an
application doing the "telekinesis" thing - user could play with some
simple objects throwing them (collectively) at each other, doing some
"explosions", etc. This was real fun to write, but It appeared rather
unappropriate. Mainly, because there was not enough movement of objects
and not enough collisions. I could - potentially - increase number of
bodies, but then, on the other hand, it would be uncomfortable for
user. So I think rather of something more simulation-like than
game-like. There is so called "N Bodies Problem" and I've used this
idea. I've closed N identical bodies in a cubic vessel. I am
continuously applying force to each of them in the direction it is
moving, so they are always in the rush, bouncing off the vessel walls
and colliding with each other. Here's the simulation working under
Havok, I've made a simple movie and two screenshots to give you idea
(note that "shiny", nice graphics isn't the point here, so from this
side it doesn't look brilliant):



http://ds5.agh.edu.pl/~promyk/nBodies/



However, using CamStudio really slowed down a system. So, though you
see there only 100 boxes, the framerate is only bout 15 fps (or
something like this), while normally it would be 85 fps. Like I said -
just to give you idea...



So what am I trying to do? This "N Bodies" idea is the best thing I
have now, and I don't have much time to do major changes. However, it'd
be nice to somehow make it more interesting. Now I am going to change
shapes of bodies: also use balls (or spheres) as something simple and
rather complicated convex or even concave objects created with prepared
vertex data. Of course, there will be playing with objects' number and
size. It may be also interesting to see how the size of vessel
influences simulation.

Playing with these settings I'm going to observe: FPS (I guess, that's
the most important thing), CPU time usage and maybe memory usage
too. Of course, some eye-made observations will be important as well. I
tried also to count collisions (not collision points but collisions
between objects), but in Havok I have a problem with it. The callbacks
interface gives detailed information on every contact point. This
means, that I would have to have kind of register saving info on what
body collided with what other body - sort of inconvenient for me...
(Some other way here?)



Concluding, if you have any ideas how to make simulation more interesting, please share.

Thanks for reading this,

____________

Konrad


m.becker's picture

Hi!

I couldn't play the video (with my normal programs). Maybe you should use a more common codec like mpg, or wmv.

When you are doing an academic research you should first specify in !detail! what you want to evaluate.

Do you want to messure how fast each engine computes collisions between simple shapes (spere, cube), or betwen komplex ones? Do you want to messure collision betwen solid and deformable object? Do you want to use continuous collision detection or raycasting? Do you want to simulate liquids.......and so on!!!

You see, there is a vast number of possible things you can evaluate. First make yourselfe aware of the many features and optimisations along with them that the different engines posses.

After that specify what you want to evalutate. When you are done with that finding an appropriate simulation is much easier.

Greetings
Magnus

1000devilsinthejar's picture

Hi M.Becker!

It is a DivX codec and I created also a Shockwave Flash version if you
still want to see it. Actually you can get an idea from screenshots -
many boxes flying around, bouncing of each other.

Regarding my research, it is not that easy to "specify in !detail!"
what you want to do, when, actually, you are moving in an unknown area.
I mean, it is a research, and I can't be sure from the very start,
where it will take me and what is most interesting to study! Of course,
I started from reading physics engines' documentations as much as I
could and I got pretty good idea that studying collisions would be the
most interesting thing for me. I don't know if you've read what I wrote
in last post, but I stated there that I want to measure efficiency of
collisions of solid objects - both simple and complex ones. And I'm
definitely not interested in liquids or deformable objects :-)

In my last post I asked if anyone has an idea how to vary my experiment
and how to make it more interesting, but I didn't mean ideas like:
"maybe you should 'pour' there some liquid objects", but rather "try
tetrahedral objects" or "try flattened objects - this could create some
problems to physics engines" ...

Anyway, thanks for reply and good luck with your projects!

____________

Konrad


whugang's picture
Just gave my options. I found Irrlicht Engine gave the Integratation tuitor with ODE, PhysX ... physics engine, but I have not seen the Havk part, so little confused about it. At the same time, Havk does not gave users tuitor to render the results except in the demoframework, which confused me.

Login to leave a comment.