Creating a new hkpCollisionAgent

Creating a new hkpCollisionAgent


I'm currently writing code to add a new shape to Havok detection collision system. Along with a new hkpShape class, I must also write several hkpCollisionAgent to handle the collision between my new shapes and other Havok shapes.

However, the documentation seems poor on this topic, and I'm not sure where to start from. Is there some code in the demo or available somewhere that demonstrates the definition of a new hkpcollisionAgent ?

Thanks in advance !!


8 posts / novo 0
Último post
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.

Hi _loeiz_,

Unfortunately creating new user shapes not well documented. While it is possible to extend Havok collision detection with custom shape types and collision agents, it's not easy and only recommended for advanced users with access to level 2 source.

What is your use case for needing a new shape type? If at all possible, it is much easier to use an existing shape type. For reference, which version of Havok are you using?
- Tyler

Hi Tyler, and thank you for the answer.

In the context of a reasearch project, we are working on a new type of collision detetction structures. Our idea was to leverage Havok broadphase, agent collision system and constraint solver (this would save use a lot of time, and a guarantee of a fast and robust solver). I'm using version 6.6.0 of Havok, but I can update if needed. We are using an academic license, and we do not have access to level 2 code. But I guess it is possible to make it works without this access ?


Hi again,

Since I can not find any source code to start with, i may reformulate my need (I don't want to spend to much time on the integration of the new hkpCollisionAgent... Although it does not seem so difficult ?)

The other possibility for us is to manage the response by ourselves, but we need an efficient broadphase. The idea would be to use Havok for the broaphase and the time integration of our rigid bodies, and we manage the narrow phase and the contact response (Through the application of impulses on the bodies).

Does it sound reasonable ?

That said, if anyone has some code for the hkpCollisionAgent, I would appreciate :)

Thanks in advance,


Here's something to get you started with creating new collision agents.

Take a look athkpCollisionAgent.h You need to implement a newhkpCollisionAgent type for each pair of shapes. The main functions for you to implement are getPenetrations() and getClosestPoints(). You can derive off ofhkpIterativeLinearCastAgent in order to implement linearCast().

Next you need to register your agents with the collision dispatcher ( seehkpCollisionDispatcher.h ). Use registerCollisionAgent() to register the required functions (AgentFuncs). You will want to register the agent twice for symmetric handling of ShapeA vs ShapeB and ShapeB vs ShapeA - check outhkpSymmetricAgent to ease this.

Other than creating the new shape type, those are the main steps.I'll try and get back to you with more details soon.

Hi Tyler,

Thanks for your advices.

We actually managed to make things to work creating new shape and collision agents. The curious thing is that we re implemented agetPenetrations() andgetClosestPoints() functions, but they are never called. Is that normal ? -by the way, we updated to the last version of Havok.

The only function called is processCollision, which provides the collision points data.

It kind of work, but the behavior of the colliding bodies is sometimes strange. This is due of course of the way we compute the collision points position and normal (we still have to improve this part), but also I guess we do something wrong during the processCollision call. For example, should the process collision add the contact points at each frame, or not ? also, should we remove the contact points in some way at some time ?

The first simulation works well, but when we reposition the bodies back to their initial position, and launch again the simulation, the bodies act as if they were in contact somewhere, event if they are not colliding with any other body.

Thanks in advance for your answer,


Best Reply

Hey Loeiz,

I'm glad to hear you've got things going!

The short answer is getPenetrations() and getClosestPoints() are used by other, usually user-driven, query functions and are not necessarily called during collision detection.

should the process collision add the contact points at each frame, or not ?

This is actually up to you, but you should be aware that contact points are cached internally. This way an agent can detect if a contact point is being added, removed or modified. It also means your algorithm can detect contact points iteratively over multiple passes, picking up only say 1 or 2 contacts per frame. When you use hkpContactManager::addContactPoint() it returns back an hkContactPointId for that contact point. You want to store on to these ids in the agent so later you can remove them with removeContactPoint().

should we remove the contact points in some way at some time

Yes! You want to implement the cleanup() function to remove all contacts that were added with addContactPoint(). cleanup() should also delete the agent ("delete this"). You should also remove contact points that were added in the previous pass but are no longer contacting this frame.

Like I said, how you implement adding, removing, or modifying contact points is up to you. The simplest options are to either ignore caching contact points by removing them all at the beginning of process and then add back any that you detect, or take advantage of hkpClosestPointManifold. If you want a <=4 point contact manifold then hkpClosestPointManifold will take care of managing the 4 closest contact points for you. I would recommend using this and not removing and re-adding contact points each frame except as a naive first-pass implementation.

To use hkpClosestPointManifold you want to store a manifold in your agent. In processCollision() you can use your getClosestPoints() to pick up closests points, then add the closest points to the manifold via hkpClosestPointManifold::addPoint() and use hkpClosestPointManifold.getPoints() to copy the manifold points back in to the result. If no points are penetrating you can just remove all the points currently in the manifold. You can easily remove all contact points with this one-liner : hkpClosestPointManifold::cleanup( m_manifold.m_contactPoints, m_manifold.m_numPoints, m_contactMgr, info );

I hope this helps!
- Tyler

Hi Tyler,

Thank you for your precious advices. We managed to do a first naive implementation, removing all the previous points, and re-creating them at each frame, and it works well! It is impressive how stable are the solver responses even at this stage.

Thank you again.


Faça login para deixar um comentário.