Beispiel #1
0
func (w *World) nearCallback(data interface{}, obj1, obj2 ode.Geom) {
	body1 := obj1.Body()
	body2 := obj2.Body()

	cts := obj1.Collide(obj2, 1, 0)
	for _, ct := range cts {
		/* contact info */
		contact := ode.NewContact()
		contact.Surface.Mode = ode.BounceCtParam | ode.SoftCFMCtParam
		contact.Surface.Mu = math.Inf(1)
		contact.Surface.Mu2 = 0
		contact.Surface.Bounce = 0.01
		contact.Surface.BounceVel = 0.1
		contact.Geom = ct

		/* add contact joint until next frame */
		ctj := w.world.NewContactJoint(w.contacts, contact)
		ctj.Attach(body1, body2)

		/* collision events */
		event_contact := Contact{
			Position: FromOdeVec3(ct.Pos),
			Normal:   FromOdeVec3(ct.Normal),
			Depth:    float32(ct.Depth),
		}

		if obj1.Data() != nil && obj1.Data() != nil {
			col1 := obj1.Data().(Collider)
			col2 := obj2.Data().(Collider)
			col1.OnCollision(col2, event_contact)
			col2.OnCollision(col1, event_contact)
		}
	}
}
Beispiel #2
0
func cb(data interface{}, obj1, obj2 ode.Geom) {
	contact := ode.NewContact()
	body1, body2 := obj1.Body(), obj2.Body()
	if body1 != 0 && body2 != 0 && body1.Connected(body2) {
		return
	}
	contact.Surface.Mode = 0
	contact.Surface.Mu = 0.1
	contact.Surface.Mu2 = 0
	cts := obj1.Collide(obj2, 1, 0)
	if len(cts) > 0 {
		contact.Geom = cts[0]
		ct := world.NewContactJoint(ctGrp, contact)
		ct.Attach(body1, body2)
	}
}