Added Utility function angleBetween() which returns the positive angle between any two 3D vectors.

This commit is contained in:
Philip Rosedale 2013-05-06 18:45:06 -07:00
parent 631ee8f478
commit 00c8673ceb
3 changed files with 15 additions and 0 deletions

View file

@ -469,6 +469,14 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) {
glm::vec3 v(_joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position);
v -= otherAvatar->getJointPosition(AVATAR_JOINT_RIGHT_SHOULDER);
/*
// Test: Show angle between your fwd vector and nearest avatar
glm::vec3 vectorBetweenUs = otherAvatar->getJointPosition(AVATAR_JOINT_PELVIS) -
getJointPosition(AVATAR_JOINT_PELVIS);
glm::vec3 myForwardVector = _orientation.getFront();
printLog("Angle between: %f\n", angleBetween(&vectorBetweenUs, &myForwardVector));
*/
float distance = glm::length(v);
if (distance < _distanceToNearestAvatar) {_distanceToNearestAvatar = distance;}

View file

@ -65,6 +65,11 @@ float angle_to(glm::vec3 head_pos, glm::vec3 source_pos, float render_yaw, float
return atan2(head_pos.x - source_pos.x, head_pos.z - source_pos.z) * 180.0f / PIf + render_yaw + head_yaw;
}
// Helper function computes the angle between two 3D vectors
float angleBetween(glm::vec3 * v1, glm::vec3 * v2) {
return acos((glm::dot(*v1,*v2))/(glm::length(*v1) * glm::length(*v2))) * 180.f/PI;
}
// Draw a 3D vector floating in space
void drawVector(glm::vec3 * vector)
{

View file

@ -42,6 +42,8 @@ void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, gl
void drawVector(glm::vec3* vector);
float angleBetween(glm::vec3 * v1, glm::vec3 * v2);
double diffclock(timeval *clock1,timeval *clock2);
void drawGroundPlaneGrid(float size);