瀏覽代碼

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
 
2
 
3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
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
     [ 20140517 ]
10
     [ 20140517 ]
6
     * Wrote new assert() implementation for Unix that prints a call stack
11
     * Wrote new assert() implementation for Unix that prints a call stack
7
     * Service provider methods (getCamera(), etc...) are now prototyped
12
     * Service provider methods (getCamera(), etc...) are now prototyped

+ 1
- 0
data/OpenRaider.ini 查看文件

32
 bind crouch   "leftctrl"
32
 bind crouch   "leftctrl"
33
 bind use      "leftmouse"
33
 bind use      "leftmouse"
34
 bind holster  "rightmouse"
34
 bind holster  "rightmouse"
35
+bind walk     "leftshift"

+ 8
- 17
include/Camera.h 查看文件

9
 #define _CAMERA_H_
9
 #define _CAMERA_H_
10
 
10
 
11
 #include "math/math.h"
11
 #include "math/math.h"
12
-#include "math/Matrix.h"
13
 #include "math/Quaternion.h"
12
 #include "math/Quaternion.h"
14
 
13
 
15
 /*!
14
 /*!
33
     Camera();
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
      * \brief Get the target currently looked at
35
      * \brief Get the target currently looked at
43
      * \param target where the target will be stored
36
      * \param target where the target will be stored
44
      */
37
      */
87
     void command(enum camera_command cmd);
80
     void command(enum camera_command cmd);
88
 
81
 
89
 private:
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
 Camera &getCamera();
93
 Camera &getCamera();

+ 1
- 0
include/global.h 查看文件

57
     crouchAction,
57
     crouchAction,
58
     useAction,
58
     useAction,
59
     holsterAction,
59
     holsterAction,
60
+    walkAction,
60
 
61
 
61
     ActionEventCount // Should always be at the end
62
     ActionEventCount // Should always be at the end
62
 } ActionEvents;
63
 } ActionEvents;

+ 1
- 1
include/math/math.h 查看文件

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

+ 8
- 34
src/Camera.cpp 查看文件

6
  * \author xythobuz
6
  * \author xythobuz
7
  */
7
  */
8
 
8
 
9
-#include <stdio.h>
10
-#include <math.h>
11
-
12
 #include "global.h"
9
 #include "global.h"
10
+#include "math/Matrix.h"
13
 #include "Camera.h"
11
 #include "Camera.h"
14
 
12
 
15
 Camera::Camera() {
13
 Camera::Camera() {
27
     mTarget[1] = 0.0f;
25
     mTarget[1] = 0.0f;
28
     mTarget[2] = mViewDistance;
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
     mQ.setIdentity();
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
 void Camera::getTarget(vec3_t target) {
31
 void Camera::getTarget(vec3_t target) {
48
     target[0] = mTarget[0];
32
     target[0] = mTarget[0];
49
     target[1] = mTarget[1];
33
     target[1] = mTarget[1];
73
 }
57
 }
74
 
58
 
75
 void Camera::update() {
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
 void Camera::rotate(float angle, float x, float y, float z) {
65
 void Camera::rotate(float angle, float x, float y, float z) {
82
     Quaternion t, n;
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
     vec_t look[4] = { 0.0f, 0.0f, -1.0f, 1.0f };
67
     vec_t look[4] = { 0.0f, 0.0f, -1.0f, 1.0f };
87
-    matrix_t m;
88
 
68
 
89
     t.set(angle, x, y, z);
69
     t.set(angle, x, y, z);
90
     n = mQ * t;
70
     n = mQ * t;
91
     n.normalize();
71
     n.normalize();
92
 
72
 
93
-    n.getMatrix(m);
94
-    matrix.setMatrix(m);
95
-    matrix.multiply4v(side, mSide);
73
+    Matrix matrix(n);
96
     matrix.multiply4v(look, mTarget);
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
         mTarget[i] += mPos[i];
77
         mTarget[i] += mPos[i];
102
-        mUp[i] += mPos[i];
103
-    }
104
 
78
 
105
     mQ = n;
79
     mQ = n;
106
 }
80
 }
108
 void Camera::command(enum camera_command cmd) {
82
 void Camera::command(enum camera_command cmd) {
109
     switch (cmd) {
83
     switch (cmd) {
110
         case CAMERA_ROTATE_UP:
84
         case CAMERA_ROTATE_UP:
111
-            if (mTheta2 < (M_PI / 2)) {
85
+            if (mTheta2 < (OR_PI / 2)) {
112
                 mTheta2 += mRotationDeltaY;
86
                 mTheta2 += mRotationDeltaY;
113
                 rotate(mTheta2, 1.0f, 0.0f, 0.0f);
87
                 rotate(mTheta2, 1.0f, 0.0f, 0.0f);
114
             }
88
             }
115
             break;
89
             break;
116
 
90
 
117
         case CAMERA_ROTATE_DOWN:
91
         case CAMERA_ROTATE_DOWN:
118
-            if (mTheta2 > -(M_PI / 2)) {
92
+            if (mTheta2 > -(OR_PI / 2)) {
119
                 mTheta2 -= mRotationDeltaY;
93
                 mTheta2 -= mRotationDeltaY;
120
                 rotate(mTheta2, 1.0f, 0.0f, 0.0f);
94
                 rotate(mTheta2, 1.0f, 0.0f, 0.0f);
121
             }
95
             }

+ 2
- 0
src/OpenRaider.cpp 查看文件

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

+ 5
- 2
src/Render.cpp 查看文件

356
         case Entity::MoveTypeFly:
356
         case Entity::MoveTypeFly:
357
         case Entity::MoveTypeNoClipping:
357
         case Entity::MoveTypeNoClipping:
358
         case Entity::MoveTypeSwim:
358
         case Entity::MoveTypeSwim:
359
-            camOffsetH = 64.0f;
359
+            //camOffsetH = 64.0f;
360
+            camOffsetH = 512.0f;
360
             break;
361
             break;
361
         case Entity::MoveTypeWalk:
362
         case Entity::MoveTypeWalk:
362
         case Entity::MoveTypeWalkNoSwim:
363
         case Entity::MoveTypeWalkNoSwim:
382
     int sector = getWorld().getSector(index, camPos[0], camPos[2]);
383
     int sector = getWorld().getSector(index, camPos[0], camPos[2]);
383
 
384
 
384
     // Handle camera out of world
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
         camPos[0] = curPos[0] + (64.0f * sinf(yaw));
389
         camPos[0] = curPos[0] + (64.0f * sinf(yaw));
387
         camPos[1] -= 64.0f;
390
         camPos[1] -= 64.0f;
388
         camPos[2] = curPos[2] + (64.0f * cosf(yaw));
391
         camPos[2] = curPos[2] + (64.0f * cosf(yaw));

Loading…
取消
儲存