mirror of
https://github.com/lubosz/overte.git
synced 2025-04-27 15:55:26 +02:00
added postTransform filter
This commit is contained in:
parent
6daf68b338
commit
afe7c386c3
8 changed files with 69 additions and 4 deletions
libraries/controllers/src/controllers
|
@ -69,5 +69,24 @@ namespace controller {
|
|||
pose.valid = valid;
|
||||
return pose;
|
||||
}
|
||||
|
||||
Pose Pose::postTransform(const glm::mat4& mat) const {
|
||||
glm::mat4 original = getMat4();
|
||||
glm::mat4 result = original * mat;
|
||||
|
||||
auto translationOut = ::extractTranslation(result);
|
||||
auto rotationOut = ::glmExtractRotation(result);
|
||||
auto velocityOut = velocity + glm::cross(angularVelocity, translation - translationOut); // warning: this may be completely wrong
|
||||
auto angularVelocityOut = angularVelocity;
|
||||
|
||||
Pose pose(translationOut,
|
||||
rotationOut,
|
||||
velocityOut,
|
||||
angularVelocityOut);
|
||||
|
||||
pose.valid = valid;
|
||||
return pose;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,9 @@ namespace controller {
|
|||
vec3 getAngularVelocity() const { return angularVelocity; }
|
||||
|
||||
Pose transform(const glm::mat4& mat) const;
|
||||
Pose postTransform(const glm::mat4& mat) const;
|
||||
|
||||
glm::mat4 getMat4() const { return ::createMatFromQuatAndPos(rotation, translation); }
|
||||
|
||||
static QScriptValue toScriptValue(QScriptEngine* engine, const Pose& event);
|
||||
static void fromScriptValue(const QScriptValue& object, Pose& event);
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include "filters/ScaleFilter.h"
|
||||
#include "filters/TranslateFilter.h"
|
||||
#include "filters/TransformFilter.h"
|
||||
#include "filters/PostTransformFilter.h"
|
||||
#include "filters/RotateFilter.h"
|
||||
|
||||
using namespace controller;
|
||||
|
||||
|
@ -41,6 +43,8 @@ REGISTER_FILTER_CLASS_INSTANCE(ScaleFilter, "scale")
|
|||
REGISTER_FILTER_CLASS_INSTANCE(PulseFilter, "pulse")
|
||||
REGISTER_FILTER_CLASS_INSTANCE(TranslateFilter, "translate")
|
||||
REGISTER_FILTER_CLASS_INSTANCE(TransformFilter, "transform")
|
||||
REGISTER_FILTER_CLASS_INSTANCE(PostTransformFilter, "postTransform")
|
||||
REGISTER_FILTER_CLASS_INSTANCE(RotateFilter, "rotate")
|
||||
|
||||
const QString JSON_FILTER_TYPE = QStringLiteral("type");
|
||||
const QString JSON_FILTER_PARAMS = QStringLiteral("params");
|
||||
|
@ -114,7 +118,7 @@ bool Filter::parseVec3Parameter(const QJsonValue& parameters, const QString& nam
|
|||
return false;
|
||||
}
|
||||
|
||||
bool Filter::parseMat4Parameter(const QJsonValue& parameters, const QString& name, glm::mat4& output) {
|
||||
bool Filter::parseMat4Parameter(const QJsonValue& parameters, glm::mat4& output) {
|
||||
if (parameters.isObject()) {
|
||||
auto objectParameters = parameters.toObject();
|
||||
|
||||
|
|
|
@ -47,8 +47,8 @@ namespace controller {
|
|||
|
||||
static bool parseSingleFloatParameter(const QJsonValue& parameters, const QString& name, float& output);
|
||||
static bool parseVec3Parameter(const QJsonValue& parameters, const QString& name, glm::vec3& output);
|
||||
static bool parseMat4Parameter(const QJsonValue& parameters, const QString& name, glm::mat4& output);
|
||||
static bool parseQuatParameter(const QJsonValue& parameters, const QString& name, glm::quat& output);
|
||||
static bool parseMat4Parameter(const QJsonValue& parameters, glm::mat4& output);
|
||||
protected:
|
||||
static Factory _factory;
|
||||
};
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "filters/ScaleFilter.h"
|
||||
#include "filters/TranslateFilter.h"
|
||||
#include "filters/TransformFilter.h"
|
||||
#include "filters/PostTransformFilter.h"
|
||||
#include "filters/RotateFilter.h"
|
||||
#include "conditionals/AndConditional.h"
|
||||
|
||||
|
@ -116,6 +117,11 @@ QObject* RouteBuilderProxy::transform(glm::mat4 transform) {
|
|||
return this;
|
||||
}
|
||||
|
||||
QObject* RouteBuilderProxy::postTransform(glm::mat4 transform) {
|
||||
addFilter(std::make_shared<PostTransformFilter>(transform));
|
||||
return this;
|
||||
}
|
||||
|
||||
QObject* RouteBuilderProxy::rotate(glm::quat rotation) {
|
||||
addFilter(std::make_shared<RotateFilter>(rotation));
|
||||
return this;
|
||||
|
|
|
@ -50,6 +50,7 @@ class RouteBuilderProxy : public QObject {
|
|||
Q_INVOKABLE QObject* constrainToPositiveInteger();
|
||||
Q_INVOKABLE QObject* translate(glm::vec3 translate);
|
||||
Q_INVOKABLE QObject* transform(glm::mat4 transform);
|
||||
Q_INVOKABLE QObject* postTransform(glm::mat4 transform);
|
||||
Q_INVOKABLE QObject* rotate(glm::quat rotation);
|
||||
|
||||
private:
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
//
|
||||
// Created by Brad Hefta-Gaub 2017/04/11
|
||||
// Copyright 2017 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#ifndef hifi_Controllers_Filters_PostTransform_h
|
||||
#define hifi_Controllers_Filters_PostTransform_h
|
||||
|
||||
#include <glm/gtx/transform.hpp>
|
||||
|
||||
#include "../Filter.h"
|
||||
|
||||
namespace controller {
|
||||
|
||||
class PostTransformFilter : public Filter {
|
||||
REGISTER_FILTER_CLASS(PostTransformFilter);
|
||||
public:
|
||||
PostTransformFilter() { }
|
||||
PostTransformFilter(glm::mat4 transform) : _transform(transform) {}
|
||||
virtual float apply(float value) const override { return value; }
|
||||
virtual Pose apply(Pose value) const override { return value.postTransform(_transform); }
|
||||
virtual bool parseParameters(const QJsonValue& parameters) override { return parseMat4Parameter(parameters, _transform); }
|
||||
private:
|
||||
glm::mat4 _transform;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -16,6 +16,5 @@
|
|||
using namespace controller;
|
||||
|
||||
bool TransformFilter::parseParameters(const QJsonValue& parameters) {
|
||||
static const QString JSON_TRANSFORM = QStringLiteral("transform");
|
||||
return parseMat4Parameter(parameters, JSON_TRANSFORM, _transform);
|
||||
return parseMat4Parameter(parameters, _transform);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue