Created a drawVector() call that will draw a vector in 3-space with axes for testing

This commit is contained in:
Philip Rosedale 2013-05-06 16:18:27 -07:00
parent 3b3e6ae075
commit ff88d1fc06
3 changed files with 37 additions and 26 deletions

View file

@ -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; 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); glDisable(GL_LIGHTING);
glColor4f(1.0, 1.0, 1.0, 1.0); glEnable(GL_POINT_SMOOTH);
glLineWidth(1.0); glPointSize(3.0);
glBegin(GL_LINES); glLineWidth(2.0);
// Draw axes // Draw axes
glBegin(GL_LINES);
glColor3f(1,0,0); glColor3f(1,0,0);
glVertex3f(-1,0,0); glVertex3f(0,0,0);
glVertex3f(1,0,0); glVertex3f(1,0,0);
glColor3f(0,1,0); glColor3f(0,1,0);
glVertex3f(0,-1,0); glVertex3f(0,0,0);
glVertex3f(0, 1, 0); glVertex3f(0, 1, 0);
glColor3f(0,0,1); glColor3f(0,0,1);
glVertex3f(0,0,-1); glVertex3f(0,0,0);
glVertex3f(0, 0, 1); glVertex3f(0, 0, 1);
// Draw vector glEnd();
// Draw the vector itself
glBegin(GL_LINES);
glColor3f(1,1,1); glColor3f(1,1,1);
glVertex3f(0,0,0); glVertex3f(0,0,0);
glVertex3f(vec->x, vec->y, vec->z); glVertex3f(vector->x, vector->y, vector->z);
// Draw marker dots for magnitude
glEnd(); 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); // Draw spheres for magnitude
glPointSize(10.0); glPushMatrix();
glBegin(GL_POINTS);
glColor3f(1,0,0); glColor3f(1,0,0);
glVertex3f(vec->x,0,0); glTranslatef(vector->x,0,0);
glutSolidSphere(0.02, 10, 10);
glColor3f(0,1,0); glColor3f(0,1,0);
glVertex3f(0,vec->y,0); glTranslatef(-vector->x, vector->y, 0);
glutSolidSphere(0.02, 10, 10);
glColor3f(0,0,1); glColor3f(0,0,1);
glVertex3f(0,0,vec->z); glTranslatef(0, -vector->y, vector->z);
glEnd(); glutSolidSphere(0.02, 10, 10);
glPopMatrix();
glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, particleAttenuationConstant );
} }
void render_world_box() 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, void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, glm::vec3 vec,
float r, float g, float b) 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(); glPopMatrix();
} }
void drawGroundPlaneGrid(float size) void drawGroundPlaneGrid(float size)
{ {

View file

@ -33,13 +33,15 @@ float angle_to(glm::vec3 head_pos, glm::vec3 source_pos, float render_yaw, float
float randFloat(); float randFloat();
void render_world_box(); void render_world_box();
void render_vector(glm::vec3 * vec);
int widthText(float scale, int mono, char const* string); int widthText(float scale, int mono, char const* string);
float widthChar(float scale, int mono, char ch); float widthChar(float scale, int mono, char ch);
void drawtext(int x, int y, float scale, float rotate, float thick, int mono, 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); 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, 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); float r=1.0, float g=1.0, float b=1.0);
void drawVector(glm::vec3* vector);
double diffclock(timeval *clock1,timeval *clock2); double diffclock(timeval *clock1,timeval *clock2);
void drawGroundPlaneGrid(float size); void drawGroundPlaneGrid(float size);

View file

@ -1081,6 +1081,15 @@ void display(void)
// important... // important...
myCamera.update( 1.f/FPS ); 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 // 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 // main camera, vs, an alternate camera. The alternate camera we support right now