mirror of
https://github.com/overte-org/overte.git
synced 2025-06-07 09:12:04 +02:00
Adding the state controller
This commit is contained in:
parent
a0104884f5
commit
6ec87086bc
7 changed files with 62 additions and 15 deletions
|
@ -32,6 +32,7 @@ var RIGHT_HAND = 1;
|
||||||
|
|
||||||
var COLORS = [ { red: 255, green: 0, blue: 0 }, { red: 0, green: 0, blue: 255 } ];
|
var COLORS = [ { red: 255, green: 0, blue: 0 }, { red: 0, green: 0, blue: 255 } ];
|
||||||
|
|
||||||
|
|
||||||
function index(handNum, indexNum) {
|
function index(handNum, indexNum) {
|
||||||
return handNum * NUM_HANDS + indexNum;
|
return handNum * NUM_HANDS + indexNum;
|
||||||
}
|
}
|
||||||
|
@ -84,9 +85,46 @@ function updateHand(handNum, deltaTime) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateHydra(handNum, deltaTime) {
|
||||||
|
var pose;
|
||||||
|
var handName = "right";
|
||||||
|
if (handNum == LEFT_HAND) {
|
||||||
|
pose = Controller.getPoseValue(Controller.Hardware.Hydra.LeftHand);
|
||||||
|
handName = "left";
|
||||||
|
} else {
|
||||||
|
pose = Controller.getPoseValue(Controller.Hardware.Hydra.RightHand);
|
||||||
|
handName = "right";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pose.valid) {
|
||||||
|
//print(handName + " hand moving" + JSON.stringify(pose));
|
||||||
|
var wpos = Vec3.sum(MyAvatar.getPosition(), pose.translation);
|
||||||
|
|
||||||
|
Overlays.editOverlay(app.spheres[index(handNum, 0)], {
|
||||||
|
position: pose.translation,
|
||||||
|
visible: true,
|
||||||
|
});
|
||||||
|
/*var vpos = Vec3.sum(Vec3.multiply(10 * deltaTime, pose.velocity), pose.translation);
|
||||||
|
Overlays.editOverlay(app.spheres[index(handNum, 1)], {
|
||||||
|
position: vpos,
|
||||||
|
visible: true,
|
||||||
|
});*/
|
||||||
|
} else {
|
||||||
|
Overlays.editOverlay(app.spheres[index(handNum, 0)], {
|
||||||
|
visible: false
|
||||||
|
});
|
||||||
|
|
||||||
|
Overlays.editOverlay(app.spheres[index(handNum, 1)], {
|
||||||
|
visible: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function update(deltaTime) {
|
function update(deltaTime) {
|
||||||
updateHand(LEFT_HAND, deltaTime);
|
//updateHand(LEFT_HAND, deltaTime);
|
||||||
updateHand(RIGHT_HAND, deltaTime);
|
//updateHand(RIGHT_HAND, deltaTime);
|
||||||
|
updateHydra(LEFT_HAND, deltaTime);
|
||||||
|
updateHydra(RIGHT_HAND, deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
function scriptEnding() {
|
function scriptEnding() {
|
||||||
|
|
|
@ -3,8 +3,7 @@
|
||||||
"channels": [
|
"channels": [
|
||||||
{ "from": "Standard.LY", "to": "Actions.TranslateZ" },
|
{ "from": "Standard.LY", "to": "Actions.TranslateZ" },
|
||||||
{ "from": "Standard.LX", "to": "Actions.TranslateX" },
|
{ "from": "Standard.LX", "to": "Actions.TranslateX" },
|
||||||
{ "from": "Standard.RX", "with": "Actions.InHMD", "to": "Actions.StepYaw" },
|
{ "from": "Standard.RX", "to": "Actions.Yaw" },
|
||||||
{ "from": "Standard.RX", "to": "Actions.Yaw" },
|
|
||||||
{ "from": "Standard.RY", "to": "Actions.Pitch" },
|
{ "from": "Standard.RY", "to": "Actions.Pitch" },
|
||||||
|
|
||||||
{ "from": [ "Standard.DU", "Standard.DU", "Standard.DU", "Standard.DD" ], "to": "Standard.LeftPrimaryThumb" },
|
{ "from": [ "Standard.DU", "Standard.DU", "Standard.DU", "Standard.DD" ], "to": "Standard.LeftPrimaryThumb" },
|
||||||
|
|
|
@ -2707,7 +2707,7 @@ void Application::update(float deltaTime) {
|
||||||
userInputMapper->resetActionState(controller::Action::IN_HMD, (float)qApp->getAvatarUpdater()->isHMDMode());
|
userInputMapper->resetActionState(controller::Action::IN_HMD, (float)qApp->getAvatarUpdater()->isHMDMode());
|
||||||
|
|
||||||
userInputMapper->setSensorToWorldMat(myAvatar->getSensorToWorldMatrix());
|
userInputMapper->setSensorToWorldMat(myAvatar->getSensorToWorldMatrix());
|
||||||
userInputMapper->update(deltaTime);
|
// userInputMapper->update(deltaTime);
|
||||||
|
|
||||||
bool jointsCaptured = false;
|
bool jointsCaptured = false;
|
||||||
for (auto inputPlugin : PluginManager::getInstance()->getInputPlugins()) {
|
for (auto inputPlugin : PluginManager::getInstance()->getInputPlugins()) {
|
||||||
|
@ -2718,6 +2718,7 @@ void Application::update(float deltaTime) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
userInputMapper->update(deltaTime);
|
||||||
|
|
||||||
// Transfer the user inputs to the driveKeys
|
// Transfer the user inputs to the driveKeys
|
||||||
// FIXME can we drop drive keys and just have the avatar read the action states directly?
|
// FIXME can we drop drive keys and just have the avatar read the action states directly?
|
||||||
|
|
|
@ -26,6 +26,5 @@ namespace controller {
|
||||||
return NAN;
|
return NAN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,8 @@ namespace controller {
|
||||||
|
|
||||||
using Modifiers = std::vector<Input>;
|
using Modifiers = std::vector<Input>;
|
||||||
typedef QPair<Input, QString> InputPair;
|
typedef QPair<Input, QString> InputPair;
|
||||||
|
class Endpoint;
|
||||||
|
using EndpointPtr = std::shared_ptr<Endpoint>;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
using InputGetter = std::function<T(const Input& input, int timestamp)>;
|
using InputGetter = std::function<T(const Input& input, int timestamp)>;
|
||||||
|
@ -32,6 +33,7 @@ namespace controller {
|
||||||
using PoseGetter = InputGetter<Pose>;
|
using PoseGetter = InputGetter<Pose>;
|
||||||
using ResetBindings = std::function<bool()>;
|
using ResetBindings = std::function<bool()>;
|
||||||
using AvailableInputGetter = std::function<Input::NamedVector()>;
|
using AvailableInputGetter = std::function<Input::NamedVector()>;
|
||||||
|
using EndpointCreator = std::function<EndpointPtr(const Input&)>;
|
||||||
|
|
||||||
class DeviceProxy {
|
class DeviceProxy {
|
||||||
public:
|
public:
|
||||||
|
@ -42,6 +44,9 @@ namespace controller {
|
||||||
PoseGetter getPose = [](const Input& input, int timestamp) -> Pose { return Pose(); };
|
PoseGetter getPose = [](const Input& input, int timestamp) -> Pose { return Pose(); };
|
||||||
AvailableInputGetter getAvailabeInputs = []() -> Input::NamedVector const { return Input::NamedVector(); };
|
AvailableInputGetter getAvailabeInputs = []() -> Input::NamedVector const { return Input::NamedVector(); };
|
||||||
float getValue(const Input& input, int timestamp = 0) const;
|
float getValue(const Input& input, int timestamp = 0) const;
|
||||||
|
|
||||||
|
EndpointCreator createEndpoint = [](const Input& input) -> EndpointPtr { return EndpointPtr(); };
|
||||||
|
|
||||||
QString _name;
|
QString _name;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
|
|
||||||
namespace controller {
|
namespace controller {
|
||||||
const uint16_t UserInputMapper::ACTIONS_DEVICE = Input::INVALID_DEVICE - 0xFF;
|
const uint16_t UserInputMapper::ACTIONS_DEVICE = Input::INVALID_DEVICE - 0xFF;
|
||||||
|
const uint16_t UserInputMapper::STATE_DEVICE = ACTIONS_DEVICE - 0xFF;
|
||||||
const uint16_t UserInputMapper::STANDARD_DEVICE = 0;
|
const uint16_t UserInputMapper::STANDARD_DEVICE = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,13 +90,16 @@ void UserInputMapper::registerDevice(InputDevice* device) {
|
||||||
if (_endpointsByInput.count(input)) {
|
if (_endpointsByInput.count(input)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Endpoint::Pointer endpoint;
|
|
||||||
if (input.device == STANDARD_DEVICE) {
|
Endpoint::Pointer endpoint = proxy->createEndpoint(input);
|
||||||
endpoint = std::make_shared<StandardEndpoint>(input);
|
if (!endpoint) {
|
||||||
} else if (input.device == ACTIONS_DEVICE) {
|
if (input.device == STANDARD_DEVICE) {
|
||||||
endpoint = std::make_shared<ActionEndpoint>(input);
|
endpoint = std::make_shared<StandardEndpoint>(input);
|
||||||
} else {
|
} else if (input.device == ACTIONS_DEVICE) {
|
||||||
endpoint = std::make_shared<InputEndpoint>(input);
|
endpoint = std::make_shared<ActionEndpoint>(input);
|
||||||
|
} else {
|
||||||
|
endpoint = std::make_shared<InputEndpoint>(input);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_inputsByEndpoint[endpoint] = input;
|
_inputsByEndpoint[endpoint] = input;
|
||||||
_endpointsByInput[input] = endpoint;
|
_endpointsByInput[input] = endpoint;
|
||||||
|
@ -1020,7 +1024,7 @@ void UserInputMapper::disableMapping(const Mapping::Pointer& mapping) {
|
||||||
void UserInputMapper::resetActionState(Action action, float value) {
|
void UserInputMapper::resetActionState(Action action, float value) {
|
||||||
auto endpoint = endpointFor(inputFromAction(action));
|
auto endpoint = endpointFor(inputFromAction(action));
|
||||||
if (endpoint) {
|
if (endpoint) {
|
||||||
endpoint->apply(value, 0.0f, Endpoint::Pointer());
|
endpoint->apply(value, Endpoint::Pointer());
|
||||||
}
|
}
|
||||||
_actionStates[toInt(action)] = value;
|
_actionStates[toInt(action)] = value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,7 @@ namespace controller {
|
||||||
|
|
||||||
static const uint16_t ACTIONS_DEVICE;
|
static const uint16_t ACTIONS_DEVICE;
|
||||||
static const uint16_t STANDARD_DEVICE;
|
static const uint16_t STANDARD_DEVICE;
|
||||||
|
static const uint16_t STATE_DEVICE;
|
||||||
|
|
||||||
UserInputMapper();
|
UserInputMapper();
|
||||||
virtual ~UserInputMapper();
|
virtual ~UserInputMapper();
|
||||||
|
|
Loading…
Reference in a new issue