Raycasting: What is a short ray, and what is a long ray?

Raycasting: What is a short ray, and what is a long ray?

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?

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

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,

Volume sounds a great idea, already using hkpPhantomShape for buttons so I get the general idea.I do have another problem though, first additional information.Scene View:http://twitpic.com/85nxgbThe 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/85o363Moving Onto Button:http://twitpic.com/85nt7qThe 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();

Ogre::Vector3 boxPos =	mCameraSystem->GetCamera()->getDerivedPosition() + 10.0f *  mCameraSystem->GetCamera()->getDerivedDirection() + up;  // position the object 10 units away from the camera,

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/85nvtcOnce 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/85nrskAny ideas, how I can have Havok handle collisions, while still getting to position my cube outside of the simulation.

Hi,The immediate problem here is forcing the position directly outside the physics step like you said. The approach you want to take instead is to apply an impulse or force such that the box will move to the point you want within the next frame. I see you're already modifying the velocity, so you could just add to that :linearVelocity += ( boxPos - boxCurrentPos ) / timeDeltaThat said, the best thing to do here would be to encapsulate this behavior inside an hkpAction (Docs: Havok Physics/Hello World!/Populating and Updating the World/Actions). This way Havok will execute your code to modify the velocity within the physics step and it will also give you the correct time step information. All you need to do is create a new type of action with your code in the applyAction function. Then when you want to start controlling the object just create an instance of this action, set the camera and the rigidBody you want to control and call world->addAction(). To drop it, call world->removeAction().The docs and demo (Demo/Demos/Physics/Api/Dynamics/Actions/UnaryAction) actually make an anti-gravity action (with a cool hover/floaty effect), which looks especially relevant :)Cheers,Tyler

Melden Sie sich an, um einen Kommentar zu hinterlassen.