Showing the changes to interface/src/Util.cpp (1 of 51 files). Show all
Unified · Split
| @@ -68,19 +68,21 @@ void printVector(glm::vec3 vec) { · 67 unmodified lines | |||
| 68 | printf("%4.2f, %4.2f, %4.2f\n", vec.x, vec.y, vec.z); | 68 | printf("%4.2f, %4.2f, %4.2f\n", vec.x, vec.y, vec.z); |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | // Return the azimuth angle in degrees between two points. | 71 | // Return the azimuth angle (in radians) between two points. |
| 72 | float azimuth_to(glm::vec3 head_pos, glm::vec3 source_pos) { | 72 | 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); |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 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. | ||
| 77 | float angle_to(glm::vec3 head_pos, glm::vec3 source_pos, float render_yaw, float head_yaw) { | 79 | 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; |
| 79 | } | 81 | } |
| 80 | 82 | ||
| 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 |
| 82 | float angleBetween(const glm::vec3& v1, const glm::vec3& v2) { | 84 | 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))); |
| 84 | } | 86 | } |
| 85 | 87 | ||
| 86 | // Helper function return the rotation from the first vector onto the second | 88 | // 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 | |||
| 90 | return glm::quat(); | 92 | return glm::quat(); |
| 91 | } | 93 | } |
| 92 | glm::vec3 axis; | 94 | 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 |
| 94 | axis = glm::cross(v1, glm::vec3(1.0f, 0.0f, 0.0f)); | 96 | axis = glm::cross(v1, glm::vec3(1.0f, 0.0f, 0.0f)); |
| 95 | float axisLength = glm::length(axis); | 97 | float axisLength = glm::length(axis); |
| 96 | if (axisLength < EPSILON) { // parallel to x; y will work | 98 | if (axisLength < EPSILON) { // parallel to x; y will work |
| @@ -314,7 +316,7 @@ float widthChar(float scale, int mono, char ch) { · 217 unmodified lines | |||
| 314 | return textRenderer(mono)->computeWidth(ch) * (scale / 0.10); | 316 | return textRenderer(mono)->computeWidth(ch) * (scale / 0.10); |
| 315 | } | 317 | } |
| 316 | 318 | ||
| 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, |
| 318 | char const* string, const float* color) { | 320 | char const* string, const float* color) { |
| 319 | // | 321 | // |
| 320 | // Draws text on screen as stroked so it can be resized | 322 | // 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 | |||
| 322 | glPushMatrix(); | 324 | glPushMatrix(); |
| 323 | glTranslatef(static_cast<float>(x), static_cast<float>(y), 0.0f); | 325 | glTranslatef(static_cast<float>(x), static_cast<float>(y), 0.0f); |
| 324 | glColor3fv(color); | 326 | glColor3fv(color); |
| 325 | glRotated(rotate,0,0,1); | 327 | glRotated(double(radians * DEGREES_PER_RADIAN), 0.0, 0.0, 1.0); |
| 326 | glScalef(scale / 0.10, scale / 0.10, 1.0); | 328 | glScalef(scale / 0.1f, scale / 0.1f, 1.f); |
| 327 | textRenderer(mono)->draw(0, 0, string); | 329 | textRenderer(mono)->draw(0, 0, string); |
| 328 | glPopMatrix(); | 330 | glPopMatrix(); |
| 329 | } | 331 | } |
| 330 | 332 | ||
| 331 | 333 | ||
| 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) { |
| 333 | // | 335 | // |
| 334 | // Draws text on screen as stroked so it can be resized | 336 | // Draws vec3 on screen as stroked so it can be resized |
| 335 | // | 337 | // |
| 336 | char vectext[20]; | 338 | char vectext[20]; |
| 337 | sprintf(vectext,"%3.1f,%3.1f,%3.1f", vec.x, vec.y, vec.z); | 339 | 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 | |||
| 339 | glPushMatrix(); | 341 | glPushMatrix(); |
| 340 | glTranslatef(static_cast<float>(x), static_cast<float>(y), 0); | 342 | glTranslatef(static_cast<float>(x), static_cast<float>(y), 0); |
| 341 | glColor3f(r,g,b); | 343 | glColor3f(r,g,b); |
| 342 | glRotated(180+rotate,0,0,1); | 344 | glRotated(180.0 + double(radians * DEGREES_PER_RADIAN), 0.0, 0.0, 1.0); |
| 343 | glRotated(180,0,1,0); | 345 | glRotated(180.0, 0.0, 1.0, 0.0); |
| 344 | glLineWidth(thick); | 346 | glLineWidth(thick); |
| 345 | glScalef(scale, scale, 1.0); | 347 | glScalef(scale, scale, 1.f); |
| 346 | len = (int) strlen(vectext); | 348 | len = (int) strlen(vectext); |
| 347 | for (i = 0; i < len; i++) { | 349 | for (i = 0; i < len; i++) { |
| 348 | if (!mono) glutStrokeCharacter(GLUT_STROKE_ROMAN, int(vectext[i])); | 350 | 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 | |||
| 371 | 373 | ||
| 372 | glBegin(GL_LINE_STRIP); | 374 | glBegin(GL_LINE_STRIP); |
| 373 | for (int i=0; i<numSides+1; i++) { | 375 | for (int i=0; i<numSides+1; i++) { |
| 374 | float r = ((float)i / (float)numSides) * PIf * 2.0; | 376 | float r = ((float)i / (float)numSides) * TWO_PI; |
| 375 | float s = radius * sin(r); | 377 | float s = radius * sinf(r); |
| 376 | float c = radius * cos(r); | 378 | float c = radius * cosf(r); |
| 377 | 379 | ||
| 378 | glVertex3f | 380 | glVertex3f |
| 379 | ( | 381 | ( |
| @@ -394,9 +396,9 @@ void renderCircle(glm::vec3 position, float radius, glm::vec3 surfaceNormal, int · 14 unmodified lines | |||
| 394 | glBegin(GL_LINE_STRIP); | 396 | glBegin(GL_LINE_STRIP); |
| 395 | 397 | ||
| 396 | for (int i=0; i<numSides+1; i++) { | 398 | for (int i=0; i<numSides+1; i++) { |
| 397 | float r = ((float)i / (float)numSides) * PIf * 2.0; | 399 | float r = ((float)i / (float)numSides) * TWO_PI; |
| 398 | float s = radius * sin(r); | 400 | float s = radius * sinf(r); |
| 399 | float c = radius * cos(r); | 401 | float c = radius * cosf(r); |
| 400 | glVertex3f | 402 | glVertex3f |
| 401 | ( | 403 | ( |
| 402 | position.x + perp1.x * s + perp2.x * c, | 404 | 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 | |||
| 440 | numPointsCorner = MAX_POINTS_CORNER; | 442 | numPointsCorner = MAX_POINTS_CORNER; |
| 441 | } | 443 | } |
| 442 | 444 | ||
| 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) |
| 444 | double radiusTimesSin[MAX_POINTS_CORNER]; | 446 | double radiusTimesSin[MAX_POINTS_CORNER]; |
| 445 | double radiusTimesCos[MAX_POINTS_CORNER]; | 447 | double radiusTimesCos[MAX_POINTS_CORNER]; |
| 446 | int i = 0; | 448 | int i = 0; |
| 447 | for (int i = 0; i < numPointsCorner; i++) { | 449 | 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); |
| 449 | radiusTimesSin[i] = radius * sin(t); | 451 | radiusTimesSin[i] = radius * sin(t); |
| 450 | radiusTimesCos[i] = radius * cos(t); | 452 | radiusTimesCos[i] = radius * cos(t); |
| 451 | } | 453 | } |