def _near_callback(self, args, geom1, geom2): """Callback function for the collide() method. This function checks if the given geoms do collide and creates contact joints if they do.""" # only check parse list, if objects have name if geom1.name != None and geom2.name != None: # Preliminary checking, only collide with certain objects for p in self.passpairs: g1 = False g2 = False for x in p: g1 = g1 or (geom1.name.find(x) != -1) g2 = g2 or (geom2.name.find(x) != -1) if g1 and g2: return() # Check if the objects do collide contacts = ode.collide(geom1, geom2) # Create contact joints world, contactgroup = args for c in contacts: p = c.getContactGeomParams() # parameters from Niko Wolf c.setBounce(0.2) c.setBounceVel(0.05) #Set the minimum incoming velocity necessary for bounce c.setSoftERP(0.6) #Set the contact normal "softness" parameter c.setSoftCFM(0.00005) #Set the contact normal "softness" parameter c.setSlip1(0.02) #Set the coefficient of force-dependent-slip (FDS) for friction direction 1 c.setSlip2(0.02) #Set the coefficient of force-dependent-slip (FDS) for friction direction 2 c.setMu(self.FricMu) #Set the Coulomb friction coefficient j = ode.ContactJoint(world, contactgroup, c) j.name = None j.attach(geom1.getBody(), geom2.getBody())
def addContact(self, geom1, geom2, c): # add a contact between a capped cylinder BP and the ground (cpos, cnor, cdep, cg1, cg2) = c.getContactGeomParams() # figure out which cylinder foot this contact describes if type(geom1) is ode.GeomCCylinder: cylinder = geom1 elif type(geom2) is ode.GeomCCylinder: cylinder = geom2 # find endpoints of cylinder r = mat3(cylinder.getRotation()) p = vec3(cylinder.getPosition()) (radius, length) = cylinder.getParams() # is collision point c in an endpoint? ep0 = p + r * vec3(0, 0, -length / 2) ep1 = p + r * vec3(0, 0, length / 2) # is cpos in sphere around ep0 or ep1? for ep in ep0, ep1: cpos = vec3(cpos) d2 = (cpos - ep).length() if (d2 <= radius + 0.1): epc = ep # we will get two addContact() calls for each real contact, one for each # of the joined capped cylinders, so only add a contact for the # 'furthest out' from the root. If geom is the root then always add the # contact. if not cylinder.parent or epc == ep1: mu = 300 self.points.append((cpos, (0, 1, 1), mu / 1000.0)) c.setMu(mu) j = ode.ContactJoint(self.world, self.contactGroup, c) j.attach(geom1.getBody(), geom2.getBody()) # remember contact for touch sensors self.geom_contact[geom1] = 1 self.geom_contact[geom2] = 1
def near_callback(self, args, geom1, geom2): """ Callback function for the collide() method. This function checks if the given geoms do collide and creates contact joints if they do. """ # Are both geoms static? We don't care if they touch. if geom1.getBody() is None and geom2.getBody() is None: return # Are both geoms connected? if (ode.areConnected(geom1.getBody(), geom2.getBody())): return # check if the objects collide contacts = ode.collide(geom1, geom2) # create contact joints self.world, self.contactgroup = args for c in contacts: c.setBounce(0.2) # ode.ContactApprox1 makes maximum frictional force proportional to # normal force c.setMode(ode.ContactApprox1) # Friction coefficient: Max friction (tangent) force = Mu*Normal force c.setMu(0.5) j = ode.ContactJoint(self.world, None, c) # FIXME: Store the position of the contact j.position = c.getContactGeomParams()[0] self.contactlist.append(j) j.attach(geom1.getBody(), geom2.getBody()) j.setFeedback(True)
def nearcb(self, args, geom1, geom2): """Create contact joints between colliding geoms""" body1, body2 = geom1.getBody(), geom2.getBody() pos = () if body1 is None: body1 = ode.environment else: pos = body1.getPosition() if body2 is None: body2 = ode.environment else: pos = body2.getPosition() if ode.areConnected(body1, body2): return contacts = ode.collide(geom1, geom2) for c in contacts: # c.setBounce(0.2) # c.setMu(10000) c.setBounce(1) c.setMu(0) j = ode.ContactJoint(self.world, self.contactgroup, c) j.attach(body1, body2) # report collision self._outlet(3,(self.geoms[geom1],self.geoms[geom2])+pos)
def near_callback(self, args, geom1, geom2): """Callback function for the collide() method. This function checks if the given geoms do collide and creates contact joints if they do. """ body1 = geom1.getBody() body2 = geom2.getBody() # Contacts in the same group are ignored # e.g. foot and lower leg for group in allGroups: if body1 in group and body2 in group: return # Check if the objects do collide contacts = ode.collide(geom1, geom2) # Create contact joints self.world, self.contactgroup = args for c in contacts: c.setBounce(0.2) c.setMu(5000) j = ode.ContactJoint(self.world, self.contactgroup, c) j.attach(geom1.getBody(), geom2.getBody())
def create_contact_joint(self, c): """ Create a contact joint between two objects. Args: c: contact point between two bodies """ return ode.ContactJoint(self.world, self.contactgroup, c)
def _near_callback(self, args, geom1, geom2): world, contactgroup = args try: i = self.ball_geoms.index(geom1) if not self.on_table[i]: return except: pass try: j = self.ball_geoms.index(geom2) if not self.on_table[j]: return except: pass contacts = ode.collide(geom1, geom2) if contacts: body1, body2 = geom1.getBody(), geom2.getBody() for c in contacts: if isinstance(geom1, ode.GeomPlane) or isinstance( geom2, ode.GeomPlane): c.setBounce(0.24) c.setMu(0.16) c.setBounceVel(0.033) c.setSoftERP(0.4) c.setSoftCFM(1e4) c.setSlip1(0.05) elif isinstance(geom1, ode.GeomTriMesh) or isinstance( geom2, ode.GeomTriMesh): c.setBounce(0.86) c.setMu(0.16) c.setBounceVel(0.02) c.setSoftERP(0.4) c.setSoftCFM(1e2) c.setSlip1(0.04) elif isinstance(geom1, ode.GeomCylinder) or isinstance( geom2, ode.GeomCylinder): c.setBounce(0.69) c.setMu(0.25) c.setSoftERP(0.2) c.setSoftCFM(1e1) pos, normal, depth, g1, g2 = c.getContactGeomParams() v_n = np.array(normal).dot( np.array(body1.getPointVel(pos)) - np.array(body2.getPointVel(pos))) if self._on_cue_ball_collide: self._on_cue_ball_collide(impact_speed=abs(v_n)) else: c.setBounce(0.93) c.setMu(0.13) pos, normal, depth, g1, g2 = c.getContactGeomParams() v_n = abs( np.array(normal).dot( np.array(body1.getLinearVel()) - np.array(body2.getLinearVel()))) vol = max(0.02, min(0.8, 0.45 * v_n + 0.55 * v_n**2)) if vol > 0.02: play_ball_ball_collision_sound(vol=vol) j = ode.ContactJoint(world, contactgroup, c) j.attach(body1, body2)
def near_callback(args, geom1, geom2): contacts = ode.collide(geom1, geom2) world,contactgroup = args for c in contacts: c.setBounce(0.1) c.setMu(10000) j = ode.ContactJoint(world, contactgroup, c) j.attach(geom1.getBody(), geom2.getBody())
def nearCallback(self, args, geom1, geom2): contacts = ode.collide(geom1, geom2) for c in contacts: c.setBounce(0.2) c.setMu(5000) j = ode.ContactJoint(self.world, self.contactGroup, c) j.attach(geom1.getBody(), geom2.getBody())
def _onCollision(self, args, geom1, geom2): contacts = ode.collide(geom1, geom2) world, contact_group = args for c in contacts: c.setBounce(self._contact_bounce) c.setMu(self._contact_friction) j = ode.ContactJoint(world, contact_group, c) j.attach(geom1.getBody(), geom2.getBody())
def _collision(self, args, geom1, geom2): # Check if the objects do collide contacts = ode.collide(geom1, geom2) # Create contact joints world, contactgroup = args for c in contacts: c.setBounce(0.1) c.setMu(50000) j = ode.ContactJoint(world, contactgroup, c) j.attach(geom1.getBody(), geom2.getBody())
def near_callback(args, geometria1, geometria2): contacto = ode.collide(geometria1, geometria2) mundo, grupo_contacto = args for c in contacto: c.setBounce(0.2) c.setMu(5000) j = ode.ContactJoint(mundo, grupo_contacto, c) j.attach(geometria1.getBody(), geometria2.getBody())
def Collision_Callback(args, geom1, geom2): contacts = ode.collide(geom1, geom2) world, contactgroup = args for c in contacts: c.setBounce(0) # 反発係数 c.setMu(2) # クーロン摩擦係数 j = ode.ContactJoint(world, contactgroup, c) j.attach(geom1.getBody(), geom2.getBody()) global Col Col=True
def _collidecallback(cls, args, geom1, geom2): go1 = geom1.gameobject go2 = geom2.gameobject go1.oncollision(go2) go2.oncollision(go1) for contact in ode.collide(geom1, geom2): contact.setBounce(0) contact.setMu(10000) j = ode.ContactJoint(cls.world, cls.contactgroup, contact) j.attach(geom1.getBody(), geom2.getBody())
def near_callback(self, args, geom1, geom2): # Check if the objects do collide contacts = ode.collide(geom1, geom2) # Create contact joints self.world, self.contactgroup = args for c in contacts: c.setBounce(0.2) c.setMu(5000) j = ode.ContactJoint(self.world, self.contactgroup, c) j.attach(geom1.getBody(), geom2.getBody())
def wheel_contact_callback(args, geom1, geom2): #GENERIC collision (like webots) if geom1 == geom2: #geom2 is the wheel! return contacts = ode.collide(geom1, geom2) # Check if the objects do collide world, contactgroup = args for c in contacts: # Create contact joints c.setBounce(0.2) c.setMu(10) #is friction? j = ode.ContactJoint(world, contactgroup, c) j.attach(None, geom2.getBody())
def near_callback(args, geom1, geom2): """Callback function for the collide() method below. This function checks if the given geoms do collide and creates contact joints if they do. """ contacts = ode.collide(geom1, geom2) world,contactgroup = args for c in contacts: c.setBounce(0.01) c.setMu(60000) j = ode.ContactJoint(world, contactgroup, c) j.attach(geom1.getBody(), geom2.getBody())
def contact_callback(args, geom1, geom2): #GENERIC collision (like webots) if geom1 == geom2: return #print "generic two-way contact" contacts = ode.collide(geom1, geom2) # Check if the objects do collide world, contactgroup = args for c in contacts: # Create contact joints c.setBounce(0.2) c.setMu(5000) #is friction? j = ode.ContactJoint(world, contactgroup, c) j.attach(geom1.getBody(), geom2.getBody())
def oneway_contact_callback(args, geom1, geom2): #ignore opposite force on environment if geom1 == geom2: #geom2 is the object to experience the force return #print "oneway contact" contacts = ode.collide(geom1, geom2) # Check if the objects do collide world, contactgroup = args for c in contacts: # Create contact joints c.setBounce(0.2) c.setMu(0) #no friction j = ode.ContactJoint(world, contactgroup, c) j.attach(None, geom2.getBody( )) #None=link to environment instead of other body (see ODE FAQ)
def collide_callback(args, obj1: ode.GeomObject, obj2: ode.GeomObject): if ode.areConnected(obj1.getBody(), obj2.getBody()): pass print("COLLISION!!!!") contacts = ode.collide(obj1, obj2) world, joint_group = args for c in contacts: j = ode.ContactJoint(world, joint_group, c) j.attach(obj1.getBody(), obj2.getBody())
def near_callback(args, geometria1, geometria2): contacto = ode.collide(geometria1, geometria2) mundo, grupo_contacto = args for c in contacto: c.setBounce(REBOTE) c.setMu(MU) c.setMu2(MU2) c.setBounceVel(REBOTE_VEL) c.setSoftCFM(SOFT_CFM) j = ode.ContactJoint(mundo, grupo_contacto, c) j.attach(geometria1.getBody(), geometria2.getBody())
def near_callback(args, geom1, geom2): """ Callback function for the collide method. This function checks if the given geoms do collide and creates contact joints if they do. """ # Check if the objects do collide contacts = ode.collide(geom1, geom2) # Create contact joints (world, contactgroup) = args for c in contacts: c.setBounce(0.2) c.setMu(5000) j = ode.ContactJoint(world, contactgroup, c) j.attach(geom1.getBody(), geom2.getBody())
def _near_callback(self, geom1, geom2): """Callback function for the collide() method. This function checks if the given self.geoms do collide and creates contact joints if they do. """ # Set of geoms gset = {geom1, geom2} # Check if the objects do collide contacts = ode.collide(geom1, geom2) # Create contact joints for c in contacts: c.setBounce(0.77) # standard bounce pingpong labda + asztal kozott c.setMu(0.25) # approx mu j = ode.ContactJoint(self.world, self.contactGroup, c) j.attach(geom1.getBody(), geom2.getBody()) if {self.lastBall} <= gset: if not {self.tableNet, self.hitFloor}.isdisjoint(gset): self.hitState = self.BallState.invalidBounce elif {self.hitWall} <= gset: if self.hitState == self.BallState.nearHit: self.hitState = self.BallState.wallHit else: self.hitState = self.BallState.invalidBounce elif {self.tableFar} <= gset: if self.hitState == self.BallState.noneHit: self.hitState = self.BallState.farHit elif self.hitState == self.BallState.batHit: self.hitState = self.BallState.farSecondHit else: self.hitState = self.BallState.invalidBounce elif {self.tableNear} <= gset: if self.hitState == self.BallState.farHit: self.hitState = self.BallState.nearHit elif self.hitState == self.BallState.batHit: self.hitState = self.BallState.nearSecondHit else: self.hitState = self.BallState.invalidBounce elif {self.bat} <= gset: if self.hitState == self.BallState.nearHit: self.hitState = self.BallState.batHit else: self.hitState = self.BallState.invalidHit elif {self.bat, self.tableNear} == gset: self.hitState = self.BallState.invalidHit
def collision_callback(self, args, geom1, geom2): world, contactgroup = args body1, body2 = geom1.getBody(), geom2.getBody() if (body1 is None): body1 = ode.environment if (body2 is None): body2 = ode.environment contacts = ode.collide(geom1, geom2) for c in contacts: c.setBounce(0.5) c.setMu(10000) j = ode.ContactJoint(world, contactgroup, c) j.attach(body1, body2)
def _collision_callback(self, args, geom1, geom2): """Callback function for the collide() method. This function checks if the given geoms do collide and creates contact joints if they do. """ #print 'Collision detected' # Check if the objects do collide contacts = ode.collide(geom1, geom2) # Create contact joints world,contactgroup = args for c in contacts: c.setBounce(self.bounce) # Restitution parameter c.setMu(self.friction) # Coulomb friction j = ode.ContactJoint(world, contactgroup, c) j.attach(geom1.getBody(), geom2.getBody())
def near_callback(args, geom1, geom2): """Callback function for the collide() method. This function checks if the given geoms do collide and creates contact joints if they do. """ # Check if the objects do collide contacts = ode.collide(geom1, geom2) # Create contact joints world, contactgroup = args for c in contacts: c.setBounce(0.8) # bouncyness c.setMu(800) # friction for both surfaces j = ode.ContactJoint(world, contactgroup, c) j.attach(geom1.getBody(), geom2.getBody())
def near_callback(Args, Geom1, Geom2): """Callback function for the collide() method. This function checks if the given geoms do collide and creates contact joints if they do. """ # Check if the objects do collide contacts = ode.collide(Geom1, Geom2) # Create contact joints world, contactGroup = Args for contact in contacts: contact.setBounce(0.2) contact.setMu(5000) joint = ode.ContactJoint(world, contactGroup, contact) joint.attach(Geom1.getBody(), Geom2.getBody())
def _near_callback(self, _, geom1, geom2): g1 = (geom1 == self.ground) g2 = (geom2 == self.ground) if not (g1 ^ g2): return b1 = geom1.getBody() b2 = geom2.getBody() contact = ode.collide(geom1, geom2) if contact: for con in contact[:3]: con.setMode(ode.ContactSoftCFM | ode.ContactApprox1) con.setMu(MU) con.setSoftCFM(0.01) j = ode.ContactJoint(self.world, self.contactgroup, con) j.attach(b1, b2)
def near_callback(args, g1, g2): try: if getattr(g1, 'isImmovable', False) and getattr( g2, 'isImmovable', False): return if g1.isSpace() or g2.isSpace(): if g1.isSpace() and not getattr(g1, 'isImmovable', False): g1.collide(args, near_callback) if g2.isSpace() and not getattr(g2, 'isImmovable', False): g2.collide(args, near_callback) ode.collide2(g1, g2, args, near_callback) contacts = ode.collide(g1, g2) if ode.areConnected(g1.getBody(), g2.getBody()): return d1 = getattr(g1.getBody(), 'data', None) d2 = getattr(g2.getBody(), 'data', None) if d1 is None: d1 = getattr(g1, 'data', None) if d2 is None: d2 = getattr(g2, 'data', None) if d1 is not None: d1 = d1() if d2 is not None: d2 = d2() # TODO: if d1 and/or d2 are not None, use them to handle collision r1 = True r2 = True if len(contacts) > 0: if d1 is not None and hasattr(d1, 'onCollision'): r1 = d1.onCollision(d2) if d2 is not None and hasattr(d2, 'onCollision'): r2 = d2.onCollision(d1) if r1 and r2: for c in contacts: c.setBounce(0.8) c.setMu(250) c.setMode(ode.ContactApprox1) objects.DebugPoint(c.getContactGeomParams()[0]) j = ode.ContactJoint(objects.world, objects.contactgroup, c) j.attach(g1.getBody(), g2.getBody()) except BaseException, e: print "Exception in collision handler: ", str(e)
def near_callback(args, geom1, geom2): """Callback function for the collide() method. This function checks if the given geoms do collide and creates contact joints if they do. """ #COULD THIS FUNCTION ALLOW ANY GEOM TO ALTER COLLISION BEHAVIOR, FOR INSTANCE FOR AN OPEN BOUNDARY # Check if the objects do collide contacts = ode.collide(geom1, geom2) # Create contact joints world, contactgroup = args for c in contacts: c.setBounce(0.01) #c.setMu(5000) c.setMu(1.0) j = ode.ContactJoint(world, contactgroup, c) j.attach(geom1.getBody(), geom2.getBody())