Package jinngine.geometry.contact

Examples of jinngine.geometry.contact.ContactGenerator$ContactPoint


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


              geometrypair = new Pair<Geometry>(inputpair.getSecond(),inputpair.getFirst());           
            }
           
                               
            //add a new contact generator to this contact constraint
            ContactGenerator generator = getContactGenerator(geometrypair);
            contactGenerators.put(geometrypair, generator);
            contactConstraint.addGenerator(generator);

          //no contact constraint is present
          } else {         
            //do not act if some other constraint(joint) is already present
            //in the contact graph
            if (constraintGraph.getEdge(bodypair) == null)  {
              //create a new contact generator
              ContactGenerator generator = getContactGenerator(inputpair);
             
              // try custom contact constraint generators
              for ( ContactConstraintCreator c : contactConstraintCreators) {
                contactConstraint = c.createContactConstraint(bodypair.getFirst(), bodypair.getSecond(), generator);
                if (contactConstraint != null)
                  break;
              }
             
              // if no contact constraint was obtained, use the default creator
              if ( contactConstraint == null) {
                contactConstraint = defaultcreator.createContactConstraint(bodypair.getFirst(), bodypair.getSecond(), generator);
              }
                 
              //insert into data structures
              contactConstraints.put(bodypair, contactConstraint);
              contactGenerators.put(inputpair, generator);
              constraintGraph.addEdge( bodypair, contactConstraint);
             
              // signal handlers
              for (Handler h: handlers) {
                h.contactConstraintCreated(bodypair, contactConstraint);
              }
             
            }
          }
        }
       
        @Override
        public final void separation(Pair<Geometry> geometrypair) {
          //retrieve the bodies associated with overlapping geometries
          Body a = geometrypair.getFirst().getBody();
          Body b = geometrypair.getSecond().getBody();
          Pair<Body> bodypair = new Pair<Body>(a,b);

          //ignore overlaps stemming from the same body       
          if ( a == b) return;
          //ignore overlaps for non-body geometries
          if ( a == null || b == null) return;
          //ignore overlaps of fixed bodies
          if ( a.isFixed() && b.isFixed() ) return;
         
          //if this geometry pair has an acting contact constraint,
          //we must remove the contact generator
          if (contactConstraints.containsKey(bodypair)) {
            //check that we have the generator (if not, something is very wrong)
            if (contactGenerators.containsKey(geometrypair)) {
         
              //remove the generator from the contact constraint
              ContactConstraint constraint = contactConstraints.get(bodypair);
              ContactGenerator cg = contactGenerators.get(geometrypair);
             
              //notify contact generator (for possible clean-up)
              cg.remove();
             
              // remove from contact constraint
              constraint.removeGenerator(cg);
             
              //remove the generator from our list
View Full Code Here

    contactConstraintCreators.remove(c);
  }
 
  private ContactGenerator getContactGenerator(Pair<Geometry> pair) {
    for ( ContactGeneratorClassifier gc: geometryClassifiers) {
      ContactGenerator g = gc.getGenerator(pair.getFirst(), pair.getSecond());
     
      if (g!=null) {
        return g;
      }
    }
View Full Code Here

TOP

Related Classes of jinngine.geometry.contact.ContactGenerator$ContactPoint

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.