def roll_hand_r(cont): """ roll the right hand """ armature = cont.owner human = armature.parent hand_r = armature.channels['Hand.R'] # if the human is external, do nothing if human.get('External_Robot_Tag') or human['disable_keyboard_control']: return keyboard = cont.sensors['All_Keys'] wheel_down = cont.sensors['WheelDown'] wheel_up = cont.sensors['WheelUp'] if not ((wheel_down.positive or wheel_up.positive) and human['Manipulate']): return roll_speed = 0.1 keylist = keyboard.events for key in keylist: # key[0] == events.keycode, key[1] = status if key[1] == blenderapi.input_active( ) and key[0] == blenderapi.LEFTCTRLKEY: if wheel_down.positive: roll_speed = -roll_speed hand_r.rotation_quaternion += Vector((0.0, 0.0, roll_speed, 0.0)) armature.update()
def default_action(self): """ Interpret keyboard presses and assign them to movement for the robot.""" keyboard = blenderapi.keyboard() is_actived = blenderapi.input_active() # Reset movement variables vx, vy, vz = 0.0, 0.0, 0.0 rx, ry, rz = 0.0, 0.0, 0.0 if keyboard.events[blenderapi.UPARROWKEY] == is_actived: vx = self._speed if keyboard.events[blenderapi.DOWNARROWKEY] == is_actived: vx = -self._speed if keyboard.events[blenderapi.LEFTARROWKEY] == is_actived: rz = self._speed if keyboard.events[blenderapi.RIGHTARROWKEY] == is_actived: rz = -self._speed if self._type == "Position" or self._type == "Velocity": self.robot_parent.apply_speed(self._type, [vx, vy, vz], [rx, ry, rz / 2.0]) elif self._type == "Differential": self.robot_parent.apply_vw_wheels(vx, rz)
def default_action(self): """ Main loop of the actuator. Implements the component behaviour """ robot = self.robot_parent force = (robot.bge_object.mass * -9.81) #robot.bge_object.applyForce([0.0, 0.0, force], False) force2 = (robot.bge_object.mass * blenderapi.game_settings().physics_gravity) robot.bge_object.applyForce([0.0, 0.0, force2], False) keyboard = blenderapi.keyboard() is_actived = blenderapi.input_active() if keyboard.events[blenderapi.ZKEY] == is_actived: self.local_data['V'] = self.local_data['V'] + 1.0 print(self.local_data['V']) if keyboard.events[blenderapi.XKEY] == is_actived: self.local_data['V'] = self.local_data['V'] - 1.0 print(self.local_data['V']) force3 = self.local_data['V'] #robot.bge_object.applyForce([0.0, 0.0, force3], False) if not self.do_once: print(robot.bge_object.mass) print(robot.bge_object.getPropertyNames()) print(blenderapi.game_settings().physics_gravity) #print(robot.bge_object.getLinearVelocity()) self.do_once = True
def default_action(self): """ Interpret keyboard presses and assign them to movement for the robot.""" keyboard = blenderapi.keyboard() is_actived = blenderapi.input_active() # Reset movement variables vx, vy, vz = 0.0, 0.0, 0.0 rx, ry, rz = 0.0, 0.0, 0.0 if keyboard.events[blenderapi.UPARROWKEY] == is_actived: vx = self._speed if keyboard.events[blenderapi.DOWNARROWKEY] == is_actived: vx = -self._speed if keyboard.events[blenderapi.LEFTARROWKEY] == is_actived: rz = self._speed if keyboard.events[blenderapi.RIGHTARROWKEY] == is_actived: rz = -self._speed if self._type == 'Position' or self._type == 'Velocity': self.robot_parent.apply_speed(self._type, [vx, vy, vz], [rx, ry, rz / 2.0]) elif self._type == 'Differential': self.robot_parent.apply_vw_wheels(vx, rz)
def roll_hand_r(cont): """ roll the right hand """ armature = cont.owner human = armature.parent hand_r = armature.channels['Hand.R'] # if the human is external, do nothing if human.get('External_Robot_Tag') or human['disable_keyboard_control']: return keyboard = cont.sensors['All_Keys'] wheel_down = cont.sensors['WheelDown'] wheel_up = cont.sensors['WheelUp'] if not ((wheel_down.positive or wheel_up.positive) and human['Manipulate']): return roll_speed = 0.1 keylist = keyboard.events for key in keylist: # key[0] == events.keycode, key[1] = status if key[1] == blenderapi.input_active() and key[0] == blenderapi.LEFTCTRLKEY: if wheel_down.positive: roll_speed = -roll_speed hand_r.rotation_quaternion += Vector((0.0, 0.0, roll_speed, 0.0)) armature.update()
def default_action(self): keyboard = blenderapi.keyboard() is_actived = blenderapi.input_active() if keyboard.events[blenderapi.UPARROWKEY] == is_actived: self.local_data['up'] = True else: self.local_data['up'] = False if keyboard.events[blenderapi.DOWNARROWKEY] == is_actived: self.local_data['down'] = True else: self.local_data['down'] = False if keyboard.events[blenderapi.LEFTARROWKEY] == is_actived: self.local_data['left'] = True else: self.local_data['left'] = False if keyboard.events[blenderapi.RIGHTARROWKEY] == is_actived: self.local_data['right'] = True else: self.local_data['right'] = False if keyboard.events[blenderapi.IKEY] == is_actived: self.local_data['i'] = True else: self.local_data['i'] = False if keyboard.events[blenderapi.JKEY] == is_actived: self.local_data['j'] = True else: self.local_data['j'] = False if keyboard.events[blenderapi.KKEY] == is_actived: self.local_data['k'] = True else: self.local_data['k'] = False if keyboard.events[blenderapi.LKEY] == is_actived: self.local_data['l'] = True else: self.local_data['l'] = False
def move(contr): """ Read the keys for specific combinations that will make the camera move in 3D space. """ # get the object this script is attached to camera = contr.owner scene = blenderapi.scene() # Do not move the camera if the current view is using another camera if camera != scene.active_camera: return if 'Human' in scene.objects: human = scene.objects['Human'] if not human['move_cameraFP']: return # set the movement speed speed = camera['Speed'] # Get Blender keyboard sensor keyboard = contr.sensors['All_Keys'] # Default movement speed move_speed = [0.0, 0.0, 0.0] keylist = keyboard.events for key in keylist: if key[1] == blenderapi.input_active(): # Also add the corresponding key for an AZERTY keyboard if key[0] == blenderapi.WKEY or key[0] == blenderapi.ZKEY: move_speed[2] = -speed elif key[0] == blenderapi.SKEY: move_speed[2] = speed # Also add the corresponding key for an AZERTY keyboard elif key[0] == blenderapi.AKEY or key[0] == blenderapi.QKEY: move_speed[0] = -speed elif key[0] == blenderapi.DKEY: move_speed[0] = speed elif key[0] == blenderapi.RKEY: move_speed[1] = speed elif key[0] == blenderapi.FKEY: move_speed[1] = -speed else: move_speed[0] = 0 move_speed[1] = 0 move_speed[2] = 0 # The second parameter of 'applyMovement' determines # a movement with respect to the object's local # coordinate system camera.applyMovement( move_speed, True ) elif key[1] == blenderapi.input_just_activated(): # Other actions activated with the keyboard # Reset camera to center if key[0] == blenderapi.F8KEY and keyboard.positive: reset_position(contr)
def set_human_animation(contr): """ Toggle the animation actions (walking, standing still...) of the armature. """ # Get sensor named Mouse armature = contr.owner # get the suffix of the human to reference the right objects suffix = armature.name[-4:] if armature.name[-4] == "." else "" scene = blenderapi.scene() active_camera = scene.active_camera human = scene.objects[armature.parent.name] # if the human is external, do nothing if human.get('External_Robot_Tag') or human['disable_keyboard_control']: return keyboard = contr.sensors['All_Keys'] keylist = keyboard.events pressed = [] #all keys that are currently pressed for key in keylist: # key[0] == blenderapi.keycode, key[1] = status if key[1] == blenderapi.input_just_activated(): pressed.append(key[0]) # Keys for moving forward or turning """ if key[0] == blenderapi.WKEY or key[0] == blenderapi.ZKEY: armature['movingForward'] = True elif key[0] == blenderapi.SKEY: armature['movingBackward'] = True """ # TEST: Read the rotation of the bones in the armature if key[0] == blenderapi.BKEY: read_pose(contr) #elif key[0] == blenderapi.VKEY: #reset_pose(contr) #elif key[1] == blenderapi.input_just_released(): """ if key[0] == blenderapi.WKEY or key[0] == blenderapi.ZKEY: armature['movingForward'] = False elif key[0] == blenderapi.SKEY: armature['movingBackward'] = False """ elif key[1] == blenderapi.input_active(): pressed.append(key[0]) if human['move_cameraFP'] and active_camera.name != 'Human_Camera': return if (FORWARDS in pressed or LEFT in pressed or BACKWARDS in pressed or RIGHT in pressed): armature['movingForward'] = True else: armature['movingForward'] = False
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 = blenderapi.scene() 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 # Get sensor named Mouse mouse = contr.sensors['Mouse'] # Get Blender keyboard sensor keyboard = contr.sensors['All_Keys'] # Show the cursor mouse_visible = True keylist = keyboard.events for key in keylist: if key[1] == blenderapi.input_active(): # Left CTRL key allow to rotate the camera if key[0] == blenderapi.LEFTCTRLKEY: # Hide the cursor while we control the camera mouse_visible = False if mouse.positive: # get width and height of game window width = blenderapi.render().getWindowWidth() height = blenderapi.render().getWindowHeight() # get mouse movement from function move = mouse_move(camera, mouse, width, height) # set mouse sensitivity sensitivity = camera['Sensitivity'] # Amount, direction and sensitivity leftRight = move[0] * sensitivity upDown = move[1] * sensitivity # set the values camera.applyRotation([0.0, 0.0, leftRight], 0) camera.applyRotation([upDown, 0.0, 0.0], 1) # Center mouse in game window # Using the '//' operator (floor division) to produce an integer result blenderapi.render().setMousePosition( width // 2, height // 2) # Set the cursor visibility blenderapi.mousepointer(visible=mouse_visible)
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 = blenderapi.scene() 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 # Get sensor named Mouse mouse = contr.sensors['Mouse'] # Get Blender keyboard sensor keyboard = contr.sensors['All_Keys'] # Show the cursor mouse_visible = True keylist = keyboard.events for key in keylist: if key[1] == blenderapi.input_active(): # Left CTRL key allow to rotate the camera if key[0] == blenderapi.LEFTCTRLKEY: # Hide the cursor while we control the camera mouse_visible = False if mouse.positive: # get width and height of game window width = blenderapi.render().getWindowWidth() height = blenderapi.render().getWindowHeight() # get mouse movement from function move = mouse_move(camera, mouse, width, height) # set mouse sensitivity sensitivity = camera['Sensitivity'] # Amount, direction and sensitivity leftRight = move[0] * sensitivity upDown = move[1] * sensitivity # set the values camera.applyRotation( [0.0, 0.0, leftRight], 0 ) camera.applyRotation( [upDown, 0.0, 0.0], 1 ) # Center mouse in game window # Using the '//' operator (floor division) to produce an integer result blenderapi.render().setMousePosition(width//2, height//2) # Set the cursor visibility blenderapi.mousepointer(visible = mouse_visible)
def move(contr): """ Read the keys for specific combinations that will make the camera move in 3D space. """ # get the object this script is attached to human = contr.owner # set the movement speed speed = human['Speed'] # Get sensor named Mouse keyboard = contr.sensors['All_Keys'] # Default movement speed move_speed = [0.0, 0.0, 0.0] rotation_speed = [0.0, 0.0, 0.0] keylist = keyboard.events for key in keylist: if key[1] == blenderapi.input_active(): if key[0] == blenderapi.IKEY: move_speed[0] = speed elif key[0] == blenderapi.KKEY: move_speed[0] = -speed elif key[0] == blenderapi.JKEY: rotation_speed[2] = speed elif key[0] == blenderapi.LKEY: rotation_speed[2] = -speed elif key[0] == blenderapi.UKEY: move_speed[1] = speed elif key[0] == blenderapi.OKEY: move_speed[1] = -speed # The second parameter of 'applyMovement' determines # a movement with respect to the object's local # coordinate system human.applyMovement( move_speed, True ) human.applyRotation( rotation_speed, True ) """
def move(contr): """ Read the keys for specific combinations that will make the camera move in 3D space. """ # Get the currently active camera to adapt control method scene = blenderapi.scene() active_camera = scene.active_camera # 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 "" # set the movement speed speed = human['Speed'] # Get sensor named Mouse keyboard = contr.sensors['All_Keys'] # Default movement speed move_speed = [0.0, 0.0, 0.0] rotation_speed = [0.0, 0.0, 0.0] human_camera = "Human_Camera" + suffix if human['move_cameraFP'] and active_camera.name != human_camera: return keylist = keyboard.events for key in keylist: # key[0] == blenderapi.keycode, key[1] = status if key[1] == blenderapi.input_active(): if human['Manipulate']: if key[0] == FORWARDS: move_speed[0] = speed elif key[0] == BACKWARDS: move_speed[0] = -speed elif key[0] == TURN_LEFT: rotation_speed[2] = speed elif key[0] == TURN_RIGHT: rotation_speed[2] = -speed elif key[0] == RIGHT: if active_camera.name == human_camera: move_speed[1] = -speed else: rotation_speed[2] = -speed elif key[0] == LEFT: if active_camera.name == human_camera: move_speed[1] = speed else: rotation_speed[2] = speed else: if key[0] in (FORWARDS, BACKWARDS, LEFT, RIGHT): move_speed[0] = speed if active_camera.name != human_camera and key[ 0] == BACKWARDS: move_speed[0] = -speed # The second parameter of 'applyMovement' determines # a movement with respect to the object's local # coordinate system human.applyMovement(move_speed, True) human.applyRotation(rotation_speed, True) """ if key[0] == blenderapi.UPARROWKEY: move_speed[0] = speed elif key[0] == blenderapi.DOWNARROWKEY: move_speed[0] = -speed elif key[0] == blenderapi.LEFTARROWKEY: rotation_speed[2] = speed elif key[0] == blenderapi.RIGHTARROWKEY: rotation_speed[2] = -speed elif key[0] == blenderapi.AKEY: move_speed[2] = speed elif key[0] == blenderapi.EKEY: move_speed[2] = -speed """ elif key[1] == blenderapi.input_just_activated(): # Other actions activated with the keyboard # Reset camera to center if key[0] == blenderapi.NKEY and keyboard.positive: reset_view(contr) # Switch between look and manipulate elif key[0] == blenderapi.XKEY: toggle_manipulate(contr)
def rotate(co): """ Set the human orientation in reference to the camera orientation. """ ow = co.owner # get the suffix of the human to reference the right objects suffix = ow.name[-4:] if ow.name[-4] == "." else "" keyboard = co.sensors['All_Keys'] scene = blenderapi.scene() human_pos = co.owner pos = scene.objects['POS_EMPTY' + suffix] active_camera = scene.active_camera # if the human is external, do nothing if human_pos.get( 'External_Robot_Tag') or human_pos['disable_keyboard_control']: return if human_pos['move_cameraFP'] and active_camera.name != ('Human_Camera' + suffix): return keylist = keyboard.events k = [] #initiate a list with all currently pressed keys for key in keylist: if key[1] == blenderapi.input_active(): k.append(key[0]) # add all pressed keys to a list - as ASCII CODES pos.worldPosition = ow.worldPosition # Get active camera scene = blenderapi.scene() active_camera = scene.active_camera if ow['Manipulate']: ow.worldOrientation = pos.worldOrientation # lock camera to head in Manipulation Mode else: if FORWARDS in k and not (LEFT in k or RIGHT in k): if active_camera.name == ("Human_Camera" + suffix): applyrotate(pos.worldOrientation, ow) else: applyrotate(human_pos.worldOrientation, ow) elif LEFT in k and not (FORWARDS in k or BACKWARDS in k): if active_camera.name == ("Human_Camera" + suffix): applyrotate( pos.worldOrientation * Matrix.Rotation(math.pi / 2, 3, 'Z'), ow) else: applyrotate( human_pos.worldOrientation * Matrix.Rotation(math.pi / 2, 3, 'Z'), ow) # turn around 90 deg elif RIGHT in k and not (FORWARDS in k or BACKWARDS in k): if active_camera.name == ("Human_Camera" + suffix): applyrotate( pos.worldOrientation * Matrix.Rotation(math.pi * 3 / 2, 3, 'Z'), ow) else: applyrotate( human_pos.worldOrientation * Matrix.Rotation(math.pi * 3 / 2, 3, 'Z'), ow) # turn around 270 deg elif LEFT in k and FORWARDS in k: if active_camera.name == ("Human_Camera" + suffix): applyrotate( pos.worldOrientation * Matrix.Rotation(math.pi / 4, 3, 'Z'), ow) else: applyrotate( human_pos.worldOrientation * Matrix.Rotation(math.pi / 4, 3, 'Z'), ow) # turn around 45 deg elif RIGHT in k and FORWARDS in k: if active_camera.name == ("Human_Camera" + suffix): applyrotate( pos.worldOrientation * Matrix.Rotation(math.pi * 7 / 4, 3, 'Z'), ow) else: applyrotate( human_pos.worldOrientation * Matrix.Rotation(math.pi * 7 / 4, 3, 'Z'), ow) # turn around 315 deg elif BACKWARDS in k and not (LEFT in k or RIGHT in k): if active_camera.name == ("Human_Camera" + suffix): applyrotate( pos.worldOrientation * Matrix.Rotation(math.pi, 3, 'Z'), ow) # turn around 180 deg if in game-mode elif LEFT in k and BACKWARDS in k: if active_camera.name == ("Human_Camera" + suffix): applyrotate( pos.worldOrientation * Matrix.Rotation(math.pi * 3 / 4, 3, 'Z'), ow) else: applyrotate( human_pos.worldOrientation * Matrix.Rotation(math.pi / 4, 3, 'Z'), ow) # turn around 135 deg if in game-mode, else turn 45 deg elif RIGHT in k and BACKWARDS in k: if active_camera.name == ("Human_Camera" + suffix): applyrotate( pos.worldOrientation * Matrix.Rotation(math.pi * 5 / 4, 3, 'Z'), ow) else: applyrotate( human_pos.worldOrientation * Matrix.Rotation(math.pi * 7 / 4, 3, 'Z'), ow)
def move(contr): """ Read the keys for specific combinations that will make the camera move in 3D space. """ # Get the currently active camera to adapt control method scene = blenderapi.scene() active_camera = scene.active_camera # 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 "" # set the movement speed speed = human['Speed'] # Get sensor named Mouse keyboard = contr.sensors['All_Keys'] # Default movement speed move_speed = [0.0, 0.0, 0.0] rotation_speed = [0.0, 0.0, 0.0] human_camera = "Human_Camera" + suffix if human['move_cameraFP'] and active_camera.name != human_camera: return keylist = keyboard.events for key in keylist: # key[0] == blenderapi.keycode, key[1] = status if key[1] == blenderapi.input_active(): if human['Manipulate']: if key[0] == FORWARDS: move_speed[0] = speed elif key[0] == BACKWARDS: move_speed[0] = -speed elif key[0] == TURN_LEFT: rotation_speed[2] = speed elif key[0] == TURN_RIGHT: rotation_speed[2] = -speed elif key[0] == RIGHT: if active_camera.name == human_camera: move_speed[1] = -speed else: rotation_speed[2] = -speed elif key[0] == LEFT: if active_camera.name == human_camera: move_speed[1] = speed else: rotation_speed[2] = speed else: if key[0] in (FORWARDS, BACKWARDS, LEFT, RIGHT): move_speed[0] = speed if active_camera.name != human_camera and key[0] == BACKWARDS: move_speed[0] = -speed # The second parameter of 'applyMovement' determines # a movement with respect to the object's local # coordinate system human.applyMovement( move_speed, True ) human.applyRotation( rotation_speed, True ) """ if key[0] == blenderapi.UPARROWKEY: move_speed[0] = speed elif key[0] == blenderapi.DOWNARROWKEY: move_speed[0] = -speed elif key[0] == blenderapi.LEFTARROWKEY: rotation_speed[2] = speed elif key[0] == blenderapi.RIGHTARROWKEY: rotation_speed[2] = -speed elif key[0] == blenderapi.AKEY: move_speed[2] = speed elif key[0] == blenderapi.EKEY: move_speed[2] = -speed """ elif key[1] == blenderapi.input_just_activated(): # Other actions activated with the keyboard # Reset camera to center if key[0] == blenderapi.NKEY and keyboard.positive: reset_view(contr) # Switch between look and manipulate elif key[0] == blenderapi.XKEY: toggle_manipulate(contr)
def rotate(co): """ Set the human orientation in reference to the camera orientation. """ ow = co.owner # get the suffix of the human to reference the right objects suffix = ow.name[-4:] if ow.name[-4] == "." else "" keyboard = co.sensors['All_Keys'] scene = blenderapi.scene() human_pos = co.owner pos = scene.objects['POS_EMPTY' + suffix] active_camera = scene.active_camera # if the human is external, do nothing if human_pos.get('External_Robot_Tag') or human_pos['disable_keyboard_control']: return if human_pos['move_cameraFP'] and active_camera.name != ('Human_Camera'+suffix): return keylist = keyboard.events k = [] #initiate a list with all currently pressed keys for key in keylist: if key[1] == blenderapi.input_active(): k.append(key[0]) # add all pressed keys to a list - as ASCII CODES pos.worldPosition = ow.worldPosition # Get active camera scene = blenderapi.scene() active_camera = scene.active_camera if ow['Manipulate']: ow.worldOrientation = pos.worldOrientation # lock camera to head in Manipulation Mode else: if FORWARDS in k and not(LEFT in k or RIGHT in k): if active_camera.name == ("Human_Camera"+suffix): applyrotate(pos.worldOrientation, ow) else: applyrotate(human_pos.worldOrientation, ow) elif LEFT in k and not(FORWARDS in k or BACKWARDS in k): if active_camera.name == ("Human_Camera"+suffix): applyrotate(pos.worldOrientation * Matrix.Rotation(math.pi / 2, 3, 'Z'), ow) else: applyrotate(human_pos.worldOrientation * Matrix.Rotation(math.pi / 2, 3, 'Z'), ow) # turn around 90 deg elif RIGHT in k and not(FORWARDS in k or BACKWARDS in k): if active_camera.name == ("Human_Camera"+suffix): applyrotate(pos.worldOrientation * Matrix.Rotation(math.pi * 3/2, 3, 'Z'), ow) else: applyrotate(human_pos.worldOrientation * Matrix.Rotation(math.pi * 3/2, 3, 'Z'), ow) # turn around 270 deg elif LEFT in k and FORWARDS in k: if active_camera.name == ("Human_Camera"+suffix): applyrotate(pos.worldOrientation * Matrix.Rotation(math.pi / 4, 3, 'Z'), ow) else: applyrotate(human_pos.worldOrientation * Matrix.Rotation(math.pi / 4, 3, 'Z'), ow) # turn around 45 deg elif RIGHT in k and FORWARDS in k: if active_camera.name == ("Human_Camera"+suffix): applyrotate(pos.worldOrientation * Matrix.Rotation(math.pi * 7 / 4, 3, 'Z'), ow) else: applyrotate(human_pos.worldOrientation * Matrix.Rotation(math.pi * 7 / 4, 3, 'Z'), ow) # turn around 315 deg elif BACKWARDS in k and not(LEFT in k or RIGHT in k): if active_camera.name == ("Human_Camera"+suffix): applyrotate(pos.worldOrientation * Matrix.Rotation(math.pi, 3, 'Z'), ow) # turn around 180 deg if in game-mode elif LEFT in k and BACKWARDS in k: if active_camera.name == ("Human_Camera"+suffix): applyrotate(pos.worldOrientation * Matrix.Rotation(math.pi * 3/4, 3, 'Z'), ow) else: applyrotate(human_pos.worldOrientation * Matrix.Rotation(math.pi / 4, 3, 'Z'), ow) # turn around 135 deg if in game-mode, else turn 45 deg elif RIGHT in k and BACKWARDS in k: if active_camera.name == ("Human_Camera"+suffix): applyrotate(pos.worldOrientation * Matrix.Rotation(math.pi * 5/4, 3, 'Z'), ow) else: applyrotate(human_pos.worldOrientation * Matrix.Rotation(math.pi * 7 / 4, 3, 'Z'), ow)
def default_action(self): """ Interpret keyboard presses and assign them to movement for the robot.""" keyboard = blenderapi.keyboard() is_actived = blenderapi.input_active() # Reset movement variables vx, vy, vz = 0.0, 0.0, 0.0 rx, ry, rz = 0.0, 0.0, 0.0 # move forward if keyboard.events[blenderapi.UPARROWKEY] == is_actived: vx = self._speed # move backward if keyboard.events[blenderapi.DOWNARROWKEY] == is_actived: vx = -self._speed # turn left if keyboard.events[blenderapi.LEFTARROWKEY] == is_actived: rz = self._speed # turn right if keyboard.events[blenderapi.RIGHTARROWKEY] == is_actived: rz = -self._speed # move up if keyboard.events[blenderapi.TKEY] == is_actived: vz = self._speed # move down if keyboard.events[blenderapi.GKEY] == is_actived: vz = -self._speed # strafe left if keyboard.events[blenderapi.UKEY] == is_actived: vy = self._speed # strafe right if keyboard.events[blenderapi.OKEY] == is_actived: vy = -self._speed # roll left if keyboard.events[blenderapi.JKEY] == is_actived: rx = -self._speed # roll right if keyboard.events[blenderapi.LKEY] == is_actived: rx = self._speed # pitch forward if keyboard.events[blenderapi.IKEY] == is_actived: ry = self._speed # pitch backward if keyboard.events[blenderapi.KKEY] == is_actived: ry = -self._speed # Send a 'zero motion' only once in a row. if self.zero_motion and (vx,vy,vz,rx,ry,rz) == (0,0,0,0,0,0): return if self._type == 'Position' or self._type == 'Velocity': self.robot_parent.apply_speed(self._type, [vx, vy, vz], [rx, ry, rz / 2.0]) elif self._type == 'Differential': self.robot_parent.apply_vw_wheels(vx, rz) if (vx,vy,vz,rx,ry,rz) == (0,0,0,0,0,0): self.zero_motion = True else: self.zero_motion = False
def move(contr): """ Read the keys for specific combinations that will make the camera move in 3D space. """ # get the object this script is attached to camera = contr.owner scene = blenderapi.scene() 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 # Do not move the camera if another object has set move_cameraFP for obj in keyboard_ctrl_objects: if not obj['move_cameraFP']: return # set camera position increment from the movement speed pos_inc = camera['Speed'] / blenderapi.getfrequency() # Get Blender keyboard sensor keyboard = contr.sensors['All_Keys'] # Default movement move_translation = [0.0, 0.0, 0.0] keylist = keyboard.events for key in keylist: if key[1] == blenderapi.input_active(): # Also add the corresponding key for an AZERTY keyboard if key[0] == blenderapi.WKEY or key[0] == blenderapi.ZKEY: move_translation[2] = -pos_inc elif key[0] == blenderapi.SKEY: move_translation[2] = pos_inc # Also add the corresponding key for an AZERTY keyboard elif key[0] == blenderapi.AKEY or key[0] == blenderapi.QKEY: move_translation[0] = -pos_inc elif key[0] == blenderapi.DKEY: move_translation[0] = pos_inc elif key[0] == blenderapi.RKEY: move_translation[1] = pos_inc elif key[0] == blenderapi.FKEY: move_translation[1] = -pos_inc else: move_translation[0] = 0 move_translation[1] = 0 move_translation[2] = 0 # The second parameter of 'applyMovement' determines # a movement with respect to the object's local # coordinate system camera.applyMovement( move_translation, True ) elif key[1] == blenderapi.input_just_activated(): # Other actions activated with the keyboard # Reset camera to center if key[0] == blenderapi.F8KEY and keyboard.positive: reset_position(contr)
def move(contr): """ Read the keys for specific combinations that will make the camera move in 3D space. """ # get the object this script is attached to camera = contr.owner scene = blenderapi.scene() 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 # Do not move the camera if another object has set move_cameraFP for obj in keyboard_ctrl_objects: if not obj['move_cameraFP']: return # set camera position increment from the movement speed pos_inc = camera['Speed'] / blenderapi.getfrequency() # Get Blender keyboard sensor keyboard = contr.sensors['All_Keys'] # Default movement move_translation = [0.0, 0.0, 0.0] keylist = keyboard.events for key in keylist: if key[1] == blenderapi.input_active(): # Also add the corresponding key for an AZERTY keyboard if key[0] == blenderapi.WKEY or key[0] == blenderapi.ZKEY: move_translation[2] = -pos_inc elif key[0] == blenderapi.SKEY: move_translation[2] = pos_inc # Also add the corresponding key for an AZERTY keyboard elif key[0] == blenderapi.AKEY or key[0] == blenderapi.QKEY: move_translation[0] = -pos_inc elif key[0] == blenderapi.DKEY: move_translation[0] = pos_inc elif key[0] == blenderapi.RKEY: move_translation[1] = pos_inc elif key[0] == blenderapi.FKEY: move_translation[1] = -pos_inc else: move_translation[0] = 0 move_translation[1] = 0 move_translation[2] = 0 # The second parameter of 'applyMovement' determines # a movement with respect to the object's local # coordinate system camera.applyMovement(move_translation, True) elif key[1] == blenderapi.input_just_activated(): # Other actions activated with the keyboard # Reset camera to center if key[0] == blenderapi.F8KEY and keyboard.positive: reset_position(contr)
def default_action(self): """ Main loop of the actuator. Implements the component behaviour """ keyboardController = blenderapi.keyboard() active_state = blenderapi.input_active() linear_change = 0.0 angular_change = 0.0 local_x = self.local_data['XDot'] local_y = self.local_data['YDot'] #if self.Mode == "Acceleration": # logger.info("Acc Mode") if keyboardController.events[blenderapi.UPARROWKEY] == active_state: linear_change += self.Acceleration if keyboardController.events[blenderapi.DOWNARROWKEY] == active_state: linear_change -= self.Acceleration if keyboardController.events[blenderapi.LEFTARROWKEY] == active_state: angular_change += self.AngularAcc if keyboardController.events[blenderapi.RIGHTARROWKEY] == active_state: angular_change -= self.AngularAcc local_x += linear_change local_y += angular_change if local_x < 0: local_x = max(local_x,-self.MaxSpeed) else: local_x = min(local_x,self.MaxSpeed) if local_y < 0: local_y = max(local_y,-self.MaxAngularSpeed) else: local_y = min(local_y,self.MaxAngularSpeed) if linear_change == 0: local_x *= self.decay if abs(local_x) < 0.005: local_x = 0.0 if angular_change == 0: local_y *= self.decay if abs(local_y) < 0.005: local_y = 0.0 # logger.info("YDot: %s" % self.local_data['YDot']) self.local_data['XDot'] = local_x self.local_data['YDot'] = local_y self.local_data["LastData"] -= 1 self.robot_parent.apply_speed('Position',[local_x ,0 ,0],[0,0,local_y / 2.0])