Thomas Buck пре 10 година
родитељ
комит
237a34b03d
6 измењених фајлова са 30 додато и 29 уклоњено
  1. 0
    1
      include/Game.h
  2. 3
    0
      include/main.h
  3. 2
    2
      src/Camera.cpp
  4. 7
    18
      src/Game.cpp
  5. 8
    8
      src/Render.cpp
  6. 10
    0
      src/main.cpp

+ 0
- 1
include/Game.h Прегледај датотеку

@@ -43,7 +43,6 @@ public:
43 43
     //! \fixme should be private
44 44
     entity_t *mLara;
45 45
     Render *mRender;
46
-    Camera *mCamera;
47 46
 
48 47
 private:
49 48
 

+ 3
- 0
include/main.h Прегледај датотеку

@@ -7,6 +7,7 @@
7 7
 #ifndef _MAIN_H_
8 8
 #define _MAIN_H_
9 9
 
10
+#include "Camera.h"
10 11
 #include "Console.h"
11 12
 #include "Game.h"
12 13
 #include "Menu.h"
@@ -15,6 +16,8 @@
15 16
 #include "Window.h"
16 17
 #include "World.h"
17 18
 
19
+Camera &getCamera();
20
+
18 21
 Console &getConsole();
19 22
 
20 23
 Game &getGame();

+ 2
- 2
src/Camera.cpp Прегледај датотеку

@@ -14,7 +14,7 @@
14 14
 Camera::Camera() {
15 15
     mFlags = 0;
16 16
     mViewDistance = 14.0f;
17
-    mTranslateDelta = 256.0f;
17
+    mTranslateDelta = 512.0f; // 256.0f
18 18
     mFlags &= Camera_FlyMode;
19 19
     reset();
20 20
 }
@@ -138,7 +138,7 @@ void Camera::reset() {
138 138
     mSide[2] = 0.0f;
139 139
 
140 140
     mUp[0] = 0.0f;
141
-    mUp[1] = 1.0f;
141
+    mUp[1] = -1.0f; // 1.0f
142 142
     mUp[2] = 0.0f;
143 143
 
144 144
     mQ.setIdentity();

+ 7
- 18
src/Game.cpp Прегледај датотеку

@@ -38,7 +38,6 @@ Game::Game() {
38 38
     mTextureLevelOffset = 0;
39 39
     mTextureOffset = 0;
40 40
 
41
-    mCamera = NULL;
42 41
     mRender = NULL;
43 42
 }
44 43
 
@@ -47,19 +46,9 @@ Game::~Game() {
47 46
 
48 47
     if (mRender)
49 48
         delete mRender;
50
-
51
-    if (mCamera)
52
-        delete mCamera;
53 49
 }
54 50
 
55 51
 int Game::initialize() {
56
-    // Set up Camera
57
-    vec3_t up = {0.0f, -1.0f, 0.0f};
58
-    mCamera = new Camera();
59
-    mCamera->reset();
60
-    mCamera->setSpeed(512);
61
-    mCamera->setUp(up);
62
-
63 52
     // Set up Renderer
64 53
     mRender = new Render();
65 54
     mRender->initTextures(getOpenRaider().mDataDir, &mTextureStart, &mTextureLevelOffset);
@@ -160,22 +149,22 @@ void Game::handleMouseMotion(int xrel, int yrel) {
160 149
         // Move Camera on X Axis
161 150
         if (xrel > 0)
162 151
             while (xrel-- > 0)
163
-                mCamera->command(CAMERA_ROTATE_RIGHT);
152
+                getCamera().command(CAMERA_ROTATE_RIGHT);
164 153
         else if (xrel < 0)
165 154
             while (xrel++ < 0)
166
-                mCamera->command(CAMERA_ROTATE_LEFT);
155
+                getCamera().command(CAMERA_ROTATE_LEFT);
167 156
 
168 157
         // Move Camera on Y Axis
169 158
         if (yrel > 0)
170 159
             while (yrel-- > 0)
171
-                mCamera->command(CAMERA_ROTATE_UP);
160
+                getCamera().command(CAMERA_ROTATE_UP);
172 161
         else if (yrel < 0)
173 162
             while (yrel++ < 0)
174
-                mCamera->command(CAMERA_ROTATE_DOWN);
163
+                getCamera().command(CAMERA_ROTATE_DOWN);
175 164
 
176 165
         // Fix Laras rotation
177
-        mLara->angles[1] = mCamera->getRadianYaw();
178
-        mLara->angles[2] = mCamera->getRadianPitch();
166
+        mLara->angles[1] = getCamera().getRadianYaw();
167
+        mLara->angles[2] = getCamera().getRadianPitch();
179 168
     }
180 169
 }
181 170
 
@@ -750,7 +739,7 @@ void Game::processMoveable(int index, int i, int *ent,
750 739
         gLaraModel = r_model; // hack to avoid broken system until new event sys
751 740
 
752 741
         lara = true;
753
-        mCamera->translate(pos[0], pos[1] - 470, pos[2]);
742
+        getCamera().translate(pos[0], pos[1] - 470, pos[2]);
754 743
         thing->type = 0x02;
755 744
         mLara = thing; // Mongoose 2002.03.22, Cheap hack for now
756 745
         mLara->master = 0x0;

+ 8
- 8
src/Render.cpp Прегледај датотеку

@@ -554,16 +554,16 @@ void Render::Display()
554 554
             camPos[2] = curPos[2] + (64.0f * cosf(yaw));
555 555
         }
556 556
 
557
-        getGame().mCamera->setPosition(camPos);
557
+        getCamera().setPosition(camPos);
558 558
     }
559 559
 
560 560
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
561 561
     glLoadIdentity();
562 562
 
563 563
     // Setup view in OpenGL with camera
564
-    getGame().mCamera->update();
565
-    getGame().mCamera->getPosition(camPos);
566
-    getGame().mCamera->getTarget(atPos);
564
+    getCamera().update();
565
+    getCamera().getPosition(camPos);
566
+    getCamera().getTarget(atPos);
567 567
     // Mongoose 2002.08.13, Quick fix to render OpenRaider upside down
568 568
 
569 569
     gluLookAt(camPos[0], camPos[1], camPos[2], atPos[0], atPos[1], atPos[2], 0.0f, -1.0f, 0.0f);
@@ -1023,13 +1023,13 @@ void Render::drawObjects()
1023 1023
         glPushMatrix();
1024 1024
 
1025 1025
 #ifdef USING_FPS_CAMERA
1026
-        getGame().mCamera->getPosition(curPos);
1026
+        getCamera().getPosition(curPos);
1027 1027
         glTranslated(curPos[0], curPos[1], curPos[2]);
1028
-        glRotated(getGame().mCamera->getYaw(), 0, 1, 0);
1028
+        glRotated(getCamera().getYaw(), 0, 1, 0);
1029 1029
         glTranslated(0, 500, 1200);
1030 1030
 #else
1031 1031
         glTranslated(getGame().mLara->pos[0], getGame().mLara->pos[1], getGame().mLara->pos[2]);
1032
-        glRotated(getGame().mCamera->getYaw(), 0, 1, 0);
1032
+        glRotated(getCamera().getYaw(), 0, 1, 0);
1033 1033
 #endif
1034 1034
 
1035 1035
         drawModel(static_cast<SkeletalModel *>(getGame().mLara->tmpHook));
@@ -1554,7 +1554,7 @@ void Render::drawSprite(sprite_t *sprite)
1554 1554
     glTranslated(sprite->pos[0], sprite->pos[1], sprite->pos[2]);
1555 1555
 
1556 1556
     // Sprites must always face camera, because they have no depth  =)
1557
-    glRotated(getGame().mCamera->getYaw(), 0, 1, 0);
1557
+    glRotated(getCamera().getYaw(), 0, 1, 0);
1558 1558
 
1559 1559
     switch (mMode)
1560 1560
     {

+ 10
- 0
src/main.cpp Прегледај датотеку

@@ -15,6 +15,7 @@
15 15
 #include "utils/time.h"
16 16
 #include "WindowSDL.h"
17 17
 
18
+Camera *gCamera = NULL;
18 19
 Console *gConsole = NULL;
19 20
 Game *gGame = NULL;
20 21
 Menu *gMenu = NULL;
@@ -23,6 +24,11 @@ Sound *gSound = NULL;
23 24
 Window *gWindow = NULL;
24 25
 World *gWorld = NULL;
25 26
 
27
+Camera &getCamera() {
28
+    assert(gCamera != NULL);
29
+    return *gCamera;
30
+}
31
+
26 32
 Console &getConsole() {
27 33
     assert(gConsole != NULL);
28 34
     return *gConsole;
@@ -71,6 +77,9 @@ void cleanupHandler(void) {
71 77
     if (gWorld)
72 78
         delete gWorld;
73 79
 
80
+    if (gCamera)
81
+        delete gCamera;
82
+
74 83
     if (gOpenRaider)
75 84
         delete gOpenRaider;
76 85
 
@@ -127,6 +136,7 @@ int main(int argc, char *argv[]) {
127 136
     gWindow = new WindowSDL();
128 137
     gSound = new Sound();
129 138
     gWorld = new World();
139
+    gCamera = new Camera();
130 140
     gConsole = new Console();
131 141
     gMenu = new Menu();
132 142
     gGame = new Game();

Loading…
Откажи
Сачувај