How to use PhysicsRay?

Hi all!



I need a little tutorial on how to use PhysicsRay…



Here is my little piece of code:


PhysicsRay r;
r = tank.createRay("ChaseRay");



Now I have two questions:

1) How can I position the Ray orthogonally to a certain object(tank is a DynamicPhysicsNode, obviously)?
Currently I solved my problem like this:

r.getLocalTranslation().set(0,-200,0)


2) Which Method do I have to use to check if my Ray collided with another object?
I already checked with findPick(Ray, PickResults), but its not compatible with PhysicsRay...:(

Please help!!!

Thanks in advance

PhysicsRay generates events as other physics geometries do. Have a look at the physics tutorial and tests. There's a test for rays as well.

The Ray class is for picking. Maybe you want to use that instead? What do you try to achieve? And what means "orthogonally to a certain object"? A straight line can be orthogonal to a plane, but what would be the plane of your "object"?

Hey Guys,



It's really urgent and the jme physics wiki does not give ANY clue about the usage of PhysicsRays…



HEEEEELLLLLPPPP! :frowning:

This is pretty much pushing, isn't it? My topic is also very urgent (think we've got the same DEADline ;)). Hope you'll find any help, unfortunately I have no idea of PhysicRays…



Kind regards, Jan :wink:

o19 said:

This is pretty much pushing, isn't it? My topic is also very urgent (think we've got the same DEADline ;)). Hope you'll find any help, unfortunately I have no idea of PhysicRays...

Kind regards, Jan ;)


Yeah well, maybe I was getting a little emotional...^^
Sorry for that, I didn't mean other projects are less important, but my headache becomes stronger and stronger...

irrisor said:

PhysicsRay generates events as other physics geometries do. Have a look at the physics tutorial and tests. There's a test for rays as well.
The Ray class is for picking. Maybe you want to use that instead? What do you try to achieve? And what means "orthogonally to a certain object"? A straight line can be orthogonal to a plane, but what would be the plane of your "object"?


First of all, thanks for replying :)
I tried with the CollisionEventHandler, but I've seen, that this was the wrong way...

So, maybe when I explain, what I am trying to do this will bring light into the discussion:
First of all I am coding a tank game. I am generating a floor (consisting of several boxes) with walls on it.
like the one in attachment 1.

I placed into the floor (walls excluded) little disks (but not visible, you can see an example how they are placed in attachment 2) which I use for checking if a Ray going through the ground collided with one of these disks. An abstract example is shown in the 3rd attachment.

and now how I programmed it:


      Vector3f worldCoords,worldCoords2;
      worldCoords = tank.getLocalTranslation(); //get the location of our tank
      worldCoords2 = tank.getLocalTranslation();
      worldCoords2 = worldCoords2.add(0,0,-10);  //subtract now 10 from it
      r = new Ray(worldCoords, worldCoords2
            .subtractLocal(worldCoords).normalizeLocal());
      pr.clear();
      floor.findPick(r, pr); //finds nothing :(
//      ...



If I try to do it with rootNode I get a ODE internal error 2.

do your disks have boundingboxes set?

Alessandro said:

If I try to do it with rootNode I get a ODE internal error 2.

Ray has nothing to do with ODE. That error means you were altering the scenegraph (at least the physics part) while ODE was taking a simulation step. Thus make sure that 1) you do not alter the data while checking rays (beware: getLocalTranslations() get a reference to the position data) and 2) you don't use threads or use proper locking to avoid modification while in simulation step (PhysicsSpace.update).
So essentially: pick on rootNode should work without any ODE errors.
Core-Dump said:

do your disks have boundingboxes set?


Well, this was the problem...^^
But the collisions are not recognized very well...Oo
Many thanks!!!!

irrisor said:

Alessandro said:

If I try to do it with rootNode I get a ODE internal error 2.

Ray has nothing to do with ODE. That error means you were altering the scenegraph (at least the physics part) while ODE was taking a simulation step. Thus make sure that 1) you do not alter the data while checking rays (beware: getLocalTranslations() get a reference to the position data) and 2) you don't use threads or use proper locking to avoid modification while in simulation step (PhysicsSpace.update).
So essentially: pick on rootNode should work without any ODE errors.


As far as I know there are no other threads, which could interfere with the ODE simulation.
I modified the code to use no references and this method works now without ODE errors :) thanks


Thanks for helping me out, I think I can solve the problem now for myself... But I will post the final solution for others having a similar problem.

Alessandro