Esempio n. 1
0
def static_rotate(own, mouse):
    if own['cur_pos'] != 0:
        render.setMousePosition(*own['cur_pos'])
        own['cur_pos'] = 0.0
    render.showMouse(True)
    own['init'] = False
    player_rot(0, 0, 0)
Esempio n. 2
0
 def update(self):
     if not self.is_open:
         # menu's not open, listen to in-game hotkeys
         R.setMousePosition(*self.screen_center)
         self.cursor.localPosition = self.mouse.raySource
         if G.keyboard.events[self.kh_menu] == RELEASED:
             self.toggle_menu()
         elif G.keyboard.events[self.kh_view_toggle] == RELEASED:
             controls.movement_controls.view_toggle()
         return
     # menu is open
     self.cursor.localPosition = self.mouse.raySource
     obj = self.mouse.hitObject
     if obj and 'highlight' in obj and obj['highlight']:
         self.menu_highlight.localPosition = obj.position
         self.menu_highlight.localPosition.z = obj.position.z - 1.0
         self.menu_highlight.setVisible(True)
         if E.LEFTMOUSE in G.mouse.active_events and 'start_game' in obj:
             print('mouse button', obj)
             if obj.name == 'choose_fly':
                 try:
                     #controls.start_game()
                     self.toggle_menu(False)
                 except Exception as e:
                     print(e)
             elif obj.name == 'choose_exit':
                 G.endGame()
    def __init__(self, cont):

        self.body = cont.owner
        self.camera_parent = self.body.children[
            'shortcuts_third_person_camera_parent']
        self.camera_parent_rotation = self.camera_parent.localOrientation.copy(
        )

        # Player movement variables
        self.move_speed = 5.0
        self.run_multiplier = 2.0
        self.jump_force = 5.0

        # Mouse variables
        self.mouse_sensitivity = 0.002
        self.mouse_smoothing = 0.5

        # Used for smoothing the mouselook
        self.old_x = 0.0
        self.old_y = 0.0

        # Screen variables used for the mouselook
        self.screen_width = render.getWindowWidth()
        self.screen_height = render.getWindowHeight()
        self.screen_center = (self.screen_width // 2, self.screen_height // 2)

        # Set the mouse position to the center of the screen
        render.setMousePosition(*self.screen_center)

        # logic.mouse.position is incorrect on the first frame. This variable is used to get around that
        self.delay = 0
Esempio n. 4
0
def m(cont):
    global mousePos, mouseSensitivity
    ob = cont.owner
    mouse = cont.sensors["Mouse"]
    
    # calculate the amount mouse cursor moved from the center since last frame
    mouseDelta = [
        (mouse.position[0] - centerX) * mouseSensitivity,
        (centerY - mouse.position[1]) * mouseSensitivity]

    # move mouse cursor back to center
    render.setMousePosition(centerX, centerY)

    # update our secret internal mouse position
    mousePos[0] += mouseDelta[0]
    mousePos[1] += mouseDelta[1]

    # move cube onscreen
    ob.localPosition.x = mousePos[0]
    ob.localPosition.y = mousePos[1]

    # rotate 45 degrees to convert to motor impulses
    motorPos = [
        -mousePos[0]*cos45 + mousePos[1]*cos45,
        (mousePos[0]*cos45 + mousePos[1]*cos45),
    ]

    print(mousePos)

    # send new motor positions to uC
    # NO LONGER SUPPORTED
    #sendChairCmd('R', int(motorPos[0]))
    #sendChairCmd('L', int(motorPos[1]))
Esempio n. 5
0
 def __init__(self, cont):
     
     self.body = cont.owner
     self.camera = self.body.children['shortcuts_fps_camera']
     
     # Player movement variables
     self.move_speed = 5.0
     self.run_multiplier = 2.0        
     self.jump_force = 5.0
     
     # Mouse variables
     self.mouse_sensitivity = 0.002
     self.mouse_smoothing = 0.5
 
     # Used for smoothing the mouselook
     self.old_x = 0.0
     self.old_y = 0.0
     
     # Screen variables used for the mouselook
     self.screen_width = render.getWindowWidth()
     self.screen_height = render.getWindowHeight()
     self.screen_center = (self.screen_width//2, self.screen_height//2)
     
     # Set the mouse position to the center of the screen
     render.setMousePosition(*self.screen_center) 
     
     # logic.mouse.position is incorrect on the first frame. This variable is used to get around that
     self.delay = 0
Esempio n. 6
0
def main(cont):
	global dest, from_quat, slerp_factor, to_quat
	own = cont.owner
	#where we are going
	dest = cam_defualt_pos.worldPosition.copy()
	diff = dest - own.worldPosition.copy()
	#lerping
	if diff.magnitude > 0.1:
		 diff *= 0.025

	if slerp_factor < 1.0:
		slerp_factor += 0.005
		#print ('slerp', slerp_factor)
	
	own.worldPosition += diff
	#slerping rotation
	quatInterpolation = from_quat.slerp(to_quat, slerp_factor)
	own.worldOrientation = quatInterpolation.to_matrix()
	#reached our destination
	if own.worldPosition == dest:
		#own.orientation = cam_defualt_pos.orientation
		logic.sendMessage('player_unfreeze')
		logic.sendMessage('HUD_on')
		render.setMousePosition(int(render.getWindowWidth() / 2), int(render.getWindowHeight() / 2))
		own.state = logic.KX_STATE1
Esempio n. 7
0
def m(cont):
    global mousePos, mouseSensitivity
    ob = cont.owner
    mouse = cont.sensors["Mouse"]

    # calculate the amount mouse cursor moved from the center since last frame
    mouseDelta = [(mouse.position[0] - centerX) * mouseSensitivity,
                  (centerY - mouse.position[1]) * mouseSensitivity]

    # move mouse cursor back to center
    render.setMousePosition(centerX, centerY)

    # update our secret internal mouse position
    mousePos[0] += mouseDelta[0]
    mousePos[1] += mouseDelta[1]

    # move cube onscreen
    ob.localPosition.x = mousePos[0]
    ob.localPosition.y = mousePos[1]

    # rotate 45 degrees to convert to motor impulses
    motorPos = [
        -mousePos[0] * cos45 + mousePos[1] * cos45,
        (mousePos[0] * cos45 + mousePos[1] * cos45),
    ]

    print(mousePos)
Esempio n. 8
0
def main():
    
    cont = bge.logic.getCurrentController()
    own = cont.owner

    mouse = cont.sensors ["Mouse"]
    rotx = cont.actuators ["RotX"]
    rotz = cont.actuators ["RotZ"]
    
    cont.activate(rotx)
    cont.activate(rotz)
    
    x = render.getWindowWidth()//2
    y = render.getWindowHeight()//2
    
    screen_center = (x,y)
    center = Vector(screen_center)
    mouse_position = Vector(mouse.position)
    
    offset = (mouse_position - center) * -0.002
    
    rotx.dRot = [offset.y, 0, 0]
    rotz.dRot = [0, 0, offset.x]
    
    render.setMousePosition(x,y)
Esempio n. 9
0
    def main(self):#

        vec_offset = self.getMouseOffset()
        vec_offset *= -0.005
        self.act_rotx.dRot = [vec_offset.y, 0, 0]
        self.act_rotz.dRot = [0, 0, vec_offset.x]
        render.setMousePosition(*self.screen_center)
Esempio n. 10
0
def head_control(contr):
    """ Move the target of the head and camera

    Use the movement of the mouse to determine the rotation
    for the human head and camera. """
    # get the object this script is attached to
    human = contr.owner
    scene = logic.getCurrentScene()
    target = scene.objects['Target_Empty']
    POS_EMPTY = scene.objects['POS_EMPTY']
    Head_Empty = scene.objects['Head_Empty']
    right_hand = scene.objects['Hand_Grab.R']
    mmb = contr.sensors['MMB']


    # If the manipulation mode is active, an object is grabbed
    # and the Middle Mouse Button is pressed, do nothing
    if (human['Manipulate'] and right_hand['selected'] != 'None' and
        right_hand['selected'] != '' and mmb.positive):
        return

    if mmb.positive:
        target = scene.objects['IK_Target_Empty.R']

    # Get sensor named Mouse
    mouse = contr.sensors['Mouse']

    if mouse.positive:
        # get width and height of game window
        width = render.getWindowWidth()
        height = render.getWindowHeight()

        # get mouse movement from function
        move = mouse_move(human, mouse, width, height)

        # set mouse sensitivity
        sensitivity = human['Sensitivity']

        # Amount, direction and sensitivity
        left_right = move[0] * sensitivity
        up_down = move[1] * sensitivity

        if not human['FOCUSED']:
            POS_EMPTY.applyRotation([0.0, 0.0, left_right], True)
            if not ((Head_Empty.localOrientation.to_euler()[1] >= 0.7
                     and up_down < 0) or
                    (Head_Empty.localOrientation.to_euler()[1] <= -0.4
                     and up_down > 0)) and not human['Manipulate']:
                # capping the rotation to prevent the camera to be upside down
                if not mmb.positive:
                    Head_Empty.applyRotation([0.0, -up_down, 0.0], True)
                target.applyMovement([0.0, 0.0, up_down], True)
            elif human['Manipulate']:
                Head_Empty.applyRotation([0.0, -up_down, 0.0], True)
                target.applyMovement([0.0, 0.0, up_down], True)

        # Reset mouse position to the centre of the screen
        # Using the '//' operator (floor division) to produce an integer result
        render.setMousePosition(width//2, height//2)
Esempio n. 11
0
def main(cont):
    own = cont.owner

    mousemove = cont.sensors['mousemove']

    cranezrot = cont.actuators['cranezrot']
    crane_move = cont.actuators['crane_move']
    gear_rot = cont.actuators['gear_rot']
    gear_s_rot = cont.actuators['gear_s_rot']

    #set mouse pos
    screenwidth = render.getWindowWidth()
    screenheight = render.getWindowHeight()

    render.setMousePosition(int(screenwidth / 2), int(screenheight / 2))

    crane_tip = cont.sensors['crane_tip'].owner

    if mousemove.positive:
        zmouse = (screenwidth / 2 - mousemove.position[0]) * own['sensitivity']
        ymouse = (screenheight / 2 -
                  mousemove.position[1]) * own['sensitivity']

        own['previousz'] = (own['previousz'] * .8 + zmouse * .2)
        own['previousy'] = (own['previousy'] * .8 + ymouse * .2)

        zmouse = own['previousz']
        #set max speed
        zmouse = max(min(zmouse, .02), -.02)
        ymouse = max(min(ymouse, .06), -.06)

        #restrict crane tip
        #loc = crane_tip.localPosition[0]
        crane_tip.localPosition[0] = max(min(crane_tip.localPosition[0], 5),
                                         -20)
        #restrict crane rotation
        #print (own['start_rot'])
        crane_angle = own.localOrientation.to_euler()
        crane_angle[2] = max(min(crane_angle[2], (own['start_rot'] + 1.4)),
                             (own['start_rot'] - 1.4))

        crane_angle.to_matrix()
        own.localOrientation = crane_angle
        #rotate the crane
        crane_move.dLoc = (ymouse * 8, 0, 0)
        cranezrot.dRot = (0, 0, -zmouse)
        gear_rot.dRot = (0, 0, zmouse * 2.5)
        gear_s_rot.dRot = (0, -zmouse * 2.5, 0)

        cont.activate(gear_rot)
        cont.activate(gear_s_rot)
        cont.activate(cranezrot)
        cont.activate(crane_move)
    else:
        cont.deactivate(gear_rot)
        cont.deactivate(gear_s_rot)
        cont.deactivate(cranezrot)
        cont.deactivate(crane_move)
Esempio n. 12
0
def main(cont):
    """called once by the "Always" sensor named InitGame,
    will remove sensors if we have time its kinda complicated"""
    bge.c = Controller(0)  # hard codded, will be the players list index (i++)
    bge.c.game = Game(2)
    bge.c.game.game_init()
    bge.c.display = bgui.bge_utils.System('../../themes/default')
    bge.c.display.load_layout(MainDisplay, None)
    render.showMouse(True)
    render.setMousePosition(400, 400)
Esempio n. 13
0
def main(cont):
	own = cont.owner
	
	mousemove = cont.sensors['mousemove']

	cranezrot = cont.actuators['cranezrot']
	crane_move = cont.actuators['crane_move']
	gear_rot = cont.actuators['gear_rot']
	gear_s_rot = cont.actuators['gear_s_rot']

	#set mouse pos
	screenwidth = render.getWindowWidth()
	screenheight = render.getWindowHeight()

	render.setMousePosition(int(screenwidth/2), int(screenheight/2))
	
	crane_tip = cont.sensors['crane_tip'].owner

	if mousemove.positive:
		zmouse = (screenwidth/2 - mousemove.position[0]) * own['sensitivity']
		ymouse = (screenheight / 2 - mousemove.position[1]) * own['sensitivity']
		
		own['previousz'] = (own['previousz'] * .8 + zmouse * .2)
		own['previousy'] = (own['previousy'] * .8 + ymouse * .2)
		
		zmouse = own['previousz']
		#set max speed
		zmouse = max(min(zmouse, .02), -.02)
		ymouse = max(min(ymouse, .06), -.06)
		
		#restrict crane tip
		#loc = crane_tip.localPosition[0]
		crane_tip.localPosition[0] = max(min(crane_tip.localPosition[0], 5), -20)
		#restrict crane rotation
		#print (own['start_rot'])
		crane_angle = own.localOrientation.to_euler()
		crane_angle[2] = max(min(crane_angle[2], (own['start_rot'] + 1.4)), (own['start_rot'] - 1.4))
		
		crane_angle.to_matrix()
		own.localOrientation = crane_angle
		#rotate the crane
		crane_move.dLoc =(ymouse *8, 0, 0)
		cranezrot.dRot =(0, 0, -zmouse)
		gear_rot.dRot =(0, 0, zmouse *2.5)
		gear_s_rot.dRot =(0, -zmouse *2.5, 0)

		cont.activate(gear_rot)
		cont.activate(gear_s_rot)
		cont.activate(cranezrot)
		cont.activate(crane_move)
	else:
		cont.deactivate(gear_rot)
		cont.deactivate(gear_s_rot)
		cont.deactivate(cranezrot)
		cont.deactivate(crane_move)
Esempio n. 14
0
def activate_mouse():
	cont = logic.getCurrentController()
	own = cont.owner
	mPosi = cont.sensors['MousePosi']

	if own['init']:
	    render.setMousePosition( render.getWindowWidth() // 2, render.getWindowHeight() // 2 )
	    own['init'] = 0
	    
	### move cursor to mouse position
	own.localPosition = mPosi.raySource
Esempio n. 15
0
def rotate(contr):
    """ Read the movements of the mouse and apply them
        as a rotation to the camera. """
    # get the object this script is attached to
    camera = contr.owner

    scene = logic.getCurrentScene()
    if not scene:
        # not ready, main reload(blenderapi)
        return

    # Do not move the camera if the current view is using another camera
    if camera != scene.active_camera:
        return
    camera = scene.cameras["BodyCam"]
    # Get sensor named Mouse
    mouse = contr.sensors['Mouse']
    # Get Blender keyboard sensor

    # Show the cursor
    mouse_visible = True

    # Hide the cursor while we control the camera
    mouse_visible = False
    if mouse.positive:
        # get width and height of game window
        width = render.getWindowWidth()
        height = render.getWindowHeight()

        # get mouse movement from function
        move = mouse_move(camera, mouse, width, height)

        # set mouse sensitivity
        sensitivity = 0.003  # camera['Sensitivity']
        print(camera.localOrientation)
        # Amount, direction and sensitivity
        leftRight = move[0] * sensitivity
        upDown = move[1] * sensitivity

        print(upDown, leftRight)
        # set the values
        camera.localOrientation = Euler((upDown, 0.0, leftRight), 'XYZ')
        print(Euler((upDown, 0.0, leftRight), 'XYZ'))

        # Center mouse in game window
        # Using the '//' operator (floor division) to produce an integer result

        render.setMousePosition(width // 2, height // 2)

    # Show the cursor
    mouse_visible = True

    # Set the cursor visibility
    render.showMouse(mouse_visible)
Esempio n. 16
0
def mouseCenter(c, size, mouse, enabled):
	
	if mouse != None:
		width = size[0]
		height = size[1]
		
		pos = mouse.position
		
		if pos != [int(width/2), int(height/2)]:
			if enabled != False:
				r.setMousePosition(int(width/2), int(height/2))   
Esempio n. 17
0
def mouse_move(own, mouse):
    if own['cur_pos'] == 0:
        own['cur_pos'] = mouse.position
    render.showMouse(False)
    render.setMousePosition(*own['win_size'])
    x_pos = (own['win_size'][0] - mouse.position[0]) * SENSITIVITY
    y_pos = (own['win_size'][1] - mouse.position[1]) * SENSITIVITY
    if own['init'] == False:
        x_pos = y_pos = 0
        own['init'] = True
    return x_pos, y_pos
Esempio n. 18
0
def mouseMove():
    cont = logic.getCurrentController()
    logic.car = cont.owner
    mouse = cont.sensors["Mouse"]

    # Set mouse sensitivity
    sensitivity = 0.07

    h = r.getWindowHeight()//2
    w = r.getWindowWidth()//2
    x = (h - mouse.position[0])*sensitivity
    y = (w - mouse.position[1])*sensitivity

    #  reset mouse for next frame and keep mouse in the game window
    r.setMousePosition(h, w)

    rot = logic.car.localOrientation.to_euler()

    #  Bank / Lean when gliding, but not for car shapes
    if logic.car["onGround"] == False and logic.car["activeShape"] <= 4:
        yaw = math.degrees(rot[2]) + x / 6
        rot[2] = math.radians(yaw)

        roll = math.degrees(rot[1]) + x * -1
        rot[1] = math.radians(roll)

        pitch = math.degrees(rot[0]) + y / 4
        rot[0] = math.radians(pitch)

        #  Apply rotation
        logic.car.localOrientation = rot.to_matrix()

    # Mouse "dead zone" 0.45 to help moving straight
    #  Right
    if x < -0.45:
        #  Turn Wheels
        logic.car["steer"] -= logic.car["steerAmount"] / 2
        if logic.car["onGround"] == False:
            #  Vector thrust to move (and stay in the air)
            logic.car.linearVelocity[0] += logic.car["glideJumpZ"]
            logic.car.linearVelocity[2] += logic.car["glideBonusZ"] / 4
    #  Left
    if x > 0.45:
        #  Turn Wheels
        logic.car["steer"] += logic.car["steerAmount"] / 2
        if logic.car["onGround"] == False:
            #  Vector thrust to move (and stay in the air)
            logic.car.linearVelocity[0] -= logic.car["glideJumpZ"]
            logic.car.linearVelocity[2] += logic.car["glideBonusZ"] / 4


    #  reset mouse for next frame and keep mouse in the game window
    r.setMousePosition(h, w)
Esempio n. 19
0
def _mouselook_core(self, id):
    deadzone = 0.001  # used to prevent floating when mouse isn't moving
    screen_x = 0.5 - logic.mouse.position[0]
    if -deadzone < screen_x < deadzone:
        screen_x = 0
    screen_y = 0.5 - logic.mouse.position[1]
    if -deadzone < screen_y < deadzone:
        screen_y = 0

    self.applyRotation([screen_y * sensitivity_x, 0, screen_x * sensitivity_y], True, per_second=True)

    render.setMousePosition(int(render.getWindowWidth() / 2), int(render.getWindowHeight() / 2))
def main():
    #get screen size
    screen_width = render.getWindowWidth()
    screen_height = render.getWindowHeight()
    #center the mouse
    render.setMousePosition(int(screen_width / 2), int(screen_height / 2))
    #if mouse is moving
    if mouse_move.positive:

        x_mouse = (screen_width / 2 -
                   mouse_move.position[0]) * own['SENSITIVITY']
        y_mouse = (screen_height / 2 -
                   mouse_move.position[1]) * own['SENSITIVITY']

        own['previous_x'] = (own['previous_x'] * .8 + x_mouse * .2)
        own['previous_y'] = (own['previous_y'] * .8 + y_mouse * .2)
        #limit camera rotation
        cam_angle = own.localOrientation.to_euler()
        #print (cam_angle)
        #cam_angle[0] = max(min(cam_angle[0], 0), 3)
        cam_angle.to_matrix()
        own.localOrientation = cam_angle
        #move the camera
        cam_x_rot.dRot = (0, 0, x_mouse)
        cam_y_rot.dRot = (y_mouse, 0, 0)

        cont.activate(cam_x_rot)
        cont.activate(cam_y_rot)
    else:
        cont.deactivate(cam_x_rot)
        cont.deactivate(cam_y_rot)

    #camera lense transition - thanks to YoFrankie
    old_lens = player_camera.lens
    if sintel_col['RUNNING'] == True and sintel_col['MOVING'] == True:
        lens = 22
        own['SENSITIVITY'] = .00075
    if sintel_col['RUNNING'] == True and sintel_col['MOVING'] == False:
        lens = 35
        own['SENSITIVITY'] = .001
    if sintel_col['RUNNING'] == False:
        lens = 35
        own['SENSITIVITY'] = .001
    if lens != old_lens:
        player_camera.lens = (lens * 0.02) + (old_lens * 0.98)

    #camera collision
    if cam_col_check.positive:
        player_camera.worldPosition = cam_col_check.hitPosition
        player_camera.localPosition.y += MARGIN
    else:
        player_camera.worldPosition = cam_col.worldPosition
        player_camera.localPosition.y -= cam_col_check.range - MARGIN
Esempio n. 21
0
def Player():
#T# get the scene from where the module was called
    scene1 = logic.getCurrentScene()

#T# get a particular object in the scene
    scene_obj1 = scene1.objects['Object_name']

#T# get the controller that called the module
    controller1 = logic.getCurrentController()

#T# get the owner of the controller
    object1 = controller1.owner

#T# get a named actuator connected to the controller
    motion = controller1.actuators['motion_actuator_name1']

#T# get a named sensor connected to the controller
    sensor1 = controller1.sensors['sensor_name1']

#T# get the UPBGE window width and height
    win_width1 = render.getWindowWidth()
    win_height1 = render.getWindowHeight()

#T# an enum dictionary with the keyboard keys can be accessed with
    key = logic.keyboard.events

#T# save the value of interesting keys pressed from the keyboard, 0 not pressed, 1 started, 2 hold, 3 released
    kb_left = key[events.LEFTARROWKEY]
    kb_right = key[events.RIGHTARROWKEY]

    x_pos1 = 480
    y_pos1 = 240
#T# set the mouse position
    render.setMousePosition(x_pos1, y_pos1)
    
#T# the Update() function is common and executes in each frame
    def Update():
        movespd = 0.2
        deltaX = 0
        deltaY = 0
        
        if kb_left > 0:
            deltaX += -movespd
        if kb_right > 0:
            deltaX += movespd

#T# change the location
        motion.dLoc = [deltaX, deltaY, 0.0]

#T# activate the actuator connected to the controller
        controller1.activate(motion)
        
    Update()
Esempio n. 22
0
    def __init__(self, cont):

        #get Dependencies
        self.cont = cont
        self.camera = cont.owner
        self.mouse = logic.mouse

        x = render.getWindowWidth() // 2
        y = render.getWindowHeight() // 2
        self.screen_center = (x, y)
        render.setMousePosition(x + 1, y + 1)
        #show Mouse
        render.showMouse(1)
Esempio n. 23
0
def main():
	#get screen size
	screen_width = render.getWindowWidth()
	screen_height = render.getWindowHeight()
	#center the mouse
	render.setMousePosition(int(screen_width/2), int(screen_height/2))
	#if mouse is moving
	if mouse_move.positive:
		
		x_mouse = (screen_width / 2 - mouse_move.position[0]) * own['SENSITIVITY']
		y_mouse = (screen_height / 2 - mouse_move.position[1]) * own['SENSITIVITY']
		
		own['previous_x'] = (own['previous_x'] * .8 + x_mouse * .2)
		own['previous_y'] = (own['previous_y'] * .8 + y_mouse * .2)
		#limit camera rotation
		cam_angle = own.localOrientation.to_euler()
		#print (cam_angle)
		#cam_angle[0] = max(min(cam_angle[0], 0), 3)
		cam_angle.to_matrix()
		own.localOrientation = cam_angle
		#move the camera
		cam_x_rot.dRot =(0, 0, x_mouse)
		cam_y_rot.dRot =(y_mouse, 0, 0)
			
		cont.activate(cam_x_rot)
		cont.activate(cam_y_rot)
	else:
		cont.deactivate(cam_x_rot)
		cont.deactivate(cam_y_rot)
		
	#camera lense transition - thanks to YoFrankie
	old_lens = player_camera.lens	
	if sintel_col['RUNNING']==True and sintel_col['MOVING'] ==True:
		lens = 22
		own['SENSITIVITY'] = .00075
	if sintel_col['RUNNING']==True and sintel_col['MOVING'] ==False:
		lens = 35
		own['SENSITIVITY'] = .001
	if sintel_col['RUNNING']==False:
		lens = 35
		own['SENSITIVITY'] = .001
	if lens != old_lens:
		player_camera.lens = (lens*0.02) + (old_lens*0.98)
	
	#camera collision
	if cam_col_check.positive:
		player_camera.worldPosition = cam_col_check.hitPosition
		player_camera.localPosition.y += MARGIN
	else:
		player_camera.worldPosition = cam_col.worldPosition
		player_camera.localPosition.y -= cam_col_check.range - MARGIN
Esempio n. 24
0
def _mouselook_core(self, id):
    deadzone = 0.001  # used to prevent floating when mouse isn't moving
    screen_x = 0.5 - logic.mouse.position[0]
    if -deadzone < screen_x < deadzone:
        screen_x = 0
    screen_y = 0.5 - logic.mouse.position[1]
    if -deadzone < screen_y < deadzone:
        screen_y = 0

    self.applyRotation([screen_y * sensitivity_x, 0, screen_x * sensitivity_y],
                       True,
                       per_second=True)

    render.setMousePosition(int(render.getWindowWidth() / 2),
                            int(render.getWindowHeight() / 2))
Esempio n. 25
0
def initialize_var(own):
    if not 'init' in own:
        own['init'] = False
        own['cur_pos'] = 0.0
        own['snap_start'] = False
        own['snap'] = 0.0
        own['fp'] = False
        own['dist'] = own.localPosition[1]
        own['cam_degr'] = 0.0
        own['zsmooth'] = 0.0
        own['wsmooth'] = 0.0
        x = render.getWindowWidth() // 2
        y = render.getWindowHeight() // 2
        own['win_size'] = x, y
        render.setMousePosition(*own['win_size'])
Esempio n. 26
0
    def __init__(self, cont):#

        self.cont = cont

        self.sen_mouse = self.cont.sensors["mouse"]

        self.act_rotx = self.cont.actuators["rotx"]
        self.act_rotz = self.cont.actuators["rotz"]

        self.cont.activate(self.act_rotx)        
        self.cont.activate(self.act_rotz) 

        x = render.getWindowWidth()//2
        y = render.getWindowHeight()//2
        self.screen_center = (x, y)

        render.setMousePosition(*self.screen_center)
Esempio n. 27
0
def DeltaMouse(Xcenter,Ycenter,lockToCenter=False,Xpos=mouse.position[0],
                                                    Ypos=mouse.position[1]):
    ''' This function calculates the ditance (in pixels) 
    of the mouse from two given points '''
    #Calculates the x variation
    Dx = Xpos - Xcenter
    #the y variation
    Dy = Ypos - Ycenter
    #Put in a list
    delta = [Dx,Dy]

    #If the "lockToCenter" flag is true AND the mouse is NOT in the center
    if lockToCenter and Dx or Dy:
        #It centers the mouse
        render.setMousePosition(Xcenter,Ycenter)
    
    #Returns a list with the values
    return delta
Esempio n. 28
0
    def __init__(self, cont):   

        self.camera = cont.owner

        self.move_speed = 0.2
        self.mouse_sensitivity = 0.002
        self.mouse_smoothing = 0.5

        self.old_x = 0.0
        self.old_y = 0.0
        
        self.screen_width = render.getWindowWidth()
        self.screen_height = render.getWindowHeight()
        self.screen_center = (self.screen_width//2, self.screen_height//2)

        render.setMousePosition(*self.screen_center) 

        # logic.mouse.position is incorrect on the first frame. This variable is used to get around that
        self.delay = 0
Esempio n. 29
0
def rotateCamera(cont):
	#print(cont)

	owner = cont.owner
	parent = owner.parent
	
	mouse = cont.sensors["mouse"]
	
	sensitivity = 0.05
	
	#camera rotation limits
	high_limit = 180
	low_limit = 0
	
	h = render.getWindowHeight()//2
	w = render.getWindowWidth()//2
	y = (h-mouse.position[1])*sensitivity
	x = (w-mouse.position[0])*sensitivity
	'''print('H W:', h, w)
	print('Mouse position:', mouse.position)
	print('Y X:', y, x)'''
	
	rot = owner.localOrientation.to_euler()
	pitch = abs(math.degrees(rot[0]))
	
	pitch += y
	
	if(pitch) < low_limit:
		pitch = low_limit
	elif(pitch) > high_limit:
		pitch = high_limit
	rot[0] = math.radians(pitch)
	
	owner.localOrientation = rot.to_matrix()
	
	parentRotation = parent.localOrientation.to_euler()
	yaw = math.degrees(parentRotation[2]) + x #Check this if anything goes wrong
	parentRotation[2] = math.radians(yaw)
	parent.localOrientation = parentRotation.to_matrix()

	
	render.setMousePosition(int(w),int(h))
Esempio n. 30
0
    def mouse_move(self, controller):
        if not self.mouse_move_s:
            self.mouse_move_s = controller.sensors['MouseMove']
        width, height = render.getWindowWidth(), render.getWindowHeight()
        x = (width / 2 - self.mouse_move_s.position[0]) * self.mouse_sensitivity
        y = (height / 2 - self.mouse_move_s.position[1]) * self.mouse_sensitivity

        if self.lock_mouse:
            if 'rotations' not in self.lock_mouse:
                self.lock_mouse['rotations'] = [math.pi / 2, 0, 0]
            rotations = self.lock_mouse['rotations']
            if (rotations[0] + y > math.pi) or \
                (rotations[0] + y < 0):
                y = 0
            rotations[2] += x
            rotations[0] += y
            self.lock_mouse.localOrientation = (0.0, 0.0, rotations[2])
            logic.getCurrentScene().active_camera.localOrientation = (rotations[0], 0.0, 0.0)

            render.setMousePosition(int(width / 2), int(height / 2))
Esempio n. 31
0
def DeltaMouse(Xcenter,
               Ycenter,
               lockToCenter=False,
               Xpos=mouse.position[0],
               Ypos=mouse.position[1]):
    ''' This function calculates the ditance (in pixels)
    of the mouse from two given points '''
    #Calculates the x variation
    Dx = Xpos - Xcenter
    #the y variation
    Dy = Ypos - Ycenter
    #Put in a list
    delta = [Dx, Dy]

    #If the "lockToCenter" flag is true AND the mouse is NOT in the center
    if lockToCenter and Dx or Dy:
        #It centers the mouse
        Rasterizer.setMousePosition(Xcenter, Ycenter)

    #Returns a list with the values
    return delta
Esempio n. 32
0
def FPS_main():
    mouse = gl.mouse

    objDict = GetBlenderObject.get()
    cam = objDict["Camera.003"]
    cylinder = objDict["me"]

    Hrot = 3 * (0.5 - mouse.position[0])
    if -0.002 < Hrot < 0.002:
        Hrot = 0
    # en radians ?
    cylinder.applyRotation([0, 0, Hrot], False)

    Vrot = 1 * (0.5 - mouse.position[1])
    if -0.001 < Vrot < 0.001:
        Vrot = 0
    cam.applyRotation([Vrot, 0, 0], True)

    # Center the mouse
    render.setMousePosition(int(render.getWindowWidth() / 2),
                                int(render.getWindowHeight() / 2))
Esempio n. 33
0
def FPS_main():
    mouse = gl.mouse

    objDict = GetBlenderObject.get()
    cam = objDict["Camera.003"]
    cylinder = objDict["me"]

    Hrot = 3 * (0.5 - mouse.position[0])
    if -0.002 < Hrot < 0.002:
        Hrot = 0
    # en radians ?
    cylinder.applyRotation([0, 0, Hrot], False)

    Vrot = 1 * (0.5 - mouse.position[1])
    if -0.001 < Vrot < 0.001:
        Vrot = 0
    cam.applyRotation([Vrot, 0, 0], True)

    # Center the mouse
    render.setMousePosition(int(render.getWindowWidth() / 2),
                            int(render.getWindowHeight() / 2))
Esempio n. 34
0
def main():
    co = bge.logic.getCurrentController()
    o= co.owner
    
    #sensor
    mouse = co.sensors["mousesensor"]
    
    #objects
    Cube= scene.objects["Cube"]
    cameraTarget= scene.objects["cameraTarget"]
    
    #####mouse movemente
    
    movSpeed = 0.02
    rotSpeed = (0.0003, 0.0001)
    
     # mouse look
    x = (render.getWindowWidth() / 2 - mouse.position[0])
    y = (render.getWindowHeight() / 2 - mouse.position[1])
    
    
    Cube.applyRotation((0 , 0, int(x) * rotSpeed[0]), False)
    cameraTarget.applyRotation((int(y) * rotSpeed[1], 0, 0), True)
    render.setMousePosition(int(render.getWindowWidth() / 2), int(render.getWindowHeight() / 2))
Esempio n. 35
0
 def edge_scroll(self, scene, cam, mouse_pos):
     """Detect if mouse is close to the screen edge
     and if so, move the camera."""
     if mouse_pos.position[0] <= 5:
         self.move_cam(scene, cam, 1)
         if mouse_pos.position[0] < 0:
             render.setMousePosition(2, mouse_pos.position[1])
     elif mouse_pos.position[1] <= 5:
         self.move_cam(scene, cam, 2)
         if mouse_pos.position[1] < 0:
             render.setMousePosition(mouse_pos.position[0], 2)
     elif mouse_pos.position[0] >= render.getWindowWidth() - 5:
         self.move_cam(scene, cam, 3)
         if mouse_pos.position[0] > render.getWindowWidth():
             render.setMousePosition(render.getWindowWidth(), mouse_pos.position[1] - 2)
     elif mouse_pos.position[1] >= render.getWindowHeight() - 5:
         self.move_cam(scene, cam, 4)
         if mouse_pos.position[1] > render.getWindowHeight():
             render.setMousePosition(mouse_pos.position[0], render.getWindowHeight() - 2)
Esempio n. 36
0
def hand_control(contr):
    """ Move the hand following the mouse

    Use the movement of the mouse to determine the rotation
    for the IK arm (right arm)
    
    stays for better placing of objects - >(QKEY + EKEY) to rotate body<
    """
    # get the object this script is attached to
    human = contr.owner
    
    # if the human is external, do nothing
    if human.get('External_Robot_Tag') or human['disable_keyboard_control']:
        return

    # get the suffix of the human to reference the right objects
    suffix = human.name[-4:] if human.name[-4] == "." else ""
    
    scene = logic.getCurrentScene()
    target = scene.objects['IK_Target_Empty.R' + suffix]
    right_hand = scene.objects['Hand_Grab.R' + suffix]
    mmb = human.sensors['MMB']

    # If the manipulation mode is inactive, do nothing
    if not human['Manipulate']:
        return

    # set mouse sensitivity
    sensitivity = human['Sensitivity']

    # Get sensors for mouse wheel
    wheel_up = contr.sensors['Wheel_Up']
    wheel_down = contr.sensors['Wheel_Down']
    keyboard = contr.sensors['All_Keys']

    keylist = keyboard.events
    for key in keylist:
        # key[0] == events.keycode, key[1] = status
        if key[1] == logic.KX_INPUT_NONE and key[0] == events.LEFTCTRLKEY:
            if wheel_up.positive:
                front = 50.0 * sensitivity
                target.applyMovement([front, 0.0, 0.0], True)

            if wheel_down.positive:
                back = -50.0 * sensitivity
                target.applyMovement([back, 0.0, 0.0], True)

    # If nothing grabbed or Middle Mouse Button is not pressed,
    # do nothing of the following
    if (right_hand['selected'] == 'None' or right_hand['selected'] == '' or
        (not mmb.positive)):
        #use head_control for this
        return

    # Get sensor named Mouse
    mouse = contr.sensors['Mouse']

    if mouse.positive:
        # get width and height of game window
        width = render.getWindowWidth()
        height = render.getWindowHeight()

        # get mouse movement from function
        move = mouse_move(human, mouse, width, height)

        # Amount, direction and sensitivity
        left_right = move[0] * sensitivity
        up_down = move[1] * sensitivity

        if not human['FOCUSED']:
            target.applyMovement([0.0, left_right, 0.0], True)
            target.applyMovement([0.0, 0.0, up_down], True)

        # Reset mouse position to the centre of the screen
        # Using the '//' operator (floor division) to produce an integer result
        render.setMousePosition(width//2, height//2)
Esempio n. 37
0
from helpers import search_object, get_object
import controls
from bge import events as E
from bge import logic as G
from bge import render as R
from mathutils import Vector
RELEASED = G.KX_INPUT_JUST_RELEASED
R.setMousePosition(R.getWindowWidth()//2, R.getWindowHeight()//2)


class HUD(object):
    def __init__(self):
        self.is_open = False
        # hotkeys
        self.kh_menu = E.QKEY
        self.kh_view_toggle = E.ZKEY
        #
        self.cursor = search_object('cursor')
        self.mouse = self.cursor.sensors['mouse_over']
        self.menu_highlight = get_object('menu_highlight')
        self.camera = search_object('camera')
        self.scene = G.getCurrentScene()
        self.menu = search_object('hud_menu')
        if not self.menu or not self.menu_highlight:
            raise Exception('Cannot proceed')
        print('HUD', self.scene)
        self.toggle_menu(True)

    def update_screen_size(self):
        self.W = R.getWindowWidth()
        self.H = R.getWindowHeight()
Esempio n. 38
0
 def setCenter(self):
     render.setMousePosition(self.size[0] // 2, self.size[1] // 2)
Esempio n. 39
0
y = (h2 - y)*s

if x > 0.1:
    x = 0.1
elif x < -0.1:
    x = -0.1
if y > 0.1:
    y = 0.1
elif y < -0.1:
    y = -0.1

if "cap" in o:
    import mathutils
    camOrient = o.localOrientation
    camZ = [camOrient[0][2],camOrient[1][2],camOrient[2][2]]
    vec1 = mathutils.Vector(camZ)
    camParent = p
    parentZ = [0,0,1]
    vec2 = mathutils.Vector(parentZ)
    rads = mathutils.Vector.angle(vec2, vec1)
    angle = rads * (180.00 / 3.14)
    capAngle = o["cap"]
    moveY = y
    if (angle > (90 + capAngle/2) and moveY > 0)   or (angle < (90 - capAngle/2) and moveY < 0)  == True:
        y = 0

o.applyRotation([y,0,0],True)
p.applyRotation([0,0,x],False)

r.setMousePosition(h1, h2)
Esempio n. 40
0
    ucChair.write(struct.pack('>B', ord(cmd)))
    #ucChair.write(struct.pack('>b', val))
    #ucChair.write(struct.pack('>B', ord('\n')))


#########################################################################

mousePos = [0, 0]
mouseSensitivity = .05
cos45 = 1 / sqrt(2)

centerY = render.getWindowHeight() // 2
centerX = render.getWindowWidth() // 2

# move mouse cursor to center
render.setMousePosition(centerX, centerY)


# keyboard subroutine for interactive wheelchair movement
# control left and right motors independently, as in controlling a tank
# each motor can move forward or backward
# hit spacebar to stop motors immediately
def k(cont):
    global mousePos
    # heartbeat character sent every frame;
    # uC will stop motion if this is not received after a short amount of time
    sendChairCmd('~')

    # left motor increase/decrease speed
    if keydown(bge.events.UKEY): sendChairCmd('L')
    if keydown(bge.events.HKEY): sendChairCmd('l')
Esempio n. 41
0
from bge import logic, render
from mathutils import Vector

W = render.getWindowWidth()
H = render.getWindowHeight()
screen_center = Vector((W // 2, H // 2))

render.showMouse(True)
render.setMousePosition(int(screen_center.x), int(screen_center.y))


def _restrict_movement():

    for i in (0, 2):
        if player.worldPosition[i] > limits[i]:
            player.worldPosition[i] = limits[i]
        elif player.worldPosition[i] < -limits[i]:
            player.worldPosition[i] = -limits[i]


def move():

    mouse_position = Vector(mouse_sensor.position)
    mouse_offset = mouse_position - screen_center
    mouse_offset.magnitude *= 0.001
    movement = Vector((mouse_offset.x, 0, -mouse_offset.y))
    player.worldPosition += movement

    _restrict_movement()

Esempio n. 42
0
    def update(self):
        
        # ---------
        # Mouselook
        # ---------
        
        if self.delay >= 1:
            # Get the center of the screen and the current mouse position
            center = Vector(self.screen_center)
            mouse_position = Vector([logic.mouse.position[0] * self.screen_width, logic.mouse.position[1] * self.screen_height])

            x = center.x - mouse_position.x
            y = center.y - mouse_position.y
            
            # Smooth movement
            self.old_x = (self.old_x*self.mouse_smoothing + x*(1.0-self.mouse_smoothing))
            self.old_y = (self.old_y*self.mouse_smoothing + y*(1.0-self.mouse_smoothing))
                
            x = self.old_x* self.mouse_sensitivity
            y = self.old_y* self.mouse_sensitivity
                 
            # set the values
            self.body.applyRotation([0, 0, x], False)
            self.camera.applyRotation([y, 0, 0], True)
                
            # Center mouse in game window
            render.setMousePosition(*self.screen_center)
            
        if self.delay <= 1:
            self.delay += 1        
        
         
         
        # --------
        # Movement
        # --------
        
        keyboard = logic.keyboard.events
        
        # Use two variables to track the directions
        forward = 0
        side = 0
        
        # Get the keyboard inputs and manipulate the direction variables
        if keyboard[events.WKEY]:
            forward += 1
        
        if keyboard[events.SKEY]:
            forward -= 1  
        
        if keyboard[events.AKEY]:
            side -= 1            
        
        if keyboard[events.DKEY]:
            side += 1            
        
        # Calculate the speed that the player will be moving at. Holding left shift activates the run multiplier
        speed = self.move_speed
        if keyboard[events.LEFTSHIFTKEY]:
            speed = self.move_speed * self.run_multiplier
            
        # Calculate the z_speed (fall speed) and add the jump force if the player presses the spacebar
        z_speed = self.body.getLinearVelocity().z            
        if keyboard[events.SPACEKEY] == 1:            
            z_speed += self.jump_force            
        
        # Move the object using linear velocities
        self.body.setLinearVelocity([side * speed, forward * speed, z_speed], True)
parent = own.parent

#set speed for camera movement
sensitivity = 0.05

#set camera rotation limits
high_limit = 180
low_limit = 0

h = r.getWindowHeight() // 2
w = r.getWindowWidth() // 2
x = (h - mouse.position[0]) * sensitivity
y = (w - mouse.position[1]) * sensitivity

if own["startup"]:
    r.setMousePosition(h, w)
    own["startup"] = False
else:
    rot = own.localOrientation.to_euler()
    pitch = abs(math.degrees(rot[0]))
    if high_limit > (pitch + y) > low_limit:
        pitch += y
    elif (pitch + y) < low_limit:
        pitch = low_limit
    elif (pitch + y) > high_limit:
        pitch = high_limit
    rot[0] = math.radians(pitch)
    own.localOrientation = rot.to_matrix()

    parentRot = parent.localOrientation.to_euler()
    yaw = math.degrees(parentRot[2]) + x
Esempio n. 44
0
def main():
    cont = bge.logic.getCurrentController()
    own = cont.owner

    #Gather sensors + actuators
    mousemove = cont.sensors['mousemove']
    cam = cont.sensors['playercam'].owner
    rightmouse = cont.sensors['rightmouse'].positive
    Ray = cont.sensors["collision"]

    #camact = cont.actuators['camact']
    camxrot = cont.actuators['camxrot']
    camyrot = cont.actuators['camyrot']
    lock_cam = cont.actuators['lock_cam']
    lock_cam_track = cont.actuators['lock_cam_track']

    Player = bge.logic.getCurrentScene().objects["PlayerCol"]

    #Set mouse pos
    screenwidth = render.getWindowWidth()
    screenheight = render.getWindowHeight()

    render.setMousePosition(int(screenwidth / 2), int(screenheight / 2))

    #Rotate camera, but not instantly (bug fix)
    if mousemove.positive and own['wtime'] >= .1:
        #Rotate by mouse x + y
        xmouse = (screenwidth / 2 - mousemove.position[0]) * own['sensitivity']
        ymouse = (screenheight / 2 -
                  mousemove.position[1]) * own['sensitivity']
        #Calculate cam rotation
        #if Player['Fightmode']==True:
        #own['previousx'] = (own['previousx']*.4 + xmouse*.1)
        #own['previousy'] = (own['previousy']*.4 + ymouse*.1)
        #else:
        own['previousx'] = (own['previousx'] * .8 + xmouse * .2)
        own['previousy'] = (own['previousy'] * .8 + ymouse * .2)
        xmouse = own['previousx']
        ymouse = own['previousy']
        #print (ymouse,xmouse)
        #Set cam rotation
        camyrot.dRot = (ymouse, 0, 0)
        camxrot.dRot = (0, 0, xmouse)
        cont.activate(camxrot)
        cont.activate(camyrot)
    else:
        cont.deactivate(camxrot)
        cont.deactivate(camyrot)

    #Something is in the way of the camera
    if Ray.positive:
        Newcampos = Ray.hitPosition
        Newcampos[2] = Newcampos[2] + .2
        cam.position = Newcampos
        OrigCamera = cont.sensors["campos"].owner
        cam.worldOrientation = OrigCamera.worldOrientation
    else:
        OrigCamera = cont.sensors["campos"].owner
        cam.position = OrigCamera.position
    if Player['Locked'] == False:
        cam.worldOrientation = OrigCamera.worldOrientation

    #Camera trick - Thanks to YoFrankie
    old_lens = cam.lens
    if cam['run'] == True or Player['Locked'] == True:
        lens = 28
    if cam['run'] == False and Player['Locked'] == False:
        lens = 35

    if lens != old_lens:
        cam.lens = (lens * 0.04) + (old_lens * 0.96)

    #BATTLE CAM
    if Player['Locked'] == True:
        cont.activate(lock_cam)
        try:
            lock_cam_track.object = Player['Target']
            cont.activate(lock_cam_track)
        except:
            pass
    else:
        cont.deactivate(lock_cam)
        cont.deactivate(lock_cam_track)
Esempio n. 45
0
    if cmd != '~' :print(cmd)
    ucChair.write(struct.pack('>B', ord(cmd)))
    #ucChair.write(struct.pack('>b', val))
    #ucChair.write(struct.pack('>B', ord('\n')))

#########################################################################

mousePos = [0, 0]
mouseSensitivity = .05
cos45 = 1/sqrt(2)

centerY = render.getWindowHeight()//2
centerX = render.getWindowWidth()//2

# move mouse cursor to center
render.setMousePosition(centerX, centerY)

# keyboard subroutine for interactive wheelchair movement
# control left and right motors independently, as in controlling a tank
# each motor can move forward or backward
# hit spacebar to stop motors immediately
def k(cont):
    global mousePos
    # heartbeat character sent every frame;
    # uC will stop motion if this is not received after a short amount of time
    sendChairCmd('~')

    # left motor increase/decrease speed
    if keydown(bge.events.UKEY): sendChairCmd('L')
    if keydown(bge.events.HKEY): sendChairCmd('l')
    # right motor increase/decrease speed
Esempio n. 46
0
 def position_pix(self, vec):
     render.setMousePosition(*[int(v) for v in vec])
Esempio n. 47
0
    def update(self):

        # Mouselook
        if self.delay >= 1:
            
            # Get the center of the screen and the current mouse position
            center = Vector(self.screen_center)
            mouse_position = Vector([logic.mouse.position[0] * self.screen_width, logic.mouse.position[1] * self.screen_height])

            x = center.x - mouse_position.x
            y = center.y - mouse_position.y
            
            # Smooth movement
            self.old_x = (self.old_x*self.mouse_smoothing + x*(1.0-self.mouse_smoothing))
            self.old_y = (self.old_y*self.mouse_smoothing + y*(1.0-self.mouse_smoothing))
                
            x = self.old_x* self.mouse_sensitivity
            y = self.old_y* self.mouse_sensitivity
                 
            # set the values
            self.camera.applyRotation([0, 0, x], False)
            self.camera.applyRotation([y, 0, 0], True)
                
            # Center mouse in game window
            render.setMousePosition(*self.screen_center)
            
        if self.delay <= 1:
            self.delay += 1
        
        
        # Keyboard movement
        keyboard = logic.keyboard.events
        
        if logic.getAverageFrameRate() != 0:
            frame_equaliser = 60 / logic.getAverageFrameRate()
        else:
            frame_equaliser == 1
        
        speed = self.move_speed * frame_equaliser
        
                
        if keyboard[events.LEFTSHIFTKEY]:
            speed = self.move_speed * 3 * frame_equaliser

        if keyboard[events.LEFTCTRLKEY]:
            speed = self.move_speed / 3 * frame_equaliser
        
        if keyboard[events.WKEY]:
            self.camera.applyMovement([0, 0, -speed], True)

        if keyboard[events.SKEY]:
            self.camera.applyMovement([0, 0, speed], True)
            
        if keyboard[events.AKEY]:
            self.camera.applyMovement([-speed, 0, 0], True)
            
        if keyboard[events.DKEY]:
            self.camera.applyMovement([speed, 0, 0], True)
            
        if keyboard[events.EKEY]:
            self.camera.applyMovement([0, speed, 0], True)
            
        if keyboard[events.QKEY]:
            self.camera.applyMovement([0, -speed, 0], True)
Esempio n. 48
0
# set camera rotation limits
high_limit = 180
low_limit = 60

#original script used w and h, pand swapped them!

# determine center of window
cy = r.getWindowHeight()//2  
cx = r.getWindowWidth()//2  

# calculate dx and dy based on position
# dx and dy are actually distance from center
dx = (cx - mouse.position[0])*sensitivity
dy = (cy - mouse.position[1])*sensitivity

r.setMousePosition(cx, cy)
rot = camera.localOrientation.to_euler()

# calculate new pitch (rotation around local X)
pitch = abs(math.degrees(rot[0]))

if high_limit > (pitch+dy) > low_limit:
    pitch += dy
elif (pitch+dy) < low_limit:
    pitch = low_limit
elif (pitch+dy) > high_limit:
    pitch = high_limit
    
rot[0] = math.radians(pitch)
camera.localOrientation = rot.to_matrix()
Esempio n. 49
0
File: inputs.py Progetto: GoranM/nlu
	def position_pix(self, vec):
		render.setMousePosition(*[int(v) for v in vec])
Esempio n. 50
0
if x > 0.1:
    x = 0.1
elif x < -0.1:
    x = -0.1
if y > 0.1:
    y = 0.1
elif y < -0.1:
    y = -0.1

if "cap" in o:
    import mathutils
    camOrient = o.localOrientation
    camZ = [camOrient[0][2], camOrient[1][2], camOrient[2][2]]
    vec1 = mathutils.Vector(camZ)
    camParent = p
    parentZ = [0, 0, 1]
    vec2 = mathutils.Vector(parentZ)
    rads = mathutils.Vector.angle(vec2, vec1)
    angle = rads * (180.00 / 3.14)
    capAngle = o["cap"]
    moveY = y
    if (angle >
        (90 + capAngle / 2) and moveY > 0) or (angle < (90 - capAngle / 2)
                                               and moveY < 0) == True:
        y = 0

o.applyRotation([y, 0, 0], True)
p.applyRotation([0, 0, x], False)

r.setMousePosition(h1, h2)
Esempio n. 51
0
def main():
	cont = bge.logic.getCurrentController()
	own = cont.owner

	#Gather sensors + actuators
	mousemove = cont.sensors['mousemove']
	cam = cont.sensors['playercam'].owner
	rightmouse = cont.sensors['rightmouse'].positive
	Ray = cont.sensors["collision"]
	
	#camact = cont.actuators['camact']
	camxrot = cont.actuators['camxrot']
	camyrot = cont.actuators['camyrot']
	lock_cam = cont.actuators['lock_cam']
	lock_cam_track = cont.actuators['lock_cam_track']
	
	Player = bge.logic.getCurrentScene().objects["PlayerCol"]

	#Set mouse pos
	screenwidth = render.getWindowWidth()
	screenheight = render.getWindowHeight()
	
	render.setMousePosition(int(screenwidth/2), int(screenheight/2))
				
	#Rotate camera, but not instantly (bug fix)
	if mousemove.positive and own['wtime']>=.1:
		#Rotate by mouse x + y
		xmouse = (screenwidth/2 - mousemove.position[0]) * own['sensitivity']
		ymouse = (screenheight/2 - mousemove.position[1]) * own['sensitivity']
		#Calculate cam rotation
		#if Player['Fightmode']==True:
			#own['previousx'] = (own['previousx']*.4 + xmouse*.1)
			#own['previousy'] = (own['previousy']*.4 + ymouse*.1)
		#else:
		own['previousx'] = (own['previousx']*.8 + xmouse*.2)
		own['previousy'] = (own['previousy']*.8 + ymouse*.2)
		xmouse = own['previousx']
		ymouse = own['previousy']
		#print (ymouse,xmouse)
		#Set cam rotation
		camyrot.dRot =(ymouse, 0, 0)
		camxrot.dRot =(0, 0, xmouse)
		cont.activate(camxrot)
		cont.activate(camyrot)
	else:
		cont.deactivate(camxrot)
		cont.deactivate(camyrot)
		
	#Something is in the way of the camera
	if Ray.positive:
		Newcampos = Ray.hitPosition
		Newcampos[2] = Newcampos[2] +.2
		cam.position = Newcampos
		OrigCamera = cont.sensors["campos"].owner
		cam.worldOrientation = OrigCamera.worldOrientation
	else:
		OrigCamera = cont.sensors["campos"].owner
		cam.position = OrigCamera.position
	if Player['Locked'] ==False:
		cam.worldOrientation = OrigCamera.worldOrientation 

	#Camera trick - Thanks to YoFrankie
	old_lens = cam.lens	
	if cam['run']==True or Player['Locked'] ==True:
		lens = 28
	if cam['run']==False and Player['Locked'] ==False:
		lens = 35
		
	if lens != old_lens:
		cam.lens = (lens*0.04) + (old_lens*0.96)
	
	#BATTLE CAM
	if Player['Locked'] ==True:
		cont.activate(lock_cam)
		try:
			lock_cam_track.object = Player['Target']
			cont.activate(lock_cam_track)
		except:
			pass
	else:
		cont.deactivate(lock_cam)
		cont.deactivate(lock_cam_track)
Esempio n. 52
0
    def update(self):

        # ---------
        # Mouselook
        # ---------

        if self.delay >= 1:
            # Get the center of the screen and the current mouse position
            center = Vector(self.screen_center)
            mouse_position = Vector([
                logic.mouse.position[0] * self.screen_width,
                logic.mouse.position[1] * self.screen_height
            ])

            x = center.x - mouse_position.x
            y = center.y - mouse_position.y

            # Smooth movement
            self.old_x = (self.old_x * self.mouse_smoothing + x *
                          (1.0 - self.mouse_smoothing))
            self.old_y = (self.old_y * self.mouse_smoothing + y *
                          (1.0 - self.mouse_smoothing))

            x = self.old_x * self.mouse_sensitivity
            y = self.old_y * self.mouse_sensitivity

            # set the values
            self.body.applyRotation([0, 0, x], False)
            # self.camera.applyRotation([y, 0, 0], True)

            # Center mouse in game window
            render.setMousePosition(*self.screen_center)

        if self.delay <= 1:
            self.delay += 1

        # -----------------------------
        # Movement and camera rotation
        # -----------------------------

        keyboard = logic.keyboard.events
        mouse = logic.mouse.events

        # Use two variables to track the directions
        forward = 0
        side = 0

        # Get the keyboard inputs and manipulate the direction variables
        if keyboard[events.WKEY]:
            forward += 1

        if keyboard[events.SKEY]:
            forward -= 1

        if keyboard[events.AKEY]:
            side -= 1

        if keyboard[events.DKEY]:
            side += 1

        # Calculate the speed that the player will be moving at. Holding left shift activates the run multiplier
        speed = self.move_speed
        if keyboard[events.LEFTSHIFTKEY]:
            speed = self.move_speed * self.run_multiplier

        # Calculate the z_speed (fall speed) and add the jump force if the player presses the spacebar
        z_speed = self.body.getLinearVelocity().z
        if keyboard[events.SPACEKEY] == 1:
            z_speed += self.jump_force

        # Move the object using linear velocities
        self.body.setLinearVelocity([side * speed, forward * speed, z_speed],
                                    True)

        # Camera rotation when right click is pressed
        if mouse[events.RIGHTMOUSE]:
            pass
Esempio n. 53
0
	def setCenter(self):
		render.setMousePosition(self.size[0]//2, self.size[1]//2)
Esempio n. 54
0
cont = G.getCurrentController()

#owner = scene.cameras["Camera"]
#cam.worldOrientation = rot

owner = cont.owner
Mouse = cont.sensors["Mouse"]

w = R.getWindowWidth()//2
h = R.getWindowHeight()//2
screen_center = (w, h)

# center mouse on first frame, create temp variables
if "oldX" not in owner:

	R.setMousePosition(w + 1, h + 1)
	
	owner["oldX"] = 0.0
	owner["oldY"] = 0.0

else:
	
	scrc = Vector(screen_center)
	mpos = Vector(Mouse.position)
	
	x = scrc.x-mpos.x
	y = scrc.y-mpos.y

	
	# Smooth movement
	owner['oldX'] = (owner['oldX']*smooth + x*(1.0-smooth))
parent = own.parent

#set speed for camera movement
sensitivity = 0.05

#set camera rotation limits
high_limit = 180
low_limit = 0

h = r.getWindowHeight()//2
w = r.getWindowWidth()//2
x = (h - mouse.position[0])*sensitivity
y = (w - mouse.position[1])*sensitivity

if own["startup"]:
    r.setMousePosition(h, w)
    own ["startup"] = False
else:
    rot = own.localOrientation.to_euler()
    pitch = abs(math.degrees(rot[0]))
    if high_limit > (pitch+y) > low_limit:
        pitch += y
    elif (pitch+y) < low_limit:
        pitch = low_limit
    elif (pitch+y) > high_limit:
        pitch = high_limit
    rot[0] = math.radians(pitch)
    own.localOrientation = rot.to_matrix()

    parentRot = parent.localOrientation.to_euler()
    yaw = math.degrees(parentRot[2]) + x
Esempio n. 56
0
def hand_control(contr):
    """ Move the hand following the mouse

    Use the movement of the mouse to determine the rotation
    for the IK arm (right arm)
    
    stays for better placing of objects - >(QKEY + EKEY) to rotate body<
    """
    # get the object this script is attached to
    human = contr.owner
    scene = logic.getCurrentScene()
    target = scene.objects['IK_Target_Empty.R']
    right_hand = scene.objects['Hand_Grab.R']
    mmb = human.sensors['MMB']

    # If the manipulation mode is inactive, do nothing
    if not human['Manipulate']:
        return

    # set mouse sensitivity
    sensitivity = human['Sensitivity']

    # Get sensors for mouse wheel
    wheel_up = contr.sensors['Wheel_Up']
    wheel_down = contr.sensors['Wheel_Down']

    if wheel_up.positive:
        front = 50.0 * sensitivity
        target.applyMovement([front, 0.0, 0.0], True)

    if wheel_down.positive:
        back = -50.0 * sensitivity
        target.applyMovement([back, 0.0, 0.0], True)

    # If nothing grabbed or Middle Mouse Button is not pressed,
    # do nothing of the following
    if (right_hand['selected'] == 'None' or right_hand['selected'] == '' or
        (not mmb.positive)):
        #use head_control for this
        return

    # Get sensor named Mouse
    mouse = contr.sensors['Mouse']

    if mouse.positive:
        # get width and height of game window
        width = render.getWindowWidth()
        height = render.getWindowHeight()

        # get mouse movement from function
        move = mouse_move(human, mouse, width, height)

        # Amount, direction and sensitivity
        left_right = move[0] * sensitivity
        up_down = move[1] * sensitivity

        if not human['FOCUSED']:
            target.applyMovement([0.0, left_right, 0.0], True)
            target.applyMovement([0.0, 0.0, up_down], True)

        # Reset mouse position to the centre of the screen
        # Using the '//' operator (floor division) to produce an integer result
        render.setMousePosition(width//2, height//2)