16 сентября 2010

Blender 2.5 SVN Mouse Look Script

Заметка...

Для мышивозни для Blender 2.5.

***

""" MouseLook.py  Controls mouselook. """ import GameLogic as gl, Rasterizer, mathutils c = gl.getCurrentController() scene = gl.getCurrentScene() own = c.owner objects = scene.objects player = objects["Player"] mouse = c.sensors["MouseLook"] # Mouse sensor zoom = c.actuators["Zoom"] # Zooming actuator # set default values sensFactor = 0.000125 capped = False invert = 1 # adjust the sensitivity sensitivity = gl.mouseSens * sensFactor capAngle = gl.mouseCap # adjust the inversion if gl.mouseInv == "True": invert = -1 else: invert = 1 # Holds values for how far the gun can zoom ZOOMDICT = {"HMG" : 35, "HG" : 10} if gl.aiming: if own["zoomFrame"] < ZOOMDICT[gl.CurrentGun]: own["zoomFrame"] += 1 else: if own["zoomFrame"] > 0: own["zoomFrame"] -= 1 c.activate(c.actuators["Zoom"]) # Get width and height of game window: width = Rasterizer.getWindowWidth() height = Rasterizer.getWindowHeight() # Get mouse movement: x = width/2 - mouse.position[0] y = height/2 - mouse.position[1] # initialize mouse: if not hasattr(gl, "mouseInit"): x = 0 y = 0 gl.mouseInit = True # If mouse isn't moved, don't move: if not mouse.positive: x = 0 y = 0 # Calculate movement: upDown = y * sensitivity * invert leftRight = x * sensitivity #--------------Calculate Cap----------------# # Make sure cap is in range if own["cap"] > 180: own["cap"] = 180 elif own["cap"] < 0: own["cap"] = 0 # Create a Z-axis vector for the camera: camVec = mathutils.Vector(own.orientation[2]) # Create a Z-axis vector for the player: playerVec = mathutils.Vector(player.orientation[2]) # find angle between two angle = camVec.angle(playerVec) # check capped angle against against camera z-axis and mouse y movement if (angle > (1.5 + own["cap"]/130) and upDown > 0) or (angle < (1.5 - own["cap"]/130) and upDown < 0): capped = True # If capped, stop movement: if capped == True: upDown = 0 #--------------Move View--------------------# own.applyRotation([upDown, 0.0, 0.0], 1) own.parent.applyRotation([0.0, 0.0, leftRight], 0) #--------------Center Cursor----------------# if mouse.position != [int(width/2), int(height/2)]: Rasterizer.setMousePosition(int(width/2), int(height/2)) #-------------------------------------------#

Сектора Лирики