Hi guys, I'm using Havok with Ogre to develop a physics based platform game for a college project. One of the use cases is being able to pick up (via ray cast) a block from the scene and use it on a button to trigger an action. At the moment I have this working with the global castRay function, but the documentation says that the hkpShape's version is better for short rays.In a game we probably want to pick up items which are 20-50m away at a maximum, and we want to shoot objects which are 500m away. Should I change my item pick ups to hkpShape casts?
Raycasting: What is a short ray, and what is a long ray?
The difference between a short ray and long ray is almost entirely a performance issue: the longer the ray is the more objects it could potentially intersect which means Havok has to do more work. When a ray cast happens, it first does a broadphase check to see what objects could potentially get intersected, and then it does the individual ray-to-object intersection tests sorted by distance from the start of the ray. So limiting the number of potential objects to check can result in some pretty major performance wins. If the volume in which you want to do the intersection test is limited and known, then you could use a hkpPhantom--this allows you to define a volume and only the objects inside that volume are raycast against. In your case, you could attach the phantom to the character so that it keeps track of only what's around the character. See PhantomObjectDemo for more information (.\Demo\Demos\Physics\Api\Dynamics\Phantoms\PhantomObject\).
I don't think hkpShape::castRay is quite what you want because it doesn't take into account any of the other objects in the scene. But I dont have a really clear picture of what youre trying to accomplish, so if Im not answering your question, please give some more details on what exactly youre trying to do (e.g. are you using the mouse to pick up the object?).
Best regards,
--Joel
Scene View:http://twitpic.com/85nxgb
The boxes on the left can be picked up by left clicking on them, the brown cuboid on the right is a door activated when a block is dropped on a button(out of sight).
Picking Up Block:http://twitpic.com/85o363
Moving Onto Button:http://twitpic.com/85nt7q
The problem I'm having now is that I want the picked up cube to collide with other physics objects. But it passes through them. This happens because in the following code, I set the picked cube's position to a point in front of the camera. This results in fighting between Havok and my update.
In the player's update, if hehas a cube
Ogre::Vector3 up = mCameraSystem->GetCamera()->getUp(); up.normalise(); Ogre::Vector3 boxPos = mCameraSystem->GetCamera()->getDerivedPosition() + 10.0f * mCameraSystem->GetCamera()->getDerivedDirection() + up; // position the object 10 units away from the camera, mItem>getRigidBodyPtr()>setPositionAndRotation(UtilityFunctions::toHKVec(boxPos),hkQuaternion::getIdentity()); mItem->getRigidBodyPtr()->setLinearVelocity(hkVector4(0,9.81,0)); //don't want gravity applied.Block Can Be Pushed Through Physics Objects such as the floor plane and other cubes :http://twitpic.com/85nvtc Once I release the cube, everything is fine as Im no longer fighting with Havok. The camera is set to the character controller's position. Visual Debugger Shows The Cube's rigid body is moving with the camera. http://twitpic.com/85nrsk Any ideas, how I can have Havok handle collisions, while still getting to position my cube outside of the simulation.



