Преглед изворни кода

Added walk action. No longer crashes in World::isWall()

Thomas Buck пре 10 година
родитељ
комит
ab8b1ba104
8 измењених фајлова са 31 додато и 54 уклоњено
  1. 5
    0
      ChangeLog.md
  2. 1
    0
      data/OpenRaider.ini
  3. 8
    17
      include/Camera.h
  4. 1
    0
      include/global.h
  5. 1
    1
      include/math/math.h
  6. 8
    34
      src/Camera.cpp
  7. 2
    0
      src/OpenRaider.cpp
  8. 5
    2
      src/Render.cpp

+ 5
- 0
ChangeLog.md Прегледај датотеку

@@ -2,6 +2,11 @@
2 2
 
3 3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4 4
 
5
+    [ 20140519 ]
6
+    * No longer crashes simply by walking in the wrong place
7
+    * Added walk Action, supposed to switch to slow walking/sidesteps
8
+    * Removed unused Camera functionality (side and up vector)
9
+
5 10
     [ 20140517 ]
6 11
     * Wrote new assert() implementation for Unix that prints a call stack
7 12
     * Service provider methods (getCamera(), etc...) are now prototyped

+ 1
- 0
data/OpenRaider.ini Прегледај датотеку

@@ -32,3 +32,4 @@ bind jump     "space"
32 32
 bind crouch   "leftctrl"
33 33
 bind use      "leftmouse"
34 34
 bind holster  "rightmouse"
35
+bind walk     "leftshift"

+ 8
- 17
include/Camera.h Прегледај датотеку

@@ -9,7 +9,6 @@
9 9
 #define _CAMERA_H_
10 10
 
11 11
 #include "math/math.h"
12
-#include "math/Matrix.h"
13 12
 #include "math/Quaternion.h"
14 13
 
15 14
 /*!
@@ -33,12 +32,6 @@ public:
33 32
     Camera();
34 33
 
35 34
     /*!
36
-     * \brief Returns the current position
37
-     * \param pos where the position will be stored
38
-     */
39
-    void getPosition(vec3_t pos);
40
-
41
-    /*!
42 35
      * \brief Get the target currently looked at
43 36
      * \param target where the target will be stored
44 37
      */
@@ -87,16 +80,14 @@ public:
87 80
     void command(enum camera_command cmd);
88 81
 
89 82
 private:
90
-    Quaternion mQ;                //!< Quaternion for rotation
91
-    vec_t mPos[4];                //!< Location in 3 space (aka eye)
92
-    vec_t mTarget[4];             //!< Postition we're looking at
93
-    vec_t mUp[4];                 //!< Up vector
94
-    vec_t mSide[4];               //!< Side vector
95
-    vec_t mViewDistance;          //!< Distance from target
96
-    vec_t mTheta;                 //!< View angle Y
97
-    vec_t mTheta2;                //!< View angle Z
98
-    vec_t mRotationDeltaX;
99
-    vec_t mRotationDeltaY;
83
+    Quaternion mQ;         //!< Quaternion for rotation
84
+    vec4_t mPos;           //!< Location in 3 space (aka eye)
85
+    vec4_t mTarget;        //!< Postition we're looking at
86
+    vec_t mViewDistance;   //!< Distance from target
87
+    vec_t mTheta;          //!< View angle Y
88
+    vec_t mTheta2;         //!< View angle Z
89
+    vec_t mRotationDeltaX; //!< Horizontal mouse sensitivity
90
+    vec_t mRotationDeltaY; //!< Vertical mouse sensitivity
100 91
 };
101 92
 
102 93
 Camera &getCamera();

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

@@ -57,6 +57,7 @@ typedef enum {
57 57
     crouchAction,
58 58
     useAction,
59 59
     holsterAction,
60
+    walkAction,
60 61
 
61 62
     ActionEventCount // Should always be at the end
62 63
 } ActionEvents;

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

@@ -7,7 +7,7 @@
7 7
  * \author xythobuz
8 8
  */
9 9
 
10
-#include <math.h>
10
+#include <cmath>
11 11
 
12 12
 #ifndef _MATH_MATH_H
13 13
 #define _MATH_MATH_H

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

@@ -6,10 +6,8 @@
6 6
  * \author xythobuz
7 7
  */
8 8
 
9
-#include <stdio.h>
10
-#include <math.h>
11
-
12 9
 #include "global.h"
10
+#include "math/Matrix.h"
13 11
 #include "Camera.h"
14 12
 
15 13
 Camera::Camera() {
@@ -27,23 +25,9 @@ Camera::Camera() {
27 25
     mTarget[1] = 0.0f;
28 26
     mTarget[2] = mViewDistance;
29 27
 
30
-    mSide[0] = 1.0f;
31
-    mSide[1] = 0.0f;
32
-    mSide[2] = 0.0f;
33
-
34
-    mUp[0] = 0.0f;
35
-    mUp[1] = -1.0f; // 1.0f
36
-    mUp[2] = 0.0f;
37
-
38 28
     mQ.setIdentity();
39 29
 }
40 30
 
41
-void Camera::getPosition(vec3_t pos) {
42
-    pos[0] = mPos[0];
43
-    pos[1] = mPos[1];
44
-    pos[2] = mPos[2];
45
-}
46
-
47 31
 void Camera::getTarget(vec3_t target) {
48 32
     target[0] = mTarget[0];
49 33
     target[1] = mTarget[1];
@@ -73,34 +57,24 @@ void Camera::setSensitivityY(vec_t sens) {
73 57
 }
74 58
 
75 59
 void Camera::update() {
76
-    mTarget[2] = (mViewDistance * cosf(mTheta)) + mPos[2];
77
-    mTarget[0] = (mViewDistance * sinf(mTheta)) + mPos[0];
78
-    mTarget[1] = (mViewDistance * sinf(mTheta2)) + mPos[1]; // + height_offset;
60
+    mTarget[0] = (mViewDistance * std::sin(mTheta)) + mPos[0];
61
+    mTarget[1] = (mViewDistance * std::sin(mTheta2)) + mPos[1]; // + height_offset;
62
+    mTarget[2] = (mViewDistance * std::cos(mTheta)) + mPos[2];
79 63
 }
80 64
 
81 65
 void Camera::rotate(float angle, float x, float y, float z) {
82 66
     Quaternion t, n;
83
-    Matrix matrix;
84
-    vec_t side[4] = { 1.0f, 0.0f,  0.0f, 1.0f };
85
-    vec_t up[4] =   { 0.0f, 1.0f,  0.0f, 1.0f };
86 67
     vec_t look[4] = { 0.0f, 0.0f, -1.0f, 1.0f };
87
-    matrix_t m;
88 68
 
89 69
     t.set(angle, x, y, z);
90 70
     n = mQ * t;
91 71
     n.normalize();
92 72
 
93
-    n.getMatrix(m);
94
-    matrix.setMatrix(m);
95
-    matrix.multiply4v(side, mSide);
73
+    Matrix matrix(n);
96 74
     matrix.multiply4v(look, mTarget);
97
-    matrix.multiply4v(up, mUp);
98 75
 
99
-    for (int i = 0; i < 3; ++i) {
100
-        mSide[i] += mPos[i];
76
+    for (int i = 0; i < 3; ++i)
101 77
         mTarget[i] += mPos[i];
102
-        mUp[i] += mPos[i];
103
-    }
104 78
 
105 79
     mQ = n;
106 80
 }
@@ -108,14 +82,14 @@ void Camera::rotate(float angle, float x, float y, float z) {
108 82
 void Camera::command(enum camera_command cmd) {
109 83
     switch (cmd) {
110 84
         case CAMERA_ROTATE_UP:
111
-            if (mTheta2 < (M_PI / 2)) {
85
+            if (mTheta2 < (OR_PI / 2)) {
112 86
                 mTheta2 += mRotationDeltaY;
113 87
                 rotate(mTheta2, 1.0f, 0.0f, 0.0f);
114 88
             }
115 89
             break;
116 90
 
117 91
         case CAMERA_ROTATE_DOWN:
118
-            if (mTheta2 > -(M_PI / 2)) {
92
+            if (mTheta2 > -(OR_PI / 2)) {
119 93
                 mTheta2 -= mRotationDeltaY;
120 94
                 rotate(mTheta2, 1.0f, 0.0f, 0.0f);
121 95
             }

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

@@ -310,6 +310,8 @@ int OpenRaider::bind(const char *action, const char *key) {
310 310
         return bind(useAction, key);
311 311
     } else if (strcmp(tmp, "holster") == 0) {
312 312
         return bind(holsterAction, key);
313
+    } else if (strcmp(tmp, "walk") == 0) {
314
+        return bind(walkAction, key);
313 315
     } else {
314 316
         getConsole().print("bind-Error: Unknown action (%s --> %s)", key, action);
315 317
         return -1;

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

@@ -356,7 +356,8 @@ void Render::display()
356 356
         case Entity::MoveTypeFly:
357 357
         case Entity::MoveTypeNoClipping:
358 358
         case Entity::MoveTypeSwim:
359
-            camOffsetH = 64.0f;
359
+            //camOffsetH = 64.0f;
360
+            camOffsetH = 512.0f;
360 361
             break;
361 362
         case Entity::MoveTypeWalk:
362 363
         case Entity::MoveTypeWalkNoSwim:
@@ -382,7 +383,9 @@ void Render::display()
382 383
     int sector = getWorld().getSector(index, camPos[0], camPos[2]);
383 384
 
384 385
     // Handle camera out of world
385
-    if (sector < 0 || getWorld().isWall(index, sector)) {
386
+    if ((sector < 0) ||
387
+            ((unsigned int)sector >= getWorld().getRoom(index).sizeSectors()) ||
388
+            getWorld().isWall(index, sector)) {
386 389
         camPos[0] = curPos[0] + (64.0f * sinf(yaw));
387 390
         camPos[1] -= 64.0f;
388 391
         camPos[2] = curPos[2] + (64.0f * cosf(yaw));

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