DanisRace/Scripts/Mouse.py
Victorious Children Studios 594e088a83 07-07-24
2024-07-13 16:15:50 +03:00

57 lines
1.4 KiB
Python

# Gpl3 or later
# (C) J.Y.Amihud 2024
# Stuff related to mouse control
import bge
def MouseLook(cont):
MouseLookActual(cont)
def MouseLookActual(cont, workanyway=False):
if not bge.logic.globalDict.get("mouse-active", True):
return
# We need this to be able disable mouse look from the
# the code.
# Getting object that will rotate.
if type(cont) == bge.types.SCA_PythonController:
obj = cont.owner
else: obj = cont
scene = bge.logic.getCurrentScene()
dani = scene.objects["Dani_Box"]
# Disabling the camera rotation
if not workanyway and dani.get("driving") and dani["driving"].get("dynamiccam", True):
return
# Getting mouse position on the screen.
mouse = bge.logic.mouse
pos = list(mouse.position)
# Mouse positions are normalized to be 0.5 at the center.
# We need center to be 0.0.
pos[0] -= 0.5
pos[1] -= 0.5
# Getting factor information about how to move the mouse
# from the object.
my = -obj.get("mouse_Y", 1.0)
mx = -obj.get("mouse_X", 1.0)
mg = obj.get("mouse_global", True)
# Applying the rotation.
obj.applyRotation((pos[1]*my, 0, pos[0]*mx), mg)
# Centring the mouse.
CenterCursor()
def CenterCursor():
if not bge.logic.globalDict.get("mouse-active", True):
return
bge.render.setMousePosition(int(bge.render.getWindowWidth() / 2), int(bge.render.getWindowHeight() / 2))