mirror of
https://github.com/overte-org/overte.git
synced 2025-04-25 20:36:38 +02:00
47 lines
1.5 KiB
C++
47 lines
1.5 KiB
C++
//
|
|
// Billboardable.cpp
|
|
// interface/src/ui/overlays
|
|
//
|
|
// Created by Zander Otavka on 8/7/15.
|
|
// Modified by Daniela Fontes on 24/10/17.
|
|
// Copyright 2014 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 "Billboardable.h"
|
|
|
|
#include <Application.h>
|
|
#include <Transform.h>
|
|
#include "avatar/AvatarManager.h"
|
|
|
|
void Billboardable::setProperties(const QVariantMap& properties) {
|
|
auto isFacingAvatar = properties["isFacingAvatar"];
|
|
if (isFacingAvatar.isValid()) {
|
|
setIsFacingAvatar(isFacingAvatar.toBool());
|
|
}
|
|
}
|
|
|
|
QVariant Billboardable::getProperty(const QString &property) {
|
|
if (property == "isFacingAvatar") {
|
|
return isFacingAvatar();
|
|
}
|
|
return QVariant();
|
|
}
|
|
|
|
bool Billboardable::pointTransformAtCamera(Transform& transform, glm::quat offsetRotation) {
|
|
if (isFacingAvatar()) {
|
|
glm::vec3 billboardPos = transform.getTranslation();
|
|
glm::vec3 cameraPos = qApp->getCamera().getPosition();
|
|
// use the referencial from the avatar, y isn't always up
|
|
glm::vec3 avatarUP = DependencyManager::get<AvatarManager>()->getMyAvatar()->getOrientation()*Vectors::UP;
|
|
|
|
glm::quat rotation(conjugate(toQuat(glm::lookAt(billboardPos, cameraPos, avatarUP))));
|
|
|
|
transform.setRotation(rotation);
|
|
transform.postRotate(offsetRotation);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|