mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 04:43:31 +02:00
Render other avatar's lookat to point at my camera if the other avatar
is looking at my head.
This commit is contained in:
parent
ea0fa8e5c7
commit
1790b0595c
4 changed files with 26 additions and 1 deletions
|
@ -2244,7 +2244,7 @@ Avatar* Application::isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3
|
||||||
if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) {
|
if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) {
|
||||||
Avatar* avatar = (Avatar *) node->getLinkedData();
|
Avatar* avatar = (Avatar *) node->getLinkedData();
|
||||||
glm::vec3 headPosition = avatar->getHead().getPosition();
|
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();
|
eyePosition = avatar->getHead().getEyePosition();
|
||||||
_lookatIndicatorScale = avatar->getScale();
|
_lookatIndicatorScale = avatar->getScale();
|
||||||
_lookatOtherPosition = headPosition;
|
_lookatOtherPosition = headPosition;
|
||||||
|
@ -2256,6 +2256,16 @@ Avatar* Application::isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3
|
||||||
return NULL;
|
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) {
|
void Application::renderLookatIndicator(glm::vec3 pointOfInterest, Camera& whichCamera) {
|
||||||
|
|
||||||
const float DISTANCE_FROM_HEAD_SPHERE = 0.1f * _lookatIndicatorScale;
|
const float DISTANCE_FROM_HEAD_SPHERE = 0.1f * _lookatIndicatorScale;
|
||||||
|
@ -2988,6 +2998,9 @@ void Application::displaySide(Camera& whichCamera) {
|
||||||
if (!avatar->isInitialized()) {
|
if (!avatar->isInitialized()) {
|
||||||
avatar->init();
|
avatar->init();
|
||||||
}
|
}
|
||||||
|
if (isLookingAtMyAvatar(avatar)) {
|
||||||
|
avatar->getHead().setLookAtPosition(_myCamera.getPosition());
|
||||||
|
}
|
||||||
avatar->render(false, _renderAvatarBalls->isChecked());
|
avatar->render(false, _renderAvatarBalls->isChecked());
|
||||||
avatar->setDisplayingLookatVectors(_renderLookatOn->isChecked());
|
avatar->setDisplayingLookatVectors(_renderLookatOn->isChecked());
|
||||||
}
|
}
|
||||||
|
|
|
@ -212,6 +212,7 @@ private:
|
||||||
void update(float deltaTime);
|
void update(float deltaTime);
|
||||||
Avatar* isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection,
|
Avatar* isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection,
|
||||||
glm::vec3& eyePosition, uint16_t& nodeID);
|
glm::vec3& eyePosition, uint16_t& nodeID);
|
||||||
|
bool isLookingAtMyAvatar(Avatar* avatar);
|
||||||
|
|
||||||
void renderLookatIndicator(glm::vec3 pointOfInterest, Camera& whichCamera);
|
void renderLookatIndicator(glm::vec3 pointOfInterest, Camera& whichCamera);
|
||||||
void updateAvatar(float deltaTime);
|
void updateAvatar(float deltaTime);
|
||||||
|
|
|
@ -607,3 +607,12 @@ bool rayIntersectsSphere(glm::vec3& rayStarting, glm::vec3& rayNormalizedDirecti
|
||||||
}
|
}
|
||||||
return false;
|
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 rayIntersectsSphere(glm::vec3& rayStarting, glm::vec3& rayNormalizedDirection, glm::vec3& sphereCenter, double sphereRadius);
|
||||||
|
|
||||||
|
bool pointInSphere(glm::vec3& point, glm::vec3& sphereCenter, double sphereRadius);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue