mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 08:04:01 +02:00
Merge pull request #783 from LionTurtle/master
Render other avatar's lookat to point at my camera if the other avatar is looking at my head.
This commit is contained in:
commit
7ccab1a32c
4 changed files with 26 additions and 1 deletions
|
@ -2252,7 +2252,7 @@ Avatar* Application::isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3
|
|||
if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) {
|
||||
Avatar* avatar = (Avatar *) node->getLinkedData();
|
||||
glm::vec3 headPosition = avatar->getHead().getPosition();
|
||||
if (rayIntersectsSphere(mouseRayOrigin, mouseRayDirection, headPosition, HEAD_SPHERE_RADIUS)) {
|
||||
if (rayIntersectsSphere(mouseRayOrigin, mouseRayDirection, headPosition, HEAD_SPHERE_RADIUS * avatar->getScale())) {
|
||||
eyePosition = avatar->getHead().getEyePosition();
|
||||
_lookatIndicatorScale = avatar->getScale();
|
||||
_lookatOtherPosition = headPosition;
|
||||
|
@ -2264,6 +2264,16 @@ Avatar* Application::isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3
|
|||
return NULL;
|
||||
}
|
||||
|
||||
bool Application::isLookingAtMyAvatar(Avatar* avatar) {
|
||||
glm::vec3 theirLookat = avatar->getHead().getLookAtPosition();
|
||||
glm::vec3 myHeadPosition = _myAvatar.getHead().getPosition();
|
||||
|
||||
if (pointInSphere(theirLookat, myHeadPosition, HEAD_SPHERE_RADIUS * _myAvatar.getScale())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Application::renderLookatIndicator(glm::vec3 pointOfInterest, Camera& whichCamera) {
|
||||
|
||||
const float DISTANCE_FROM_HEAD_SPHERE = 0.1f * _lookatIndicatorScale;
|
||||
|
@ -3013,6 +3023,9 @@ void Application::displaySide(Camera& whichCamera) {
|
|||
if (!avatar->isInitialized()) {
|
||||
avatar->init();
|
||||
}
|
||||
if (isLookingAtMyAvatar(avatar)) {
|
||||
avatar->getHead().setLookAtPosition(_myCamera.getPosition());
|
||||
}
|
||||
avatar->render(false, _renderAvatarBalls->isChecked());
|
||||
avatar->setDisplayingLookatVectors(_renderLookatOn->isChecked());
|
||||
}
|
||||
|
|
|
@ -212,6 +212,7 @@ private:
|
|||
void update(float deltaTime);
|
||||
Avatar* isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection,
|
||||
glm::vec3& eyePosition, uint16_t& nodeID);
|
||||
bool isLookingAtMyAvatar(Avatar* avatar);
|
||||
|
||||
void renderLookatIndicator(glm::vec3 pointOfInterest, Camera& whichCamera);
|
||||
void updateAvatar(float deltaTime);
|
||||
|
|
|
@ -607,3 +607,12 @@ bool rayIntersectsSphere(glm::vec3& rayStarting, glm::vec3& rayNormalizedDirecti
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool pointInSphere(glm::vec3& point, glm::vec3& sphereCenter, double sphereRadius) {
|
||||
glm::vec3 diff = point - sphereCenter;
|
||||
double mag = sqrt(glm::dot(diff, diff));
|
||||
if (mag <= sphereRadius) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
|
@ -76,4 +76,6 @@ float loadSetting(QSettings* settings, const char* name, float defaultValue);
|
|||
|
||||
bool rayIntersectsSphere(glm::vec3& rayStarting, glm::vec3& rayNormalizedDirection, glm::vec3& sphereCenter, double sphereRadius);
|
||||
|
||||
bool pointInSphere(glm::vec3& point, glm::vec3& sphereCenter, double sphereRadius);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue