Package jinngine.collision

Examples of jinngine.collision.RayCast


        Geometry gi = geometries.next();

        // if geometry is usable
        if ( gi instanceof SupportMap3) {

          RayCast raycast = new RayCast();
          Vector3 pb = new Vector3(), pc = new Vector3();
          double t = raycast.run((SupportMap3)gi, null, point, direction, pb, pc, 0, 0.05, 1e-7, true);

//          write out t for debugging
//          System.out.println("t="+t);
         
          if (t<parameter) {
View Full Code Here


 
  /**
   * create a sphere and cast a ray against it
   */
  public void testRay1() {
    RayCast raycast = new RayCast();
   
    // setup cube geometry
    Sphere s1 = new Sphere(1);
    Body b1 = new Body("default", s1);
   
    // pick a point outside the sphere, and let the direction point towards
    // the centre of the sphere.
    Vector3 point = new Vector3(-4, 6, 9);
    Vector3 direction = point.multiply(-1);
   
    // do the raycast
    double lambda = raycast.run(s1, null, point, direction, new Vector3(), new Vector3(), 0, envelope, epsilon, false );
   
    // we know the exact intersection point
    Vector3 expected = point.normalize();
   
    // calculate the deviation of the returned point and the reference point
View Full Code Here

 
  /**
   * A similar ray test where the sphere is moved off the origo
   */
  public void testRay2() {
    RayCast raycast = new RayCast();
   
    // setup cube geometry
    Sphere s1 = new Sphere(1);
    Body b1 = new Body("default", s1);
    b1.setPosition(2,-3,-1);
   
    // pick a point outside the sphere, and let the direction point towards
    // the centre of the sphere.
    Vector3 point = new Vector3(-4, 6, 9);
    Vector3 direction = b1.getPosition().sub(point);
   
    // do the raycast
    double lambda = raycast.run(s1, null, point, direction, new Vector3(), new Vector3(), 0, envelope, epsilon, false );
   
    // we know the exact intersection point ( go from the centre of the sphere
    // to the boundary along the oposite ray direction )
    Vector3 expected = b1.getPosition().sub(direction.normalize());
   
View Full Code Here

   * exactly misses the sphere. Due to the envelope, we still expect a hit,
   * and this hitpoint should be within the envelope around the sphere.
   * Next, we move the sphere a bit, such that we expect a miss.
   */
  public void testRay3() {
    RayCast raycast = new RayCast();
   
    // setup sphere geometry
    Sphere s1 = new Sphere(1);
    Body b1 = new Body("default", s1);

    // select a point (5,1,0) and the raydirection (-1,0,0)
    Vector3 point = new Vector3(5, 1, 0);
    Vector3 direction = new Vector3(-1,0,0);
   
    System.out.println("*********************************************************************");
   
    // do the raycast
    double lambda = raycast.run(s1, null, point, direction, new Vector3(), new Vector3(), 0, envelope, epsilon, false );
   
    // calculate the  point
    Vector3 p = point.add(direction.multiply(lambda));
   
    System.out.println("p norm="+p.norm());
   
    // the hitpoint must be within the envelope
    assertTrue( Math.abs(p.norm()-1) < envelope+epsilon);
   
    // move the sphere a bit downwards
    b1.setPosition(0,-envelope-2*epsilon, 0);
   
    // do the raycast
    lambda = raycast.run(s1, null, point, direction, new Vector3(), new Vector3(), 0, envelope, epsilon, false );
   
    System.out.println("returned lambda="+lambda);
   
    assertTrue( lambda == Double.POSITIVE_INFINITY);
   
View Full Code Here

 
  /**
   * A ray against box test
   */
  public void testRay4() {
    RayCast raycast = new RayCast();
   
    // setup cube geometry
    Box box = new Box(1,1,1);
    Body b1 = new Body("default", box);

    // select a point (5,1,0) and the raydirection (-1,0,0)
    Vector3 point = new Vector3(0, 5, 0);
    Vector3 direction = new Vector3(0,-1,0);
   
    // do the raycast
    double lambda = raycast.run(box, null, point, direction, new Vector3(), new Vector3(), 0, envelope, epsilon, false );
   
    // calculate the  point
    Vector3 p = point.add(direction.multiply(lambda));
   
    // expected point
View Full Code Here

  /**
   * A ray against box corner test
   */
  public void testRay5() {
    RayCast raycast = new RayCast();
   
    // setup cube geometry
    Box box = new Box(1,1,1);
    Body b1 = new Body("default", box);

    // select a point (5,1,0) and the raydirection (-1,0,0)
    Vector3 point = new Vector3(2, 5, 9);
    Vector3 direction = new Vector3(0.5,0.5,0.5).sub(point);
   
    // do the raycast
    double lambda = raycast.run(box, null, point, direction, new Vector3(), new Vector3(), 0, envelope, epsilon, false );
   
    // calculate the  point
    Vector3 p = point.add(direction.multiply(lambda));
   
    // expected point
View Full Code Here

TOP

Related Classes of jinngine.collision.RayCast

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.