Browse Source

Replaced deprecated gluLookAt()!

Thomas Buck 11 years ago
parent
commit
87674534b1
2 changed files with 54 additions and 7 deletions
  1. 5
    4
      src/OpenRaider.cpp
  2. 49
    3
      src/Render.cpp

+ 5
- 4
src/OpenRaider.cpp View File

@@ -91,7 +91,9 @@ void killOpenRaiderSingleton()
91 91
 	printf("Shutting down Game...\n");
92 92
 
93 93
 	// Requires public deconstructor
94
-	delete OpenRaider::Instance();
94
+    // Causes pointer-being-freed-not-allocated error!
95
+	//delete OpenRaider::Instance();
96
+#warning "We can't delete our Game Instance without a not-allocated-free error. Somethings fishy here."
95 97
 
96 98
 #ifdef DEBUG_MEMEORY
97 99
 	printf("\n[Mongoose MEMEORY_DEBUG]\nMemory leak table:\n");
@@ -3583,12 +3585,11 @@ void OpenRaider::handleCommand(char *cmd, unsigned int mode)
3583 3585
 
3584 3586
 int main(int argc, char *argv[])
3585 3587
 {
3586
-	OpenRaider &game = *OpenRaider::Instance();
3587
-
3588
+	OpenRaider *game = OpenRaider::Instance();
3588 3589
 
3589 3590
 	atexit(killOpenRaiderSingleton);
3590 3591
 
3591
-	game.start();
3592
+	game->start();
3592 3593
 
3593 3594
 	return 0;
3594 3595
 }

+ 49
- 3
src/Render.cpp View File

@@ -753,6 +753,52 @@ void Render::setMode(int n)
753 753
 	}
754 754
 }
755 755
 
756
+// Replaced the deprecated gluLookAt with slightly modified code from here:
757
+// http://www.khronos.org/message_boards/showthread.php/4991
758
+void CrossProd(float x1, float y1, float z1, float x2, float y2, float z2, float res[3])
759
+{
760
+    res[0] = y1*z2 - y2*z1;
761
+    res[1] = x2*z1 - x1*z2;
762
+    res[2] = x1*y2 - x2*y1;
763
+}
764
+void deprecated_gluLookAt(float eyeX, float eyeY, float eyeZ, float lookAtX, float lookAtY, float lookAtZ, float upX, float upY, float upZ)
765
+{
766
+    float f[3];
767
+    // calculating the viewing vector
768
+    f[0] = lookAtX - eyeX;
769
+    f[1] = lookAtY - eyeY;
770
+    f[2] = lookAtZ - eyeZ;
771
+    float fMag, upMag;
772
+    fMag = sqrt(f[0]*f[0] + f[1]*f[1] + f[2]*f[2]);
773
+    upMag = sqrt(upX*upX + upY*upY + upZ*upZ);
774
+    // normalizing the viewing vector
775
+    if( fMag != 0)
776
+    {
777
+        f[0] = f[0]/fMag;
778
+        f[1] = f[1]/fMag;
779
+        f[2] = f[2]/fMag;
780
+    }
781
+    // normalising the up vector. no need for this here if you have your
782
+    // up vector already normalised, which is mostly the case.
783
+    if( upMag != 0 )
784
+    {
785
+        upX = upX/upMag;
786
+        upY = upY/upMag;
787
+        upZ = upZ/upMag;
788
+    }
789
+    float s[3], u[3];
790
+    CrossProd(f[0], f[1], f[2], upX, upY, upZ, s);
791
+    CrossProd(s[0], s[1], s[2], f[0], f[1], f[2], u);
792
+    float M[]=
793
+    {
794
+        s[0], u[0], -f[0], 0,
795
+        s[1], u[1], -f[1], 0,
796
+        s[2], u[2], -f[2], 0,
797
+        0, 0, 0, 1
798
+    };
799
+    glMultMatrixf(M);
800
+    glTranslatef (-eyeX, -eyeY, -eyeZ);
801
+}
756 802
 
757 803
 void Render::Display()
758 804
 {
@@ -848,9 +894,9 @@ void Render::Display()
848 894
 	mCamera->getPosition(camPos);
849 895
 	mCamera->getTarget(atPos);
850 896
 	// Mongoose 2002.08.13, Quick fix to render OpenRaider upside down
851
-	gluLookAt(camPos[0], camPos[1], camPos[2],
852
-				 atPos[0], atPos[1], atPos[2],
853
-	          0.0, -1.0, 0.0);
897
+	// gluLookAt(camPos[0], camPos[1], camPos[2], atPos[0], atPos[1], atPos[2], 0.0, -1.0, 0.0);
898
+
899
+    deprecated_gluLookAt(camPos[0], camPos[1], camPos[2], atPos[0], atPos[1], atPos[2], 0.0, -1.0, 0.0);
854 900
 
855 901
 	// Update view volume for vising
856 902
 	updateViewVolume();

Loading…
Cancel
Save