mirror of
https://github.com/overte-org/overte.git
synced 2025-08-05 11:19:51 +02:00
update jointraypicks from joints, dirOffset needs work
This commit is contained in:
parent
916a99c670
commit
783750a0bc
7 changed files with 43 additions and 12 deletions
|
@ -10,6 +10,9 @@
|
|||
//
|
||||
#include "JointRayPick.h"
|
||||
|
||||
#include "DependencyManager.h"
|
||||
#include "avatar/AvatarManager.h"
|
||||
|
||||
JointRayPick::JointRayPick(const QString& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const uint16_t filter, const float maxDistance, const bool enabled) :
|
||||
RayPick(filter, maxDistance, enabled),
|
||||
_jointName(jointName),
|
||||
|
@ -18,10 +21,26 @@ JointRayPick::JointRayPick(const QString& jointName, const glm::vec3& posOffset,
|
|||
{
|
||||
}
|
||||
|
||||
const PickRay JointRayPick::getPickRay() {
|
||||
// TODO:
|
||||
// get pose for _jointName
|
||||
// apply offset
|
||||
// create and return PickRay
|
||||
const PickRay JointRayPick::getPickRay(bool& valid) {
|
||||
auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
||||
int jointIndex = myAvatar->getJointIndex(_jointName);
|
||||
if (jointIndex != -1) {
|
||||
glm::vec3 jointPos = myAvatar->getAbsoluteJointTranslationInObjectFrame(jointIndex);
|
||||
glm::quat jointRot = myAvatar->getAbsoluteJointRotationInObjectFrame(jointIndex);
|
||||
glm::vec3 avatarPos = myAvatar->getPosition();
|
||||
glm::quat avatarRot = myAvatar->getOrientation();
|
||||
|
||||
glm::vec3 pos = avatarPos + (avatarRot * jointPos);
|
||||
glm::quat rot = avatarRot * jointRot;
|
||||
|
||||
// Apply offset
|
||||
pos = pos + (rot * _posOffset);
|
||||
glm::vec3 dir = rot * glm::normalize(_dirOffset);
|
||||
|
||||
valid = true;
|
||||
return PickRay(pos, dir);
|
||||
}
|
||||
|
||||
valid = false;
|
||||
return PickRay();
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ class JointRayPick : public RayPick {
|
|||
public:
|
||||
JointRayPick(const QString& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const uint16_t filter, const float maxDistance = 0.0f, const bool enabled = false);
|
||||
|
||||
const PickRay getPickRay() override;
|
||||
const PickRay getPickRay(bool& valid) override;
|
||||
|
||||
private:
|
||||
QString _jointName;
|
||||
|
|
|
@ -26,12 +26,13 @@ uint32_t LaserPointerScriptingInterface::createLaserPointer(const QVariant& prop
|
|||
if (propertyMap["joint"].isValid()) {
|
||||
QString jointName = propertyMap["joint"].toString();
|
||||
|
||||
// x = upward, y = forward, z = lateral
|
||||
glm::vec3 posOffset = Vectors::ZERO;
|
||||
if (propertyMap["posOffset"].isValid()) {
|
||||
posOffset = vec3FromVariant(propertyMap["posOffset"]);
|
||||
}
|
||||
|
||||
glm::vec3 dirOffset = Vectors::FRONT;
|
||||
glm::vec3 dirOffset = Vectors::UP;
|
||||
if (propertyMap["dirOffset"].isValid()) {
|
||||
posOffset = vec3FromVariant(propertyMap["dirOffset"]);
|
||||
}
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
class RayPick {
|
||||
|
||||
public:
|
||||
RayPick(const uint16_t filter, const float maxDistance, const bool enabled);
|
||||
RayPick(const uint16_t filter, const float maxDistance, const bool enabled);
|
||||
|
||||
virtual const PickRay getPickRay() = 0;
|
||||
virtual const PickRay getPickRay(bool& valid) = 0;
|
||||
|
||||
void enable() { _enabled = true; }
|
||||
void disable() { _enabled = false; }
|
||||
|
|
|
@ -54,7 +54,13 @@ void RayPickManager::update() {
|
|||
continue;
|
||||
}
|
||||
|
||||
PickRay ray = rayPick->getPickRay();
|
||||
bool valid;
|
||||
PickRay ray = rayPick->getPickRay(valid);
|
||||
|
||||
if (!valid) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// get rid of this and make PickRay hashable
|
||||
QPair<glm::vec3, glm::vec3> rayKey = QPair<glm::vec3, glm::vec3>(ray.origin, ray.direction);
|
||||
|
@ -139,7 +145,7 @@ void RayPickManager::update() {
|
|||
}
|
||||
}
|
||||
|
||||
if (res.distance < rayPick->getMaxDistance()) {
|
||||
if (rayPick->getMaxDistance() == 0.0f || (rayPick->getMaxDistance() > 0.0f && res.distance < rayPick->getMaxDistance())) {
|
||||
rayPick->setRayPickResult(res);
|
||||
} else {
|
||||
rayPick->setRayPickResult(RayPickResult());
|
||||
|
|
|
@ -15,3 +15,8 @@ StaticRayPick::StaticRayPick(const glm::vec3& position, const glm::vec3& directi
|
|||
_pickRay(position, direction)
|
||||
{
|
||||
}
|
||||
|
||||
const PickRay StaticRayPick::getPickRay(bool& valid) {
|
||||
valid = true;
|
||||
return _pickRay;
|
||||
}
|
|
@ -18,7 +18,7 @@ class StaticRayPick : public RayPick {
|
|||
public:
|
||||
StaticRayPick(const glm::vec3& position, const glm::vec3& direction, const uint16_t filter, const float maxDistance = 0.0f, const bool enabled = false);
|
||||
|
||||
const PickRay getPickRay() override { return _pickRay; };
|
||||
const PickRay getPickRay(bool& valid) override;
|
||||
|
||||
private:
|
||||
PickRay _pickRay;
|
||||
|
|
Loading…
Reference in a new issue