From ff88d1fc069820c8a4aa61d98ea80f4b89eb2a74 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Mon, 6 May 2013 16:18:27 -0700 Subject: [PATCH] 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