DanisRace/Scripts/Mouse.py~
Victorious Children Studios db92590087 Version 08-08-24
2024-08-27 15:34:26 +03:00

64 lines
1.5 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
if round(pos[0], 2) == 0:
pos[0] = 0
if round(pos[1], 2) == 0:
pos[1] = 0
# 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))