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);
|
||||
|
||||
// call our idle function whenever we can
|
||||
connect(&idleTimer, &QTimer::timeout, this, &Application::idle);
|
||||
idleTimer.start(TARGET_SIM_FRAME_PERIOD_MS);
|
||||
// connect(&idleTimer, &QTimer::timeout, this, &Application::idle);
|
||||
// idleTimer.start(TARGET_SIM_FRAME_PERIOD_MS);
|
||||
_idleLoopStdev.reset();
|
||||
|
||||
// update before the first render
|
||||
|
@ -1023,6 +1023,10 @@ void Application::paintGL() {
|
|||
if (_inPaint) {
|
||||
return;
|
||||
}
|
||||
|
||||
// this is a good idea
|
||||
idle();
|
||||
|
||||
_inPaint = true;
|
||||
Finally clearFlagLambda([this] { _inPaint = false; });
|
||||
|
||||
|
@ -2070,7 +2074,7 @@ void Application::idle() {
|
|||
float secondsSinceLastUpdate = timeSinceLastUpdateUs / USECS_PER_SECOND;
|
||||
|
||||
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();
|
||||
|
|
|
@ -35,7 +35,8 @@ AvatarActionHold::~AvatarActionHold() {
|
|||
qDebug() << "AvatarActionHold::~AvatarActionHold";
|
||||
#endif
|
||||
}
|
||||
|
||||
#include <plugins/PluginManager.h>
|
||||
#include <input-plugins/ViveControllerManager.h>
|
||||
void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
|
||||
bool gotLock = false;
|
||||
glm::quat rotation;
|
||||
|
@ -51,7 +52,24 @@ void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
|
|||
glm::vec3 offset;
|
||||
glm::vec3 palmPosition;
|
||||
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();
|
||||
palmRotation = holdingAvatar->getRightPalmRotation();
|
||||
} else {
|
||||
|
|
|
@ -217,6 +217,15 @@ void ViveControllerManager::renderHand(UserInputMapper::PoseValue pose, gpu::Bat
|
|||
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) {
|
||||
#ifdef Q_OS_WIN
|
||||
_poseStateMap.clear();
|
||||
|
@ -250,7 +259,7 @@ void ViveControllerManager::update(float deltaTime, bool jointsCaptured) {
|
|||
numTrackedControllers++;
|
||||
|
||||
const mat4& mat = _trackedDevicePoseMat4[device];
|
||||
|
||||
|
||||
if (!jointsCaptured) {
|
||||
handlePoseEvent(mat, numTrackedControllers - 1);
|
||||
}
|
||||
|
@ -372,16 +381,23 @@ void ViveControllerManager::handlePoseEvent(const mat4& mat, int index) {
|
|||
// Q = (deltaQ * QOffset) * (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 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 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);
|
||||
}
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
class ViveControllerManager : public InputPlugin, public InputDevice {
|
||||
Q_OBJECT
|
||||
public:
|
||||
static const QString NAME;
|
||||
|
||||
enum JoystickAxisChannel {
|
||||
AXIS_Y_POS = 1U << 1,
|
||||
AXIS_Y_NEG = 1U << 2,
|
||||
|
@ -74,6 +76,10 @@ public:
|
|||
UserInputMapper::Input makeInput(unsigned int button, int index);
|
||||
UserInputMapper::Input makeInput(JoystickAxisChannel axis, int index);
|
||||
UserInputMapper::Input makeInput(JointChannel joint);
|
||||
|
||||
int getNumDevices() const;
|
||||
glm::vec3 getPosition(int device) const;
|
||||
glm::quat getRotation(int device) const;
|
||||
|
||||
private:
|
||||
void renderHand(UserInputMapper::PoseValue pose, gpu::Batch& batch, int index);
|
||||
|
@ -92,8 +98,6 @@ private:
|
|||
int _rightHandRenderID;
|
||||
|
||||
bool _renderControllers;
|
||||
|
||||
static const QString NAME;
|
||||
};
|
||||
|
||||
#endif // hifi__ViveControllerManager
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#include <glm/gtc/quaternion.hpp>
|
||||
|
||||
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
|
||||
glm::quat computeBulletRotationStep(const glm::vec3& angularVelocity, float timeStep);
|
||||
|
|
Loading…
Reference in a new issue