mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 09:52:27 -04:00
small cleanup of sample files
Further documentation simplyfy lines by separately storing the value of findControl
This commit is contained in:
parent
f2a3a45100
commit
dc1ec6b877
@ -56,16 +56,19 @@ class App(ShowBase):
|
|||||||
# movements by ourself
|
# movements by ourself
|
||||||
self.disableMouse()
|
self.disableMouse()
|
||||||
|
|
||||||
|
# list of connected gamepad devices
|
||||||
|
gamepads = base.devices.getDevices(InputDevice.DC_gamepad)
|
||||||
|
|
||||||
# set the center position of the control sticks
|
# set the center position of the control sticks
|
||||||
# NOTE: here we assume, that the wheel is centered when the application get started.
|
# NOTE: here we assume, that the wheel is centered when the application get started.
|
||||||
# In real world applications, you should notice the user and give him enough time
|
# In real world applications, you should notice the user and give him enough time
|
||||||
# to center the wheel until you store the center position of the controler!
|
# to center the wheel until you store the center position of the controler!
|
||||||
gamepads = base.devices.getDevices(InputDevice.DC_gamepad)
|
|
||||||
self.lxcenter = gamepads[0].findControl(InputDevice.C_left_x).state
|
self.lxcenter = gamepads[0].findControl(InputDevice.C_left_x).state
|
||||||
self.lycenter = gamepads[0].findControl(InputDevice.C_left_y).state
|
self.lycenter = gamepads[0].findControl(InputDevice.C_left_y).state
|
||||||
self.rxcenter = gamepads[0].findControl(InputDevice.C_right_x).state
|
self.rxcenter = gamepads[0].findControl(InputDevice.C_right_x).state
|
||||||
self.rycenter = gamepads[0].findControl(InputDevice.C_right_y).state
|
self.rycenter = gamepads[0].findControl(InputDevice.C_right_y).state
|
||||||
|
|
||||||
|
|
||||||
self.taskMgr.add(self.moveTask, "movement update task")
|
self.taskMgr.add(self.moveTask, "movement update task")
|
||||||
|
|
||||||
def connect(self, device):
|
def connect(self, device):
|
||||||
@ -106,13 +109,17 @@ class App(ShowBase):
|
|||||||
|
|
||||||
# we will use the first found gamepad
|
# we will use the first found gamepad
|
||||||
# Move the camera left/right
|
# Move the camera left/right
|
||||||
movementVec.setX(gamepads[0].findControl(InputDevice.C_left_x).state - self.lxcenter)
|
left_x = gamepads[0].findControl(InputDevice.C_left_x)
|
||||||
|
movementVec.setX(left_x.state - self.lxcenter)
|
||||||
# Move the camera forward/backward
|
# Move the camera forward/backward
|
||||||
movementVec.setY(gamepads[0].findControl(InputDevice.C_left_y).state - self.lycenter)
|
left_y = gamepads[0].findControl(InputDevice.C_left_y)
|
||||||
|
movementVec.setY(left_y.state - self.lycenter)
|
||||||
# Control the cameras heading
|
# Control the cameras heading
|
||||||
base.camera.setH(base.camera, 100 * dt * (gamepads[0].findControl(InputDevice.C_right_x).state - self.rxcenter))
|
right_x = gamepads[0].findControl(InputDevice.C_right_x)
|
||||||
|
base.camera.setH(base.camera, 100 * dt * (right_x.state - self.rxcenter))
|
||||||
# Control the cameras pitch
|
# Control the cameras pitch
|
||||||
base.camera.setP(base.camera, 100 * dt * (gamepads[0].findControl(InputDevice.C_right_y).state - self.rycenter))
|
right_y = gamepads[0].findControl(InputDevice.C_right_y)
|
||||||
|
base.camera.setP(base.camera, 100 * dt * (right_y.state - self.rycenter))
|
||||||
|
|
||||||
# calculate movement
|
# calculate movement
|
||||||
base.camera.setX(base.camera, 100 * dt * movementVec.getX())
|
base.camera.setX(base.camera, 100 * dt * movementVec.getX())
|
||||||
|
@ -114,13 +114,15 @@ class App(ShowBase):
|
|||||||
|
|
||||||
# we will use the first found wheel
|
# we will use the first found wheel
|
||||||
# Acclerate
|
# Acclerate
|
||||||
accleration = wheels[0].findControl(InputDevice.C_accelerator).state * self.maxAccleration
|
acclearatorPedal = wheels[0].findControl(InputDevice.C_accelerator).state
|
||||||
if self.currentMoveSpeed > wheels[0].findControl(InputDevice.C_accelerator).state * self.maxSpeed:
|
accleration = accleratorPedal * self.maxAccleration
|
||||||
|
if self.currentMoveSpeed > accleratorPedal * self.maxSpeed:
|
||||||
self.currentMoveSpeed -= dt * self.deaccleration
|
self.currentMoveSpeed -= dt * self.deaccleration
|
||||||
self.currentMoveSpeed += dt * accleration
|
self.currentMoveSpeed += dt * accleration
|
||||||
|
|
||||||
# Break
|
# Break
|
||||||
deacleration = wheels[0].findControl(InputDevice.C_brake).state * self.deaclerationBreak
|
breakPedal = wheels[0].findControl(InputDevice.C_brake).state
|
||||||
|
deacleration = breakPedal * self.deaclerationBreak
|
||||||
self.currentMoveSpeed -= dt * deacleration
|
self.currentMoveSpeed -= dt * deacleration
|
||||||
if self.currentMoveSpeed < 0:
|
if self.currentMoveSpeed < 0:
|
||||||
self.currentMoveSpeed = 0
|
self.currentMoveSpeed = 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user