Creating hkpCollidable for linearCast/getPenetrations

Creating hkpCollidable for linearCast/getPenetrations


I'm using the linearCast/getPenetrations functions. Its first argument is an hkpCollidable object. However the input shapes are gameplay-related objects unrelated to Havok (i.e. they don't exist as Havok objects in the game code), so I don't have ready-to-use hkpCollidable objects for them.

I can't pre-create those hkpCollidable objects either, since most of them are created on-the-fly anyway, during the game.

So I am currently creating rigid bodies on-the-fly, just to access its hkpCollidable. Something like this:

    const hkpSphereShape SphereShape(sphere.mRadius);

    hkpRigidBodyCinfo ci;
    ci.m_shape        = &SphereShape;
    ci.m_motionType    = hkpMotion::MOTION_FIXED;
    ci.m_rotation    = hkQuaternion(0.0f, 0.0f, 0.0f, 1.0f);
    ci.m_position    = ToHkVector4(sphere.mCenter);
    hkpRigidBody rigidBody(ci);

    mPhysicsWorld->linearCast(rigidBody.getCollidable(), input, castCollector);

Is there a better way to do this? This looks both inefficient and weird (after all I don't need a "rigid body" here, just a shape really).


3 post / 0 nuovi
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione
Ritratto di HavokTim

Hi Pierre--

You can create a collidable directly; it's neither necessary nor desirable to create a rigid body to perform the cast. There's an example of doing this in the ShapeQueryDemo - look for buildQueryObects() in ShapeQueryDemo.cpp. You can see the basic idea in the snippet below:

hkpSphereShape shape(sphere.mRadius);
hkTransform transform(rotation, position);
hkpCollidable query(&shape, &transform);
mPhysicsWorld->linearCast(&query, input, castCollector);

Please let me know if you have any trouble getting this to work - thanks!


Thanks! It works and it makes a lot more sense now.

Accedere per lasciare un commento.