-1

Take a look at the picture.

enter image description here

I've got a camera(brown) and its ray(red). As I know ray has a direction and unlimited length(if you don't set it yourself). But now I need to determine ray's vector that starts at camera point and ends when it crosses a floor. How can I do that?

Tony
  • 3,605
  • 14
  • 52
  • 84
  • It can be helpful in questions like this to include _why_ you want to do what you are doing. Often with more sophisticated libraries there is a specific way of achieving a certain goal that may be easier to use than calculating it out manually but unless you say what you hope to achieve it would be hard for people to help you identify that. – glenatron Dec 12 '14 at 10:03

2 Answers2

1

It's a while since I have spent any time with JMonkeyEngine, but the calculation you are trying to perform here is a collision - knowing that name can help you to know what to search for.

You need to ensure your floor is collidable and then you should be able to use a collision from your camera ray to find the point at which it intersects with the floor using the getContactPointmethod of the collision.

glenatron
  • 11,018
  • 13
  • 64
  • 112
0

It sounds like you're trying to solve a Line-Plane Intersection problem. The solution is the point where the ray hits the floor plane. Determining the distance between your begin point (at camera) and this intersection point will give you the length of your vector.

In JMonkey (which I'm not familiar with), it seems there are nice methods for finding collisions between two objects, provided that they are "collidable".

Collidable

The interface com.jme3.collision.Collidable declares one method that returns how many collisions were found between two Collidables: collideWith(Collidable other, CollisionResults results). A com.jme3.collision.CollisionResults object is an ArrayList of comparable com.jme3.collision.CollisionResult objects. You can iterate over the CollisionResults to identify the other parties involved in the collision. Note that jME counts all collisions, this means a ray intersecting a box will be counted as two hits, one on the front where the ray enters, and one on the back where the ray exits.

See also: hub.jmonkeyengine.org/wiki/doku.php/jme3:advanced:collision_and_intersection

Then, as Glenatron said, you need to use the getContactPoint() method of the collision to get the actual point in space. Your vector is then defined by the ray's point of origin, and the contactpoint.

Community
  • 1
  • 1
Michael
  • 204
  • 2
  • 10
  • Updated my answer, Tony. Hopefully this will enable you to find a suitable solution for your particular case. – Michael Dec 12 '14 at 12:57
  • There is a better solution. I can get ray direction vector `d`(possibly normalized) and multiple on `-cam.y/d.y`. http://gamedev.stackexchange.com/questions/89585/how-to-determine-this-kind-of-vector – Tony Dec 12 '14 at 13:25