1
from panda3d.core import Vec3, ButtonHandle, loadPrcFileData
2
#loadPrcFileData("", "notify-level-device debug")
4
from panda3d.core import InputDevice
9
class PluginWiiRemote():
10
"""This plugin provides gamepad support for wii remotes plus nunchuk"""
11
def __init__(self, parent):
12
if not gamepadsupport: return
13
if not self.hasGamepad(): return
16
self.deviceMap = self.parent.deviceMap
17
self.usedGamepadID = self.parent.usedGamepadID
18
self.deadzone_x = self.parent.deadzone_x
19
self.deadzone_y = self.parent.deadzone_y
23
# set the center position of the control sticks
24
# NOTE: here we assume, that the wheel is centered when the application get started.
25
# In real world applications, you should notice the user and give him enough time
26
# to center the wheel until you store the center position of the controler!
27
self.lxcenter = self.nunchuck.findControl(self.deviceMap["axis-left-x"]).state
28
self.lycenter = self.nunchuck.findControl(self.deviceMap["axis-left-y"]).state
30
self.sprintState = False
32
def checkGamepads(self):
33
# list of connected gamepad devices
36
connectedDevices = base.devices.getDevices()
37
for device in connectedDevices:
38
if device.get_device_class() == InputDevice.DC_gamepad \
39
and "Nintendo Wii Remote" in device.name \
40
and "Nintendo Wii Remote Nunchuk" not in device.name:
41
self.gamepads.append(device)
42
elif "Nintendo Wii Remote Nunchuk" in device.name:
43
self.gamepads.append(device)
44
self.nunchuck = device
47
if not gamepadsupport: return False
48
if base.devices.get_devices(InputDevice.DC_gamepad):
52
def getMovementVec(self):
53
if not gamepadsupport: return Vec3()
56
axis_x = self.nunchuck.findControl(self.deviceMap["axis-left-x"]).state
57
if abs(axis_x) > self.deadzone_x:
58
movementVec.setX(axis_x - self.lxcenter)
59
# Move forward/backward
60
axis_y = self.nunchuck.findControl(self.deviceMap["axis-left-y"]).state
61
if abs(axis_y) > self.deadzone_y:
62
movementVec.setY(-(axis_y - self.lycenter))
65
def getRotationVec(self):
66
if not gamepadsupport: return Vec3()
68
rotationVec.setX(self.gamepads[self.usedGamepadID].findControl(self.deviceMap["axis-right-x"]).state - self.rxcenter)
69
rotationVec.setY(self.gamepads[self.usedGamepadID].findControl(self.deviceMap["axis-right-y"]).state - self.rycenter)
72
def getCamButton(self, direction):
73
if not gamepadsupport: return False
74
if direction not in self.deviceMap: return False
77
return self.gamepads[self.usedGamepadID].findButton(self.deviceMap[direction]).state == InputDevice.S_down
79
def getJumpState(self):
80
if not gamepadsupport: return False
81
return self.gamepads[self.usedGamepadID].findButton(self.deviceMap["jump"]).state == InputDevice.S_down
83
def getCenterCamState(self):
84
if not gamepadsupport: return False
85
return self.gamepads[self.usedGamepadID].findButton(self.deviceMap["center-camera"]).state == InputDevice.S_down
87
def getIntelActionState(self):
88
if not gamepadsupport: return False
89
return self.gamepads[self.usedGamepadID].findButton(self.deviceMap["intel-action"]).state == InputDevice.S_down
91
def getSprintState(self):
92
if not gamepadsupport: return False
93
return self.nunchuck.findButton(self.deviceMap["sprint"]).state == InputDevice.S_down