mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 18:44:00 +02:00
mouse ray pick
This commit is contained in:
parent
c6b3f69db0
commit
912b417dd4
7 changed files with 99 additions and 10 deletions
|
@ -12,6 +12,7 @@
|
|||
|
||||
#include "JointRayPick.h"
|
||||
#include "StaticRayPick.h"
|
||||
#include "MouseRayPick.h"
|
||||
|
||||
#include "Application.h"
|
||||
#include "avatar/AvatarManager.h"
|
||||
|
@ -48,6 +49,21 @@ LaserPointer::LaserPointer(const glm::vec3& position, const glm::vec3& direction
|
|||
}
|
||||
}
|
||||
|
||||
LaserPointer::LaserPointer(const uint16_t filter, const float maxDistance, const QHash<QString, RenderState>& renderStates, const bool faceAvatar, const bool centerEndY, const bool enabled) :
|
||||
_renderingEnabled(enabled),
|
||||
_renderStates(renderStates),
|
||||
_faceAvatar(faceAvatar),
|
||||
_centerEndY(centerEndY)
|
||||
{
|
||||
_rayPickUID = DependencyManager::get<RayPickManager>()->addRayPick(std::make_shared<MouseRayPick>(filter, maxDistance, enabled));
|
||||
|
||||
for (auto& state : _renderStates.keys()) {
|
||||
if (!enabled || state != _currentRenderState) {
|
||||
disableRenderState(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LaserPointer::~LaserPointer() {
|
||||
DependencyManager::get<RayPickManager>()->removeRayPick(_rayPickUID);
|
||||
for (RenderState& renderState : _renderStates) {
|
||||
|
|
|
@ -50,6 +50,8 @@ public:
|
|||
const QHash<QString, RenderState>& renderStates, const bool faceAvatar, const bool centerEndY, const bool enabled);
|
||||
LaserPointer(const glm::vec3& position, const glm::vec3& direction, const uint16_t filter, const float maxDistance,
|
||||
const QHash<QString, RenderState>& renderStates, const bool faceAvatar, const bool centerEndY, const bool enabled);
|
||||
LaserPointer(const uint16_t filter, const float maxDistance, const QHash<QString, RenderState>& renderStates, const bool faceAvatar,
|
||||
const bool centerEndY, const bool enabled);
|
||||
~LaserPointer();
|
||||
|
||||
unsigned int getUID() { return _rayPickUID; }
|
||||
|
|
|
@ -28,6 +28,13 @@ unsigned int LaserPointerManager::createLaserPointer(const glm::vec3& position,
|
|||
return uid;
|
||||
}
|
||||
|
||||
unsigned int LaserPointerManager::createLaserPointer(const uint16_t filter, const float maxDistance, const QHash<QString, RenderState>& renderStates, const bool faceAvatar, const bool centerEndY, const bool enabled) {
|
||||
std::shared_ptr<LaserPointer> laserPointer = std::make_shared<LaserPointer>(filter, maxDistance, renderStates, faceAvatar, centerEndY, enabled);
|
||||
unsigned int uid = laserPointer->getUID();
|
||||
_laserPointers[uid] = laserPointer;
|
||||
return uid;
|
||||
}
|
||||
|
||||
void LaserPointerManager::enableLaserPointer(const unsigned int uid) {
|
||||
if (_laserPointers.contains(uid)) {
|
||||
_laserPointers[uid]->enable();
|
||||
|
|
|
@ -29,6 +29,8 @@ public:
|
|||
const QHash<QString, RenderState>& renderStates, const bool faceAvatar, const bool centerEndY, const bool enabled);
|
||||
unsigned int createLaserPointer(const glm::vec3& position, const glm::vec3& direction, const uint16_t filter, const float maxDistance,
|
||||
const QHash<QString, RenderState>& renderStates, const bool faceAvatar, const bool centerEndY, const bool enabled);
|
||||
unsigned int createLaserPointer(const uint16_t filter, const float maxDistance, const QHash<QString, RenderState>& renderStates, const bool faceAvatar,
|
||||
const bool centerEndY, const bool enabled);
|
||||
void removeLaserPointer(const unsigned int uid) { _laserPointers.remove(uid); }
|
||||
void enableLaserPointer(const unsigned int uid);
|
||||
void disableLaserPointer(const unsigned int uid);
|
||||
|
|
|
@ -88,18 +88,22 @@ 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"]);
|
||||
}
|
||||
if (jointName != "Mouse") {
|
||||
// x = upward, y = forward, z = lateral
|
||||
glm::vec3 posOffset = Vectors::ZERO;
|
||||
if (propertyMap["posOffset"].isValid()) {
|
||||
posOffset = vec3FromVariant(propertyMap["posOffset"]);
|
||||
}
|
||||
|
||||
glm::vec3 dirOffset = Vectors::UP;
|
||||
if (propertyMap["dirOffset"].isValid()) {
|
||||
dirOffset = vec3FromVariant(propertyMap["dirOffset"]);
|
||||
}
|
||||
glm::vec3 dirOffset = Vectors::UP;
|
||||
if (propertyMap["dirOffset"].isValid()) {
|
||||
dirOffset = vec3FromVariant(propertyMap["dirOffset"]);
|
||||
}
|
||||
|
||||
return DependencyManager::get<LaserPointerManager>()->createLaserPointer(jointName, posOffset, dirOffset, filter, maxDistance, renderStates, faceAvatar, centerEndY, enabled);
|
||||
return DependencyManager::get<LaserPointerManager>()->createLaserPointer(jointName, posOffset, dirOffset, filter, maxDistance, renderStates, faceAvatar, centerEndY, enabled);
|
||||
} else {
|
||||
return DependencyManager::get<LaserPointerManager>()->createLaserPointer(filter, maxDistance, renderStates, faceAvatar, centerEndY, enabled);
|
||||
}
|
||||
} else if (propertyMap["position"].isValid()) {
|
||||
glm::vec3 position = vec3FromVariant(propertyMap["position"]);
|
||||
|
||||
|
|
32
interface/src/raypick/MouseRayPick.cpp
Normal file
32
interface/src/raypick/MouseRayPick.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
//
|
||||
// MouseRayPick.cpp
|
||||
// interface/src/raypick
|
||||
//
|
||||
// Created by Sam Gondelman 7/19/2017
|
||||
// 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
|
||||
//
|
||||
#include "MouseRayPick.h"
|
||||
|
||||
#include "DependencyManager.h"
|
||||
#include "Application.h"
|
||||
#include "display-plugins/CompositorHelper.h"
|
||||
|
||||
MouseRayPick::MouseRayPick(const uint16_t filter, const float maxDistance, const bool enabled) :
|
||||
RayPick(filter, maxDistance, enabled)
|
||||
{
|
||||
}
|
||||
|
||||
const PickRay MouseRayPick::getPickRay(bool& valid) const {
|
||||
QVariant position = qApp->getApplicationCompositor().getReticleInterface()->getPosition();
|
||||
if (position.isValid()) {
|
||||
QVariantMap posMap = position.toMap();
|
||||
valid = true;
|
||||
return qApp->getCamera().computePickRay(posMap["x"].toFloat(), posMap["y"].toFloat());
|
||||
}
|
||||
|
||||
valid = false;
|
||||
return PickRay();
|
||||
}
|
26
interface/src/raypick/MouseRayPick.h
Normal file
26
interface/src/raypick/MouseRayPick.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
//
|
||||
// MouseRayPick.h
|
||||
// interface/src/raypick
|
||||
//
|
||||
// Created by Sam Gondelman 7/19/2017
|
||||
// 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
|
||||
//
|
||||
#ifndef hifi_MouseRayPick_h
|
||||
#define hifi_MouseRayPick_h
|
||||
|
||||
#include "RayPick.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
class MouseRayPick : public RayPick {
|
||||
|
||||
public:
|
||||
MouseRayPick(const uint16_t filter, const float maxDistance = 0.0f, const bool enabled = false);
|
||||
|
||||
const PickRay getPickRay(bool& valid) const override;
|
||||
};
|
||||
|
||||
#endif // hifi_MouseRayPick_h
|
Loading…
Reference in a new issue