mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 02:42:49 -04:00
Renamed gamepad sample script to gamepad.py
Renamed gamepad sample script Changed axis usage to the newly created functions and exposed classes
This commit is contained in:
parent
e1661111c2
commit
2565f4b423
@ -56,6 +56,16 @@ class App(ShowBase):
|
|||||||
# movements by ourself
|
# movements by ourself
|
||||||
self.disableMouse()
|
self.disableMouse()
|
||||||
|
|
||||||
|
# set the center position of the control sticks
|
||||||
|
# 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
|
||||||
|
# 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.lycenter = gamepads[0].findControl(InputDevice.C_left_y).state
|
||||||
|
self.rxcenter = gamepads[0].findControl(InputDevice.C_right_x).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):
|
||||||
@ -95,16 +105,14 @@ class App(ShowBase):
|
|||||||
return task.cont
|
return task.cont
|
||||||
|
|
||||||
# we will use the first found gamepad
|
# we will use the first found gamepad
|
||||||
for i in range(gamepads[0].getNumControls()):
|
# Move the camera left/right
|
||||||
if gamepads[0].getControlMap(i) == InputDevice.C_left_x:
|
movementVec.setX(gamepads[0].findControl(InputDevice.C_left_x).state - self.lxcenter)
|
||||||
movementVec.setX(gamepads[0].getControlState(i))
|
# Move the camera forward/backward
|
||||||
elif gamepads[0].getControlMap(i) == InputDevice.C_left_y:
|
movementVec.setY(gamepads[0].findControl(InputDevice.C_left_y).state - self.lycenter)
|
||||||
movementVec.setY(gamepads[0].getControlState(i))
|
# Control the cameras heading
|
||||||
|
base.camera.setH(base.camera, 100 * dt * (gamepads[0].findControl(InputDevice.C_right_x).state - self.rxcenter))
|
||||||
if gamepads[0].getControlMap(i) == InputDevice.C_right_x:
|
# Control the cameras pitch
|
||||||
base.camera.setH(base.camera, 100 * dt * (gamepads[0].getControlState(i)))
|
base.camera.setP(base.camera, 100 * dt * (gamepads[0].findControl(InputDevice.C_right_y).state - self.rycenter))
|
||||||
elif gamepads[0].getControlMap(i) == InputDevice.C_right_y:
|
|
||||||
base.camera.setP(base.camera, 100 * dt * (gamepads[0].getControlState(i)))
|
|
||||||
|
|
||||||
# calculate movement
|
# calculate movement
|
||||||
base.camera.setX(base.camera, 100 * dt * movementVec.getX())
|
base.camera.setX(base.camera, 100 * dt * movementVec.getX())
|
Loading…
x
Reference in New Issue
Block a user