mirror of
https://github.com/overte-org/overte.git
synced 2025-07-24 01:23:55 +02:00
added all buttons triggers and joysticks
This commit is contained in:
parent
70e9781ad9
commit
efdef1ad35
3 changed files with 132 additions and 3 deletions
|
@ -23,6 +23,38 @@ const PalmData* ControllerScriptingInterface::getPrimaryPalm() const {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ControllerScriptingInterface::getNumberOfActivePalms() const {
|
||||||
|
const HandData* handData = Application::getInstance()->getAvatar()->getHandData();
|
||||||
|
int numberOfPalms = handData->getNumPalms();
|
||||||
|
int numberOfActivePalms = 0;
|
||||||
|
for (int i = 0; i < numberOfPalms; i++) {
|
||||||
|
if (getPalm(i)->isActive()) {
|
||||||
|
numberOfActivePalms++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return numberOfActivePalms;
|
||||||
|
}
|
||||||
|
|
||||||
|
const PalmData* ControllerScriptingInterface::getPalm(int palmIndex) const {
|
||||||
|
const HandData* handData = Application::getInstance()->getAvatar()->getHandData();
|
||||||
|
return &handData->getPalms()[palmIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
const PalmData* ControllerScriptingInterface::getActivePalm(int palmIndex) const {
|
||||||
|
const HandData* handData = Application::getInstance()->getAvatar()->getHandData();
|
||||||
|
int numberOfPalms = handData->getNumPalms();
|
||||||
|
int numberOfActivePalms = 0;
|
||||||
|
for (int i = 0; i < numberOfPalms; i++) {
|
||||||
|
if (getPalm(i)->isActive()) {
|
||||||
|
if (numberOfActivePalms == palmIndex) {
|
||||||
|
return &handData->getPalms()[i];
|
||||||
|
}
|
||||||
|
numberOfActivePalms++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
bool ControllerScriptingInterface::isPrimaryButtonPressed() const {
|
bool ControllerScriptingInterface::isPrimaryButtonPressed() const {
|
||||||
const PalmData* primaryPalm = getPrimaryPalm();
|
const PalmData* primaryPalm = getPrimaryPalm();
|
||||||
if (primaryPalm) {
|
if (primaryPalm) {
|
||||||
|
@ -43,3 +75,68 @@ glm::vec2 ControllerScriptingInterface::getPrimaryJoystickPosition() const {
|
||||||
return glm::vec2(0);
|
return glm::vec2(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ControllerScriptingInterface::getNumberOfButtons() const {
|
||||||
|
return getNumberOfActivePalms() * NUMBER_OF_BUTTONS_PER_PALM;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ControllerScriptingInterface::isButtonPressed(int buttonIndex) const {
|
||||||
|
int palmIndex = buttonIndex / NUMBER_OF_BUTTONS_PER_PALM;
|
||||||
|
int buttonOnPalm = buttonIndex % NUMBER_OF_BUTTONS_PER_PALM;
|
||||||
|
const PalmData* palmData = getActivePalm(palmIndex);
|
||||||
|
if (palmData) {
|
||||||
|
switch (buttonOnPalm) {
|
||||||
|
case 0:
|
||||||
|
return palmData->getControllerButtons() & BUTTON_0;
|
||||||
|
case 1:
|
||||||
|
return palmData->getControllerButtons() & BUTTON_1;
|
||||||
|
case 2:
|
||||||
|
return palmData->getControllerButtons() & BUTTON_2;
|
||||||
|
case 3:
|
||||||
|
return palmData->getControllerButtons() & BUTTON_3;
|
||||||
|
case 4:
|
||||||
|
return palmData->getControllerButtons() & BUTTON_4;
|
||||||
|
case 5:
|
||||||
|
return palmData->getControllerButtons() & BUTTON_FWD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ControllerScriptingInterface::getNumberOfTriggers() const {
|
||||||
|
return getNumberOfActivePalms() * NUMBER_OF_TRIGGERS_PER_PALM;
|
||||||
|
}
|
||||||
|
|
||||||
|
float ControllerScriptingInterface::getTriggerValue(int triggerIndex) const {
|
||||||
|
// we know there's one trigger per palm, so the triggerIndex is the palm Index
|
||||||
|
int palmIndex = triggerIndex;
|
||||||
|
const PalmData* palmData = getActivePalm(palmIndex);
|
||||||
|
if (palmData) {
|
||||||
|
return palmData->getTrigger();
|
||||||
|
}
|
||||||
|
return 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ControllerScriptingInterface::getNumberOfJoysticks() const {
|
||||||
|
return getNumberOfActivePalms() * NUMBER_OF_JOYSTICKS_PER_PALM;
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::vec2 ControllerScriptingInterface::getJoystickPosition(int joystickIndex) const {
|
||||||
|
// we know there's one joystick per palm, so the joystickIndex is the palm Index
|
||||||
|
int palmIndex = joystickIndex;
|
||||||
|
const PalmData* palmData = getActivePalm(palmIndex);
|
||||||
|
if (palmData) {
|
||||||
|
return glm::vec2(palmData->getJoystickX(), palmData->getJoystickY());
|
||||||
|
}
|
||||||
|
return glm::vec2(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ControllerScriptingInterface::getNumberOfSpatialControls() const {
|
||||||
|
return getNumberOfActivePalms() * NUMBER_OF_SPATIALCONTROLS_PER_PALM;
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::vec3 ControllerScriptingInterface::getSpatialControlPosition(int controlIndex) const {
|
||||||
|
return glm::vec3(0); // not yet implemented
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
|
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef __hifi__InterfaceControllerScriptingInterface__
|
#ifndef __hifi__ControllerScriptingInterface__
|
||||||
#define __hifi__InterfaceControllerScriptingInterface__
|
#define __hifi__ControllerScriptingInterface__
|
||||||
|
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
|
|
||||||
|
@ -21,8 +21,28 @@ public slots:
|
||||||
virtual bool isPrimaryButtonPressed() const;
|
virtual bool isPrimaryButtonPressed() const;
|
||||||
virtual glm::vec2 getPrimaryJoystickPosition() const;
|
virtual glm::vec2 getPrimaryJoystickPosition() const;
|
||||||
|
|
||||||
|
virtual int getNumberOfButtons() const;
|
||||||
|
virtual bool isButtonPressed(int buttonIndex) const;
|
||||||
|
|
||||||
|
virtual int getNumberOfTriggers() const;
|
||||||
|
virtual float getTriggerValue(int triggerIndex) const;
|
||||||
|
|
||||||
|
virtual int getNumberOfJoysticks() const;
|
||||||
|
virtual glm::vec2 getJoystickPosition(int joystickIndex) const;
|
||||||
|
|
||||||
|
virtual int getNumberOfSpatialControls() const;
|
||||||
|
virtual glm::vec3 getSpatialControlPosition(int controlIndex) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const PalmData* getPrimaryPalm() const;
|
const PalmData* getPrimaryPalm() const;
|
||||||
|
const PalmData* getPalm(int palmIndex) const;
|
||||||
|
int getNumberOfActivePalms() const;
|
||||||
|
const PalmData* getActivePalm(int palmIndex) const;
|
||||||
|
|
||||||
|
const int NUMBER_OF_SPATIALCONTROLS_PER_PALM = 0;
|
||||||
|
const int NUMBER_OF_JOYSTICKS_PER_PALM = 1;
|
||||||
|
const int NUMBER_OF_TRIGGERS_PER_PALM = 1;
|
||||||
|
const int NUMBER_OF_BUTTONS_PER_PALM = 6;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* defined(__hifi__InterfaceControllerScriptingInterface__) */
|
#endif /* defined(__hifi__ControllerScriptingInterface__) */
|
||||||
|
|
|
@ -19,6 +19,18 @@ class AbstractControllerScriptingInterface : public QObject {
|
||||||
public slots:
|
public slots:
|
||||||
virtual bool isPrimaryButtonPressed() const = 0;
|
virtual bool isPrimaryButtonPressed() const = 0;
|
||||||
virtual glm::vec2 getPrimaryJoystickPosition() const = 0;
|
virtual glm::vec2 getPrimaryJoystickPosition() const = 0;
|
||||||
|
|
||||||
|
virtual int getNumberOfButtons() const = 0;
|
||||||
|
virtual bool isButtonPressed(int buttonIndex) const = 0;
|
||||||
|
|
||||||
|
virtual int getNumberOfTriggers() const = 0;
|
||||||
|
virtual float getTriggerValue(int triggerIndex) const = 0;
|
||||||
|
|
||||||
|
virtual int getNumberOfJoysticks() const = 0;
|
||||||
|
virtual glm::vec2 getJoystickPosition(int joystickIndex) const = 0;
|
||||||
|
|
||||||
|
virtual int getNumberOfSpatialControls() const = 0;
|
||||||
|
virtual glm::vec3 getSpatialControlPosition(int controlIndex) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* defined(__hifi__AbstractControllerScriptingInterface__) */
|
#endif /* defined(__hifi__AbstractControllerScriptingInterface__) */
|
||||||
|
|
Loading…
Reference in a new issue