So for my next blog I decided to do some more Havok!
Here I will post how we plan to implement Phantom Triggers for our game. These are some notes I took while reviewing the havok demos on phantom events.
Here I will post how we plan to implement Phantom Triggers for our game. These are some notes I took while reviewing the havok demos on phantom events.
Can use: #include <common/visualize/hkDebugDisplay.h>
to display some collision based info
This is where all of the ‘magic’ for this demo takes place
and it all centres around the custom implementations of the two pure virtual
methods in the base class, namely phantomEnterEvent(…) and
phantomLeaveEvent(…). These methods notify us of an entry or exit event for the
phantom volume and most importantly the provide a reference to the collidable
that has penetrated the phantom. The pseudo code is below
Class MyPhantomShape:
public hkpPhantomCallbackShape
{
{
Public:
myPhantomShape(){}
//hkpPhantom interface
implementation
virtual void phantomEnterEvent(const hkpCollidable8 collidableA, const hkpCollidable* collidableB, const hkpCollisionInput& env)
{
//the color can only be changed once the entity has been added to the world
hkpRigidBody* owner = hkpGetRigidBody(collidableB);
//the “collidables” here are faked so its necessary to get the owner first in order to get the real collidable
//this is where the event code goes
}
virtual void phantomEnterEvent(const hkpCollidable8 collidableA, const hkpCollidable* collidableB, const hkpCollisionInput& env)
{
//the color can only be changed once the entity has been added to the world
hkpRigidBody* owner = hkpGetRigidBody(collidableB);
//the “collidables” here are faked so its necessary to get the owner first in order to get the real collidable
//this is where the event code goes
}
//hkpPhantom interface
implementation
virtual void phantomLeaveEvent(const hkpCollidable* collidableA, const hkpCollidable* collidableB)
{
//the color can only be changed once the entity has been added to the world
hkpRigidBody* owner = hkpGetRigidBody(collidableB);
//the “collidables” here are faked so its necessary to get the owner first in order to get the real collidable
//this is where the event code goes
}
virtual void phantomLeaveEvent(const hkpCollidable* collidableA, const hkpCollidable* collidableB)
{
//the color can only be changed once the entity has been added to the world
hkpRigidBody* owner = hkpGetRigidBody(collidableB);
//the “collidables” here are faked so its necessary to get the owner first in order to get the real collidable
//this is where the event code goes
}
}
//the reason why we call getOwner() on the original
collidable only to later call getCollidable() on the owner is that the
collidable passed by reference may be a ‘sub’ collidable of the rigid body,
perhaps a hkpTriangleShape belonging to a larger hkpMoppBvTreeShape.
Class PhantomEvents :
public hkDefaultPhysicsDemo (env, ERROR_FLAGS)
{
{
Public:
PhantomEvents(hkEnviroment* env)
{
//setup the camera
//create the world
//register the collision agents
hkpAgentRegisterUtil::registerAllAgents( m_world->getCollisionDispatcher() );
//create terrain
//create models/scenary
//below is the construction code for the phantom volume:
//creating a PHANTOM FLOOR
{
PhantomEvents(hkEnviroment* env)
{
//setup the camera
//create the world
//register the collision agents
hkpAgentRegisterUtil::registerAllAgents( m_world->getCollisionDispatcher() );
//create terrain
//create models/scenary
//below is the construction code for the phantom volume:
//creating a PHANTOM FLOOR
{
hkpRigidBodyCinfo
boxInfo;
hkVector4 boxSize( 4.0f,
1.5f , 2.0f );
hkpShape* boxShape = new
hkpBoxShape( boxSize , 0 );
boxInfo.m_motionType =
hkpMotion::MOTION_FIXED;
boxInfo.m_position.set(2.0f,
-4.0f, 0.0f);
//
MyPhantomShape is the demo implementation of the hkpPhantomCallbackShape.
MyPhantomShape*
myPhantomShape = new MyPhantomShape();
hkpBvShape* bvShape =
new hkpBvShape( boxShape, myPhantomShape );
boxShape->removeReference();
myPhantomShape->removeReference();
boxInfo.m_shape =
bvShape;
hkpRigidBody*
boxRigidBody = new hkpRigidBody( boxInfo );
bvShape->removeReference();
m_world->addEntity(
boxRigidBody );
//
the color can only be changed after the entity has been added to the world
HK_SET_OBJECT_COLOR((hkUlong)boxRigidBody->getCollidable(),
hkColor::rgbFromChars(255, 255, 255, 50));
boxRigidBody->removeReference();
}
}
}
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7ZW5DsTyNV1GDc4dff62BtVZ9YFo91LmHWSdawJduUnddmlwkdr8l4Fhzd1Xv2iylxljxkPamAzXLjIdvxJJik1xwJlN68QImnyg18-l5i8i9uCtKt5yQGPT_67UauGH824Tap1RKvZ4t/s320/green+ball.png)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiC2ZiM5mEipESBQ7HiTu6HZXHGQH7vxbard8hG40-wxssBZ98vswOVYK19gwjx_xYQ5KK1OoJRE6_qWVAcz3B1Pkbl_NeGvpuFRMukte0kqpFIKsBzbOvvR4wrHaUKVaQ1GcskVkBaKfsL/s320/red+ball.png)
So basically after making the phantom shape you use
it as the space for your phantom call back as the child shape. That volume is
fixed in space but is not restricted to be a dynamic object such as a moving
objective.
No comments:
Post a Comment