History

more windows build fixes isnan

Brad Hefta-Gaub committed 12 years ago

Commit 19012e21 parent a8fc7f42 files · +59 −53Browse files

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

Unified · Split

interface/src/Util.cpp+56−50
@@ -25,6 +25,12 @@ · 24 unmodified lines
2525
2626 #include "Util.h"
2727
28+#ifdef _WIN32
29+bool isnan(double value) { return _isnan(value); }
30+#else
31+bool isnan(double value) { return std::isnan(value); }
32+#endif
33+
2834 using namespace std;
2935
3036 // no clue which versions are affected...
@@ -37,14 +43,14 @@ void eulerToOrthonormals(glm::vec3 * angles, glm::vec3 * front, glm::vec3 * righ · 6 unmodified lines
3743 //
3844 // Angles contains (pitch, yaw, roll) in radians
3945 //
40−
46+
4147 // First, create the quaternion associated with these euler angles
4248 glm::quat q(glm::vec3(angles->x, -(angles->y), angles->z));
4349
4450 // Next, create a rotation matrix from that quaternion
4551 glm::mat4 rotation;
4652 rotation = glm::mat4_cast(q);
47−
53+
4854 // Transform the original vectors by the rotation matrix to get the new vectors
4955 glm::vec4 qup(0,1,0,0);
5056 glm::vec4 qright(-1,0,0,0);
@@ -52,7 +58,7 @@ void eulerToOrthonormals(glm::vec3 * angles, glm::vec3 * front, glm::vec3 * righ · 1 unmodified line
5258 glm::vec4 upNew = qup*rotation;
5359 glm::vec4 rightNew = qright*rotation;
5460 glm::vec4 frontNew = qfront*rotation;
55−
61+
5662 // Copy the answers to output vectors
5763 up->x = upNew.x; up->y = upNew.y; up->z = upNew.z;
5864 right->x = rightNew.x; right->y = rightNew.y; right->z = rightNew.z;
@@ -68,12 +74,12 @@ float azimuth_to(glm::vec3 head_pos, glm::vec3 source_pos) { · 9 unmodified lines
6874 return atan2(head_pos.x - source_pos.x, head_pos.z - source_pos.z) * 180.0f / PIf;
6975 }
7076
71−// 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.
77+// 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.
7278 float angle_to(glm::vec3 head_pos, glm::vec3 source_pos, float render_yaw, float head_yaw) {
7379 return atan2(head_pos.x - source_pos.x, head_pos.z - source_pos.z) * 180.0f / PIf + render_yaw + head_yaw;
7480 }
7581
76−// Helper function returns the positive angle in degrees between two 3D vectors
82+// Helper function returns the positive angle in degrees between two 3D vectors
7783 float angleBetween(const glm::vec3& v1, const glm::vec3& v2) {
7884 return acos((glm::dot(v1, v2)) / (glm::length(v1) * glm::length(v2))) * 180.f / PIf;
7985 }
@@ -92,7 +98,7 @@ glm::quat rotationBetween(const glm::vec3& v1, const glm::vec3& v2) { · 12 unmodified lines
9298 axis = glm::normalize(glm::cross(v1, glm::vec3(0.0f, 1.0f, 0.0f)));
9399 } else {
94100 axis /= axisLength;
95− }
101+ }
96102 } else {
97103 axis = glm::normalize(glm::cross(v1, v2));
98104 }
@@ -110,7 +116,7 @@ glm::vec3 safeEulerAngles(const glm::quat& q) { · 11 unmodified lines
110116 atan2f(q.y * q.z + q.x * q.w, 0.5f - (q.x * q.x + q.y * q.y)),
111117 asinf(sy),
112118 atan2f(q.x * q.y + q.z * q.w, 0.5f - (q.y * q.y + q.z * q.z))));
113−
119+
114120 } else {
115121 // not a unique solution; x + z = atan2(-m21, m11)
116122 return glm::degrees(glm::vec3(
@@ -149,7 +155,7 @@ glm::quat safeMix(const glm::quat& q1, const glm::quat& q2, float proportion) { · 32 unmodified lines
149155 float angle = acosf(cosa), sina = sinf(angle);
150156 s0 = sinf((1.0f - proportion) * angle) / sina;
151157 s1 = sinf(proportion * angle) / sina;
152−
158+
153159 } else {
154160 s0 = 1.0f - proportion;
155161 s1 = proportion;
@@ -179,7 +185,7 @@ glm::quat extractRotation(const glm::mat4& matrix, bool assumeOrthogonal) { · 23 unmodified lines
179185 for (int i = 0; i < 10; i++) {
180186 // store the results of the previous iteration
181187 glm::mat3 previous = upper;
182−
188+
183189 // compute average of the matrix with its inverse transpose
184190 float sd00 = previous[1][1] * previous[2][2] - previous[2][1] * previous[1][2];
185191 float sd10 = previous[0][1] * previous[2][2] - previous[2][1] * previous[0][2];
@@ -211,13 +217,13 @@ glm::quat extractRotation(const glm::mat4& matrix, bool assumeOrthogonal) { · 25 unmodified lines
211217 }
212218 }
213219 }
214−
220+
215221 // now that we have a nice orthogonal matrix, we can extract the rotation quaternion
216222 // using the method described in http://en.wikipedia.org/wiki/Rotation_matrix#Conversions
217223 float x2 = fabs(1.0f + upper[0][0] - upper[1][1] - upper[2][2]);
218224 float y2 = fabs(1.0f - upper[0][0] + upper[1][1] - upper[2][2]);
219225 float z2 = fabs(1.0f - upper[0][0] - upper[1][1] + upper[2][2]);
220− float w2 = fabs(1.0f + upper[0][0] + upper[1][1] + upper[2][2]);
226+ float w2 = fabs(1.0f + upper[0][0] + upper[1][1] + upper[2][2]);
221227 return glm::normalize(glm::quat(0.5f * sqrtf(w2),
222228 0.5f * sqrtf(x2) * (upper[1][2] >= upper[2][1] ? 1.0f : -1.0f),
223229 0.5f * sqrtf(y2) * (upper[2][0] >= upper[0][2] ? 1.0f : -1.0f),
@@ -255,14 +261,14 @@ void drawVector(glm::vec3 * vector) { · 31 unmodified lines
255261 glVertex3f(0,0,0);
256262 glVertex3f(0, 0, 1);
257263 glEnd();
258−
264+
259265 // Draw the vector itself
260266 glBegin(GL_LINES);
261267 glColor3f(1,1,1);
262268 glVertex3f(0,0,0);
263269 glVertex3f(vector->x, vector->y, vector->z);
264270 glEnd();
265−
271+
266272 // Draw spheres for magnitude
267273 glPushMatrix();
268274 glColor3f(1,0,0);
@@ -284,10 +290,10 @@ void noiseTest(int w, int h) { · 15 unmodified lines
284290 const float NOISE_SCALE = 10.0;
285291 float xStep = (float) w / CELLS;
286292 float yStep = (float) h / CELLS;
287− glBegin(GL_QUADS);
293+ glBegin(GL_QUADS);
288294 for (float x = 0; x < (float)w; x += xStep) {
289295 for (float y = 0; y < (float)h; y += yStep) {
290− // Generate a vector varying between 0-1 corresponding to the screen location
296+ // Generate a vector varying between 0-1 corresponding to the screen location
291297 glm::vec2 position(NOISE_SCALE * x / (float) w, NOISE_SCALE * y / (float) h);
292298 // Set the cell color using the noise value at that location
293299 float color = glm::perlin(position);
@@ -300,14 +306,14 @@ void noiseTest(int w, int h) { · 6 unmodified lines
300306 }
301307 glEnd();
302308 }
303−
309+
304310 void renderWorldBox() {
305311 // Show edge of world
306312 float red[] = {1, 0, 0};
307313 float green[] = {0, 1, 0};
308314 float blue[] = {0, 0, 1};
309315 float gray[] = {0.5, 0.5, 0.5};
310−
316+
311317 glDisable(GL_LIGHTING);
312318 glLineWidth(1.0);
313319 glBegin(GL_LINES);
@@ -355,7 +361,7 @@ double diffclock(timeval *clock1,timeval *clock2) · 41 unmodified lines
355361 {
356362 double diffms = (clock2->tv_sec - clock1->tv_sec) * 1000.0;
357363 diffms += (clock2->tv_usec - clock1->tv_usec) / 1000.0; // us to ms
358−
364+
359365 return diffms;
360366 }
361367
@@ -389,9 +395,9 @@ void drawtext(int x, int y, float scale, float rotate, float thick, int mono, · 27 unmodified lines
389395 glRotated(rotate,0,0,1);
390396 // glLineWidth(thick);
391397 glScalef(scale / 0.10, scale / 0.10, 1.0);
392−
398+
393399 textRenderer(mono)->draw(0, 0, string);
394−
400+
395401 glPopMatrix();
396402
397403 }
@@ -416,7 +422,7 @@ void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, gl · 18 unmodified lines
416422 else glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN, int(vectext[i]));
417423 }
418424 glPopMatrix();
419−}
425+}
420426
421427 void renderCollisionOverlay(int width, int height, float magnitude) {
422428 const float MIN_VISIBLE_COLLISION = 0.01f;
@@ -435,7 +441,7 @@ void renderMouseVoxelGrid(const float& mouseVoxelX, const float& mouseVoxelY, co · 12 unmodified lines
435441 glm::vec3 origin = glm::vec3(mouseVoxelX, mouseVoxelY, mouseVoxelZ);
436442
437443 glLineWidth(3.0);
438−
444+
439445 const int HALF_GRID_DIMENSIONS = 4;
440446 glBegin(GL_LINES);
441447
@@ -463,7 +469,7 @@ void renderNudgeGrid(float voxelX, float voxelY, float voxelZ, float voxelS, flo · 21 unmodified lines
463469 glm::vec3 origin = glm::vec3(voxelX, voxelY, voxelZ);
464470
465471 glLineWidth(1.0);
466−
472+
467473 const int GRID_DIMENSIONS = 4;
468474 const int GRID_SCALER = voxelS / voxelPrecision;
469475 const int GRID_SEGMENTS = GRID_DIMENSIONS * GRID_SCALER;
@@ -485,7 +491,7 @@ void renderNudgeGrid(float voxelX, float voxelY, float voxelZ, float voxelS, flo · 15 unmodified lines
485491 glEnd();
486492
487493 glColor3f(1.0f,1.0f,1.0f);
488−
494+
489495 glBegin(GL_POLYGON);//begin drawing of square
490496 glVertex3f(voxelX, 0.0f, voxelZ);//first vertex
491497 glVertex3f(voxelX + voxelS, 0.0f, voxelZ);//second vertex
@@ -498,7 +504,7 @@ void renderNudgeGuide(float voxelX, float voxelY, float voxelZ, float voxelS) { · 6 unmodified lines
498504 glm::vec3 origin = glm::vec3(voxelX, voxelY, voxelZ);
499505
500506 glLineWidth(3.0);
501−
507+
502508 glBegin(GL_LINES);
503509
504510 glm::vec3 guideColor(1.0, 1.0, 1.0);
@@ -526,21 +532,21 @@ void renderSphereOutline(glm::vec3 position, float radius, int numSides, glm::ve · 21 unmodified lines
526532 glm::vec3 vectorToPosition(glm::normalize(position - cameraPosition));
527533 glm::vec3 right = glm::cross(vectorToPosition, glm::vec3(0.0f, 1.0f, 0.0f));
528534 glm::vec3 up = glm::cross(right, vectorToPosition);
529−
530− glBegin(GL_LINE_STRIP);
535+
536+ glBegin(GL_LINE_STRIP);
531537 for (int i=0; i<numSides+1; i++) {
532538 float r = ((float)i / (float)numSides) * PIf * 2.0;
533539 float s = radius * sin(r);
534540 float c = radius * cos(r);
535−
541+
536542 glVertex3f
537543 (
538− position.x + right.x * s + up.x * c,
539− position.y + right.y * s + up.y * c,
540− position.z + right.z * s + up.z * c
541− );
544+ position.x + right.x * s + up.x * c,
545+ position.y + right.y * s + up.y * c,
546+ position.z + right.z * s + up.z * c
547+ );
542548 }
543−
549+
544550 glEnd();
545551 }
546552
@@ -548,8 +554,8 @@ void renderSphereOutline(glm::vec3 position, float radius, int numSides, glm::ve · 1 unmodified line
548554 void renderCircle(glm::vec3 position, float radius, glm::vec3 surfaceNormal, int numSides) {
549555 glm::vec3 perp1 = glm::vec3(surfaceNormal.y, surfaceNormal.z, surfaceNormal.x);
550556 glm::vec3 perp2 = glm::vec3(surfaceNormal.z, surfaceNormal.x, surfaceNormal.y);
551−
552− glBegin(GL_LINE_STRIP);
557+
558+ glBegin(GL_LINE_STRIP);
553559
554560 for (int i=0; i<numSides+1; i++) {
555561 float r = ((float)i / (float)numSides) * PIf * 2.0;
@@ -557,10 +563,10 @@ void renderCircle(glm::vec3 position, float radius, glm::vec3 surfaceNormal, int · 1 unmodified line
557563 float c = radius * cos(r);
558564 glVertex3f
559565 (
560− position.x + perp1.x * s + perp2.x * c,
561− position.y + perp1.y * s + perp2.y * c,
562− position.z + perp1.z * s + perp2.z * c
563− );
566+ position.x + perp1.x * s + perp2.x * c,
567+ position.y + perp1.y * s + perp2.y * c,
568+ position.z + perp1.z * s + perp2.z * c
569+ );
564570 }
565571 glEnd();
566572 }
@@ -570,7 +576,7 @@ void renderOrientationDirections(glm::vec3 position, const glm::quat& orientatio · 3 unmodified lines
570576 glm::vec3 pRight = position + orientation * IDENTITY_RIGHT * size;
571577 glm::vec3 pUp = position + orientation * IDENTITY_UP * size;
572578 glm::vec3 pFront = position + orientation * IDENTITY_FRONT * size;
573−
579+
574580 glColor3f(1.0f, 0.0f, 0.0f);
575581 glBegin(GL_LINE_STRIP);
576582 glVertex3f(position.x, position.y, position.z);
@@ -611,7 +617,7 @@ void runTimingTests() { · 34 unmodified lines
611617 }
612618 elapsedMsecs = diffclock(&startTime, &endTime);
613619 qDebug("gettimeofday() usecs: %f\n", 1000.0f * elapsedMsecs / (float) numTests);
614−
620+
615621 // Random number generation
616622 gettimeofday(&startTime, NULL);
617623 for (int i = 1; i < numTests; i++) {
@@ -651,13 +657,13 @@ void runTimingTests() { · 33 unmodified lines
651657 }
652658 gettimeofday(&endTime, NULL);
653659 elapsedMsecs = diffclock(&startTime, &endTime);
654− qDebug("vector math usecs: %f [%f msecs total for %d tests]\n",
660+ qDebug("vector math usecs: %f [%f msecs total for %d tests]\n",
655661 1000.0f * elapsedMsecs / (float) numTests, elapsedMsecs, numTests);
656−
662+
657663 // Vec3 test
658664 glm::vec3 vecA(randVector()), vecB(randVector());
659665 float result;
660−
666+
661667 gettimeofday(&startTime, NULL);
662668 for (int i = 1; i < numTests; i++) {
663669 glm::vec3 temp = vecA-vecB;
@@ -679,32 +685,32 @@ float loadSetting(QSettings* settings, const char* name, float defaultValue) { · 15 unmodified lines
679685 bool rayIntersectsSphere(const glm::vec3& rayStarting, const glm::vec3& rayNormalizedDirection,
680686 const glm::vec3& sphereCenter, float sphereRadius, float& distance) {
681687 glm::vec3 relativeOrigin = rayStarting - sphereCenter;
682−
688+
683689 // compute the b, c terms of the quadratic equation (a is dot(direction, direction), which is one)
684690 float b = 2.0f * glm::dot(rayNormalizedDirection, relativeOrigin);
685691 float c = glm::dot(relativeOrigin, relativeOrigin) - sphereRadius * sphereRadius;
686−
692+
687693 // compute the radicand of the quadratic. if less than zero, there's no intersection
688694 float radicand = b * b - 4.0f * c;
689695 if (radicand < 0.0f) {
690696 return false;
691697 }
692−
698+
693699 // compute the first solution of the quadratic
694700 float root = sqrtf(radicand);
695701 float firstSolution = -b - root;
696702 if (firstSolution > 0.0f) {
697− distance = firstSolution / 2.0f;
703+ distance = firstSolution / 2.0f;
698704 return true; // origin is outside the sphere
699705 }
700−
706+
701707 // now try the second solution
702708 float secondSolution = -b + root;
703709 if (secondSolution > 0.0f) {
704710 distance = 0.0f;
705711 return true; // origin is inside the sphere
706712 }
707−
713+
708714 return false;
709715 }
710716