예제 #1
0
파일: gears.go 프로젝트: nzlov/examples
// 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
	}
}
예제 #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)
	}
}
예제 #3
0
func (game *Game) KeyPress(window *glfw.Window, k glfw.Key, s int, action glfw.Action, mods glfw.ModifierKey) {
	fmt.Println("keypress", k)
	if action == glfw.Release {
		switch k {

		case 77:
			fmt.Println("m")
		case glfw.KeyEscape:
			window.SetShouldClose(true)
		}
	}
}
예제 #4
0
파일: main.go 프로젝트: spacetug/raytracer
// onKey handles key events.
func onKey(window *glfw.Window, key glfw.Key, code int, action glfw.Action, mod glfw.ModifierKey) {
	if action != glfw.Press {
		return
	}

	switch key {
	case glfw.KeyF5:
		shaderReload()

	case glfw.KeyEscape:
		window.SetShouldClose(true)

	case glfw.KeySpace:

	case glfw.KeyLeft:
	case glfw.KeyRight:

	}
}
예제 #5
0
파일: 10.go 프로젝트: 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
	}
}
예제 #6
0
파일: 09.go 프로젝트: 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
	}
}
예제 #7
0
파일: main.go 프로젝트: nick-fedesna/egles
func keyEvent(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
	switch key {
	case glfw.KeyEscape:
		w.SetShouldClose(true)
	case glfw.KeyLeft:
		if mods == glfw.ModShift {
			ModelView = ModelView.Mul4(mgl.HomogRotate3DY(5))
		} else {
			ModelView = ModelView.Mul4(mgl.Translate3D(-0.1, 0, 0))
		}
	case glfw.KeyRight:
		if mods == glfw.ModShift {
			ModelView = ModelView.Mul4(mgl.HomogRotate3DY(-5))
		} else {
			ModelView = ModelView.Mul4(mgl.Translate3D(0.1, 0, 0))
		}
	case glfw.KeyUp:
		if mods == glfw.ModShift {
			ModelView = ModelView.Mul4(mgl.HomogRotate3DX(5))
		} else {
			ModelView = ModelView.Mul4(mgl.Translate3D(0, 0.1, 0))
		}
	case glfw.KeyDown:
		if mods == glfw.ModShift {
			ModelView = ModelView.Mul4(mgl.HomogRotate3DX(-5))
		} else {
			ModelView = ModelView.Mul4(mgl.Translate3D(0, -0.1, 0))
		}
	case glfw.KeyMinus:
		ModelView = ModelView.Mul4(mgl.Translate3D(0, 0, -0.1))
	case glfw.KeyEqual:
		ModelView = ModelView.Mul4(mgl.Translate3D(0, 0, 0.1))
	}
	go func(m mgl.Mat4f) { MVP <- m }(Projection.Mul4(ModelView))

}
예제 #8
0
파일: window.go 프로젝트: nobonobo/go-three
func keyCallback(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
	if key == glfw.KeyEscape && action == glfw.Press {
		w.SetShouldClose(true)
	}
}
예제 #9
0
func keyCallback(window *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
	//fmt.Printf("%v, %v, %v, %v\n", key, scancode, action, mods)

	if key == glfw.KeyEscape && action == glfw.Press {
		window.SetShouldClose(true)
	}

	if !paused {
		if key == glfw.KeyLeft {
			if action == glfw.Press {
				ship.RotateLeft(true)
			} else if action == glfw.Release {
				ship.RotateLeft(false)
			}
		} else if key == glfw.KeyRight {
			if action == glfw.Press {
				ship.RotateRight(true)
			} else if action == glfw.Release {
				ship.RotateRight(false)
			}
		}

		if key == glfw.KeyUp {
			if action == glfw.Press {
				ship.Accelerate(true)
			} else if action == glfw.Release {
				ship.Accelerate(false)
			}
		} else if key == glfw.KeyDown {
			if action == glfw.Press {
				ship.Decelerate(true)
			} else if action == glfw.Release {
				ship.Decelerate(false)
			}
		}

		if key == glfw.KeySpace || key == glfw.KeyX {
			if action == glfw.Press {
				ship.Shoot(true)
			} else if action == glfw.Release {
				ship.Shoot(false)
			}
		}

		if (key == glfw.KeyY || key == glfw.KeyZ || key == glfw.KeyLeftShift || key == glfw.KeyRightShift) && action == glfw.Press {
			ship.DropMine()
		}

		if (key == glfw.KeyC || key == glfw.KeyLeftControl || key == glfw.KeyRightControl) && action == glfw.Press {
			ship.ShootTorpedo()
		}
	}

	if key == glfw.KeyEnter && action == glfw.Press { //&& mods == glfw.ModAlt {
		altEnter = true
	}

	if key == glfw.KeyF1 && action == glfw.Press {
		switchHighscore()
	}

	if key == glfw.KeyF2 && action == glfw.Press {
		switchColors()
	}

	if key == glfw.KeyF3 && action == glfw.Press {
		switchWireframe()
	}

	if (key == glfw.KeyF9 || key == glfw.KeyR || key == glfw.KeyBackspace) && action == glfw.Press {
		score = 0
		resetGame()
	}

	if (key == glfw.KeyPause || key == glfw.KeyP) && action == glfw.Press {
		paused = !paused
	}

	if key == glfw.KeyN && action == glfw.Press && isGameWon() {
		difficulty += 3
		resetGame()
	}

	if debug && key == glfw.KeyF10 && action == glfw.Press {
		for _, asteroid := range asteroids {
			if asteroid.IsAlive() {
				asteroid.Destroy()
			}
		}
		for _, mine := range mines {
			if mine.IsAlive() {
				mine.Destroy()
			}
		}
	}
}
예제 #10
0
func (game *Game) KeyPress(window *glfw.Window, k glfw.Key, s int, action glfw.Action, mods glfw.ModifierKey) {
	//fmt.Println("keypress", k)
	if action == glfw.Release {
		switch k {

		case glfw.KeyEscape:
			window.SetShouldClose(true)
			//b key
		case 66:
			fmt.Println((len(BreadCrumbs) - 1), "Crumz")
			//if len(BreadCrumbs) < 1{
			for i := 0; i < len(BreadCrumbs)-1; i++ {
				fmt.Println(i, ":", BreadCrumbs[i])
				//	}
			}
			// > key
		case 46:
			LookAround(MazeMan)
			inspdir := FindLowestCell(Inspection)
			if deadend == 0 {
				dir := GridAtDirection(MazeMan, inspdir)
				SetManPos(dir)
				BreadCrumbs = append(BreadCrumbs, dir)
				goback = 0
			} else {
				fmt.Println("deadend, go back")
				b := len(BreadCrumbs)
				c := BreadCrumbs[b-1-goback]
				goback++
				SetManPos(c)
			}

		case 72:
			fmt.Println("Z: RESET|X: HEURISTIC|C: COMPUTEPATH|M:BRUSH|V:NEXTPOINT")

			//X key
		case 88:
			heur := GiveHeuristic(here)
			fmt.Println("Here:", here, "Heuristic:", heur, "Crumbs:", IsCrumbed(here))

			//v Key
		case 86:
			inspdir := FindLowestCell(Inspection)
			dir := GridAtDirection(MazeMan, inspdir)
			fmt.Println("next cell is", dir)
			//Z KEY
		case 90:
			BreadCrumbs = BreadCrumbs[:0]
			for i := 0; i < 400; i++ {
				if Grid[i] == 1 {
					Grid[i] = 0
				}
			}
			SetManPos(StartPos)
			fmt.Println("MazeMan sent to StartPos")

			//C KEY
		case 67:
			LookAround(MazeMan)
			fmt.Println("ComputePath")

			sortloc := FindLowestCell(Inspection)
			fmt.Println(sortloc)

			//M KEY
		case 77:
			SwitchMode()
			modeis := "wall"
			switch mode {
			case 0:
				modeis = "wall"
			case 1:
				modeis = "start position"
			case 2:
				modeis = "end position"
			}
			fmt.Println(modeis, "brush")
		//case 46:
		//fmt.Println("MOVE FORWARDS")
		case 44:
			fmt.Println("MOVE BACKWARDS")
		}
	}
}