Exemplo n.º 1
0
// Handle movement assuming there is a physics body associated with the camera.
// This attempts to smooth out movement by adding a higher initial velocity push
// and then capping movement once max accelleration is reached.
func (c *cam) move(bod vu.Pov, x, y, z float64, dir *lin.Q) {
	if body := bod.Body(); body != nil {
		boost := 40.0    // kick into high gear from stop.
		maxAccel := 10.0 // limit accelleration.
		sx, _, sz := body.Speed()
		if x != 0 {
			switch {
			case sx == 0.0:
				// apply push in the current direction.
				dx, dy, dz := lin.MultSQ(x*boost, 0, 0, dir)
				body.Push(dx, dy, dz)
			case math.Abs(sx) < maxAccel && math.Abs(sz) < maxAccel:
				dx, dy, dz := lin.MultSQ(x, 0, 0, dir)
				body.Push(dx, dy, dz)
			}
		}
		if z != 0 {
			switch {
			case sz == 0.0:
				dx, dy, dz := lin.MultSQ(0, 0, z*boost, dir)
				body.Push(dx, dy, dz)
			case math.Abs(sx) < maxAccel && math.Abs(sz) < maxAccel:
				dx, dy, dz := lin.MultSQ(0, 0, z, dir)
				body.Push(dx, dy, dz)
			}
		}
	} else {
		bod.Move(x, y, z, dir)
	}
}