History

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

Philip Rosedale committed 13 years ago

Commit ff88d1f1 parent 3b3e6ae3 files · +37 −26Browse files

Showing the changes to interface/src/Util.cpp (1 of 3 files). Show all

Unified · Split

interface/src/Util.cpp+25−25
@@ -65,46 +65,47 @@ float angle_to(glm::vec3 head_pos, glm::vec3 source_pos, float render_yaw, float · 64 unmodified lines
6565 return atan2(head_pos.x - source_pos.x, head_pos.z - source_pos.z) * 180.0f / PIf + render_yaw + head_yaw;
6666 }
6767
68−void render_vector(glm::vec3 * vec)
68+// Draw a 3D vector floating in space
69+void drawVector(glm::vec3 * vector)
6970 {
70− // Show edge of world
7171 glDisable(GL_LIGHTING);
72− glColor4f(1.0, 1.0, 1.0, 1.0);
73− glLineWidth(1.0);
74− glBegin(GL_LINES);
72+ glEnable(GL_POINT_SMOOTH);
73+ glPointSize(3.0);
74+ glLineWidth(2.0);
75+
7576 // Draw axes
77+ glBegin(GL_LINES);
7678 glColor3f(1,0,0);
77− glVertex3f(-1,0,0);
79+ glVertex3f(0,0,0);
7880 glVertex3f(1,0,0);
7981 glColor3f(0,1,0);
80− glVertex3f(0,-1,0);
82+ glVertex3f(0,0,0);
8183 glVertex3f(0, 1, 0);
8284 glColor3f(0,0,1);
83− glVertex3f(0,0,-1);
85+ glVertex3f(0,0,0);
8486 glVertex3f(0, 0, 1);
85− // Draw vector
87+ glEnd();
88+
89+ // Draw the vector itself
90+ glBegin(GL_LINES);
8691 glColor3f(1,1,1);
8792 glVertex3f(0,0,0);
88− glVertex3f(vec->x, vec->y, vec->z);
89− // Draw marker dots for magnitude
93+ glVertex3f(vector->x, vector->y, vector->z);
9094 glEnd();
91− float particleAttenuationQuadratic[] = { 0.0f, 0.0f, 2.0f }; // larger Z = smaller particles
92− float particleAttenuationConstant[] = { 1.0f, 0.0f, 0.0f };
93−
94− glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, particleAttenuationQuadratic );
9595
96− glEnable(GL_POINT_SMOOTH);
97− glPointSize(10.0);
98− glBegin(GL_POINTS);
96+ // Draw spheres for magnitude
97+ glPushMatrix();
9998 glColor3f(1,0,0);
100− glVertex3f(vec->x,0,0);
99+ glTranslatef(vector->x,0,0);
100+ glutSolidSphere(0.02, 10, 10);
101101 glColor3f(0,1,0);
102− glVertex3f(0,vec->y,0);
102+ glTranslatef(-vector->x, vector->y, 0);
103+ glutSolidSphere(0.02, 10, 10);
103104 glColor3f(0,0,1);
104− glVertex3f(0,0,vec->z);
105− glEnd();
105+ glTranslatef(0, -vector->y, vector->z);
106+ glutSolidSphere(0.02, 10, 10);
107+ glPopMatrix();
106108
107− glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, particleAttenuationConstant );
108109 }
109110
110111 void render_world_box()
@@ -184,7 +185,6 @@ void drawtext(int x, int y, float scale, float rotate, float thick, int mono, · 73 unmodified lines
184185
185186 }
186187
187−
188188 void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, glm::vec3 vec,
189189 float r, float g, float b)
190190 {
@@ -209,7 +209,7 @@ void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, gl · 18 unmodified lines
209209 }
210210 glPopMatrix();
211211
212−}
212+}
213213
214214 void drawGroundPlaneGrid(float size)
215215 {