예제 #1
0
func NewWorld() *World {
	world := ode.NewWorld()
	space := ode.NilSpace().NewHashSpace()

	w := &World{
		gravity:  -9.82,
		timestep: 0.01,
		world:    world,
		space:    space,
		contacts: ode.NewJointGroup(10000),
	}

	world.SetGravity(ode.V3(0, float64(w.gravity), 0))
	world.SetCFM(1.0e-5)
	world.SetERP(0.2)
	world.SetContactSurfaceLayer(0.001)
	world.SetContactMaxCorrectingVelocity(0.9)
	world.SetAutoDisable(true)

	return w
}
예제 #2
0
파일: chain.go 프로젝트: bfosberry/ode
func main() {
	ode.Init(0, ode.AllAFlag)

	world = ode.NewWorld()
	space = ode.NilSpace().NewHashSpace()
	body = make([]ode.Body, numSpheres)
	joint = make([]ode.BallJoint, numSpheres-1)
	ctGrp = ode.NewJointGroup(1000000)
	sphere = make([]ode.Sphere, numSpheres)
	mass = ode.NewMass()

	world.SetGravity(ode.V3(0, 0, -0.5))
	space.NewPlane(ode.V4(0, 0, 1, 0))

	for i := 0; i < numSpheres; i++ {
		k := float64(i) * sideLen
		body[i] = world.NewBody()
		body[i].SetPosition(ode.V3(k, k, k+0.4))
		mass.SetBox(1, ode.V3(sideLen, sideLen, sideLen))
		mass.Adjust(sphereMass)
		body[i].SetMass(mass)
		sphere[i] = space.NewSphere(sphereRadius)
		sphere[i].SetBody(body[i])
	}

	for i := 0; i < numSpheres-1; i++ {
		joint[i] = world.NewBallJoint(ode.JointGroup(0))
		joint[i].Attach(body[i], body[i+1])
		k := (float64(i) + 0.5) * sideLen
		joint[i].SetAnchor(ode.V3(k, k, k+0.4))
	}

	if err := qml.Run(run); err != nil {
		fmt.Fprintf(os.Stderr, "error: %v\n", err)
		os.Exit(1)
	}
}