/** * Constructor instantiates a new <code>Ray</code> object. The origin and * direction are given. * @param origin the origin of the ray. * @param direction the direction the ray travels in. */ public Ray(Vector3f origin, Vector3f direction) { setOrigin(origin); setDirection(direction); }
private static CollisionResults pick(Camera cam, Vector2f mouseLoc, Node node) { CollisionResults results = new CollisionResults(); Ray ray = new Ray(); Vector3f pos = new Vector3f(mouseLoc.x, mouseLoc.y, -1); Vector3f dir = new Vector3f(mouseLoc.x, mouseLoc.y, 1); dir.subtractLocal(pos).normalizeLocal(); ray.setOrigin(pos); ray.setDirection(dir); node.collideWith(ray, results); return results; } }
@Test public void testBoxRayCollision() { BoundingBox box = new BoundingBox(Vector3f.ZERO, 1, 1, 1); Ray ray = new Ray(Vector3f.ZERO, Vector3f.UNIT_Z); // XXX: seems incorrect, ray inside box should only generate // one result... checkCollision(box, ray, 2); ray.setOrigin(new Vector3f(0, 0, -5)); checkCollision(box, ray, 2); // XXX: is this right? the ray origin is on the box's side.. ray.setOrigin(new Vector3f(0, 0, 2f)); checkCollision(box, ray, 0); ray.setOrigin(new Vector3f(0, 0, -2f)); checkCollision(box, ray, 2); // parallel to the edge, touching the side ray.setOrigin(new Vector3f(0, 1f, -2f)); checkCollision(box, ray, 2); // still parallel, but not touching the side ray.setOrigin(new Vector3f(0, 1f + FastMath.ZERO_TOLERANCE, -2f)); checkCollision(box, ray, 0); }
r.setOrigin(o); r.setDirection(d);
/** * Constructor instantiates a new <code>Ray</code> object. The origin and * direction are given. * @param origin the origin of the ray. * @param direction the direction the ray travels in. */ public Ray(Vector3f origin, Vector3f direction) { setOrigin(origin); setDirection(direction); }
/** * Constructor instantiates a new <code>Ray</code> object. The origin and * direction are given. * @param origin the origin of the ray. * @param direction the direction the ray travels in. */ public Ray(Vector3f origin, Vector3f direction) { setOrigin(origin); setDirection(direction); }
r.setOrigin(o); r.setDirection(d);
r.setOrigin(o); r.setDirection(d);
private void detect() { ray.setOrigin(position); ray.setLimit(distance);
r.setOrigin(new Vector3f(inputRay.start.x, 0.5f, inputRay.start.y)); Vector2 v = inputRay.end.sub(inputRay.start); r.setDirection(new Vector3f(v.x, 0, v.y));
ray.setOrigin(sceneCam.getLocation()); ray.setDirection(sceneCam.getDirection());
ray.setOrigin(sceneCam.getLocation()); ray.setDirection(sceneCam.getDirection()); plane = new Plane(Vector3f.UNIT_Y, new Vector3f(0, waterHeight, 0).dot(Vector3f.UNIT_Y));