Beispiel #1
0
// change view angle, exit upon ESC
func key(window *glfw.Window, k glfw.Key, s int, action glfw.Action, mods glfw.ModifierKey) {
	if action != glfw.Press {
		return
	}

	switch glfw.Key(k) {
	case glfw.KeyZ:
		if mods&glfw.ModShift != 0 {
			view_rotz -= 5.0
		} else {
			view_rotz += 5.0
		}
	case glfw.KeyEscape:
		window.SetShouldClose(true)
	case glfw.KeyUp:
		view_rotx += 5.0
	case glfw.KeyDown:
		view_rotx -= 5.0
	case glfw.KeyLeft:
		view_roty += 5.0
	case glfw.KeyRight:
		view_roty -= 5.0
	default:
		return
	}
}
Beispiel #2
0
func keyHandler(window *glfw.Window, k glfw.Key, s int, action glfw.Action, mods glfw.ModifierKey) {
	if action != glfw.Press {
		return
	}

	switch glfw.Key(k) {
	case glfw.KeyEscape:
		window.SetShouldClose(true)
	}
}
Beispiel #3
0
func (c *ControlBindings) Apply(receiver interface{}, bindings map[string]string) {
	mb, err := regexp.Compile("^mouse([1-9])$")
	if err != nil {
		panic(err)
	}
	receiverValue := reflect.ValueOf(receiver)
	for k, name := range bindings {
		stopName := "Stop" + name
		if len(k) == 1 {
			key := glfw.Key(k[0])
			if name == "" {
				c.UnbindKeyPress(key)
			} else {
				startAction := FindActionMethod(receiverValue, name)
				stopAction := FindActionMethod(receiverValue, stopName)
				c.BindKeyPress(key, startAction, stopAction)
			}
		} else if mb.MatchString(k) {
			i, err := strconv.Atoi(mb.FindStringSubmatch(k)[1])
			if err == nil {
				button := glfw.MouseButton1 + glfw.MouseButton(i-1)
				if name == "" {
					c.UnbindMouseClick(button)
				} else {
					// fmt.Println("bind", i, button, glfw.MouseButton1)
					startAction := FindActionMethod(receiverValue, name)
					stopAction := FindActionMethod(receiverValue, stopName)
					c.BindMouseClick(button, startAction, stopAction)
				}
			}
		} else if k == "mousemove" {
			if name == "" {
				c.UnbindMouseMovement()
			} else {
				moveAction := FindMouseMoveActionMethod(receiverValue, name)
				c.BindMouseMovement(moveAction)
			}
		}
	}
}
Beispiel #4
0
Datei: 10.go Projekt: nzlov/gogl
// change view angle, exit upon ESC
func key(window *glfw.Window, k glfw.Key, s int, action glfw.Action, mods glfw.ModifierKey) {

	switch glfw.Key(k) {
	case glfw.KeyEscape:
		window.SetShouldClose(true)
	case glfw.KeyUp:
		xpos -= float32(math.Sin(float64(heading*piover180)) * 0.05)
		zpos -= float32(math.Cos(float64(heading*piover180)) * 0.05)
		if walkbiasangle >= 359.0 {
			walkbiasangle = 0.0
		} else {
			walkbiasangle += 10
		}
		walkbias = float32(math.Sin(float64(walkbiasangle*piover180)) / 20.0)
	case glfw.KeyDown:
		xpos += float32(math.Sin(float64(heading*piover180)) * 0.05)
		zpos += float32(math.Cos(float64(heading*piover180)) * 0.05)
		if walkbiasangle <= 1.0 {
			walkbiasangle = 359.0
		} else {
			walkbiasangle -= 10
		}
		walkbias = float32(math.Sin(float64(walkbiasangle*piover180)) / 20.0)
	case glfw.KeyLeft:
		heading += 1.0
		yrot = heading
	case glfw.KeyRight:
		heading -= 1.0
		yrot = heading
	case glfw.KeyPageUp:
		z -= 0.02
		lookupdown -= 1.0
	case glfw.KeyPageDown:
		z += 0.02
		lookupdown += 1.0
	default:
		return
	}
}
Beispiel #5
0
Datei: 09.go Projekt: nzlov/gogl
// change view angle, exit upon ESC
func key(window *glfw.Window, k glfw.Key, s int, action glfw.Action, mods glfw.ModifierKey) {

	switch glfw.Key(k) {
	case glfw.KeyEscape:
		window.SetShouldClose(true)
	case glfw.KeyT:
		twinkle = !twinkle
	case glfw.KeyUp:
		tilt -= 0.5 // 屏幕向上倾斜
	case glfw.KeyDown:
		tilt += 0.5 // 屏幕向下倾斜
	case glfw.KeyLeft:
		ztilt -= 0.5 // 屏幕向上倾斜
	case glfw.KeyRight:
		ztilt += 0.5 // 屏幕向下倾斜
	case glfw.KeyPageUp:
		zoom -= 0.2 // 缩小
	case glfw.KeyPageDown:
		zoom += 0.2 // 放大
	default:
		return
	}
}
Beispiel #6
0
func (me *window) Key(key int) int {
	return int(me.Window.GetKey(glfw.Key(key)))
}
// IsKeyRepeated :: input.InputEmitter
func (self *OpenGLWindow) IsKeyRepeated(key input.KeyCode) bool {
	keyState := self.window.GetKey(glfw.Key(key))
	return keyState == glfw.Repeat
}