simulation.py
def onMovementKey(app, keys): # {{{0
  "Handle pressing one of the movement keys"
  # Rules that define what keys do what
  movementRules = { # {{{1
    CAM_AXIS_PITCH: {
      "enable": anyPressed(keys, "C-Up", "C-Down") \
          and isPressed(keys, p.B3G_CONTROL),
      "stepArgName": "cdp",
      "dir": ("Up", "Down"),
      "enableFast": False
    },
    CAM_AXIS_YAW: {
      "enable": anyPressed(keys, "Left", "Right"),
      "stepArgName": "cdy",
      "dir": ("Left", "Right"),
      "enableFast": False
    },
    CAM_AXIS_DIST: {
      "enable": anyPressed(keys, "Up", "Down") \
          and not isPressed(keys, p.B3G_CONTROL),
      "stepArgName": "cdd",
      "dir": ("Up", "Down"),
      "enableFast": True
    },
    CAM_AXIS_X: {
      "enable": anyPressed(keys, "k4", "k6"),
      "stepArgName": "cdtx",
      "dir": ("k4", "k6"),
      "enableFast": True
    },
    CAM_AXIS_Y: {
      "enable": anyPressed(keys, "k2", "k8"),
      "stepArgName": "cdty",
      "dir": ("k2", "k8"),
      "enableFast": True
    },
    CAM_AXIS_Z: {
      "enable": anyPressed(keys, "k7", "k9"),
      "stepArgName": "cdtz",
      "dir": ("k7", "k9"),
      "enableFast": True
    },
  } # 1}}}

  def getDir(negKey, posKey): # {{{1
    "Determine if we go positive or negative"
    if isPressed(keys, negKey):
      return -1 
    elif isPressed(keys, posKey):
      return 1
    return 0 # 1}}}

  # Handle generic movement keys
  movement = {}
  for axis, rules in movementRules.items():
    if rules["enable"]:
      dv = app.getArg(rules["stepArgName"]) * getDir(*rules["dir"])
      if rules.get("enableFast") and isPressed(keys, p.B3G_SHIFT):
        dv *= KEY_FAST_MULT
      movement[axis] = dv
  app.moveCamera(**movement)
  # Special movement keys
  if isPressed(keys, p.B3G_KP_5):
    if isPressed(keys, p.B3G_SHIFT):
      # S-NUMPAD_5 resets the camera to the starting position and orientation
      app.setTargetPos(CAM_START_TARGET)
      app.setPitch(CAM_START_PITCH)
      app.setYaw(CAM_START_YAW)
      app.setTargetDistance(CAM_START_DIST)
    else:
      # NUMPAD_5 resets the camera target to the world origin (z=floor)
      app.setTargetPos(app.worldFloor())
Handle pressing one of the movement keys
Handle pressing one of the movement keys
Handle pressing one of the movement keys
def onMovementKey(app, keys): 
  movementRules = { 
    CAM_AXIS_PITCH: {
      "enable": anyPressed(keys, "C-Up", "C-Down") \
          and isPressed(keys, p.B3G_CONTROL),
      "stepArgName": "cdp",
      "dir": ("Up", "Down"),
      "enableFast": False
    },
    CAM_AXIS_YAW: {
      "enable": anyPressed(keys, "Left", "Right"),
      "stepArgName": "cdy",
      "dir": ("Left", "Right"),
      "enableFast": False
    },
    CAM_AXIS_DIST: {
      "enable": anyPressed(keys, "Up", "Down") \
          and not isPressed(keys, p.B3G_CONTROL),
      "stepArgName": "cdd",
      "dir": ("Up", "Down"),
      "enableFast": True
    },
    CAM_AXIS_X: {
      "enable": anyPressed(keys, "k4", "k6"),
      "stepArgName": "cdtx",
      "dir": ("k4", "k6"),
      "enableFast": True
    },
    CAM_AXIS_Y: {
      "enable": anyPressed(keys, "k2", "k8"),
      "stepArgName": "cdty",
      "dir": ("k2", "k8"),
      "enableFast": True
    },
    CAM_AXIS_Z: {
      "enable": anyPressed(keys, "k7", "k9"),
      "stepArgName": "cdtz",
      "dir": ("k7", "k9"),
      "enableFast": True
    },
  } 
  def getDir(negKey, posKey): 
    if isPressed(keys, negKey):
      return -1 
    elif isPressed(keys, posKey):
      return 1
    return 0 
  movement = {}
  for axis, rules in movementRules.items():
    if rules["enable"]:
      dv = app.getArg(rules["stepArgName"]) * getDir(*rules["dir"])
      if rules.get("enableFast") and isPressed(keys, p.B3G_SHIFT):
        dv *= KEY_FAST_MULT
      movement[axis] = dv
  app.moveCamera(**movement)
  if isPressed(keys, p.B3G_KP_5):
    if isPressed(keys, p.B3G_SHIFT):
      app.setTargetPos(CAM_START_TARGET)
      app.setPitch(CAM_START_PITCH)
      app.setYaw(CAM_START_YAW)
      app.setTargetDistance(CAM_START_DIST)
    else:
      app.setTargetPos(app.worldFloor())
def onMovementKey ( app , keys ) : movementRules = { CAM_AXIS_PITCH : { "enable" : anyPressed ( keys , "C-Up" , "C-Down" ) and isPressed ( keys , p . B3G_CONTROL ) , "stepArgName" : "cdp" , "dir" : ( "Up" , "Down" ) , "enableFast" : False } , CAM_AXIS_YAW : { "enable" : anyPressed ( keys , "Left" , "Right" ) , "stepArgName" : "cdy" , "dir" : ( "Left" , "Right" ) , "enableFast" : False } , CAM_AXIS_DIST : { "enable" : anyPressed ( keys , "Up" , "Down" ) and not isPressed ( keys , p . B3G_CONTROL ) , "stepArgName" : "cdd" , "dir" : ( "Up" , "Down" ) , "enableFast" : True } , CAM_AXIS_X : { "enable" : anyPressed ( keys , "k4" , "k6" ) , "stepArgName" : "cdtx" , "dir" : ( "k4" , "k6" ) , "enableFast" : True } , CAM_AXIS_Y : { "enable" : anyPressed ( keys , "k2" , "k8" ) , "stepArgName" : "cdty" , "dir" : ( "k2" , "k8" ) , "enableFast" : True } , CAM_AXIS_Z : { "enable" : anyPressed ( keys , "k7" , "k9" ) , "stepArgName" : "cdtz" , "dir" : ( "k7" , "k9" ) , "enableFast" : True } , } def getDir ( negKey , posKey ) : "Determine if we go positive or negative" if isPressed ( keys , negKey ) : return - 1 elif isPressed ( keys , posKey ) : return 1 return 0 movement = { } for axis , rules in movementRules . items ( ) : if rules [ "enable" ] : dv = app . getArg ( rules [ "stepArgName" ] ) * getDir ( * rules [ "dir" ] ) if rules . get ( "enableFast" ) and isPressed ( keys , p . B3G_SHIFT ) : dv *= KEY_FAST_MULT movement [ axis ] = dv app . moveCamera ( ** movement ) if isPressed ( keys , p . B3G_KP_5 ) : if isPressed ( keys , p . B3G_SHIFT ) : app . setTargetPos ( CAM_START_TARGET ) app . setPitch ( CAM_START_PITCH ) app . setYaw ( CAM_START_YAW ) app . setTargetDistance ( CAM_START_DIST ) else : app . setTargetPos ( app . worldFloor ( ) )
Handle pressing one of the movement keys
Handle pressing one of the movement keys
# {{{0 "Handle pressing one of the movement keys" # Rules that define what keys do what # {{{1 # 1}}} # {{{1 "Determine if we go positive or negative" # 1}}} # Handle generic movement keys # Special movement keys # S-NUMPAD_5 resets the camera to the starting position and orientation # NUMPAD_5 resets the camera target to the world origin (z=floor)
app
keys