Ejemplo n.º 1
0
// returns if we are done or not
func key_handler() bool {
	var keys []uint8 = sdl.GetKeyState()

	if keys[sdl.K_i] != 0 {
		view_z += 1
	}
	if keys[sdl.K_o] != 0 {
		view_z -= 1
	}
	if keys[sdl.K_ESCAPE] != 0 {
		return true
	}
	if keys[sdl.K_UP] != 0 {
		view_rotx += 1
	}
	if keys[sdl.K_DOWN] != 0 {
		view_rotx -= 1.0
	}
	if keys[sdl.K_LEFT] != 0 {
		view_roty += 1.0
	}
	if keys[sdl.K_RIGHT] != 0 {
		view_roty -= 1.0
	}
	if keys[sdl.K_z] != 0 {
		if (sdl.GetModState() & sdl.KMOD_RSHIFT) != 0 {
			view_rotz -= 1.0
		} else {
			view_rotz += 1.0
		}
	}
	if keys[sdl.K_w] != 0 {
		gl.Translatef(0.0, 0.0, 1)
	}
	if keys[sdl.K_s] != 0 {
		gl.Translatef(0.0, 0.0, -1)
	}
	if keys[sdl.K_a] != 0 {
		gl.Translatef(-1, 0, 0)
	}
	if keys[sdl.K_d] != 0 {
		gl.Translatef(1, 0, 0)
	}
	if keys[sdl.K_q] != 0 {
		gl.Translatef(0, 1, 0)
	}
	if keys[sdl.K_e] != 0 {
		gl.Translatef(0, -1, 0)
	}
	return false
}
Ejemplo n.º 2
0
func main() {

	flag.Parse()

	var done bool
	var keys []uint8

	sdl.Init(sdl.INIT_VIDEO)

	var screen = sdl.SetVideoMode(300, 300, 16, sdl.OPENGL|sdl.RESIZABLE)

	if screen == nil {
		sdl.Quit()
		panic("Couldn't set 300x300 GL video mode: " + sdl.GetError() + "\n")
	}

	if gl.Init() != 0 {
		panic("gl error")
	}

	sdl.WM_SetCaption("Gears", "gears")

	init_()
	reshape(int(screen.W), int(screen.H))
	done = false
	for !done {

		idle()
		for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() {
			switch e.(type) {
			case *sdl.ResizeEvent:
				re := e.(*sdl.ResizeEvent)
				screen = sdl.SetVideoMode(int(re.W), int(re.H), 16,
					sdl.OPENGL|sdl.RESIZABLE)
				if screen != nil {
					reshape(int(screen.W), int(screen.H))
				} else {
					panic("we couldn't set the new video mode??")
				}
				break

			case *sdl.QuitEvent:
				done = true
				break
			}
		}
		keys = sdl.GetKeyState()

		if keys[sdl.K_ESCAPE] != 0 {
			done = true
		}
		if keys[sdl.K_UP] != 0 {
			view_rotx += 5.0
		}
		if keys[sdl.K_DOWN] != 0 {
			view_rotx -= 5.0
		}
		if keys[sdl.K_LEFT] != 0 {
			view_roty += 5.0
		}
		if keys[sdl.K_RIGHT] != 0 {
			view_roty -= 5.0
		}
		if keys[sdl.K_z] != 0 {
			if (sdl.GetModState() & sdl.KMOD_RSHIFT) != 0 {
				view_rotz -= 5.0
			} else {
				view_rotz += 5.0
			}
		}

		draw()
	}
	sdl.Quit()
	return

}