From ff88d1fc069820c8a4aa61d98ea80f4b89eb2a74 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Mon, 6 May 2013 16:18:27 -0700 Subject: [PATCH 1/5] Created a drawVector() call that will draw a vector in 3-space with axes for testing --- interface/src/Util.cpp | 50 +++++++++++++++++++++--------------------- interface/src/Util.h | 4 +++- interface/src/main.cpp | 9 ++++++++ 3 files changed, 37 insertions(+), 26 deletions(-) diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 94e0e826d1..355dec185c 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -65,46 +65,47 @@ 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; } -void render_vector(glm::vec3 * vec) +// Draw a 3D vector floating in space +void drawVector(glm::vec3 * vector) { - // Show edge of world glDisable(GL_LIGHTING); - glColor4f(1.0, 1.0, 1.0, 1.0); - glLineWidth(1.0); - glBegin(GL_LINES); + glEnable(GL_POINT_SMOOTH); + glPointSize(3.0); + glLineWidth(2.0); + // Draw axes + glBegin(GL_LINES); glColor3f(1,0,0); - glVertex3f(-1,0,0); + glVertex3f(0,0,0); glVertex3f(1,0,0); glColor3f(0,1,0); - glVertex3f(0,-1,0); + glVertex3f(0,0,0); glVertex3f(0, 1, 0); glColor3f(0,0,1); - glVertex3f(0,0,-1); + glVertex3f(0,0,0); glVertex3f(0, 0, 1); - // Draw vector + glEnd(); + + // Draw the vector itself + glBegin(GL_LINES); glColor3f(1,1,1); glVertex3f(0,0,0); - glVertex3f(vec->x, vec->y, vec->z); - // Draw marker dots for magnitude + glVertex3f(vector->x, vector->y, vector->z); glEnd(); - float particleAttenuationQuadratic[] = { 0.0f, 0.0f, 2.0f }; // larger Z = smaller particles - float particleAttenuationConstant[] = { 1.0f, 0.0f, 0.0f }; - - glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, particleAttenuationQuadratic ); - glEnable(GL_POINT_SMOOTH); - glPointSize(10.0); - glBegin(GL_POINTS); + // Draw spheres for magnitude + glPushMatrix(); glColor3f(1,0,0); - glVertex3f(vec->x,0,0); + glTranslatef(vector->x,0,0); + glutSolidSphere(0.02, 10, 10); glColor3f(0,1,0); - glVertex3f(0,vec->y,0); + glTranslatef(-vector->x, vector->y, 0); + glutSolidSphere(0.02, 10, 10); glColor3f(0,0,1); - glVertex3f(0,0,vec->z); - glEnd(); + glTranslatef(0, -vector->y, vector->z); + glutSolidSphere(0.02, 10, 10); + glPopMatrix(); - glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, particleAttenuationConstant ); } void render_world_box() @@ -184,7 +185,6 @@ void drawtext(int x, int y, float scale, float rotate, float thick, int mono, } - void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, glm::vec3 vec, float r, float g, float b) { @@ -209,7 +209,7 @@ void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, gl } glPopMatrix(); -} +} void drawGroundPlaneGrid(float size) { diff --git a/interface/src/Util.h b/interface/src/Util.h index ed253f4393..7ea65bef4c 100644 --- a/interface/src/Util.h +++ b/interface/src/Util.h @@ -33,13 +33,15 @@ float angle_to(glm::vec3 head_pos, glm::vec3 source_pos, float render_yaw, float float randFloat(); void render_world_box(); -void render_vector(glm::vec3 * vec); int widthText(float scale, int mono, char const* string); float widthChar(float scale, int mono, char ch); void drawtext(int x, int y, float scale, float rotate, float thick, int mono, char const* string, float r=1.0, float g=1.0, float b=1.0); void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, glm::vec3 vec, float r=1.0, float g=1.0, float b=1.0); + +void drawVector(glm::vec3* vector); + double diffclock(timeval *clock1,timeval *clock2); void drawGroundPlaneGrid(float size); diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 8916fcd319..44b450ce46 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -1081,6 +1081,15 @@ void display(void) // important... myCamera.update( 1.f/FPS ); + + // Render anything (like HUD items) that we want to be in 3D but not in worldspace + const float HUD_Z_OFFSET = -5.f; + glPushMatrix(); + glm::vec3 test(0.5, 0.5, 0.5); + glTranslatef(1, 1, HUD_Z_OFFSET); + drawVector(&test); + glPopMatrix(); + // Note: whichCamera is used to pick between the normal camera myCamera for our // main camera, vs, an alternate camera. The alternate camera we support right now From 69cac10cee2376a64ba2d4ac9261f15ebf690a5f Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Mon, 6 May 2013 18:21:33 -0700 Subject: [PATCH 2/5] null change --- libraries/voxels/src/AABox.cpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 libraries/voxels/src/AABox.cpp diff --git a/libraries/voxels/src/AABox.cpp b/libraries/voxels/src/AABox.cpp old mode 100755 new mode 100644 From 00c8673cebeb654d210c3291a2c43a10b81c4eec Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Mon, 6 May 2013 18:45:06 -0700 Subject: [PATCH 3/5] Added Utility function angleBetween() which returns the positive angle between any two 3D vectors. --- interface/src/Avatar.cpp | 8 ++++++++ interface/src/Util.cpp | 5 +++++ interface/src/Util.h | 2 ++ 3 files changed, 15 insertions(+) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index a1a93fbfe3..70e3907b4a 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -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;} diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 355dec185c..430d200af1 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -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) { diff --git a/interface/src/Util.h b/interface/src/Util.h index 7ea65bef4c..add347fb3b 100644 --- a/interface/src/Util.h +++ b/interface/src/Util.h @@ -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); From 31593dccd419d09a4c0649c3266d8130b93ae024 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Mon, 6 May 2013 18:46:19 -0700 Subject: [PATCH 4/5] improved comment of function --- interface/src/Util.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 430d200af1..9159fb77cc 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -65,7 +65,7 @@ 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 +// Helper function returns the positive angle in degrees 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; } From 27540f1286139aa9723b90493b7bbf3403cabd17 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Tue, 7 May 2013 09:59:37 -0700 Subject: [PATCH 5/5] Fixes per code review --- interface/src/Util.cpp | 45 ++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 282acd1f03..e70aabcd2a 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -67,12 +67,11 @@ float angle_to(glm::vec3 head_pos, glm::vec3 source_pos, float render_yaw, float // Helper function returns the positive angle in degrees 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; + 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) -{ +void drawVector(glm::vec3 * vector) { glDisable(GL_LIGHTING); glEnable(GL_POINT_SMOOTH); glPointSize(3.0); @@ -101,7 +100,7 @@ void drawVector(glm::vec3 * vector) // Draw spheres for magnitude glPushMatrix(); glColor3f(1,0,0); - glTranslatef(vector->x,0,0); + glTranslatef(vector->x, 0, 0); glutSolidSphere(0.02, 10, 10); glColor3f(0,1,0); glTranslatef(-vector->x, vector->y, 0); @@ -113,39 +112,38 @@ void drawVector(glm::vec3 * vector) } -void render_world_box() -{ +void render_world_box() { // Show edge of world glDisable(GL_LIGHTING); glColor4f(1.0, 1.0, 1.0, 1.0); glLineWidth(1.0); glBegin(GL_LINES); - glColor3f(1,0,0); - glVertex3f(0,0,0); - glVertex3f(WORLD_SIZE,0,0); - glColor3f(0,1,0); - glVertex3f(0,0,0); + glColor3f(1, 0, 0); + glVertex3f(0, 0, 0); + glVertex3f(WORLD_SIZE, 0, 0); + glColor3f(0, 1, 0); + glVertex3f(0, 0, 0); glVertex3f(0, WORLD_SIZE, 0); - glColor3f(0,0,1); - glVertex3f(0,0,0); + glColor3f(0, 0, 1); + glVertex3f(0, 0, 0); glVertex3f(0, 0, WORLD_SIZE); glEnd(); // Draw little marker dots along the axis glEnable(GL_LIGHTING); glPushMatrix(); - glTranslatef(WORLD_SIZE,0,0); - glColor3f(1,0,0); - glutSolidSphere(0.125,10,10); + glTranslatef(WORLD_SIZE, 0, 0); + glColor3f(1, 0, 0); + glutSolidSphere(0.125, 10, 10); glPopMatrix(); glPushMatrix(); - glTranslatef(0,WORLD_SIZE,0); - glColor3f(0,1,0); - glutSolidSphere(0.125,10,10); + glTranslatef(0, WORLD_SIZE, 0); + glColor3f(0, 1, 0); + glutSolidSphere(0.125, 10, 10); glPopMatrix(); glPushMatrix(); - glTranslatef(0,0,WORLD_SIZE); - glColor3f(0,0,1); - glutSolidSphere(0.125,10,10); + glTranslatef(0, 0, WORLD_SIZE); + glColor3f(0, 0, 1); + glutSolidSphere(0.125, 10, 10); glPopMatrix(); } @@ -172,8 +170,7 @@ float widthChar(float scale, int mono, char ch) { } void drawtext(int x, int y, float scale, float rotate, float thick, int mono, - char const* string, float r, float g, float b) -{ + char const* string, float r, float g, float b) { // // Draws text on screen as stroked so it can be resized //