mirror of
https://github.com/overte-org/overte.git
synced 2025-06-27 14:49:47 +02:00
get rid of valid
This commit is contained in:
parent
6d6ede075f
commit
05f4883104
9 changed files with 23 additions and 25 deletions
|
@ -20,7 +20,7 @@ JointRayPick::JointRayPick(const std::string& jointName, const glm::vec3& posOff
|
|||
{
|
||||
}
|
||||
|
||||
const PickRay JointRayPick::getMathematicalPick(bool& valid) const {
|
||||
const PickRay JointRayPick::getMathematicalPick() const {
|
||||
auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
||||
int jointIndex = myAvatar->getJointIndex(QString::fromStdString(_jointName));
|
||||
bool useAvatarHead = _jointName == "Avatar";
|
||||
|
@ -38,10 +38,8 @@ const PickRay JointRayPick::getMathematicalPick(bool& valid) const {
|
|||
pos = pos + (rot * (myAvatar->getSensorToWorldScale() * _posOffset));
|
||||
glm::vec3 dir = rot * glm::normalize(_dirOffset);
|
||||
|
||||
valid = true;
|
||||
return PickRay(pos, dir);
|
||||
}
|
||||
|
||||
valid = false;
|
||||
return PickRay();
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ class JointRayPick : public RayPick {
|
|||
public:
|
||||
JointRayPick(const std::string& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const PickFilter& filter, const float maxDistance = 0.0f, const bool enabled = false);
|
||||
|
||||
const PickRay getMathematicalPick(bool& valid) const override;
|
||||
const PickRay getMathematicalPick() const override;
|
||||
|
||||
private:
|
||||
std::string _jointName;
|
||||
|
|
|
@ -18,14 +18,12 @@ MouseRayPick::MouseRayPick(const PickFilter& filter, const float maxDistance, co
|
|||
{
|
||||
}
|
||||
|
||||
const PickRay MouseRayPick::getMathematicalPick(bool& valid) const {
|
||||
const PickRay MouseRayPick::getMathematicalPick() 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();
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ class MouseRayPick : public RayPick {
|
|||
public:
|
||||
MouseRayPick(const PickFilter& filter, const float maxDistance = 0.0f, const bool enabled = false);
|
||||
|
||||
const PickRay getMathematicalPick(bool& valid) const override;
|
||||
const PickRay getMathematicalPick() const override;
|
||||
};
|
||||
|
||||
#endif // hifi_MouseRayPick_h
|
||||
|
|
|
@ -104,7 +104,7 @@ class Pick : protected ReadWriteLockable {
|
|||
public:
|
||||
Pick(const PickFilter& filter, const float maxDistance, const bool enabled);
|
||||
|
||||
virtual const T getMathematicalPick(bool& valid) const = 0;
|
||||
virtual const T getMathematicalPick() const = 0;
|
||||
virtual RayToEntityIntersectionResult getEntityIntersection(const T& pick, bool precisionPicking,
|
||||
const QVector<EntityItemID>& entitiesToInclude,
|
||||
const QVector<EntityItemID>& entitiesToIgnore,
|
||||
|
|
|
@ -60,7 +60,7 @@ protected:
|
|||
std::shared_ptr<Pick<T>> findPick(const QUuid& uid) const;
|
||||
QHash<QUuid, std::shared_ptr<Pick<T>>> _picks;
|
||||
|
||||
typedef QHash<T, std::unordered_map<PickCacheKey, RayPickResult>> PickCache;
|
||||
typedef std::unordered_map<T, std::unordered_map<PickCacheKey, RayPickResult>> PickCache;
|
||||
|
||||
// Returns true if this ray exists in the cache, and if it does, update res if the cached result is closer
|
||||
bool checkAndCompareCachedResults(T& pick, PickCache& cache, RayPickResult& res, const PickCacheKey& key);
|
||||
|
@ -79,7 +79,7 @@ std::shared_ptr<Pick<T>> PickManager<T>::findPick(const QUuid& uid) const {
|
|||
|
||||
template<typename T>
|
||||
bool PickManager<T>::checkAndCompareCachedResults(T& pick, PickCache& cache, RayPickResult& res, const PickCacheKey& key) {
|
||||
if (cache.contains(pick) && cache[pick].find(key) != cache[pick].end()) {
|
||||
if (cache.find(pick) != cache.end() && cache[pick].find(key) != cache[pick].end()) {
|
||||
if (cache[pick][key].distance < res.distance) {
|
||||
res = cache[pick][key];
|
||||
}
|
||||
|
@ -114,14 +114,10 @@ void PickManager<T>::update() {
|
|||
continue;
|
||||
}
|
||||
|
||||
T mathematicalPick;
|
||||
T mathematicalPick = pick->getMathematicalPick();
|
||||
|
||||
{
|
||||
bool valid;
|
||||
mathematicalPick = pick->getMathematicalPick(valid);
|
||||
if (!valid) {
|
||||
continue;
|
||||
}
|
||||
if (!mathematicalPick) {
|
||||
continue;
|
||||
}
|
||||
|
||||
RayPickResult res = RayPickResult(mathematicalPick);
|
||||
|
|
|
@ -13,7 +13,6 @@ StaticRayPick::StaticRayPick(const glm::vec3& position, const glm::vec3& directi
|
|||
{
|
||||
}
|
||||
|
||||
const PickRay StaticRayPick::getMathematicalPick(bool& valid) const {
|
||||
valid = true;
|
||||
const PickRay StaticRayPick::getMathematicalPick() const {
|
||||
return _pickRay;
|
||||
}
|
|
@ -15,7 +15,7 @@ class StaticRayPick : public RayPick {
|
|||
public:
|
||||
StaticRayPick(const glm::vec3& position, const glm::vec3& direction, const PickFilter& filter, const float maxDistance = 0.0f, const bool enabled = false);
|
||||
|
||||
const PickRay getMathematicalPick(bool& valid) const override;
|
||||
const PickRay getMathematicalPick() const override;
|
||||
|
||||
private:
|
||||
PickRay _pickRay;
|
||||
|
|
|
@ -127,11 +127,15 @@ void aaCubeFromScriptValue(const QScriptValue &object, AACube& aaCube);
|
|||
|
||||
class PickRay {
|
||||
public:
|
||||
PickRay() : origin(0.0f), direction(0.0f) { }
|
||||
PickRay() : origin(NAN), direction(NAN) { }
|
||||
PickRay(const glm::vec3& origin, const glm::vec3 direction) : origin(origin), direction(direction) {}
|
||||
glm::vec3 origin;
|
||||
glm::vec3 direction;
|
||||
|
||||
operator bool() const {
|
||||
auto isNan = glm::isnan(origin) || glm::isnan(direction);
|
||||
return !isNan.x && !isNan.y && !isNan.z;
|
||||
}
|
||||
bool operator==(const PickRay& other) const {
|
||||
return (origin == other.origin && direction == other.direction);
|
||||
}
|
||||
|
@ -143,9 +147,12 @@ namespace std {
|
|||
return ((hash<float>()(a.x) ^ (hash<float>()(a.y) << 1)) >> 1) ^ (hash<float>()(a.z) << 1);
|
||||
}
|
||||
};
|
||||
}
|
||||
inline uint qHash(const PickRay& a) {
|
||||
return (uint)(std::hash<glm::vec3>()(a.origin) ^ (std::hash<glm::vec3>()(a.direction) << 1));
|
||||
template <>
|
||||
struct hash<PickRay> {
|
||||
size_t operator()(const PickRay& a) const {
|
||||
return (hash<glm::vec3>()(a.origin) ^ (hash<glm::vec3>()(a.direction) << 1));
|
||||
}
|
||||
};
|
||||
}
|
||||
Q_DECLARE_METATYPE(PickRay)
|
||||
QScriptValue pickRayToScriptValue(QScriptEngine* engine, const PickRay& pickRay);
|
||||
|
|
Loading…
Reference in a new issue