Package jinngine.physics

Examples of jinngine.physics.Body


    interacting = false;
    double parameter = Double.POSITIVE_INFINITY;
    Iterator<Body> bodies = scene.getBodies();
    // go thru each body
    while (bodies.hasNext()) {
      Body bi = bodies.next();

      // only shoot at non-fixed bodies
      if ( !bi.isFixed()) {
        Iterator<Geometry> geometries = bi.getGeometries();
        Geometry gi = geometries.next();

        // if geometry is usable
        if ( gi instanceof SupportMap3) {
View Full Code Here


    final Box box2 = new Box(1,1,1);
    box2.setEnvelope(1);

    // attach geometries to bodies (to we can change the transform of the
    // boxes by changing the transform of the bodies)
    final Body body1 = new Body("box1", box1);   
    final Body body2 = new Body("box2", box2);
       
    // contact generator
    ContactGenerator g = new SupportMapContactGenerator(box1,box1,box2,box2);
   

    /*
     * Test 1, displace along positive y-axis
     */
   
    // displace box2
    body2.setPosition(0, 1.5, 0);
   
    // run contact point generation
    g.run();
   
    // extract contact points
    result.clear();
    Iterator<ContactPoint> i = g.getContacts();
    while (i.hasNext()) {
      ContactPoint cp = i.next();
      System.out.println(cp.point);
      System.out.println("dist="+cp.distance);
      result.add(new Vector3(cp.point));
    }
   
    // expected contact points, in counter clock-wise order
    expect.clear();
    expect.add(new Vector3(0.5,0.75,0.5));
    expect.add(new Vector3(-0.5,0.75,0.5));
    expect.add(new Vector3(-0.5,0.75,-0.5));
    expect.add(new Vector3(0.5,0.75,-0.5));

    // check
    assertTrue(verifyPolygon(expect, result));

 
    /*
     * Test 2, displace along negative y-axis
     */
   
    // displace box2
    body2.setPosition(0, -1.5, 0);
   
    // run contact point generation
    g.run();
   
    // extract contact points
    result.clear();
    i = g.getContacts();
    while (i.hasNext()) {
      ContactPoint cp = i.next();
      System.out.println(cp.point);
      System.out.println("dist="+cp.distance);
      result.add(new Vector3(cp.point));
    }
   
    // expected contact points, in counter clock-wise order
    expect.clear();
    expect.add(new Vector3( 0.5,-0.75,-0.5));
    expect.add(new Vector3(-0.5,-0.75,-0.5));
    expect.add(new Vector3(-0.5,-0.75, 0.5));
    expect.add(new Vector3( 0.5,-0.75, 0.5));

    // check
    assertTrue(verifyPolygon(expect, result));

 
    /*
     * Test 3, displace along positive x-axis
     */
   
    // displace box2
    body2.setPosition(1.5, 0, 0);
   
    // run contact point generation
    g.run();
   
    // extract contact points
View Full Code Here

  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);
View Full Code Here

  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());
   
    // calculate the deviation of the returned point and the reference point
    double error = point.add(direction.multiply(lambda)).sub(expected).norm();
   
    System.out.println("error" + error);
View Full Code Here

  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);
View Full Code Here

  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);
   
View Full Code Here

  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);
   
View Full Code Here

   
    double epsilon = 1e-7;
   
    Solver s = new ConjugateGradients();
   
    Body b1 = new Body("default");
    Body b2 = new Body("default");
   
    Solver.NCPConstraint c1 = new NCPConstraint();
    Vector3 va =new Vector3(1,0,0);
    Vector3 vb =new Vector3(-1,0,0);
    Vector3 z = new Vector3(0,0,0);
View Full Code Here

  public void testConjugateGradients2() {
   
    double epsilon = 1e-7;
   
    Solver s = new ConjugateGradients();
    Body b1 = new Body("default");
    Body b2 = new Body("default");
   
    Solver.NCPConstraint c1 = new NCPConstraint();
    Solver.NCPConstraint c2 = new NCPConstraint();

    Vector3 va =new Vector3(1,0,0);
View Full Code Here

    };
  }

  @Override
  public void run() {
    Body A = Sa.getBody();
    Body B = Sb.getBody();
    int numberOfContacts = 0;
   
    numberOfContacts = bulletRunContactGeneration(
        record,
        A.state.rotation.toArray(), A.state.position.toArray(),
View Full Code Here

TOP

Related Classes of jinngine.physics.Body

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.