History

use radians instead of degrees (almost) everywhere

Andrew Meadows committed 12 years ago

Commit aa8c2fc1 parent de8165c51 files · +302 −306Browse files

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

Unified · Split

interface/src/Util.cpp+25−23
@@ -68,19 +68,21 @@ void printVector(glm::vec3 vec) { · 67 unmodified lines
6868 printf("%4.2f, %4.2f, %4.2f\n", vec.x, vec.y, vec.z);
6969 }
7070
71−// Return the azimuth angle in degrees between two points.
71+// Return the azimuth angle (in radians) between two points.
7272 float azimuth_to(glm::vec3 head_pos, glm::vec3 source_pos) {
73− return atan2(head_pos.x - source_pos.x, head_pos.z - source_pos.z) * 180.0f / PIf;
73+ return atan2(head_pos.x - source_pos.x, head_pos.z - source_pos.z);
7474 }
7575
76−// Return the angle in degrees between the head and an object in the scene. The value is zero if you are looking right at it. The angle is negative if the object is to your right.
76+// Return the angle (in radians) between the head and an object in the scene.
77+// The value is zero if you are looking right at it.
78+// The angle is negative if the object is to your right.
7779 float angle_to(glm::vec3 head_pos, glm::vec3 source_pos, float render_yaw, float head_yaw) {
78− return atan2(head_pos.x - source_pos.x, head_pos.z - source_pos.z) * 180.0f / PIf + render_yaw + head_yaw;
80+ return atan2(head_pos.x - source_pos.x, head_pos.z - source_pos.z) + render_yaw + head_yaw;
7981 }
8082
81−// Helper function returns the positive angle in degrees between two 3D vectors
83+// Helper function returns the positive angle (in radians) between two 3D vectors
8284 float angleBetween(const glm::vec3& v1, const glm::vec3& v2) {
83− return acos((glm::dot(v1, v2)) / (glm::length(v1) * glm::length(v2))) * 180.f / PIf;
85+ return acosf((glm::dot(v1, v2)) / (glm::length(v1) * glm::length(v2)));
8486 }
8587
8688 // Helper function return the rotation from the first vector onto the second
@@ -90,7 +92,7 @@ glm::quat rotationBetween(const glm::vec3& v1, const glm::vec3& v2) { · 3 unmodified lines
9092 return glm::quat();
9193 }
9294 glm::vec3 axis;
93− if (angle > 179.99f) { // 180 degree rotation; must use another axis
95+ if (angle > 179.99f * RADIANS_PER_DEGREE) { // 180 degree rotation; must use another axis
9496 axis = glm::cross(v1, glm::vec3(1.0f, 0.0f, 0.0f));
9597 float axisLength = glm::length(axis);
9698 if (axisLength < EPSILON) { // parallel to x; y will work
@@ -314,7 +316,7 @@ float widthChar(float scale, int mono, char ch) { · 217 unmodified lines
314316 return textRenderer(mono)->computeWidth(ch) * (scale / 0.10);
315317 }
316318
317−void drawText(int x, int y, float scale, float rotate, int mono,
319+void drawText(int x, int y, float scale, float radians, int mono,
318320 char const* string, const float* color) {
319321 //
320322 // Draws text on screen as stroked so it can be resized
@@ -322,16 +324,16 @@ void drawText(int x, int y, float scale, float rotate, int mono, · 1 unmodified line
322324 glPushMatrix();
323325 glTranslatef(static_cast<float>(x), static_cast<float>(y), 0.0f);
324326 glColor3fv(color);
325− glRotated(rotate,0,0,1);
326− glScalef(scale / 0.10, scale / 0.10, 1.0);
327+ glRotated(double(radians * DEGREES_PER_RADIAN), 0.0, 0.0, 1.0);
328+ glScalef(scale / 0.1f, scale / 0.1f, 1.f);
327329 textRenderer(mono)->draw(0, 0, string);
328330 glPopMatrix();
329331 }
330332
331333
332−void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, glm::vec3 vec, float r, float g, float b) {
334+void drawvec3(int x, int y, float scale, float radians, float thick, int mono, glm::vec3 vec, float r, float g, float b) {
333335 //
334− // Draws text on screen as stroked so it can be resized
336+ // Draws vec3 on screen as stroked so it can be resized
335337 //
336338 char vectext[20];
337339 sprintf(vectext,"%3.1f,%3.1f,%3.1f", vec.x, vec.y, vec.z);
@@ -339,10 +341,10 @@ void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, gl · 1 unmodified line
339341 glPushMatrix();
340342 glTranslatef(static_cast<float>(x), static_cast<float>(y), 0);
341343 glColor3f(r,g,b);
342− glRotated(180+rotate,0,0,1);
343− glRotated(180,0,1,0);
344+ glRotated(180.0 + double(radians * DEGREES_PER_RADIAN), 0.0, 0.0, 1.0);
345+ glRotated(180.0, 0.0, 1.0, 0.0);
344346 glLineWidth(thick);
345− glScalef(scale, scale, 1.0);
347+ glScalef(scale, scale, 1.f);
346348 len = (int) strlen(vectext);
347349 for (i = 0; i < len; i++) {
348350 if (!mono) glutStrokeCharacter(GLUT_STROKE_ROMAN, int(vectext[i]));
@@ -371,9 +373,9 @@ void renderSphereOutline(glm::vec3 position, float radius, int numSides, glm::ve · 22 unmodified lines
371373
372374 glBegin(GL_LINE_STRIP);
373375 for (int i=0; i<numSides+1; i++) {
374− float r = ((float)i / (float)numSides) * PIf * 2.0;
375− float s = radius * sin(r);
376− float c = radius * cos(r);
376+ float r = ((float)i / (float)numSides) * TWO_PI;
377+ float s = radius * sinf(r);
378+ float c = radius * cosf(r);
377379
378380 glVertex3f
379381 (
@@ -394,9 +396,9 @@ void renderCircle(glm::vec3 position, float radius, glm::vec3 surfaceNormal, int · 14 unmodified lines
394396 glBegin(GL_LINE_STRIP);
395397
396398 for (int i=0; i<numSides+1; i++) {
397− float r = ((float)i / (float)numSides) * PIf * 2.0;
398− float s = radius * sin(r);
399− float c = radius * cos(r);
399+ float r = ((float)i / (float)numSides) * TWO_PI;
400+ float s = radius * sinf(r);
401+ float c = radius * cosf(r);
400402 glVertex3f
401403 (
402404 position.x + perp1.x * s + perp2.x * c,
@@ -440,12 +442,12 @@ void renderRoundedCornersRect(int x, int y, int width, int height, int radius, i · 37 unmodified lines
440442 numPointsCorner = MAX_POINTS_CORNER;
441443 }
442444
443− // Precompute sin and cos for [0, pi/2) for the number of points (numPointCorner)
445+ // Precompute sin and cos for [0, PI/2) for the number of points (numPointCorner)
444446 double radiusTimesSin[MAX_POINTS_CORNER];
445447 double radiusTimesCos[MAX_POINTS_CORNER];
446448 int i = 0;
447449 for (int i = 0; i < numPointsCorner; i++) {
448− double t = i * PIf / (2.0f * (numPointsCorner - 1));
450+ double t = (double)i * (double)PI_OVER_TWO / (double)(numPointsCorner - 1);
449451 radiusTimesSin[i] = radius * sin(t);
450452 radiusTimesCos[i] = radius * cos(t);
451453 }