mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
Baseball test code
This commit is contained in:
parent
317674c89a
commit
31d92fd90a
5 changed files with 56 additions and 14 deletions
|
@ -950,8 +950,8 @@ void Application::initializeGL() {
|
||||||
checkFPStimer.start(1000);
|
checkFPStimer.start(1000);
|
||||||
|
|
||||||
// call our idle function whenever we can
|
// call our idle function whenever we can
|
||||||
connect(&idleTimer, &QTimer::timeout, this, &Application::idle);
|
// connect(&idleTimer, &QTimer::timeout, this, &Application::idle);
|
||||||
idleTimer.start(TARGET_SIM_FRAME_PERIOD_MS);
|
// idleTimer.start(TARGET_SIM_FRAME_PERIOD_MS);
|
||||||
_idleLoopStdev.reset();
|
_idleLoopStdev.reset();
|
||||||
|
|
||||||
// update before the first render
|
// update before the first render
|
||||||
|
@ -1023,6 +1023,10 @@ void Application::paintGL() {
|
||||||
if (_inPaint) {
|
if (_inPaint) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this is a good idea
|
||||||
|
idle();
|
||||||
|
|
||||||
_inPaint = true;
|
_inPaint = true;
|
||||||
Finally clearFlagLambda([this] { _inPaint = false; });
|
Finally clearFlagLambda([this] { _inPaint = false; });
|
||||||
|
|
||||||
|
@ -2070,7 +2074,7 @@ void Application::idle() {
|
||||||
float secondsSinceLastUpdate = timeSinceLastUpdateUs / USECS_PER_SECOND;
|
float secondsSinceLastUpdate = timeSinceLastUpdateUs / USECS_PER_SECOND;
|
||||||
|
|
||||||
if (isThrottled && (timeSinceLastUpdateUs / USECS_PER_MSEC) < THROTTLED_SIM_FRAME_PERIOD_MS) {
|
if (isThrottled && (timeSinceLastUpdateUs / USECS_PER_MSEC) < THROTTLED_SIM_FRAME_PERIOD_MS) {
|
||||||
return; // bail early, we're throttled and not enough time has elapsed
|
//return; // bail early, we're throttled and not enough time has elapsed
|
||||||
}
|
}
|
||||||
|
|
||||||
_lastTimeUpdated.start();
|
_lastTimeUpdated.start();
|
||||||
|
|
|
@ -35,7 +35,8 @@ AvatarActionHold::~AvatarActionHold() {
|
||||||
qDebug() << "AvatarActionHold::~AvatarActionHold";
|
qDebug() << "AvatarActionHold::~AvatarActionHold";
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#include <plugins/PluginManager.h>
|
||||||
|
#include <input-plugins/ViveControllerManager.h>
|
||||||
void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
|
void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
|
||||||
bool gotLock = false;
|
bool gotLock = false;
|
||||||
glm::quat rotation;
|
glm::quat rotation;
|
||||||
|
@ -51,7 +52,24 @@ void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
|
||||||
glm::vec3 offset;
|
glm::vec3 offset;
|
||||||
glm::vec3 palmPosition;
|
glm::vec3 palmPosition;
|
||||||
glm::quat palmRotation;
|
glm::quat palmRotation;
|
||||||
if (_hand == "right") {
|
|
||||||
|
const auto& plugins = PluginManager::getInstance()->getInputPlugins();
|
||||||
|
auto it = std::find_if(std::begin(plugins), std::end(plugins), [](const InputPluginPointer& plugin) {
|
||||||
|
return plugin->getName() == ViveControllerManager::NAME;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (it != std::end(plugins)) {
|
||||||
|
const auto& vive = it->dynamicCast<ViveControllerManager>();
|
||||||
|
auto index = (_hand == "right") ? 0 : 1; auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
||||||
|
auto translation = extractTranslation(userInputMapper->getSensorToWorldMat());
|
||||||
|
auto rotation = glm::quat_cast(userInputMapper->getSensorToWorldMat());
|
||||||
|
|
||||||
|
|
||||||
|
const glm::quat quarterX = glm::angleAxis(PI / 2.0f, glm::vec3(1.0f, 0.0f, 0.0f));
|
||||||
|
const glm::quat yFlip = glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||||
|
palmPosition = translation + rotation * vive->getPosition(index);
|
||||||
|
palmRotation = rotation * vive->getRotation(index) * yFlip * quarterX;
|
||||||
|
} else if (_hand == "right") {
|
||||||
palmPosition = holdingAvatar->getRightPalmPosition();
|
palmPosition = holdingAvatar->getRightPalmPosition();
|
||||||
palmRotation = holdingAvatar->getRightPalmRotation();
|
palmRotation = holdingAvatar->getRightPalmRotation();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -217,6 +217,15 @@ void ViveControllerManager::renderHand(UserInputMapper::PoseValue pose, gpu::Bat
|
||||||
batch.drawIndexed(gpu::TRIANGLES, mesh->getNumIndices(), 0);
|
batch.drawIndexed(gpu::TRIANGLES, mesh->getNumIndices(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glm::vec3 ViveControllerManager::getPosition(int hand) const {
|
||||||
|
const mat4& mat = _trackedDevicePoseMat4[hand ? 3 : 4];
|
||||||
|
return extractTranslation(mat);
|
||||||
|
}
|
||||||
|
glm::quat ViveControllerManager::getRotation(int hand) const {
|
||||||
|
const mat4& mat = _trackedDevicePoseMat4[hand ? 3 : 4];
|
||||||
|
return glm::quat_cast(mat);
|
||||||
|
}
|
||||||
|
|
||||||
void ViveControllerManager::update(float deltaTime, bool jointsCaptured) {
|
void ViveControllerManager::update(float deltaTime, bool jointsCaptured) {
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
_poseStateMap.clear();
|
_poseStateMap.clear();
|
||||||
|
@ -250,7 +259,7 @@ void ViveControllerManager::update(float deltaTime, bool jointsCaptured) {
|
||||||
numTrackedControllers++;
|
numTrackedControllers++;
|
||||||
|
|
||||||
const mat4& mat = _trackedDevicePoseMat4[device];
|
const mat4& mat = _trackedDevicePoseMat4[device];
|
||||||
|
|
||||||
if (!jointsCaptured) {
|
if (!jointsCaptured) {
|
||||||
handlePoseEvent(mat, numTrackedControllers - 1);
|
handlePoseEvent(mat, numTrackedControllers - 1);
|
||||||
}
|
}
|
||||||
|
@ -372,16 +381,23 @@ void ViveControllerManager::handlePoseEvent(const mat4& mat, int index) {
|
||||||
// Q = (deltaQ * QOffset) * (yFlip * quarterTurnAboutX)
|
// Q = (deltaQ * QOffset) * (yFlip * quarterTurnAboutX)
|
||||||
//
|
//
|
||||||
// Q = (deltaQ * inverse(deltaQForAlignedHand)) * (yFlip * quarterTurnAboutX)
|
// Q = (deltaQ * inverse(deltaQForAlignedHand)) * (yFlip * quarterTurnAboutX)
|
||||||
|
|
||||||
|
float sign = (index == LEFT_HAND) ? -1.0f : 1.0f;
|
||||||
|
|
||||||
const glm::quat quarterX = glm::angleAxis(PI / 2.0f, glm::vec3(1.0f, 0.0f, 0.0f));
|
const glm::quat quarterX = glm::angleAxis(PI / 2.0f, glm::vec3(1.0f, 0.0f, 0.0f));
|
||||||
const glm::quat yFlip = glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f));
|
const glm::quat yFlip = glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||||
float sign = (index == LEFT_HAND) ? -1.0f : 1.0f;
|
|
||||||
const glm::quat signedQuaterZ = glm::angleAxis(sign * PI / 2.0f, glm::vec3(0.0f, 0.0f, 1.0f));
|
const glm::quat signedQuaterZ = glm::angleAxis(sign * PI / 2.0f, glm::vec3(0.0f, 0.0f, 1.0f));
|
||||||
const glm::quat eighthX = glm::angleAxis(PI / 4.0f, glm::vec3(1.0f, 0.0f, 0.0f));
|
const glm::quat eighthX = glm::angleAxis(PI / 4.0f, glm::vec3(1.0f, 0.0f, 0.0f));
|
||||||
const glm::quat offset = glm::inverse(signedQuaterZ * eighthX);
|
|
||||||
rotation = rotation * offset * yFlip * quarterX;
|
|
||||||
|
const glm::quat rotationOffset = glm::inverse(signedQuaterZ * eighthX) * yFlip * quarterX;
|
||||||
|
const glm::vec3 translationOffset = glm::vec3(sign * CONTROLLER_LENGTH_OFFSET / 2.0f,
|
||||||
|
CONTROLLER_LENGTH_OFFSET / 2.0f,
|
||||||
|
2.0f * CONTROLLER_LENGTH_OFFSET);
|
||||||
|
|
||||||
position += rotation * glm::vec3(0, 0, -CONTROLLER_LENGTH_OFFSET);
|
position += rotation * translationOffset;
|
||||||
|
rotation = rotation * rotationOffset;
|
||||||
|
//{quat, x = 0.653281, y = -0.270598, z = 0.653281, w = 0.270598}{vec3, x = 0.0381, y = -0.0381, z = -0.1524}
|
||||||
|
|
||||||
_poseStateMap[makeInput(JointChannel(index)).getChannel()] = UserInputMapper::PoseValue(position, rotation);
|
_poseStateMap[makeInput(JointChannel(index)).getChannel()] = UserInputMapper::PoseValue(position, rotation);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
class ViveControllerManager : public InputPlugin, public InputDevice {
|
class ViveControllerManager : public InputPlugin, public InputDevice {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
static const QString NAME;
|
||||||
|
|
||||||
enum JoystickAxisChannel {
|
enum JoystickAxisChannel {
|
||||||
AXIS_Y_POS = 1U << 1,
|
AXIS_Y_POS = 1U << 1,
|
||||||
AXIS_Y_NEG = 1U << 2,
|
AXIS_Y_NEG = 1U << 2,
|
||||||
|
@ -74,6 +76,10 @@ public:
|
||||||
UserInputMapper::Input makeInput(unsigned int button, int index);
|
UserInputMapper::Input makeInput(unsigned int button, int index);
|
||||||
UserInputMapper::Input makeInput(JoystickAxisChannel axis, int index);
|
UserInputMapper::Input makeInput(JoystickAxisChannel axis, int index);
|
||||||
UserInputMapper::Input makeInput(JointChannel joint);
|
UserInputMapper::Input makeInput(JointChannel joint);
|
||||||
|
|
||||||
|
int getNumDevices() const;
|
||||||
|
glm::vec3 getPosition(int device) const;
|
||||||
|
glm::quat getRotation(int device) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void renderHand(UserInputMapper::PoseValue pose, gpu::Batch& batch, int index);
|
void renderHand(UserInputMapper::PoseValue pose, gpu::Batch& batch, int index);
|
||||||
|
@ -92,8 +98,6 @@ private:
|
||||||
int _rightHandRenderID;
|
int _rightHandRenderID;
|
||||||
|
|
||||||
bool _renderControllers;
|
bool _renderControllers;
|
||||||
|
|
||||||
static const QString NAME;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi__ViveControllerManager
|
#endif // hifi__ViveControllerManager
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#include <glm/gtc/quaternion.hpp>
|
#include <glm/gtc/quaternion.hpp>
|
||||||
|
|
||||||
const int PHYSICS_ENGINE_MAX_NUM_SUBSTEPS = 6; // Bullet will start to "lose time" at 10 FPS.
|
const int PHYSICS_ENGINE_MAX_NUM_SUBSTEPS = 6; // Bullet will start to "lose time" at 10 FPS.
|
||||||
const float PHYSICS_ENGINE_FIXED_SUBSTEP = 1.0f / 60.0f;
|
const float PHYSICS_ENGINE_FIXED_SUBSTEP = 1.0f / 90.0f;
|
||||||
|
|
||||||
// return incremental rotation (Bullet-style) caused by angularVelocity over timeStep
|
// return incremental rotation (Bullet-style) caused by angularVelocity over timeStep
|
||||||
glm::quat computeBulletRotationStep(const glm::vec3& angularVelocity, float timeStep);
|
glm::quat computeBulletRotationStep(const glm::vec3& angularVelocity, float timeStep);
|
||||||
|
|
Loading…
Reference in a new issue