Package jinngine.physics.constraint.contact

Examples of jinngine.physics.constraint.contact.ContactConstraint


//            bodypair = new Pair<Body>(b2,b1);
//            geometrypair = new Pair<Geometry>(inputpair.getSecond(), inputpair.getFirst());
//          }
         
         
          ContactConstraint contactConstraint = null;

          //a contact constraint already exists
          if (contactConstraints.containsKey(bodypair)) {
            contactConstraint = contactConstraints.get(bodypair);
           
            // order the geometry pair to match the order of the contact constraint.
            // this is necessary to keep normals pointing in the right direction when
            // contact constraints have more than one contact generator
            Pair<Body> orderedpair = contactConstraint.getBodies();
            if (orderedpair.getFirst() == bodypair.getFirst()) {
              // same order
              geometrypair = inputpair;
            } else {
              // swap
              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
              contactGenerators.remove(geometrypair);

              //if the contact constraint has no more generators, also
              //remove the contact constraint
              if (constraint.getNumberOfGenerators() < 1 ) {
                contactConstraints.remove(bodypair);
                constraintGraph.removeEdge(bodypair)
               
                // signal event handlers
                for (Handler h: handlers) {
View Full Code Here


//    timestep = s.getTimestep();

    // see if the monitored constraints can trigger an event
    ListIterator<ContactConstraint> monitored = monitoredconstraints.listIterator();
    while ( monitored.hasNext() ) {
      ContactConstraint constraint = monitored.next();
      totalforce = 0;
      numberOfNcpConstraints = 0;

      // sum up the applied contact force
      Iterator<NCPConstraint> ncps = constraint.getNcpConstraints();
      while(ncps.hasNext()) {
        NCPConstraint ncp = ncps.next();
        totalforce += ncp.lambda;     
        numberOfNcpConstraints += 1;
      }

      // check condition
      if (totalforce > impulsethreshold) { 
       
        // move constraint to triggered list
        monitored.remove();
        triggeredconstraints.add(constraint);
       
        // perform trigger event callback
        Pair<Body> bodies =  constraint.getBodies();
        Body interacting = bodies.getFirst()==body? bodies.getSecond(): bodies.getFirst();
        callback.contactAboveThreshold(interacting, constraint);

      } // if force > forcethreshold
    } // for monitored constraints 
   
    // see if triggered constraints should be moved back to monitored
    ListIterator<ContactConstraint> triggered = triggeredconstraints.listIterator();
    while ( triggered.hasNext()) {

      ContactConstraint constraint = triggered.next();
      totalforce = 0;
      numberOfNcpConstraints = 0;

      // sum up the applied contact force
      Iterator<NCPConstraint> ncps = constraint.getNcpConstraints();
      while(ncps.hasNext()) {
        NCPConstraint ncp = ncps.next();
        totalforce += ncp.lambda;       
        numberOfNcpConstraints += 1;
      }

      // check condition
      if (totalforce < impulsethreshold) { 
       
        // move constraint to monitored list
        triggered.remove();
        monitoredconstraints.add(constraint);
       
        // perform trigger event callback
        Pair<Body> bodies =  constraint.getBodies();
        Body interacting = bodies.getFirst()==body? bodies.getSecond(): bodies.getFirst();
        callback.contactBelowThreshold(interacting, constraint);

      } // if force > forcethreshold
    } // for monitored constraints 
View Full Code Here

TOP

Related Classes of jinngine.physics.constraint.contact.ContactConstraint

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.