Ejemplo n.º 1
0
// Update is the regular engine callback.
func (cr *crtag) Update(input *vu.Input) {
	if input.Resized {
		cr.resize()
	}
	dt := input.Dt
	for press, _ := range input.Down {
		switch press {
		case "W":
			cr.scene.MoveView(0, 0, dt*-cr.run)
		case "S":
			cr.scene.MoveView(0, 0, dt*cr.run)
		case "A":
			cr.scene.PanView(vu.YAxis, dt*cr.spin)
		case "D":
			cr.scene.PanView(vu.YAxis, dt*-cr.spin)
		case "B":
			ball := cr.scene.AddPart()
			ball.SetFacade("sphere", "gouraud").SetMaterial("sphere")
			ball.SetBody(vu.Sphere(1), 1, 0.9)
			ball.SetLocation(-2.5+rand.Float64(), 15, -1.5-rand.Float64())
		case "Sp":
			cr.bod.Push(-2.5, 0, -0.5)
		}
	}
}
Ejemplo n.º 2
0
// Create is the engine intialization callback. Create the physics objects.
func (cm *cmtag) Create(eng vu.Engine) {
	cm.holdoff, _ = time.ParseDuration("1000ms")
	cm.last = time.Now()
	cm.scene = eng.AddScene(vu.VF)
	cm.scene.SetPerspective(60, float64(800)/float64(600), 0.1, 50)
	cm.scene.SetLightLocation(0, 5, 0)
	cm.scene.SetLightColour(0.4, 0.7, 0.9)
	cm.scene.SetViewLocation(0, 10, 25)

	// add a base for the other physics bodies to rest on.
	slab := cm.scene.AddPart()
	slab.SetLocation(0, 1, 0)
	slab.SetFacade("cube", "gouraud").SetMaterial("floor")
	slab.SetScale(100, 50, 100)
	slab.SetBody(vu.Box(50, 25, 50), 0, 0.4)
	slab.SetLocation(0, -25, 0)

	// create a fixed part.
	box := cm.scene.AddPart()
	box.SetLocation(0, 1, 0)
	box.SetFacade("cube", "gouraud").SetMaterial("cube")
	box.SetScale(5, 5, 5)
	box.SetBody(vu.Box(2.5, 2.5, 2.5), 0, 0) // sized to match scaling.

	// create a physics body that can be associated with a camera,
	cm.bod = cm.scene.AddPart()
	cm.bod.SetFacade("sphere", "gouraud").SetMaterial("sphere")
	cm.bod.SetBody(vu.Sphere(1), 1, 0)
	cm.bod.SetLocation(-6, 2, -2)

	// set some constant state.
	cm.eng.Enable(vu.BLEND, true)
	cm.eng.Enable(vu.CULL, true)
	cm.eng.Enable(vu.DEPTH, true)
	cm.eng.Color(0.1, 0.1, 0.1, 1.0)
	return
}
Ejemplo n.º 3
0
// getBall creates a visible sphere physics body.
func (cr *crtag) getBall(bod vu.Part) {
	bod.SetFacade("sphere", "gouraud").SetMaterial("sphere")
	bod.SetBody(vu.Sphere(1), 1, 0.5)
}