Deriving a hkpMoppAgent

Deriving a hkpMoppAgent

Hello,

For a research project I need to derive the hkpMoppBvTreeShape and hkpMoppAgent. I previously managed to derive a hkpSphereShape and hkpSphereBoxAgent successfully, but with the specific case of MOPP shapes I am encountering some difficulties. Specifically, the collisions are correctly handled when my custom MOPP shape collides with another shape, but not the other way around.

The constructor of my custom shape simply calls that of hkpMoppBvTreeShape and same goes for the custom agent with the hkpMoppAgent. I created a static function to create a new custom agent that goes like this :

hkpCollisionAgent* HK_CALL CustomAgent::createCustomAgent(const hkpCdBody& collA, const hkpCdBody& collB, const hkpCollisionInput& env, hkpContactMgr* mgr)
{
    return new CustomAgent(mgr);
}

I set my custom shape as hkcdShapeType::USER1, and when I create my world, I register my custom agent this way :

hkpCollisionDispatcher::AgentFuncs f;
f.m_createFunc = CustomAgent::createCustomAgent;
f.m_isPredictive = true;
f.m_isFlipped = true;

m_world->getCollisionDispatcher()->registerCollisionAgent(f, hkcdShapeType::USER1, hkcdShapeType::ALL_SHAPE_TYPES);
m_world->getCollisionDispatcher()->registerCollisionAgent(f, hkcdShapeType::ALL_SHAPE_TYPES, hkcdShapeType::USER1);

What is it that I'm missing ?

Thanks in advance,

Anthony

5 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.
Bild des Benutzers havok_joe

Hi Anthony:

You need to create a symmetric version of the "createCustomAgent" function to handle your "another shape vs custom MOPP shape" collision.
You can use hkpSymmetricAgent template.

For example:

hkpCollisionAgent* HK_CALL CustomAgent::createCustomAgentS(...)
{
return new hkpSymmetricAgent(...);
}

hkpCollisionDispatcher::AgentFuncs f;
f.m_createFunc = CustomAgent::createCustomAgent;
f.m_isFlipped = false;
f.m_isPredictive = true;
m_world->getCollisionDispatcher()->registerCollisionAgent(f, hkcdShapeType::USER1, hkcdShapeType::ALL_SHAPE_TYPES);

f.m_createFunc = CustomAgent::createCustomAgentS;
f.m_isFlipped = true;
m_world->getCollisionDispatcher()->registerCollisionAgent(f, hkcdShapeType::ALL_SHAPE_TYPES, hkcdShapeType::USER1);

By the way, for MOPP agent, you still need to register a agent for MOPP vs MOPP collision. You can directly use hkpMoppAgent::createBvBvAgent.

Cheers

Joe

Joe Developer Support Engineer Havok www.havok.com

Hi Joe,

Thanks for your answer, now I understand better how it is all supposed to work. I am still encountering difficulties though, as now my custom shape doesn't collide with anything at all. Following your post, I created a symmetric agent creation function like this :

hkpCollisionAgent* HK_CALL CustomAgent::createCustomAgentS(const hkpCdBody& collA, const hkpCdBody& collB, const hkpCollisionInput& env, hkpContactMgr* mgr)
{
return new hkpSymmetricAgent( collA, collB, env, mgr );
}

I also registered the function in the dispatcher just like in your post. However, the hkpSymmetricAgentLinearCast function requires a constructor for my custom agent with all four arguments, but all hkpCollisionAgents only have one constructor which only takes the hkpContactMgr* as argument. I thus created a constructor for my custom agent with all four arguments that calls hkpMoppAgent( mgr ). Could this be the source of the problem ? If so, how do I get around it ?

Thanks in advance,

Anthony

Bild des Benutzers havok_joe

Hi Anthony:

If you check Source\Physics\Collide\Agent\Util\Symmetric\hkpSymmetricAgentLinearCast.h , you should find there is a constructor which just take hkpContractMgr. And I think your custom agent is inherit from hkpMoppAgent, is it correct? You should be able to call:

new hkpSymmetricAgent<CustomAgent>( mgr );

in your Symmetric version create agent function. And I've checked our hkpMoppAgent code. It seems: for normal version collA = ALL_SHAPE_TYPES, collB = MOPP.
So can you try to switch the order ?


f.m_createFunc = CustomAgent::createCustomAgent;
f.m_isFlipped = false;
m_world->getCollisionDispatcher()->registerCollisionAgent(f, hkcdShapeType::ALL_SHAPE_TYPES,hkcdShapeType::USER1);

f.m_createFunc = CustomAgent::createCustomAgentS;
f.m_isFlipped = true;
m_world->getCollisionDispatcher()->registerCollisionAgent(f, hkcdShapeType::USER1, hkcdShapeType::ALL_SHAPE_TYPES);

By the way, you need to prepare the symmetric version for all the function in hkpCollisionDispatcher::AgentFuncs

Cheers

Joe

Joe Developer Support Engineer Havok www.havok.com

Hi Joe,

Many thanks for your help, now it all works like a charm !

Cheers

Anthony

Melden Sie sich an, um einen Kommentar zu hinterlassen.