Thomas Buck 10 роки тому
джерело
коміт
c676a07a35
50 змінених файлів з 33 додано та 25123 видалено
  1. 0
    194
      include/Camera.h
  2. 0
    179
      include/Emitter.h
  3. 0
    116
      include/GLString.h
  4. 0
    201
      include/Matrix.h
  5. 0
    169
      include/Mesh.h
  6. 0
    236
      include/OpenRaider.h
  7. 0
    119
      include/Particle.h
  8. 0
    201
      include/Quaternion.h
  9. 0
    371
      include/Render.h
  10. 0
    123
      include/SDLSystem.h
  11. 0
    92
      include/SkeletalModel.h
  12. 0
    103
      include/Sound.h
  13. 0
    167
      include/System.h
  14. 0
    293
      include/Texture.h
  15. 0
    1919
      include/TombRaider.h
  16. 0
    160
      include/Vector3d.h
  17. 0
    200
      include/ViewVolume.h
  18. 0
    391
      include/World.h
  19. 0
    673
      include/games/TombRaider1.h
  20. 0
    460
      include/templates/List.h
  21. 0
    409
      include/templates/Vector.h
  22. 0
    71
      include/utils/math.h
  23. 0
    61
      include/utils/strings.h
  24. 0
    89
      include/utils/tga.h
  25. 0
    32
      include/utils/time.h
  26. 3
    20
      src/CMakeLists.txt
  27. 0
    247
      src/Camera.cpp
  28. 0
    245
      src/Emitter.cpp
  29. 0
    142
      src/GLString.cpp
  30. 0
    406
      src/Matrix.cpp
  31. 0
    625
      src/Mesh.cpp
  32. 0
    3423
      src/OpenRaider.cpp
  33. 0
    162
      src/Particle.cpp
  34. 0
    289
      src/Quaternion.cpp
  35. 0
    2236
      src/Render.cpp
  36. 0
    352
      src/SDLSystem.cpp
  37. 0
    161
      src/SkeletalModel.cpp
  38. 0
    262
      src/Sound.cpp
  39. 0
    217
      src/System.cpp
  40. 0
    1125
      src/Texture.cpp
  41. 0
    6281
      src/TombRaider.cpp
  42. 0
    135
      src/Vector3d.cpp
  43. 0
    270
      src/ViewVolume.cpp
  44. 0
    762
      src/World.cpp
  45. 30
    0
      src/main.cpp
  46. 0
    11
      src/utils/CMakeLists.txt
  47. 0
    137
      src/utils/math.cpp
  48. 0
    171
      src/utils/strings.cpp
  49. 0
    382
      src/utils/tga.cpp
  50. 0
    33
      src/utils/time.cpp

+ 0
- 194
include/Camera.h Переглянути файл

@@ -1,194 +0,0 @@
1
-/*!
2
- * \file include/Camera.h
3
- * \brief OpenGL camera class
4
- *
5
- * \author Mongoose
6
- */
7
-#ifndef _CAMERA_H_
8
-#define _CAMERA_H_
9
-
10
-#include "utils/math.h"
11
-#include "Matrix.h"
12
-#include "Quaternion.h"
13
-
14
-/*!
15
- * \brief Commands for interactive camera control
16
- */
17
-enum camera_command {
18
-  CAMERA_MOVE_FORWARD = 1,
19
-  CAMERA_MOVE_BACKWARD,
20
-  CAMERA_MOVE_UP,
21
-  CAMERA_MOVE_DOWN,
22
-  CAMERA_ROTATE_RIGHT,
23
-  CAMERA_ROTATE_LEFT,
24
-  CAMERA_SPEED_UP,
25
-  CAMERA_SPEED_DOWN,
26
-  CAMERA_ROTATE_UP,
27
-  CAMERA_ROTATE_DOWN,
28
-  CAMERA_MOVE_LEFT,
29
-  CAMERA_MOVE_RIGHT
30
-};
31
-
32
-/*!
33
- * \brief Flags a camera can have
34
- */
35
-enum CameraFlags {
36
-    Camera_FlyMode = (1 << 0) //!< Camera is flying free?
37
-};
38
-
39
-/*!
40
- * \brief OpenGL camera class
41
- *
42
- * 2002.12.16:
43
- * Mongoose - Removed perspective setting and OpenGL dependency
44
- *            API changes to reflect new direction of this object:
45
- *              Removing outdated algorithms and code
46
- *              And refactoring the class in general
47
- *
48
- * 2001.06.06:
49
- * Mongoose - Moving GLU code into here to setup break up
50
- *            into Camera base class, DynamicCamera,
51
- *            and GLUCamera child classes
52
- *
53
- * 2001.06.04:
54
- * Mongoose - Quaternion based compile option
55
- *
56
- * 2001.05.18:
57
- * Mongoose - Created, based on my old GL camera code
58
- *            that has been used in GooseEgg since alpha
59
- *            and algorithms from Yuri Zhivago's trview
60
- */
61
-class Camera {
62
-public:
63
-    /*!
64
-     * \brief Constructs an object of Camera
65
-     */
66
-    Camera();
67
-
68
-    /*!
69
-     * \brief Returns the current position
70
-     * \param pos where the position will be stored
71
-     */
72
-    void getPosition(vec3_t pos);
73
-
74
-    /*!
75
-     * \brief Returns the up vector
76
-     * \param up where the up vector will be stored
77
-     */
78
-    void getUp(vec3_t up);
79
-
80
-    /*!
81
-     * \brief Get the target currently looked at
82
-     * \param target where the target will be stored
83
-     */
84
-    void getTarget(vec3_t target);
85
-
86
-    /*!
87
-     * \brief Get current yaw in degrees
88
-     * \returns yaw in degrees
89
-     */
90
-    float getYaw();
91
-
92
-    /*!
93
-     * \brief Get angle/yaw of camera
94
-     * \returns theta angle/yaw of camera
95
-     */
96
-    vec_t getRadianYaw();
97
-
98
-    /*!
99
-     * \brief Get current angle/pitch
100
-     * \returns current pitch in degrees
101
-     */
102
-    float getPitch();
103
-
104
-    /*!
105
-     * \brief Get angle/pitch of camera
106
-     * \returns phi angle/pitch of camera
107
-     */
108
-    vec_t getRadianPitch();
109
-
110
-    /*!
111
-     * \brief Rotate the camera
112
-     * \param angle angle in radians
113
-     * \param x X coordinate of axis
114
-     * \param y Y coordinate of axis
115
-     * \param z Z coordinate of axis
116
-     */
117
-    void rotate(float angle, float x, float y, float z);
118
-
119
-    /*!
120
-     * \brief Set Camera position
121
-     * \param x new X coordinate
122
-     * \param y new Y coordinate
123
-     * \param z new Z coordinate
124
-     */
125
-    void translate(float x, float y, float z);
126
-
127
-    /*!
128
-     * \brief Set the Camera to its initial state
129
-     */
130
-    void reset();
131
-
132
-    /*!
133
-     * \brief Sets the X rotation delta
134
-     * \param angle thetas rotation delta in degrees
135
-     */
136
-    void setSensitivityX(float angle);
137
-
138
-    /*!
139
-     * \brief Sets the Y rotation delta
140
-     * \param angle thetas rotation delta in degrees
141
-     */
142
-    void setSensitivityY(float angle);
143
-
144
-    /*!
145
-     * \brief Sends interactive command to camera
146
-     * \param cmd valid camera command
147
-     */
148
-    void command(enum camera_command cmd);
149
-
150
-    /*!
151
-     * \brief Sets speed
152
-     * \param s new speed, is 256 or greater in general
153
-     */
154
-    void setSpeed(float s);
155
-
156
-    /*!
157
-     * \brief Updates view target
158
-     */
159
-    void update();
160
-
161
-    /*!
162
-     * \brief Set current position
163
-     * \param pos new position
164
-     */
165
-    void setPosition(vec3_t pos);
166
-
167
-    /*!
168
-     * \brief Sets the up vector
169
-     * \param up new up vector
170
-     */
171
-    void setUp(vec3_t up);
172
-
173
-    /*!
174
-     * \brief Sets target (look at pos)
175
-     * \param target new target
176
-     */
177
-    void setTarget(vec3_t target);
178
-
179
-private:
180
-    Quaternion mQ;                //!< Quaternion for rotation
181
-    unsigned int mFlags;          //!< For testing with flags
182
-    vec_t mPos[4];                //!< Location in 3 space (aka eye)
183
-    vec_t mTarget[4];             //!< Postition we're looking at
184
-    vec_t mUp[4];                 //!< Up vector
185
-    vec_t mSide[4];               //!< Side vector
186
-    vec_t mViewDistance;          //!< Distance from target
187
-    vec_t mTranslateDelta;        //!< Step size to move
188
-    vec_t mRotateDelta;           //!< Radians to rotate Y
189
-    vec_t mTheta;                 //!< View angle Y
190
-    vec_t mRotateDelta2;          //!< Radians to rotate Z
191
-    vec_t mTheta2;                //!< View angle Z
192
-};
193
-
194
-#endif

+ 0
- 179
include/Emitter.h Переглянути файл

@@ -1,179 +0,0 @@
1
-/*!
2
- * \file include/Emitter.h
3
- * \brief Particle emitter class.
4
- *
5
- * \author Mongoose
6
- */
7
-
8
-#ifndef _EMITTER_H_
9
-#define _EMITTER_H_
10
-
11
-#include "Particle.h"
12
-
13
-/*!
14
- * \brief Particle emitter class.
15
- */
16
-class Emitter {
17
-public:
18
-
19
-    /*!
20
-     * \brief Flags an Emitter can have
21
-     */
22
-    typedef enum {
23
-        fUseFrustumCulling = (1 << 0), //!< Use frustum culling
24
-        fUseDepthSorting   = (1 << 1)  //!< Use depth sorting
25
-    } EmitterFlags;
26
-
27
-
28
-    /*!
29
-     * \brief Constructs an object of Emitter
30
-     * \param name valid C string
31
-     * \param n greater than 0
32
-     */
33
-    Emitter(const char *name, int n);
34
-
35
-    /*!
36
-     * \brief Deconstructs an object of Emitter
37
-     */
38
-    ~Emitter();
39
-
40
-    /*!
41
-     * \brief Get the particles
42
-     * \returns array of Particles
43
-     */
44
-    Particle *Particles();
45
-
46
-    /*!
47
-     * \brief Number of particles emitted
48
-     * \returns Number of particles emitted
49
-     */
50
-    int Count();
51
-
52
-    /*!
53
-     * \brief Sets position of emitter in 3D space
54
-     * \param x X coordinate
55
-     * \param y Y coordinate
56
-     * \param z Z coordinate
57
-     */
58
-    void Pos(float x, float y, float z);
59
-
60
-    /*!
61
-     * \brief Returns position of emitter in 3D space
62
-     * \param x Where X coordinate will be stored
63
-     * \param y Where Y coordinate will be stored
64
-     * \param z Where Z coordinate will be stored
65
-     */
66
-    void Pos(float *x, float *y, float *z);
67
-
68
-    /*!
69
-     * \brief Sets orientation of emitter in 3D space
70
-     * \param x X coordinate
71
-     * \param y Y coordinate
72
-     * \param z Z coordinate
73
-     */
74
-    void Orientation(float x, float y, float z);
75
-
76
-    /*!
77
-     * \brief Returns orientation of emitter in 3D space
78
-     * \param x Where X coordinate will be stored
79
-     * \param y Where Y coordinate will be stored
80
-     * \param z Where Z coordinate will be stored
81
-     */
82
-    void Orientation(float *x, float *y, float *z);
83
-
84
-    /*!
85
-     * \brief Get the flags of this Emitter
86
-     * \returns EmitterFlags
87
-     */
88
-    unsigned int Flags();
89
-
90
-    /*!
91
-     * \brief Set or Unset a flag
92
-     * \param flag EmitterFlag to change
93
-     * \param op new state (true - set)
94
-     */
95
-    void Flags(unsigned int flag, bool op);
96
-
97
-    /*!
98
-     * \brief Allocates the particle array and sets the count.
99
-     * If the array has been allocated previously it will be
100
-     * deallocated and a new one made.
101
-     * \param n new size, greater than 0
102
-     */
103
-    void ParticleArray(int n);
104
-
105
-    /*!
106
-     * \brief Renders the particles
107
-     */
108
-    void Draw();
109
-
110
-    /*!
111
-     * \brief Sets the emitters name
112
-     * \param name is a valid C string
113
-     */
114
-    void Name(const char *name);
115
-
116
-    /*!
117
-     * \brief Resets all particle texture ids
118
-     * \param id new id
119
-     * \sa Particle::TextureId()
120
-     */
121
-    void SetTextureId(int id);
122
-
123
-    /*!
124
-     * \brief Set the texture id for a range of particles in the array
125
-     * \param particle_start start of range
126
-     * \param particle_end end of range
127
-     * \param id new id
128
-     * \sa Particle::TextureId()
129
-     */
130
-    void TextureId(unsigned int particle_start, unsigned int particle_end, int id);
131
-
132
-    /*!
133
-     * \brief Set the color of a range of particles in the array
134
-     * \param particle_start start of range
135
-     * \param particle_end end of range
136
-     * \param r new red part of color (0.0 to 1.0)
137
-     * \param g new green part of color (0.0 to 1.0)
138
-     * \param b new blue part of color (0.0 to 1.0)
139
-     * \sa Particle::Color()
140
-     */
141
-    void Color(unsigned int particle_start, unsigned int particle_end, float r, float g, float b);
142
-
143
-    /*!
144
-     * \brief Set the speed of a range of particles in the array.
145
-     * Take note that the speed starts out at 2000, and lower means faster.
146
-     * \param particle_start start of range
147
-     * \param particle_end end of range
148
-     * \param x X speed
149
-     * \param y Y speed
150
-     * \param z Z speed
151
-     * \sa Particle::Speed
152
-     */
153
-    void Speed(unsigned int particle_start, unsigned int particle_end, float x, float y, float z);
154
-
155
-    /*!
156
-     * \brief Let a force (eg. Gravity) act on a range of particles in the array
157
-     * \param particle_start start of range
158
-     * \param particle_end end of range
159
-     * \param x X force
160
-     * \param y Y force
161
-     * \param z Z force
162
-     * \sa Particle::Force()
163
-     */
164
-    void Force(unsigned int particle_start, unsigned int particle_end, float x, float y, float z);
165
-
166
-    static vec_t mFrustum[6][4]; //!< View Volume copy
167
-
168
-private:
169
-    static int compareParticleDist(const void *voidA, const void *voidB);
170
-
171
-    char *_name;         //!< Emitter name
172
-    unsigned int _flags; //!< Emitter flags
173
-    vec3_t _pos;         //!< Position in 3D space
174
-    vec3_t _mangle;      //!< Oreintation in 3D space
175
-    Particle *_particle; //!< Array of particles
176
-    unsigned int _count; //!< Particle count
177
-};
178
-
179
-#endif

+ 0
- 116
include/GLString.h Переглянути файл

@@ -1,116 +0,0 @@
1
-/*!
2
- * \file include/GLString.h
3
- * \brief Open GL rendering font/string class
4
- *
5
- * \author Mongoose
6
- * \author xythobuz
7
- */
8
-
9
-#ifndef _GLSTRING_H_
10
-#define _GLSTRING_H_
11
-
12
-/*!
13
- * \brief Internal data structure representing GL Strings
14
- */
15
-typedef struct gl_string_s {
16
-    int x; //!< X Coordinate
17
-    int y; //!< Y Coordinate
18
-    float scale; //!< Scale factor
19
-    char *text; //!< Text buffer
20
-    bool active; //!< active state
21
-    unsigned short int len; //!< length
22
-} gl_string_t;
23
-
24
-/*!
25
- * \brief Open GL rendering font/string class
26
- */
27
-class GLString {
28
-public:
29
-
30
-    /*!
31
-     * \brief Constructs an object of GLString
32
-     */
33
-    GLString();
34
-
35
-    /*!
36
-     * \brief Deconstructs an object of GLString
37
-     */
38
-    ~GLString();
39
-
40
-    /*!
41
-     * \brief Set max number of strings
42
-     * \param max_strings maximum number of strings
43
-     */
44
-    void Init(unsigned int max_strings);
45
-
46
-    /*!
47
-     * \brief Sets a single byte in a string
48
-     * \param string valid gl string id
49
-     * \param pos position in that gl string to set
50
-     * \param c character to set in gl string
51
-     */
52
-    void SetChar(unsigned int string, unsigned int pos, char c);
53
-
54
-    /*!
55
-     * \brief Gets number of bytes in a string buffer
56
-     * \param string valid gl string id
57
-     * \returns length/number of bytes of string
58
-     */
59
-    unsigned int GetStringLen(unsigned int string);
60
-
61
-    /*!
62
-     * \brief Returns string buffer
63
-     * \param string valid gl string id
64
-     * \returns pointer to string buffer
65
-     */
66
-    char *GetBuffer(unsigned int string);
67
-
68
-
69
-    void setActive(unsigned int string, bool active);
70
-
71
-    /*!
72
-     * \brief Sets text in a string.
73
-     * It will be truncated as needed to fit
74
-     * \param string valid string id
75
-     * \param s format string and args like for printf
76
-     */
77
-    void SetString(unsigned int string, const char *s, ...) __attribute__((format(printf, 3, 4)));
78
-
79
-    /*!
80
-     * \brief Sets default text scaling
81
-     * \param scale new scale factor > 0.0
82
-     */
83
-    void Scale(float scale);
84
-
85
-    /*!
86
-     * \brief Generates a new string and renders it to the gl target
87
-     * \param x valid X screen coordinate
88
-     * \param y valid Y screen coordinate
89
-     * \param string valid format string with args like for printf
90
-     * \returns 0 on success, -1 on invalid string, -2 on full string list
91
-     */
92
-    int glPrintf(int x, int y, const char *string, ...) __attribute__((format(printf, 4, 5)));
93
-
94
-    /*!
95
-     * \brief Renders strings over GL scene.
96
-     * Should be called after scene is rendered.
97
-     * GL Culling should be disabled.
98
-     */
99
-    void Render();
100
-
101
-    /*!
102
-     * \brief Get the String data structure for a string id
103
-     * \param id valid string id
104
-     * \returns string for id, or NULL if it does not exist
105
-     */
106
-    gl_string_t *GetString(unsigned int id);
107
-
108
-
109
-private:
110
-    unsigned int _num_string_max; //!< Max number of strings buffered
111
-    unsigned int _num_string; //!< Current number of strings buffered
112
-    gl_string_t *_string; //!< Buffered strings and their properities
113
-    float _scale; //!< Default scale factor for new strings
114
-};
115
-
116
-#endif

+ 0
- 201
include/Matrix.h Переглянути файл

@@ -1,201 +0,0 @@
1
-/*!
2
- * \file include/Matrix.h
3
- * \brief 3D Matrix
4
- *
5
- * \author Mongoose
6
- */
7
-
8
-#ifndef _MATRIX_H_
9
-#define _MATRIX_H_
10
-
11
-#include "utils/math.h"
12
-#include "Quaternion.h"
13
-#include "Vector3d.h"
14
-
15
-
16
-/*!
17
- * \brief 3D Matrix
18
- *
19
- * Multidim map for row order encoding
20
- *
21
- *     ///////////////////////////////////////////////
22
- *     // 0,0 - 0;   0,1 - 1;   0,2 - 2;   0,3 - 3  //
23
- *     // 1,0 - 4;   1,1 - 5;   1,2 - 6;   1,3 - 7  //
24
- *     // 2,0 - 8;   2,1 - 9;   2,2 - 10;  2,3 - 11 //
25
- *     // 3,0 - 12;  3,1 - 13;  3,2 - 14;  3,3 - 15 //
26
- *     ///////////////////////////////////////////////
27
- *
28
- * Multidim map for column order encoding
29
- *
30
- *     ///////////////////////////////////////////////
31
- *     // 0,0 - 0;   0,1 - 4;   0,2 - 8;   0,3 - 12 //
32
- *     // 1,0 - 1;   1,1 - 5;   1,2 - 9;   1,3 - 13 //
33
- *     // 2,0 - 2;   2,1 - 6;   2,2 - 10;  2,3 - 14 //
34
- *     // 3,0 - 3;   3,1 - 7;   3,2 - 11;  3,3 - 15 //
35
- *     ///////////////////////////////////////////////
36
- */
37
-class Matrix {
38
-public:
39
-
40
-    /*!
41
-     * \brief Constructs an object of Matrix
42
-     */
43
-    Matrix();
44
-
45
-    /*!
46
-     * \brief Constructs an object of Matrix
47
-     * \param mat Matrix as data source
48
-     */
49
-    Matrix(matrix_t mat);
50
-
51
-    /*!
52
-     * \brief Constructs an object of Matrix
53
-     * \param q Converts and assigns the Quaternion to the Matrix
54
-     */
55
-    Matrix(Quaternion &q);
56
-
57
-    /*!
58
-     * \brief Returns this matrix copy
59
-     * \param mat target
60
-     */
61
-    void getMatrix(matrix_t mat);
62
-
63
-    /*!
64
-     * \brief Returns this matrix transposed
65
-     * \param mat target
66
-     */
67
-    void getTransposeMatrix(matrix_t mat);
68
-
69
-    /*!
70
-     * \brief Returns this matrix inverted
71
-     * \param mat target
72
-     */
73
-    bool getInvert(matrix_t mat);
74
-
75
-    /*!
76
-     * \brief Multiplies two matrices
77
-     * \param a first matrix
78
-     * \param b second matrix
79
-     * \returns resultant matrix
80
-     */
81
-    static Matrix multiply(const Matrix &a, const Matrix &b);
82
-
83
-    /*!
84
-     * \brief Multiplies v vector and this matrix
85
-     * \param v vector
86
-     * \param result where the result will be stored, may be same as v
87
-     */
88
-    void multiply4v(vec4_t v, vec4_t result);
89
-
90
-    /*!
91
-     * \brief Multiplies v vector and this matrix
92
-     * \param v vector
93
-     * \param result where the result will be stored, may be same as v
94
-     */
95
-    void multiply3v(vec3_t v, vec3_t result);
96
-
97
-    /*!
98
-     * \brief Prints matrix values to stdout
99
-     */
100
-    void print();
101
-
102
-    /*!
103
-     * \brief Is this matrix the identity matrix?
104
-     * \returns true if it is identity, false otherwise
105
-     */
106
-    bool isIdentity();
107
-
108
-    /*!
109
-     * \brief Multiplies a and this matrix
110
-     * \param a matrix to multiply with
111
-     * \returns resultant matrix
112
-     */
113
-    Matrix operator *(const Matrix &a);
114
-
115
-    /*!
116
-     * \brief Multiply vector by this matrix
117
-     * \param v Vector to multiply with
118
-     * \returns resultant vector (mult)
119
-     */
120
-    Vector3d operator *(Vector3d v);
121
-
122
-    /*!
123
-     * \brief Sets to identity matrix
124
-     */
125
-    void setIdentity();
126
-
127
-    /*!
128
-     * \brief S et the matrix
129
-     * \fixme dangerous, scary, boo!
130
-     * \param mat new matrix
131
-     */
132
-    void setMatrix(matrix_t mat);
133
-
134
-    /*!
135
-     * \brief Rotate object in 3D space
136
-     * \param x x rotation in radians
137
-     * \param y y rotation in radians
138
-     * \param z z rotation in radians
139
-     */
140
-    void rotate(vec_t x, vec_t y, vec_t z);
141
-
142
-    /*!
143
-     * \brief Rotate object in 3D space
144
-     * \param xyz rotation in radians
145
-     */
146
-    void rotate(const vec_t *xyz);
147
-
148
-    /*!
149
-     * \brief Scale object in 3D space
150
-     * \param x x scaling
151
-     * \param y y scaling
152
-     * \param z z scaling
153
-     */
154
-    void scale(vec_t x, vec_t y, vec_t z);
155
-
156
-    /*!
157
-     * \brief Scale object in 3D space
158
-     * \param xyz scaling factors
159
-     */
160
-    void scale(const vec_t *xyz);
161
-
162
-    /*!
163
-     * \brief Translate (move) object in 3D space
164
-     * \param x x translation
165
-     * \param y y translation
166
-     * \param z z translation
167
-     */
168
-    void translate(vec_t x, vec_t y, vec_t z);
169
-
170
-    /*!
171
-     * \brief Translate (move) object in 3D space
172
-     * \param xyz translations
173
-     */
174
-    void translate(const vec_t *xyz);
175
-
176
-    /*!
177
-     * \brief Transpose this matrix
178
-     */
179
-    void transpose();
180
-
181
-    matrix_t mMatrix; //!< Data model, moved public for faster external renderer feedback use
182
-
183
-private:
184
-
185
-    /*!
186
-     * \brief Copys value from source to dest
187
-     * \param source source
188
-     * \param dest destination
189
-     */
190
-    static void copy(matrix_t source, matrix_t dest);
191
-
192
-    /*!
193
-     * \brief Multiplies matrices a and b. Neither a or b is also the result.
194
-     * \param a first matrix
195
-     * \param b second matrix
196
-     * \param result wil be set to resultant matrix value
197
-     */
198
-    static void multiply(const matrix_t a, const matrix_t b, matrix_t result);
199
-};
200
-
201
-#endif

+ 0
- 169
include/Mesh.h Переглянути файл

@@ -1,169 +0,0 @@
1
-/*!
2
- * \file include/Mesh.h
3
- * \brief OpenGL Mesh
4
- *
5
- * \author Mongoose
6
- *
7
- * \todo Unify the parallel systems here, arrays and the allocate/set
8
- */
9
-
10
-#ifndef _OPENGLMESH_H_
11
-#define _OPENGLMESH_H_
12
-
13
-#include "utils/math.h"
14
-
15
-/*!
16
- * \brief OpenGL Mesh
17
- */
18
-class Mesh {
19
-public:
20
-
21
-    typedef enum {
22
-        MeshModeSolid,
23
-        MeshModeWireframe,
24
-        MeshModeTexture,
25
-        MeshModeMultiTexture
26
-    } MeshMode;
27
-
28
-    typedef enum {
29
-        fMesh_UseVertexArray = (1 << 0)
30
-    } MeshFlags;
31
-
32
-    typedef struct {
33
-        int texture;
34
-#ifdef MULTITEXTURE
35
-        int bumpmap;
36
-#endif
37
-
38
-        unsigned int cnum_triangles;
39
-        unsigned int cnum_alpha_triangles;
40
-
41
-        unsigned int num_texcoors;
42
-        vec2_t *texcoors;
43
-
44
-        unsigned int num_texcoors2;
45
-        vec2_t *texcoors2;
46
-
47
-        //! Arrays of triangle indices sorted by texture
48
-        unsigned int num_triangles;
49
-        unsigned int *triangles; //!< ABCABCABC...
50
-
51
-        //! Arrays of alpha triangle indices sorted by texture
52
-        unsigned int num_alpha_triangles;
53
-        unsigned int *alpha_triangles; //!< ABCABCABC...
54
-    } tris_t;
55
-
56
-    typedef struct {
57
-
58
-        int texture;
59
-#ifdef MULTITEXTURE
60
-        int bumpmap;
61
-#endif
62
-
63
-        unsigned int cnum_quads;
64
-        unsigned int cnum_alpha_quads;
65
-
66
-        unsigned int num_texcoors;
67
-        vec2_t *texcoors;
68
-
69
-        unsigned int num_texcoors2;
70
-        vec2_t *texcoors2;
71
-
72
-        //! Arrays of rectangle indices sorted by texture
73
-        unsigned int num_quads;
74
-        unsigned int *quads; //!< ABCDABCDABCD...
75
-
76
-        //! Arrays of alpha rectangle indices sorted by texture
77
-        unsigned int num_alpha_quads;
78
-        unsigned int *alpha_quads; //!< ABCDABCDABCD...
79
-
80
-    } rect_t;
81
-
82
-    /*!
83
-     * \brief Constructs an object of Mesh
84
-     */
85
-    Mesh();
86
-
87
-    /*!
88
-     * \brief Deconstructs an object of Mesh
89
-     */
90
-    ~Mesh();
91
-
92
-    void drawAlpha();
93
-
94
-    void drawSolid();
95
-
96
-    void allocateColors(unsigned int n);
97
-
98
-    void allocateNormals(unsigned int n);
99
-
100
-    void allocateRectangles(unsigned int n);
101
-
102
-    void allocateTriangles(unsigned int n);
103
-
104
-    void allocateVertices(unsigned int n);
105
-
106
-    void bufferColorArray(unsigned int colorCount, vec_t *colors);
107
-
108
-    void bufferNormalArray(unsigned int normalCount, vec_t *normals);
109
-
110
-    void bufferTriangles(unsigned int count,
111
-                            unsigned int *indices, vec_t *texCoords,
112
-                            int *textures, unsigned int *flags);
113
-
114
-    void bufferVertexArray(unsigned int vertexCount, vec_t *vertices);
115
-
116
-    void setColor(unsigned int index, float r, float g, float b, float a);
117
-
118
-    void setColor(unsigned int index, float rgba[4]);
119
-
120
-    void setNormal(unsigned int index, float i, float j, float k);
121
-
122
-    void setVertex(unsigned int index, float x, float y, float z);
123
-
124
-#ifdef NOT_IMPLEMENTED
125
-    void sortFacesByTexture();
126
-
127
-    void addFace(int textureIndex, int textureIndexB, unsigned int flags,
128
-                    unsigned int vertexIndexCount, vec_t *vertexIndices);
129
-
130
-    void addTexTiledFace(int textureIndex, int textureIndexB,
131
-                            unsigned int flags, unsigned int indexCount,
132
-                            vec_t *vertexIndices, vec_t *texcoords);
133
-
134
-    void bufferTexcoords(unsigned int texcoordCount, vec_t *texcoords);
135
-
136
-    void duplicateArraysForTexTiledTexcoords();
137
-#endif
138
-
139
-    unsigned int mFlags;
140
-
141
-    MeshMode mMode;
142
-
143
-    unsigned int mNumVertices;
144
-    vec3_t *mVertices; //!< XYZ
145
-
146
-    unsigned int mNumNormals;
147
-    vec3_t *mNormals; //!< IJK
148
-
149
-    unsigned int mNumColors;
150
-    vec4_t *mColors; //!< RGBA
151
-
152
-    unsigned int mNumTris;
153
-    tris_t *mTris;
154
-
155
-    unsigned int mNumQuads;
156
-    rect_t *mQuads;
157
-
158
-    unsigned int mTriangleCount;
159
-    int *mTriangleTextures;
160
-    unsigned int *mTriangleIndices;
161
-    unsigned int *mTriangleFlags;
162
-    vec_t *mTriangleTexCoordArray;
163
-
164
-    vec_t *mVertexArray;
165
-    vec_t *mNormalArray;
166
-    vec_t *mColorArray;
167
-};
168
-
169
-#endif

+ 0
- 236
include/OpenRaider.h Переглянути файл

@@ -1,236 +0,0 @@
1
-/*!
2
- * \file include/OpenRaider.h
3
- * \brief Main Game Singleton
4
- *
5
- * \author Mongoose
6
- */
7
-
8
-#ifndef _OPENRAIDER_H_
9
-#define _OPENRAIDER_H_
10
-
11
-#include <map>
12
-
13
-#include "Config.h"
14
-#include "TombRaider.h"
15
-#include "Camera.h"
16
-#include "Render.h"
17
-#include "Sound.h"
18
-#include "SDLSystem.h"
19
-#include "World.h"
20
-#include "templates/List.h"
21
-#include "templates/Vector.h"
22
-#include "utils/strings.h"
23
-
24
-/*!
25
- * \brief OpenRaider key events.
26
- *
27
- * 0 event reserved for console in System.
28
- */
29
-typedef enum {
30
-    OpenRaiderKey_console = 1, //!< Toggle console
31
-    OpenRaiderKey_attack,      //!< Attack
32
-    OpenRaiderKey_forward,     //!< Move forward
33
-    OpenRaiderKey_left,        //!< Move left
34
-    OpenRaiderKey_right,       //!< Move right
35
-    OpenRaiderKey_backward,    //!< Move backward
36
-    OpenRaiderKey_jump,        //!< Jump
37
-    OpenRaiderKey_tiltUp,      //!< Tilt camera up
38
-    OpenRaiderKey_tiltDown,    //!< Tilt camera down
39
-    OpenRaiderKey_panLeft,     //!< Pan camera left
40
-    OpenRaiderKey_panRight,    //!< Pan camera right
41
-    OpenRaiderKey_crouch       //!< Crouch
42
-} OpenRaider_KeyEvent;
43
-
44
-typedef enum {
45
-    OpenRaider_ShowFPS     = (1 << 0),
46
-    OpenRaider_DebugMap    = (1 << 1),
47
-    OpenRaider_DebugModel  = (1 << 2),
48
-    OpenRaider_EnableSound = (1 << 3),
49
-    OpenRaider_DumpTexture = (1 << 4), //!< \fixme Not used!
50
-    OpenRaider_Loading     = (1 << 5)
51
-} OpenRaider_Flags;
52
-
53
-/*!
54
- * \brief Main Game Singleton
55
- */
56
-class OpenRaider : public SDLSystem {
57
-public:
58
-
59
-    /*!
60
-     * \brief Constructs or returns the OpenRaider Singleton
61
-     * \returns OpenRaider Singleton
62
-     */
63
-    static OpenRaider *Instance();
64
-
65
-    /*!
66
-     * \brief Deconstructs an object of OpenRaider
67
-     */
68
-    ~OpenRaider();
69
-
70
-    /*!
71
-     * \brief Initialize the Game
72
-     */
73
-    void start();
74
-
75
-    /*!
76
-     * \brief Resizes game window and updated renderer
77
-     * \param width new width
78
-     * \param height new height
79
-     */
80
-    virtual void resize(unsigned int width, unsigned int height);
81
-
82
-    /*!
83
-     * \brief Mouse motion input
84
-     * \param x relative x motion
85
-     * \param y relative y motion
86
-     */
87
-    void handleMouseMotionEvent(float x, float y);
88
-
89
-    /*!
90
-     * \brief Receives `Event` bound to `Cmd` from `Key` press
91
-     * \param key valid keyboard code
92
-     */
93
-    void handleBoundKeyPressEvent(unsigned int key);
94
-
95
-    /*!
96
-     * \brief Receives `Event` bound to `Cmd` from `Key` release
97
-     * \param key valid keyboard code
98
-     */
99
-    void handleBoundKeyReleaseEvent(unsigned int key);
100
-
101
-    /*!
102
-     * \brief Executes valid command based on keyword
103
-     * \param command valid keyword optionally followed by space separated arguments
104
-     * \param mode current type or resource mode
105
-     */
106
-    void handleCommand(char *command, unsigned int mode);
107
-
108
-    /*!
109
-     * \brief Receives `Key` code from text input in console mode
110
-     * \param key valid keyboard code
111
-     * \param mod valid modifier code
112
-     */
113
-    void handleConsoleKeyPressEvent(unsigned int key, unsigned int mod);
114
-
115
-    /*!
116
-     * \brief Executes command associated with key press, if any
117
-     * \param key valid keyboard code
118
-     * \param mod valid modifier code
119
-     */
120
-    void handleKeyPressEvent(unsigned int key, unsigned int mod);
121
-
122
-    /*!
123
-     * \brief Executes command associated with key release, if any
124
-     * \param key valid keyboard code
125
-     * \param mod valid modifier code
126
-     */
127
-    void handleKeyReleaseEvent(unsigned int key, unsigned int mod);
128
-
129
-    /*!
130
-     * \brief Pass a time frame and render a new frame
131
-     */
132
-    void gameFrame();
133
-
134
-    /*!
135
-     * \brief Outputs message in game console
136
-     * \param dump_stdout if true, also print to stdout
137
-     * \param format printf() style format string
138
-     */
139
-    void print(bool dump_stdout, const char *format, ...) __attribute__((format(printf, 3, 4)));
140
-
141
-protected:
142
-
143
-    /*!
144
-     * \brief Constructs an object of OpenRaider
145
-     */
146
-    OpenRaider();
147
-
148
-private:
149
-
150
-    void consoleCommand(char *cmd);
151
-
152
-    void soundEvent(int type, int id, vec3_t pos, vec3_t angles);
153
-
154
-    //void entityEvent(entity_t &e, RaiderEvent event);
155
-
156
-    void processPakSounds();
157
-
158
-    /*!
159
-     * \brief Loads and positions level sounds and music.
160
-     *
161
-     * Sound system has to be initialized.
162
-     */
163
-    void initSound();
164
-
165
-    /*!
166
-     * \brief Generates textures or mipmaps for fonts, splash,
167
-     * external particles.
168
-     */
169
-    void initTextures();
170
-
171
-    /*!
172
-     * \brief Generates tombraider textures or mipmaps for sprites,
173
-     * rooms and models.
174
-     */
175
-    void processTextures();
176
-
177
-    /*!
178
-     * \brief Generates render sprite sequences
179
-     */
180
-    void processSprites();
181
-
182
-    void processMoveables();
183
-
184
-    void processMoveable(int index, int i, int *ent, List <skeletal_model_t *> &cache2, List <unsigned int> &cache, int object_id);
185
-
186
-    /*!
187
-     * \brief Generates render mesh and any textures needed
188
-     * for the specified model.
189
-     * \param index valid model index
190
-     */
191
-    void processModel(int index);
192
-
193
-    /*!
194
-     * \brief Generates render mesh and any textures needed
195
-     * for the specified room
196
-     * \param index valid room index
197
-     */
198
-    void processRoom(int index);
199
-
200
-    /*!
201
-     * \brief Loads validated level pak from diskfile using maplist
202
-     * \param filename level pak file name
203
-     */
204
-    void loadLevel(char *filename);
205
-
206
-    void loadPakFolderRecursive(const char *dir);
207
-
208
-    void menuMapListMove(char dir, bool show);
209
-
210
-    static OpenRaider *mInstance; //!< Singleton use
211
-    TombRaider m_tombraider;      //!< Tombraider data support
212
-    Sound mSound;                 //!< 3d Audio support
213
-    Render m_render;              //!< Rendering support
214
-    Camera m_camera;              //!< Client camera support
215
-    GLString *mText;              //!< Hook to textbox like output
216
-
217
-    // RC vars
218
-
219
-    unsigned int mMode[8];            //!< Translate System's mode ids to OR's
220
-    unsigned int m_flags;             //!< Set options by flags
221
-    int m_testSFX;                    //!< Used for mixed channel sound tests
222
-    float m_mouseX, m_mouseY;         //!< XY axis rotation deltas
223
-    unsigned int m_texOffset;         //!< Offset of TombRaider textures in list
224
-    unsigned int mLevelTextureOffset;
225
-
226
-    // Game vars
227
-
228
-    Vector <char *> mMusicList;  //!< List of game level music
229
-    Vector <char *> mMapList;    //!< List of game maps
230
-    char m_mapName[32];          //!< Current map filename
231
-    char *m_pakDir;              //!< Current pak directory
232
-    char *m_audioDir;            //!< Current audio directory
233
-    char *m_homeDir;             //!< Current home directory
234
-};
235
-
236
-#endif

+ 0
- 119
include/Particle.h Переглянути файл

@@ -1,119 +0,0 @@
1
-/*!
2
- * \file include/Particle.h
3
- * \brief Particle system base header
4
- *
5
- * \author Mongoose
6
- */
7
-
8
-#ifndef _PARTICLE_H_
9
-#define _PARTICLE_H_
10
-
11
-#include "utils/math.h"
12
-
13
-/*!
14
- * \brief Partcle systems atomic base
15
- */
16
-class Particle {
17
-public:
18
-
19
-    /*!
20
-     * \brief Constructs an object of Sound
21
-     */
22
-    Particle();
23
-
24
-    /*!
25
-     * \brief Toggles active state of particle
26
-     * \param active new state
27
-     */
28
-    void setActive(bool active);
29
-
30
-    /*!
31
-     * \brief Sets gravity/force acting on particle
32
-     * \param x X part of force vector
33
-     * \param y Y part
34
-     * \param z Z part
35
-     */
36
-    void Force(float x, float y, float z);
37
-
38
-    /*!
39
-     * \brief Resets particle to defaults
40
-     */
41
-    void Reset();
42
-
43
-    /*!
44
-     * \brief Sets gravity/force acting on particle
45
-     * \note speed inits at 2000, lower is faster
46
-     * \param x X part of speed vector
47
-     * \param y Y part
48
-     * \param z Z part
49
-     */
50
-    void Speed(float x, float y, float z);
51
-
52
-    /*!
53
-     * \brief Sets new particle coloring
54
-     * \note White {1.0, 1.0, 1.0} is the init color
55
-     * \param r Red part, from 0.0 to 1.0
56
-     * \param g Green part, from 0.0 to 1.0
57
-     * \param b Blue part, from 0.0 to 1.0
58
-     */
59
-    void Color(float r, float g, float b);
60
-
61
-    /*!
62
-     * \brief Returns position of particle in 3 space
63
-     * \param x not NULL!
64
-     * \param y not NULL!
65
-     * \param z not NULL!
66
-     */
67
-    void Pos(float *x, float *y, float *z);
68
-
69
-    /*!
70
-     * \brief Returns current color of particle
71
-     * \param r not NULL!
72
-     * \param g not NULL!
73
-     * \param b not NULL!
74
-     */
75
-    void Color(float *r, float *g, float *b);
76
-
77
-    /*!
78
-     * \brief Returns current life (blend) of particle
79
-     * \returns fade of particle
80
-     */
81
-    float Life();
82
-
83
-    /*!
84
-     * \brief Adjusts for particle life cycle
85
-     */
86
-    void Update();
87
-
88
-    /*!
89
-     * \brief Returns texture binding for this particle
90
-     * \returns texture id
91
-     */
92
-    int Texture();
93
-
94
-    /*!
95
-     * \brief Returns active value
96
-     * \returns state
97
-     */
98
-    bool isActive();
99
-
100
-    /*!
101
-     * \brief Set the texture for this particle
102
-     * \param t new texture id
103
-     */
104
-    void TextureId(int t);
105
-
106
-
107
-private:
108
-    bool _active;  //!< Is this particle in use?
109
-    float _life;   //!< Life of particle
110
-    float _blend;  //!< Blend amount or fade
111
-    int _texture;  //!< Texture polygon to use
112
-    vec3_t _pos;   //!< Current position in 3 space
113
-    vec3_t _color; //!< Current color
114
-    vec3_t _dir;   //!< Current direction
115
-    vec3_t _force; //!< Current force or 'gravity'
116
-    vec3_t _speed; //!< Speed of particle movement
117
-};
118
-
119
-#endif

+ 0
- 201
include/Quaternion.h Переглянути файл

@@ -1,201 +0,0 @@
1
-/*!
2
- * \file include/Quaternion.h
3
- * \brief Quaternion
4
- *
5
- * \author Mongoose
6
- */
7
-
8
-#ifndef _QUATERNION_H_
9
-#define _QUATERNION_H_
10
-
11
-#include "utils/math.h"
12
-
13
-/*!
14
- * \brief Quaternion
15
- */
16
-class Quaternion {
17
-public:
18
-
19
-    /*!
20
-     * \brief Constructs an object of Quaternion
21
-     */
22
-    Quaternion();
23
-
24
-    /*!
25
-     * \brief Constructs an object of Quaternion
26
-     * \param w W part of new Quaternion
27
-     * \param x X part of new Quaternion
28
-     * \param y Y part of new Quaternion
29
-     * \param z Z part of new Quaternion
30
-     */
31
-    Quaternion(vec_t w, vec_t x, vec_t y, vec_t z);
32
-
33
-    /*!
34
-     * \brief Constructs an object of Quaternion
35
-     * \param v contents of new Quaternion
36
-     */
37
-    Quaternion(vec4_t v);
38
-
39
-    /*!
40
-     * \brief Get column order matrix equivalent of this quaternion
41
-     * \param m where matrix will be stored
42
-     */
43
-    void getMatrix(matrix_t m);
44
-
45
-    /*!
46
-     * \brief Multiplies this quaternion.
47
-     *
48
-     * Use normalize() call for unit quaternion.
49
-     *
50
-     * \param q what to multiply this quaternion with
51
-     * \returns resultant quaternion
52
-     * \sa Quaternion::normalize()
53
-     */
54
-    Quaternion operator *(const Quaternion &q);
55
-
56
-    /*!
57
-     * \brief Divide from this quaternion
58
-     * \param q what to divide from this quaternion
59
-     * \returns resultant quaternion
60
-     */
61
-    Quaternion operator /(const Quaternion &q);
62
-
63
-    /*!
64
-     * \brief Add to this quaternion
65
-     * \param q what to add to this quaternion
66
-     * \returns resultant quaternion
67
-     */
68
-    Quaternion operator +(const Quaternion &q);
69
-
70
-    /*!
71
-     * \brief Subtract from this quaternion
72
-     * \param q what to subtract from this quaternion
73
-     * \returns resultant quaternion
74
-     */
75
-    Quaternion operator -(const Quaternion &q);
76
-
77
-    /*!
78
-     * \brief Compares q to this quaternion
79
-     * \param q what to compare this quaternion to
80
-     * \returns true if equal, false otherwise
81
-     */
82
-    bool operator ==(const Quaternion &q);
83
-
84
-    /*!
85
-     * \brief Conjugate this quaternion
86
-     * \returns Conjugate of this quaternion
87
-     */
88
-    Quaternion conjugate();
89
-
90
-    /*!
91
-     * \brief Scale this quaternion
92
-     * \param s scaling factor
93
-     * \returns Scaled result of this quaternion
94
-     */
95
-    Quaternion scale(vec_t s);
96
-
97
-    /*!
98
-     * \brief Inverse this quaternion
99
-     * \returns inverse of this quaternion
100
-     */
101
-    Quaternion inverse();
102
-
103
-    /*!
104
-     * \brief Dot Product of quaternions
105
-     * \param a first argument to dot product
106
-     * \param b second argument to dot product
107
-     * \returns dot product between a and b quaternions
108
-     */
109
-    static vec_t dot(Quaternion a, Quaternion b);
110
-
111
-    /*!
112
-     * \brief Magnitude of this quaternion
113
-     * \returns Magnitude of this quaternion
114
-     */
115
-    vec_t magnitude();
116
-
117
-    /*!
118
-     * \brief Interpolates between a and b rotations.
119
-     *
120
-     * Using spherical linear interpolation:
121
-     * `I = (((B . A)^-1)^Time)A`
122
-     *
123
-     * \param a first argument for slerp
124
-     * \param b second argument for slerp
125
-     * \param time time argument for slerp
126
-     * \returns resultant quaternion
127
-     */
128
-    static Quaternion slerp(Quaternion a, Quaternion b, vec_t time);
129
-
130
-    /*!
131
-     * \brief Sets this quaternion to identity
132
-     */
133
-    void setIdentity();
134
-
135
-    /*!
136
-     * \brief Sets this quaternion
137
-     * \param angle new angle
138
-     * \param x new X coordinate
139
-     * \param y new Y coordinate
140
-     * \param z new Z coordinate
141
-     */
142
-    void set(vec_t angle, vec_t x, vec_t y, vec_t z);
143
-
144
-    /*!
145
-     * \brief Normalize this quaternion
146
-     */
147
-    void normalize();
148
-
149
-    /*!
150
-     * \brief Set this quaternion
151
-     * \param q will be copied into this quaternion
152
-     */
153
-    void copy(Quaternion q);
154
-
155
-    /*!
156
-     * \brief Sets matrix equivalent of this quaternion
157
-     * \param m matrix in valid column order
158
-     */
159
-    void setByMatrix(matrix_t m);
160
-
161
-private:
162
-
163
-    /*!
164
-     * \brief Multiplies two quaternions
165
-     * \param a first argument to multiplication
166
-     * \param b second argument to multiplication
167
-     * \returns resultant quaternion
168
-     */
169
-    static Quaternion multiply(Quaternion a, Quaternion b);
170
-
171
-    /*!
172
-     * \brief Divides B from A quaternion
173
-     * \param a first argument to division
174
-     * \param b second argument to division
175
-     * \returns quotient quaternion
176
-     */
177
-    static Quaternion divide(Quaternion a, Quaternion b);
178
-
179
-    /*!
180
-     * \brief Adds A and B quaternions
181
-     * \param a first argument to addition
182
-     * \param b second argument to addition
183
-     * \returns resultant quaternion
184
-     */
185
-    static Quaternion add(Quaternion a, Quaternion b);
186
-
187
-    /*!
188
-     * \brief Subtracts B from A quaternion
189
-     * \param a first argument to subtraction
190
-     * \param b second argument to subtraction
191
-     * \returns resultant quaternion
192
-     */
193
-    static Quaternion subtract(Quaternion a, Quaternion b);
194
-
195
-    vec_t mW; //!< Quaternion, W part
196
-    vec_t mX; //!< Quaternion, X part
197
-    vec_t mY; //!< Quaternion, Y part
198
-    vec_t mZ; //!< Quaternion, Z part
199
-};
200
-
201
-#endif

+ 0
- 371
include/Render.h Переглянути файл

@@ -1,371 +0,0 @@
1
-/*!
2
- * \file include/Render.h
3
- * \brief OpenRaider Renderer class
4
- *
5
- * \author Mongoose
6
- */
7
-
8
-#ifndef _RENDER_H_
9
-#define _RENDER_H_
10
-
11
-#include "Config.h"
12
-#include "Matrix.h"
13
-#include "ViewVolume.h"
14
-#include "World.h"
15
-#include "SkeletalModel.h"
16
-#include "Mesh.h"
17
-#include "Texture.h"
18
-#include "Camera.h"
19
-#include "GLString.h"
20
-#include "templates/Vector.h"
21
-
22
-#ifdef USING_EMITTER
23
-#include "Emitter.h"
24
-#endif
25
-
26
-/*!
27
- * \brief The GL light class
28
- */
29
-class Light {
30
-public:
31
-    /*!
32
-     * \brief Type a light can be of
33
-     */
34
-    typedef enum {
35
-        typePoint       = 1, //!< Point light
36
-        typeSpot        = 2, //!< Spot light
37
-        typeDirectional = 3  //!< Directional light
38
-    } LightType;
39
-
40
-    vec4_t mPos; //! Light position in 3 space
41
-    vec3_t mDir; //! Light direction
42
-    float mAtt;
43
-    vec4_t mColor; //! Color of light
44
-    vec_t mCutoff; //! Fade out distance
45
-    LightType mType; //! Type of light
46
-};
47
-
48
-/*!
49
- * \brief RenderRoom used by Renderer
50
- */
51
-class RenderRoom {
52
-public:
53
-
54
-    /*!
55
-     * \brief Constructs an object of RenderRoom
56
-     */
57
-    RenderRoom() {
58
-        room = 0x0;
59
-        dist = 0.0f;
60
-    }
61
-
62
-    /*!
63
-     * \brief Deconstructs an object of RenderRoom
64
-     */
65
-    ~RenderRoom() {
66
-        //! \fixme Hangs when erasing - might be shared pointers somewhere
67
-        //lights.erase();
68
-    }
69
-
70
-    vec_t dist;             //!< Distance to near plane, move to room?
71
-    Vector<Light *> lights; //!< List of lights in this room
72
-    Mesh mesh;              //!< OpenGL mesh that represents this room
73
-
74
-    //! \fixme very dangerous as allocated and used
75
-    room_mesh_t *room;      //!< Physical room stored in World
76
-};
77
-
78
-/*!
79
- * \brief OpenRaider Renderer class
80
- */
81
-class Render {
82
-public:
83
-
84
-    typedef enum {
85
-        modeDisabled,
86
-        modeLoadScreen,
87
-        modeVertexLight,
88
-        modeSolid,
89
-        modeWireframe,
90
-        modeTexture
91
-    } RenderMode;
92
-
93
-    typedef enum {
94
-        fParticles              = (1 << 0),
95
-        fPortals                = (1 << 1),
96
-        fRoomAlpha              = (1 << 2),
97
-        fViewModel              = (1 << 3),
98
-        fSprites                = (1 << 4),
99
-        fRoomModels             = (1 << 5),
100
-        fEntityModels           = (1 << 6),
101
-        fFog                    = (1 << 7),
102
-        fUsePortals             = (1 << 8),
103
-        fGL_Lights              = (1 << 9),
104
-        fOneRoom                = (1 << 10),
105
-        fRenderPonytail         = (1 << 11),
106
-        fMultiTexture           = (1 << 12),
107
-        fUpdateRoomListPerFrame = (1 << 13),
108
-        fAnimateAllModels       = (1 << 14),
109
-        fAllRooms               = (1 << 15)
110
-    } RenderFlags;
111
-
112
-    typedef enum {
113
-        roomMesh,
114
-        skeletalMesh
115
-    } RenderMeshType;
116
-
117
-    /*!
118
-     * \brief Constructs an object of Render
119
-     */
120
-    Render();
121
-
122
-    /*!
123
-     * \brief Deconstructs an object of Render
124
-     */
125
-    ~Render();
126
-
127
-    /*!
128
-     * \brief Makes a screenshot, writes to disk
129
-     * \param filenameBase basename of file to be written
130
-     */
131
-    void screenShot(char *filenameBase);
132
-
133
-    /*!
134
-     * \brief Gets current rendering mode
135
-     * \returns current RenderMode
136
-     * \fixme Don't return enum as int?!
137
-     */
138
-    int getMode();
139
-
140
-    void addRoom(RenderRoom *rRoom);
141
-
142
-    /*!
143
-     * \brief Starts and sets up OpenGL target
144
-     * \param width width of window
145
-     * \param height height of window
146
-     */
147
-    void Init(int width, int height);
148
-
149
-    /*!
150
-     * \brief Loads textures in a certain id slot
151
-     * \param image Image to load
152
-     * \param width width of image
153
-     * \param height height of image
154
-     * \param id id for texture
155
-     * \sa Texture::loadBufferSlot()
156
-     */
157
-    void loadTexture(unsigned char *image,
158
-                          unsigned int width, unsigned int height,
159
-                          unsigned int id);
160
-
161
-    /*!
162
-     * \brief Sets up textures for OpenRaider.
163
-     * \param textureDir Is valid and exists with textures
164
-     * \param numLoaded returns number of loaded textures and will update
165
-     * number of external textures loaded
166
-     * \param nextId will update next level texture id
167
-     */
168
-    void initTextures(char *textureDir, unsigned int *numLoaded,
169
-                            unsigned int *nextId);
170
-
171
-    /*!
172
-     * \brief Initializes Emitter.
173
-     *
174
-     * Emitter is set up for rendering with 2 textures in
175
-     * a overhead rain or snow like pattern.
176
-     * Textures have to be initialized!
177
-     * \param name valid C-String name
178
-     * \param size valid size
179
-     * \param snowTex1 valid first texture
180
-     * \param snowTex2 valid second texture
181
-     */
182
-    void initEmitter(const char *name, unsigned int size,
183
-                          unsigned int snowTex1, unsigned int snowTex2);
184
-
185
-    /*!
186
-     * Removes current world/entity/etc geometry
187
-     */
188
-    void ClearWorld();
189
-
190
-    /*!
191
-     * \brief Clears bitflags, changes state of renderer in some way
192
-     * \param flags RenderFlags to clear (ORed)
193
-     * \fixme use enum not integer as parameter?!
194
-     */
195
-    void clearFlags(unsigned int flags);
196
-
197
-    /*!
198
-     * \brief Sets bitflags, changes state of renderer in some way
199
-     * \param flags RenderFlags to set (ORed)
200
-     * \fixme use enum not integer as parameter?!
201
-     */
202
-    void setFlags(unsigned int flags);
203
-
204
-    void setMode(int n);
205
-
206
-    void Update(int width, int height);
207
-
208
-    /*!
209
-     * \brief Renders a single game frame
210
-     */
211
-    void Display();
212
-
213
-    void setSkyMesh(int index, bool rot);
214
-
215
-    void ViewModel(entity_t *ent, int index);
216
-
217
-    void RegisterCamera(Camera *camera);
218
-
219
-    /*!
220
-     * \brief Get the GL text output agent
221
-     * \returns Used GLString instance
222
-     */
223
-    GLString *GetString();
224
-
225
-    /*!
226
-     * \brief Renders load screen.
227
-     *
228
-     * Textures must be initialized.
229
-     * \fixme Should be private!
230
-     */
231
-    void drawLoadScreen();
232
-
233
-    void addSkeletalModel(SkeletalModel *mdl);
234
-
235
-    /*!
236
-     * \brief Show a texture for a second, for debugging
237
-     * \param textureId texture id to show
238
-     * \returns GL texture id on success, < 0 on error
239
-     */
240
-    int showTextureDebug(int textureId);
241
-
242
-private:
243
-
244
-    /*!
245
-     * \brief Check if a bounding box is in the View Volume
246
-     * \param bboxMin Start coordinates of a valid bounding box
247
-     * \param bboxMax End coordinates of a valid bounding box
248
-     * \returns true if bounding box is visible
249
-     */
250
-    bool isVisible(float bboxMin[3], float bboxMax[3]);
251
-
252
-    /*!
253
-     * \brief Check if a point is in the View Volume
254
-     * \param x X coordinate
255
-     * \param y Y coordinate
256
-     * \param z Z coordinate
257
-     * \returns true if point is visible
258
-     */
259
-    bool isVisible(float x, float y, float z);
260
-
261
-    /*!
262
-     * \brief Check if a sphere is in the View Volume
263
-     * \param x X coordinate of center of sphere
264
-     * \param y Y coordinate of center of sphere
265
-     * \param z Z coordinate of center of sphere
266
-     * \param radius radius of sphere
267
-     * \returns true if sphere is visible
268
-     */
269
-    bool isVisible(float x, float y, float z, float radius);
270
-
271
-    /*!
272
-     * \brief Build a visible room list starting at index
273
-     * \param index valid room index where to start the list
274
-     */
275
-    void newRoomRenderList(int index);
276
-
277
-    /*!
278
-     * \brief Build a visible room list starting from room and
279
-     * only considers its linked rooms and their linked rooms.
280
-     * \param room First room in list
281
-     */
282
-    void buildRoomRenderList(RenderRoom *room);
283
-
284
-    /*!
285
-     * \brief Renders visible world object.
286
-     *
287
-     * Texture must be initialized.
288
-     */
289
-    void drawObjects();
290
-
291
-    /*!
292
-     * \brief Renders Sky domes/boxes/etc by scaling factor.
293
-     *
294
-     * Texture must be initialized.
295
-     * \param scale correct scale for map size
296
-     */
297
-    void drawSkyMesh(float scale);
298
-
299
-    /*!
300
-     * \brief Renders a skeletal model.
301
-     *
302
-     * Texture must be initialized!
303
-     * \param model model to render
304
-     */
305
-    void drawModel(SkeletalModel *model);
306
-
307
-    /*!
308
-     * Renders a room in 2 seperate passes to handle alpha.
309
-     *
310
-     * Currently doesnt sort alpha but looks pretty good.
311
-     * Texture must be initialized.
312
-     * Draw all rooms with alpha false, then again with alpha true.
313
-     * \param rRoom room to render
314
-     * \param draw_alpha once false, once true
315
-     */
316
-    void drawRoom(RenderRoom *rRoom, bool draw_alpha);
317
-
318
-    /*!
319
-     * \brief Renders static room model.
320
-     *
321
-     * Texture must be initialized.
322
-     * \param mesh Static model to render
323
-     */
324
-    void drawRoomModel(static_model_t *mesh);
325
-
326
-    /*!
327
-     * \brief Renders a mesh.
328
-     *
329
-     * Texture must be initialized.
330
-     * \param r_mesh Mesh to render.
331
-     * \param type Must be object containing mesh
332
-     */
333
-    void drawModelMesh(model_mesh_t *r_mesh, RenderMeshType type);
334
-
335
-    /*!
336
-     * \brief Renders a sprite.
337
-     *
338
-     * Texture must be initialized.
339
-     * \param sprite sprite to render
340
-     */
341
-    void drawSprite(sprite_t *sprite);
342
-
343
-    /*!
344
-     * \brief Updates View Volume. Call once per render frame.
345
-     */
346
-    void updateViewVolume();
347
-
348
-    //! \fixme Let them eat cake...? O.o
349
-    void tmpRenderModelMesh(model_mesh_t *r_mesh, texture_tri_t *ttri);
350
-
351
-    Texture mTexture;                     //!< Texture subsystem
352
-    Camera *mCamera;                      //!< Camera subsystem
353
-    GLString mString;                     //!< GL Text subsystem
354
-    Vector<RenderRoom *> mRoomRenderList;
355
-    Vector<RenderRoom *> mRooms;
356
-    Vector<SkeletalModel *> mModels;
357
-    unsigned int mFlags;                  //!< Rendering flags
358
-    unsigned int mWidth;                  //!< Viewport width
359
-    unsigned int mHeight;                 //!< Viewport height
360
-    unsigned int mMode;                   //!< Rendering mode
361
-    unsigned int *mNumTexturesLoaded;
362
-    unsigned int *mNextTextureId;
363
-    int mLock;
364
-    int mSkyMesh;                         //!< Skymesh model id
365
-    bool mSkyMeshRotation;                //!< Should Skymesh be rotated?
366
-#ifdef USING_EMITTER
367
-    Emitter *mEmitter;                    //!< Particle emitter test
368
-#endif
369
-};
370
-
371
-#endif

+ 0
- 123
include/SDLSystem.h Переглянути файл

@@ -1,123 +0,0 @@
1
-/*!
2
- * \file include/SDLSystem.h
3
- * \brief SDL System interface implementation
4
- *
5
- * \author Mongoose
6
- */
7
-
8
-#ifndef _SDLSYSTEM_H_
9
-#define _SDLSYSTEM_H_
10
-
11
-#include "SDL.h"
12
-
13
-#include "Config.h"
14
-#include "System.h"
15
-
16
-/*!
17
- * \brief SDL System interface implementation
18
- */
19
-class SDLSystem : public System {
20
-public:
21
-
22
-    /*!
23
-     * \brief Constructs an object of SDLSystem
24
-     */
25
-    SDLSystem();
26
-
27
-    /*!
28
-     * \brief Deconstructs an object of SDLSystem
29
-     */
30
-    virtual ~SDLSystem();
31
-
32
-    /*
33
-     * \brief Sets Event binding Cmd to Key press
34
-     * \param cmd valid command string
35
-     * \param key valid keyboard code
36
-     * \param event valid game event id
37
-     */
38
-    //! \fixme void bindKeyCommand(const char *cmd, int key, int event);
39
-
40
-    /*!
41
-     * \brief Renders string in OpenGL (2D projection).
42
-     *
43
-     * Requires Texture::glEnterMode2d() call before entry.
44
-     *
45
-     * System::bufferString(..) can cache printf() style calls
46
-     * for use with this method.
47
-     *
48
-     * Call Texture::glExitMode2d after finishing calls to this method
49
-     * and other 2D rendering.
50
-     *
51
-     * \param x valid X world coordinate
52
-     * \param y valid Y world coordinate
53
-     * \param string valid string
54
-     *
55
-     * \sa System::bufferString()
56
-     * \sa Texture::glEnterMode2d()
57
-     * \sa Texture::glExitMode2d()
58
-     */
59
-    void glPrintf2d(float x, float y, char *string);
60
-
61
-    /*!
62
-     * \brief Renders string in OpenGL (3D projection).
63
-     *
64
-     * System::bufferString(..) can cache printf() style calls
65
-     * for use with this method.
66
-     *
67
-     * \param x valid X world coordinate
68
-     * \param y valid Y world coordinate
69
-     * \param z valid Z world coordinate
70
-     * \param string valid string
71
-     *
72
-     * \sa System::bufferString()
73
-     */
74
-    void glPrintf3d(float x, float y, float z, char *string);
75
-
76
-    /*!
77
-     * \brief Start up video subsystem
78
-     * \param width valid video mode width
79
-     * \param height valid video mode height
80
-     * \param fullscreen enables fullscreen rendering
81
-     */
82
-    void initVideo(unsigned int width, unsigned int height, bool fullscreen);
83
-
84
-    /*!
85
-     * \brief Resizes game window
86
-     * \param width new width
87
-     * \param height new height
88
-     */
89
-    virtual void resize(unsigned int width, unsigned int height);
90
-
91
-    /*!
92
-     * \brief Start game loop
93
-     */
94
-    void runGame();
95
-
96
-    void setGrabMouse(bool on);
97
-
98
-    /*!
99
-     * \brief Shuts down the game subsystems, exits game loop
100
-     * \param i exit code
101
-     */
102
-    void shutdown(int i);
103
-
104
-    /*!
105
-     * \brief Swaps OpenGL buffers.
106
-     * Call at end of frame.
107
-     */
108
-    void swapBuffersGL();
109
-
110
-    /*!
111
-     * \brief Toggle fullscreen windowing mode
112
-     */
113
-    void toggleFullscreen();
114
-
115
-protected:
116
-    bool mFullscreen;      //!< Current Fullscreen/Windowed mode
117
-
118
-private:
119
-    SDL_Window *mWindow;      //!< This is the pointer to the SDL surface
120
-    SDL_GLContext mGLContext; //!< The OpenGL Context
121
-};
122
-
123
-#endif

+ 0
- 92
include/SkeletalModel.h Переглянути файл

@@ -1,92 +0,0 @@
1
-/*!
2
- * \file include/SkeletalModel.h
3
- * \brief This is the factored out skeletal model class
4
- *
5
- * \author Mongoose
6
- *
7
- * \todo Start cutting off old hacks by simple force use of method interface.
8
- * Also move the publicly exposed attributes out  =)
9
- * Better animation system in general - this is memory wasteful
10
- */
11
-
12
-#ifndef _SKELETALMODEL_H_
13
-#define _SKELETALMODEL_H_
14
-
15
-#include "utils/math.h"
16
-#include "templates/Vector.h"
17
-
18
-typedef struct {
19
-    int mesh;
20
-    vec3_t off;
21
-    vec3_t rot;
22
-    char flag;
23
-} bone_tag_t;
24
-
25
-typedef struct {
26
-    Vector<bone_tag_t *> tag;
27
-    vec3_t pos;
28
-    float yaw;
29
-} bone_frame_t;
30
-
31
-typedef struct {
32
-    int id;
33
-    char rate;
34
-    Vector<bone_frame_t *> frame;
35
-} animation_frame_t;
36
-
37
-typedef struct {
38
-    int id;
39
-    bool tr4Overlay;
40
-    bool pigtails;
41
-    int ponytailId;
42
-    vec3_t ponytail;
43
-    int ponytailMeshId;
44
-    unsigned int ponytailNumMeshes;
45
-    float ponytailAngle;
46
-    float ponyOff;
47
-    float ponyOff2;
48
-    Vector<animation_frame_t *> animation;
49
-} skeletal_model_t;
50
-
51
-/*!
52
- * \brief This is the factored out skeletal model class
53
- */
54
-class SkeletalModel {
55
-public:
56
-    /*!
57
-     * \brief Constructs an object of SkeletalModel
58
-     */
59
-    SkeletalModel();
60
-
61
-     /*!
62
-     * \brief Deconstructs an object of SkeletalModel
63
-     */
64
-    ~SkeletalModel();
65
-
66
-    int getAnimation();
67
-
68
-    int getFrame();
69
-
70
-    int getIdleAnimation();
71
-
72
-    void setModel(skeletal_model_t *mdl);
73
-
74
-    void setAnimation(int index);
75
-
76
-    void setFrame(int index);
77
-
78
-    void setIdleAnimation(int index);
79
-
80
-    unsigned int flags;
81
-    skeletal_model_t *model; //!< World render model
82
-    float time;              //!< Interpolation use
83
-    float lastTime;
84
-    float rate;              //!< \fixme temp cache this here for old animation system use
85
-
86
-private:
87
-    int mBoneFrame;      //!< Bone frame
88
-    int mAnimationFrame; //!< Animation frame
89
-    int mIdleAnimation;  //!< Idle animation
90
-};
91
-
92
-#endif

+ 0
- 103
include/Sound.h Переглянути файл

@@ -1,103 +0,0 @@
1
-/*!
2
- * \file include/Sound.h
3
- * \brief This is the audio manager Header
4
- *
5
- * \author Mongoose
6
- * \author xythobuz
7
- */
8
-
9
-#ifndef _SOUND_H_
10
-#define _SOUND_H_
11
-
12
-/*!
13
- * \brief This is the audio manager for OpenRaider
14
- */
15
-class Sound {
16
-public:
17
-
18
-    typedef enum {
19
-        SoundFlagsNone = 0, //!< No FX
20
-        SoundFlagsLoop = 1  //!< Enable looping during playback
21
-    } SoundFlags;
22
-
23
-    /*!
24
-     * \brief Constructs an object of Sound
25
-     */
26
-    Sound();
27
-
28
-    /*!
29
-     * \brief Deconstructs an object of Sound
30
-     */
31
-    ~Sound();
32
-
33
-    /*!
34
-     * \brief Initialize sound system
35
-     * \returns 0 on success or < 0 error flags
36
-     */
37
-    int init();
38
-
39
-    /*!
40
-     * \brief Get number of registered sources
41
-     * \returns number of registered sources
42
-     */
43
-    int registeredSources();
44
-
45
-    /*!
46
-     * \brief Move listener and repositions them
47
-     * \param pos New position for listener
48
-     * \param angle New orientation for listener
49
-     */
50
-    void listenAt(float pos[3], float angle[3]);
51
-
52
-    /*!
53
-     * \brief Move sound source to position
54
-     * \param source valid source id
55
-     * \param pos new position for source
56
-     */
57
-    void sourceAt(int source, float pos[3]);
58
-
59
-    /*!
60
-     * \brief Load wav file from disk
61
-     * \param filename not NULL!
62
-     * \param source not NULL! Returns new source ID or -1 on error.
63
-     * \param flags (un)set options. Use SoundFlags enum
64
-     * \returns 0 for no error or < 0 error flag
65
-     */
66
-    int addFile(const char *filename, int *source, unsigned int flags);
67
-
68
-    /*!
69
-     * \brief Load wav file from buffer
70
-     * \param wav not NULL! Is a valid waveform buffer!
71
-     * \param length length of wav buffer
72
-     * \param source not NULL! Returns new source ID or -1 on error.
73
-     * \param flags (un)set options. Use SoundFlags enum
74
-     * \returns 0 for no error or < 0 error flag
75
-     */
76
-    int addWave(unsigned char *wav, unsigned int length, int *source, unsigned int flags);
77
-
78
-    /*!
79
-     * \brief Remove a loaded sound
80
-     * \param source valid source id
81
-     */
82
-    void remove(int source);
83
-
84
-    /*!
85
-     * \brief Play sound source
86
-     * \param source sound source to play
87
-     */
88
-    void play(int source);
89
-
90
-    /*!
91
-     * \brief Stop playing sound source
92
-     * \param source sound source to stop
93
-     */
94
-    void stop(int source);
95
-
96
-private:
97
-    bool mInit;                //!< Guard to ensure ausio system is active
98
-    unsigned int mBuffer[256]; //!< Audio buffer id list
99
-    unsigned int mSource[256]; //!< Audio source id list
100
-    int mNext;                 //!< Audio id cursor
101
-};
102
-
103
-#endif

+ 0
- 167
include/System.h Переглянути файл

@@ -1,167 +0,0 @@
1
-/*!
2
- * \file include/System.h
3
- * \brief Mostly defines the interface of System implementations.
4
- *
5
- * Currently only SDL is used, but there was a GLUT implementation.
6
- *
7
- * \author Mongoose
8
- * \author xythobuz
9
- */
10
-
11
-#ifndef _SYSTEM_H_
12
-#define _SYSTEM_H_
13
-
14
-#include <map>
15
-
16
-#include "templates/Vector.h"
17
-#include "utils/strings.h"
18
-
19
-//! \todo Replace with unicode compatible key codes
20
-#define SYS_MOUSE_LEFT    6000
21
-#define SYS_MOUSE_RIGHT   6001
22
-#define SYS_MOUSE_MIDDLE  6002
23
-#define SYS_KEY_ESC       27
24
-#define SYS_KEY_ENTER     13
25
-#define SYS_KEY_UP        5000
26
-#define SYS_KEY_DOWN      5001
27
-#define SYS_KEY_RIGHT     5002
28
-#define SYS_KEY_LEFT      5003
29
-#define SYS_KEY_PAGEDOWN  5004
30
-#define SYS_KEY_PAGEUP    5005
31
-#define SYS_KEY_F1        1000
32
-#define SYS_KEY_F2        1001
33
-#define SYS_KEY_F3        1002
34
-#define SYS_KEY_F4        1003
35
-#define SYS_KEY_F5        1004
36
-#define SYS_KEY_F6        1005
37
-#define SYS_KEY_F7        1006
38
-#define SYS_KEY_F8        1007
39
-#define SYS_KEY_F9        1008
40
-#define SYS_KEY_F10       1009
41
-#define SYS_KEY_F11       1010
42
-#define SYS_KEY_F12       1011
43
-
44
-typedef enum {
45
-    SYS_MOD_KEY_LSHIFT = 1,
46
-    SYS_MOD_KEY_RSHIFT = 2,
47
-    SYS_MOD_KEY_LCTRL  = 4,
48
-    SYS_MOD_KEY_RCTRL  = 8,
49
-    SYS_MOD_KEY_LALT   = 16,
50
-    SYS_MOD_KEY_RALT   = 32,
51
-    SYS_MOD_KEY_LMETA  = 64,
52
-    SYS_MOD_KEY_RMETA  = 128
53
-} sdl_sys_mod_key_t;
54
-
55
-/*!
56
- * \brief Basic Interface for System implementations (SDLSystem)
57
- */
58
-class System {
59
-public:
60
-    /*!
61
-     * \brief Constructs an object of System
62
-     */
63
-    System();
64
-
65
-    /*!
66
-     * \brief Deconstructs an object of System
67
-     */
68
-    virtual ~System();
69
-
70
-    /*!
71
-     * \brief Created a new Command Mode.
72
-     * \param command valid command mode for the resource file, eg "[Engine.OpenGL.Driver]"
73
-     * \returns id given to mode
74
-     */
75
-    virtual unsigned int addCommandMode(const char *command);
76
-
77
-    /*!
78
-     * \brief Binds a key to a command
79
-     * \param cmd valid command string for event
80
-     * \param key valid keyboard code
81
-     * \param event valid game event id
82
-     */
83
-    virtual void bindKeyCommand(const char *cmd, unsigned int key, int event);
84
-
85
-    /*!
86
-     * \brief Executes a command string
87
-     * \param cmd valid command string, cmd sets its var
88
-     */
89
-    virtual void command(const char *cmd);
90
-
91
-    virtual void gameFrame() = 0;
92
-
93
-    virtual void handleMouseMotionEvent(float x, float y) = 0;
94
-
95
-    /*!
96
-     * \brief Receives the event bound to the command from the key press
97
-     * \param key key pressed
98
-     */
99
-    virtual void handleBoundKeyPressEvent(unsigned int key) = 0;
100
-
101
-    /*!
102
-     * \brief Receives the event bound to the command from the key release
103
-     * \param key key released
104
-     */
105
-    virtual void handleBoundKeyReleaseEvent(unsigned int key) = 0;
106
-
107
-    /*!
108
-     * \brief Executes valid command based on keyword
109
-     * \param command valid keyword, optionally followed by space separated arguments
110
-     * \param mode current type or resource mode
111
-     */
112
-    virtual void handleCommand(char *command, unsigned int mode) = 0;
113
-
114
-    /*!
115
-     * \brief Receives key code from text input in console mode
116
-     * \param key is a valid keyboard code
117
-     * \param mod modifier key
118
-     */
119
-    virtual void handleConsoleKeyPressEvent(unsigned int key, unsigned int mod) = 0;
120
-
121
-    virtual void handleKeyPressEvent(unsigned int key, unsigned int mod) = 0;
122
-
123
-    virtual void handleKeyReleaseEvent(unsigned int key, unsigned int mod) = 0;
124
-
125
-    virtual void initVideo(unsigned int width, unsigned int height, bool fullscreen) = 0;
126
-
127
-    /*!
128
-     * \brief Init the resource vars
129
-     * \param filename resource file
130
-     * \returns < 0 on error
131
-     */
132
-    virtual int loadResourceFile(const char *filename);
133
-
134
-    virtual void resizeGL(unsigned int width, unsigned int height);
135
-
136
-    virtual void runGame() = 0;
137
-
138
-    /*!
139
-     * \brief Turns console key events on/off
140
-     * Mostly for allowing text entry vs key impulse commands
141
-     * \param on new state
142
-     */
143
-    void setConsoleMode(bool on);
144
-
145
-    void setDriverGL(const char *driver);
146
-
147
-    virtual void shutdown(int code) = 0;
148
-
149
-    virtual void swapBuffersGL() = 0;
150
-
151
-    virtual void toggleFullscreen() = 0;
152
-
153
-protected:
154
-    unsigned int m_width;              //!< Width of the viewport
155
-    unsigned int m_height;             //!< Height of the viewport
156
-    char *m_driver;                    //!< String for dynamic use of GL library
157
-    float m_clipNear;                  //!< Clip near distance
158
-    float m_clipFar;                   //!< Clip far distance
159
-    float m_fovY;                      //!< Field of vision
160
-    std::map<unsigned int, int> mKeyEvents; //!< Single key press event mappings
161
-    bool mConsoleMode;                 //!< Using text (console) event handler?
162
-    Vector<const char *> mCmdModes;    //!< Dynamic resource command collection
163
-    unsigned int mCommandMode;         //!< Current resource command mode
164
-    unsigned int mConsoleKey;          //!< Console toggle event now handled lower
165
-};
166
-
167
-#endif

+ 0
- 293
include/Texture.h Переглянути файл

@@ -1,293 +0,0 @@
1
-/*!
2
- * \file include/Texture.h
3
- * \brief Texture registry
4
- *
5
- * \author Mongoose
6
- */
7
-
8
-#ifndef _TEXTURE_H
9
-#define _TEXTURE_H
10
-
11
-#include <stdio.h>
12
-
13
-typedef struct {
14
-    int x;
15
-    int y;
16
-    int w;
17
-    int h;
18
-    int minx;
19
-    int maxx;
20
-    int miny;
21
-    int maxy;
22
-    int advance;
23
-} ttf_glyph_t;
24
-
25
-typedef struct {
26
-    unsigned int utf8Offset;
27
-    unsigned int count;
28
-
29
-/* [utf8Offset -> utf8Offset+count],
30
-     matches indexing into glyphs[0 -> count] for texcoords, etc
31
-    ----------------------------------------
32
-    41     -> 126     ASCII English w/ special chars,
33
-    0x303f -> 0x3093  Japanese hiragana kana,
34
-    0x301a -> 0x30f6  Japanese katakana kana */
35
-
36
-    unsigned int width;      //!< Width and height of RGBA texture
37
-    unsigned char *texture;  //!< RGBA texture data
38
-    ttf_glyph_t *glyphs;     //!< For typesetting and rendering use
39
-    int fontHeight;
40
-    int fontAscent;
41
-    int fontDescent;
42
-    int fontSpacing;
43
-} ttf_texture_t;
44
-
45
-typedef struct {
46
-    unsigned int utf8Offset;
47
-    unsigned int count;
48
-    int textureId;
49
-    int drawListBase;
50
-} gl_font_t;
51
-
52
-/*!
53
- * \brief Texture registry
54
- */
55
-class Texture {
56
-public:
57
-
58
-    enum ColorMode {
59
-        GREYSCALE = 1,
60
-        RGB,
61
-        RGBA,
62
-        ARGB
63
-    };
64
-
65
-    enum TextureFlag {
66
-        fUseMipmaps      = (1 << 0),
67
-        fUseMultiTexture = (1 << 1),
68
-        fUseSDL_TTF      = (1 << 2)
69
-    };
70
-
71
-    /*!
72
-    * \brief Constructs an object of Texture
73
-    */
74
-    Texture();
75
-
76
-   /*!
77
-    * \brief Deconstructs an object of Texture
78
-    */
79
-    ~Texture();
80
-
81
-    /*!
82
-     * \brief Generates a texture buffer with (width * height * 4) bytes.
83
-     * \param rgba 32bpp RGBA color to fill into buffer
84
-     * \param width width of newly allocated buffer, power of 2, pref same as height
85
-     * \param height height of newly allocated buffer, power of 2, pref same as width
86
-     * \returns newly allocated texture buffer filled with specified color
87
-     */
88
-    static unsigned char *generateColorTexture(unsigned char rgba[4],
89
-                                                unsigned int width,
90
-                                                unsigned int height);
91
-
92
-    gl_font_t *generateFont(ttf_texture_t *texture);
93
-
94
-    /*!
95
-     * \brief Generates a font texture with typeset info from TTF.
96
-     *
97
-     * Does not load the texture itself! Call loadFont() on returned ttf_texture_t
98
-     * \param filename filename of TTF font
99
-     * \param pointSize Point Size to generate
100
-     * \param textureWidth width of texture, height will match it
101
-     * \param color RGB 24bit color
102
-     * \param utf8Offset Offset into fonts encoding chart
103
-     * \param count number of glyphs to read from offset start
104
-     * \param verbose dumps debug info to stdout
105
-     * \returns font texture. Load it with loadFont()!
106
-     */
107
-    ttf_texture_t *generateFontTexture(const char *filename, int pointSize,
108
-                                        unsigned int textureWidth,
109
-                                        unsigned char color[3],
110
-                                        unsigned int utf8Offset,
111
-                                        unsigned int count,
112
-                                        char verbose);
113
-
114
-    /*!
115
-     * \brief Get number of textures in use
116
-     * \returns used texture count, or -1 on error (uninitialized)
117
-     */
118
-    int getTextureCount();
119
-
120
-    /*!
121
-     * \brief Dumps a screenshot to disk.
122
-     *
123
-     * Avoids overwriting files with same base name.
124
-     * \param base base filename
125
-     * \param width viewport width
126
-     * \param height viewport height
127
-     */
128
-    void glScreenShot(char *base, unsigned int width, unsigned int height);
129
-
130
-    /*!
131
-     * \brief Sets up multitexture rendering with passed ids
132
-     * \param texture0 first texture for multitexture
133
-     * \param texture1 second texture for multitexture
134
-     */
135
-    void bindMultiTexture(int texture0, int texture1);
136
-
137
-    /*!
138
-     * \brief Binds the texture for use in GL
139
-     * \param n valid texture index
140
-     */
141
-    void bindTextureId(unsigned int n);
142
-
143
-    /*!
144
-     * \brief Clears an option flag
145
-     * \param flag flag to clear
146
-     */
147
-    void clearFlag(TextureFlag flag);
148
-
149
-    void disableMultiTexture();
150
-
151
-    /*!
152
-     * \brief Loads SDL_TTF
153
-     */
154
-    void initSDL_TTF();
155
-
156
-    /*!
157
-     * \brief Loads Buffer as texture
158
-     * \param image pixmap matching other params
159
-     * \param width width of image
160
-     * \param height height of image
161
-     * \param mode mode of image
162
-     * \param bpp bits per pixel of image
163
-     * \returns texture ID or < 0 on error
164
-     */
165
-    int loadBuffer(unsigned char *image,
166
-                    unsigned int width, unsigned int height,
167
-                    ColorMode mode, unsigned int bpp);
168
-
169
-    /*!
170
-     * \brief Loads Buffer as texture
171
-     * \param image pixmap matching other params
172
-     * \param width width of image
173
-     * \param height height of image
174
-     * \param mode mode of image
175
-     * \param bpp bits per pixel of image
176
-     * \param slot slot (ID) of image
177
-     * \returns texture ID or < 0 on error
178
-     */
179
-    int loadBufferSlot(unsigned char *image,
180
-                        unsigned int width, unsigned int height,
181
-                        ColorMode mode, unsigned int bpp,
182
-                        unsigned int slot);
183
-
184
-    /*!
185
-     * \brief Generates and loads a solid color texture.
186
-     * \param rgba color for new texture
187
-     * \param width width of new texture
188
-     * \param height height of new texture
189
-     * \returns texture ID or -1 on error
190
-     */
191
-    int loadColorTexture(unsigned char rgba[4],
192
-                            unsigned int width, unsigned int height);
193
-
194
-    /*!
195
-     * \brief Loads a TTF, generates texture image, glyph list and drawlist
196
-     * \param filename Filename of TTF font
197
-     * \param utf8Offset Offset into Unicode table
198
-     * \param count number of glyphs to load
199
-     * \returns font id if successful, or < 0 on error
200
-     */
201
-    int loadFontTTF(const char *filename,
202
-                        unsigned int utf8Offset, unsigned int count);
203
-
204
-    /*!
205
-     * \brief Loads TGA file as texture
206
-     * \param filename Existing TGA file
207
-     * \returns ID of new texture or -1 on error
208
-     */
209
-    int loadTGA(const char *filename);
210
-
211
-    /*!
212
-     * \brief Resets all texture data
213
-     */
214
-    void reset();
215
-
216
-    /*!
217
-     * \brief Sets an option flag
218
-     * \param flag flag to set
219
-     */
220
-    void setFlag(TextureFlag flag);
221
-
222
-    /*!
223
-     * \brief Sets up GL texturing.
224
-     *
225
-     * Must be called as first setup step!
226
-     * \param n maximum number of textures you wish to allow
227
-     */
228
-    void setMaxTextureCount(unsigned int n);
229
-
230
-    void useMultiTexture(float u, float v);
231
-
232
-    void useMultiTexture(float aU, float aV, float bU, float bV);
233
-
234
-    /*!
235
-     * \brief Show a texture for a second, for debugging
236
-     * \param textureId texture id to show
237
-     * \returns GL texture id on success, < 0 on error
238
-     */
239
-    int showTextureDebug(int textureId);
240
-
241
-    /*!
242
-     * \brief Renders debug texture.
243
-     *
244
-     * Called in 2D mode from Texture::Display().
245
-     */
246
-    void debugTextureRender(int width, int height);
247
-
248
-private:
249
-
250
-    int nextPower(int seed);
251
-
252
-    unsigned char *scaleBuffer(unsigned char *image, int width, int height,
253
-                                int components);
254
-
255
-    int textureDebug;
256
-    int textureDebugFrames;
257
-
258
-    unsigned int *mTextureIds;  //!< GL texture list
259
-    unsigned int mTextureCount; //!< Texture counter
260
-    unsigned int mTextureLimit; //!< The texture limit
261
-    unsigned int mFlags;        //!< Class options
262
-    int mTextureId;             //!< Currently bound texture id
263
-    int mTextureId2;            //!< Multitexture Texture Id
264
-};
265
-
266
-
267
-// Experimental testing
268
-
269
-void bufferedPrintf(char *string, unsigned int len, char *s, ...) __attribute__((format(printf, 3, 4)));
270
-
271
-void glPrint3d(float x, float y, float z,
272
-                float pitch, float yaw, float roll,
273
-                float scale, char *string);
274
-
275
-void glPrint2d(float x, float y, float scale, char *string);
276
-
277
-/*!
278
- * \brief OpenGL ortho projection.
279
- *
280
- * Call before using glPrint2d()
281
- * \param width window width
282
- * \param height window height
283
- */
284
-void glEnterMode2d(unsigned int width, unsigned int height);
285
-
286
-/*!
287
- * \brief OpenGL model matrix projection.
288
- *
289
- * Call after using glPrint2d()
290
- */
291
-void glExitMode2d();
292
-
293
-#endif

+ 0
- 1919
include/TombRaider.h
Різницю між файлами не показано, бо вона завелика
Переглянути файл


+ 0
- 160
include/Vector3d.h Переглянути файл

@@ -1,160 +0,0 @@
1
-/*!
2
- * \file include/Vector3d.h
3
- * \brief 3D Math vector
4
- *
5
- * \author Mongoose
6
- */
7
-
8
-#ifndef _VECTOR3D_H_
9
-#define _VECTOR3D_H_
10
-
11
-#include "utils/math.h"
12
-
13
-/*!
14
- * \brief 3D Math Vector
15
- */
16
-class Vector3d {
17
-public:
18
-
19
-    /*!
20
-     * \brief Constructs an object of Vector3d
21
-     */
22
-    Vector3d();
23
-
24
-    /*!
25
-     * \brief Constructs an object of Vector3d
26
-     * \param v data to load into new Vector3d
27
-     */
28
-    Vector3d(vec3_t v);
29
-
30
-    /*!
31
-     * \brief Constructs an object of Vector3d
32
-     * \param x X part of new Vector3d
33
-     * \param y Y part of new Vector3d
34
-     * \param z Z part of new Vector3d
35
-     */
36
-    Vector3d(vec_t x, vec_t y, vec_t z);
37
-
38
-    /*!
39
-     * \brief Constructs an object of Vector3d
40
-     * \param v contents of new Vector3d
41
-     */
42
-    Vector3d(const Vector3d &v);
43
-
44
-    /*!
45
-     * \brief Calculate dot product
46
-     * \param u first argument
47
-     * \param v second argument
48
-     * \returns dot product of u and v vectors
49
-     */
50
-    static vec_t dot(const Vector3d &u, const Vector3d &v);
51
-
52
-    /*!
53
-     * \brief Calculate cross product
54
-     * \param u first argument
55
-     * \param v second argument
56
-     * \returns cross product of u and v vectors
57
-     */
58
-    static Vector3d cross(const Vector3d &u, const Vector3d &v);
59
-
60
-    /*!
61
-     * \brief Get Magnitude
62
-     * \returns magnitude of this vector
63
-     */
64
-    vec_t magnitude();
65
-
66
-    /*!
67
-     * \brief Normalize
68
-     * \returns normalized copy of this vector
69
-     */
70
-    Vector3d unit();
71
-
72
-    /*!
73
-     * \brief Get the Zero vector
74
-     * \returns (0, 0, 0) vector
75
-     */
76
-    static Vector3d zeroVector();
77
-
78
-    /*!
79
-     * \brief Add to this vector
80
-     * \param v addend
81
-     * \returns a vector = this vector + v
82
-     */
83
-    Vector3d operator +(const Vector3d &v);
84
-
85
-    /*!
86
-     * \brief Subtract from this vector
87
-     * \param v subtrahend
88
-     * \returns a vector = this vector - v
89
-     */
90
-    Vector3d operator -(const Vector3d &v);
91
-
92
-    /*!
93
-     * \brief Negate this vector
94
-     * \returns a copy of this vector, negated
95
-     */
96
-    Vector3d operator -();
97
-
98
-    /*!
99
-     * \brief Scale this vector
100
-     * \param s scaling factor
101
-     * \returns this vector multiplied with s
102
-     */
103
-    Vector3d operator *(vec_t s);
104
-
105
-    /*!
106
-     * \brief Scale this vactor
107
-     * \param s inverse scaling factor
108
-     * \returns this vector divided by s
109
-     */
110
-    Vector3d operator /(vec_t s);
111
-
112
-    /*!
113
-     * \brief Dot product this vector
114
-     * \param v second vector for dot product
115
-     * \returns dot product of V by this vector
116
-     */
117
-    vec_t operator *(const Vector3d &v);
118
-
119
-    /*!
120
-     * \brief Normalizes this vector
121
-     */
122
-    void normalize();
123
-
124
-    /*!
125
-     * \brief Set this vector to Zero (0, 0, 0)
126
-     */
127
-    void zero();
128
-
129
-    /*!
130
-     * \brief Set this vector
131
-     * \param v what this vector will be set to
132
-     * \returns this vector, now equal to v
133
-     */
134
-    Vector3d &operator =(const Vector3d &v);
135
-
136
-    /*!
137
-     * \brief Add to this vector, in place
138
-     * \param v what will be added to this vector
139
-     * \returns this vector, with v added
140
-     */
141
-    Vector3d &operator +=(const Vector3d &v);
142
-
143
-    /*!
144
-     * \brief Subtract from this vector, in place
145
-     * \param v what will be subtracted from this vector
146
-     * \returns this vector, with v subtracted
147
-     */
148
-    Vector3d &operator -=(const Vector3d &v);
149
-
150
-    /*!
151
-     * \brief Scale this vector, in place
152
-     * \param s scaling factor
153
-     * \returns this vactor multiplied by s
154
-     */
155
-    Vector3d &operator *=(vec_t s);
156
-
157
-    vec3_t mVec; //!< Vector data
158
-};
159
-
160
-#endif

+ 0
- 200
include/ViewVolume.h Переглянути файл

@@ -1,200 +0,0 @@
1
-/*!
2
- * \file include/ViewVolume.h
3
- * \brief Viewing Volume for culling use
4
- *
5
- * \author Mongoose
6
- */
7
-
8
-#ifndef _VIEWVOLUME_H_
9
-#define _VIEWVOLUME_H_
10
-
11
-#include "Matrix.h"
12
-
13
-/*!
14
- * \brief Defines a 3D sphere.
15
- */
16
-class BoundingSphere {
17
-public:
18
-    vec3_t mCenter; //!< Center of bounding sphere
19
-    vec_t mRadius; //!< Raduis of bounding sphere
20
-};
21
-
22
-/*!
23
- * \brief Defines a 3D rectangle.
24
- */
25
-class BoundingBox {
26
-public:
27
-    vec3_t mMin; //!< Bounding box MIN point
28
-    vec3_t mMax; //!< Bounding box MAX point
29
-};
30
-
31
-/*!
32
- * \brief Defines a 3D sphere and/or rectangle.
33
- */
34
-class BoundingVolume {
35
-public:
36
-    BoundingSphere mSphere; //!< Bounding sphere of this volume
37
-    BoundingBox mBox; //!< Bounding box of this volume
38
-};
39
-
40
-/*!
41
- * \brief Viewing Volume for culling use
42
- */
43
-class ViewVolume {
44
-public:
45
-
46
-    /*!
47
-     * \brief Sides of the view volume
48
-     */
49
-    enum ViewVolumeSide {
50
-        rightSide  = 0, //!< Right
51
-        leftSide   = 1, //!< Left
52
-        bottomSide = 2, //!< Bottom
53
-        topSide    = 3, //!< Top
54
-        farSide    = 4, //!< Back
55
-        nearSide   = 5  //!< Front
56
-    };
57
-
58
-    /*!
59
-     * \brief Planes of the view volume
60
-     */
61
-    enum ViewVolumePlane {
62
-        planeA = 0, //!< X value of normal
63
-        planeB = 1, //!< Y value of normal
64
-        planeC = 2, //!< Z value of normal
65
-        planeD = 3  //!< Distance to origin
66
-    };
67
-
68
-    /*!
69
-     * \brief Constructs an object of ViewVolume
70
-     */
71
-    ViewVolume();
72
-
73
-    /*!
74
-     * \brief Check if bounding volume is in view volume
75
-     * \param bvol bounding volume to check
76
-     * \returns true if frustum contains the given bounding volume
77
-     */
78
-    bool isBoundingVolumeInFrustum(BoundingVolume bvol);
79
-
80
-    /*!
81
-     * \brief Check if bounding sphere is in view volume
82
-     * \param bvol bounding sphere to check
83
-     * \returns true if frustum contains the given bounding volume
84
-     */
85
-    bool isBoundingSphereInFrustum(BoundingSphere bvol);
86
-
87
-    /*!
88
-     * \brief Check if bounding box is in view volume
89
-     * \param bvol bounding box to check
90
-     * \returns true if frustum contains the given bounding volume
91
-     */
92
-    bool isBoundingBoxInFrustum(BoundingBox bvol);
93
-
94
-    /*!
95
-     * \brief Check if point is in view volume
96
-     * \param x X coordinate of point
97
-     * \param y Y coordinate of point
98
-     * \param z Z coordinate of point
99
-     * \returns true if point in view volume
100
-     */
101
-    bool isPointInFrustum(vec_t x, vec_t y, vec_t z);
102
-
103
-    /*!
104
-     * \brief Check if bounding sphere is in view volume
105
-     * \param x X coordinate of a valid abstract sphere
106
-     * \param y Y coordinate of a valid abstract sphere
107
-     * \param z Z coordinate of a valid abstract sphere
108
-     * \param radius radius of a valid abstract sphere
109
-     * \returns true if abstract sphere in view volume
110
-     */
111
-    bool isSphereInFrustum(vec_t x, vec_t y, vec_t z, vec_t radius);
112
-
113
-    /*!
114
-     * \brief Check if bounding box is in view volume
115
-     * \param min minimum point of valid abstract bounding box
116
-     * \param max maximum point of valid abstract bounding box
117
-     * \returns true if abstract bounding box in view volume
118
-     */
119
-    bool isBboxInFrustum(vec3_t min, vec3_t max);
120
-
121
-    /*!
122
-     * \brief Distance to Bounding sphere
123
-     * \param x X coordinate of a valid abstract sphere
124
-     * \param y Y coordinate of a valid abstract sphere
125
-     * \param z Z coordinate of a valid abstract sphere
126
-     * \param radius radius of a valid abstract sphere
127
-     * \returns distance to abstract sphere bounding volume
128
-     */
129
-    vec_t getDistToSphereFromNear(vec_t x, vec_t y, vec_t z, vec_t radius);
130
-
131
-    /*!
132
-     * \brief Distance to Bounding box
133
-     * \param min minimum point of a valid abstract bounding box
134
-     * \param max maximum point of a valid abstract bounding box
135
-     * \returns distance to abstract box bounding volume
136
-     */
137
-    vec_t getDistToBboxFromNear(vec3_t min, vec3_t max);
138
-
139
-    /*!
140
-     * \brief Get a copy of the view volume
141
-     * \param frustum where frustum will be stored
142
-     */
143
-    void getFrustum(vec_t frustum[6][4]);
144
-
145
-    /*!
146
-     * \brief Get a copy of a given plane in view volume
147
-     * \param p side
148
-     * \param plane wher plane will be stored
149
-     */
150
-    void getPlane(ViewVolumeSide p, vec4_t plane);
151
-
152
-    /*!
153
-     * \brief Updates view volume for this frame.
154
-     * \param proj new projection matrix
155
-     * \param mdl new model matrix
156
-     */
157
-    void updateFrame(matrix_t proj, matrix_t mdl);
158
-
159
-    /*!
160
-     * \brief Updates view volume for this frame.
161
-     *
162
-     * Model & Projection Matrices must be set.
163
-     */
164
-    void updateFrame();
165
-
166
-    /*!
167
-     * \brief Set this class' model matrix
168
-     * \param mdl new model matrix
169
-     */
170
-    void setModel(matrix_t mdl);
171
-
172
-    /*!
173
-     * \brief Set this class' projection matrix
174
-     * \param proj new projection matrix
175
-     */
176
-    void setProjection(matrix_t proj);
177
-
178
-private:
179
-
180
-    /*!
181
-     * \brief Computes clipping matrix.
182
-     *
183
-     * Model & Projection matrices must be set!
184
-     */
185
-    void updateClip();
186
-
187
-    /*!
188
-     * \brief Computes planes of frustum.
189
-     *
190
-     * Model, Projection & Clip matrices must be set!
191
-     */
192
-    void updateFrustum();
193
-
194
-    Matrix mProjection;   //!< Projection matrix
195
-    Matrix mModel;        //!< Model matrix
196
-    Matrix mClip;         //!< Clipping matrix
197
-    vec_t mFrustum[6][4]; //!< View volume
198
-};
199
-
200
-#endif

+ 0
- 391
include/World.h Переглянути файл

@@ -1,391 +0,0 @@
1
-/*!
2
- * \file include/World.h
3
- * \brief The game world (model)
4
- *
5
- * \author Mongoose
6
- */
7
-
8
-#ifndef _WORLD_H_
9
-#define _WORLD_H_
10
-
11
-#define BAD_BLOOD  //!< \todo For temp rendering use
12
-
13
-#ifdef BAD_BLOOD
14
-#include "SkeletalModel.h"
15
-#endif
16
-
17
-#include "utils/math.h"
18
-#include "templates/List.h"
19
-#include "templates/Vector.h"
20
-
21
-// Mirrors TombRaider class' room flags really
22
-typedef enum {
23
-    roomFlag_underWater    = 0x0001
24
-} room_flags_t;
25
-
26
-typedef enum {
27
-    worldMoveType_walkNoSwim   = -1,
28
-    worldMoveType_walk         = 0,
29
-    worldMoveType_noClipping   = 1,
30
-    worldMoveType_fly          = 2,
31
-    worldMoveType_swim         = 3
32
-} worldMoveType;
33
-
34
-typedef struct {
35
-    vec3_t pos;
36
-} vertex_t;
37
-
38
-/*
39
-typedef struct {
40
-    vec2_t uv;
41
-} uv_t;
42
-
43
-typedef struct {
44
-    vec4_t rgba;
45
-} color_t;
46
-*/
47
-
48
-typedef struct {
49
-    vec2_t st;
50
-} texel_t;
51
-
52
-typedef struct {
53
-    int num_verts;      //!< 4 == Quad, 3 == Triangle, rendered as triangles
54
-    vertex_t vertex[4];
55
-    texel_t texel[4];
56
-    float pos[3];
57
-    float radius;       //!< \fixme yeah, I know
58
-    int texture;
59
-} sprite_t;
60
-
61
-typedef struct {
62
-    int num_sprites;
63
-    sprite_t *sprite;
64
-} sprite_seq_t;
65
-
66
-/*! \fixme For now shaders are textures on tex objects
67
- * and materials on color objects. If -1
68
- * then it doesn't have that information yet.
69
- */
70
-typedef struct {
71
-    int index[3];
72
-    vec_t st[6];
73
-    int texture;
74
-    unsigned short transparency;
75
-} texture_tri_t;
76
-
77
-typedef struct {
78
-    Vector<texture_tri_t *> texturedTriangles;
79
-    Vector<texture_tri_t *> coloredTriangles;
80
-    Vector<texture_tri_t *> texturedRectangles;
81
-    Vector<texture_tri_t *> coloredRectangles;
82
-
83
-    vec3_t center;
84
-    float radius;
85
-
86
-    unsigned int vertexCount;
87
-    vec_t *vertices;
88
-
89
-    unsigned int colorCount;
90
-    vec_t *colors;
91
-
92
-    unsigned int normalCount;
93
-    vec_t *normals;
94
-} model_mesh_t;
95
-
96
-typedef struct entity_s {
97
-    int id;                  //!< Unique identifier
98
-    float pos[3];            //!< World position
99
-    float angles[3];         //!< Euler angles (pitch, yaw, roll)
100
-    int type;                //!< {(0x00, item), (0x01, ai), (0x02, player)}
101
-    int room;                //!< Current room entity is in
102
-    worldMoveType moveType;  //!< Type of motion/clipping
103
-    bool moving;             //!< In motion?
104
-    struct entity_s *master; //!< Part of entity chain?
105
-
106
-    int state;               //!< State of the Player, AI, or object
107
-    int objectId;            //!< What kind of entity?
108
-
109
-    int modelId;             //!< Animation model
110
-    void *tmpHook;
111
-    bool animate;
112
-
113
-    /*
114
-    float time, lastTime;
115
-    int state, lastState;
116
-    int event, lastEvent;
117
-    int goal;
118
-    */
119
-} entity_t;
120
-
121
-typedef struct {
122
-    int index;    //!< model_mesh index
123
-    float yaw;    //!< angle of rotation on Y
124
-    float pos[3]; //!< position
125
-
126
-    //vec3_t bboxMax;
127
-    //vec3_t bboxMin;
128
-} static_model_t;
129
-
130
-typedef struct {
131
-    float vertices[4][3];
132
-    float normal[3];
133
-    int adjoining_room;
134
-} portal_t;
135
-
136
-typedef struct {
137
-    vertex_t a;
138
-    vertex_t b;
139
-    vertex_t c;
140
-    vertex_t d;
141
-} box_t;
142
-
143
-typedef struct {
144
-    vec_t floor;
145
-    vec_t ceiling;
146
-
147
-    bool wall;
148
-} sector_t;
149
-
150
-//! \fixme No room mesh list or sprites and etc
151
-typedef struct {
152
-    Vector<int> adjacentRooms;
153
-    Vector<portal_t *> portals;
154
-    Vector<static_model_t *> models;
155
-    Vector<sprite_t *> sprites;
156
-    Vector<box_t *> boxes;
157
-    Vector<sector_t *> sectors;
158
-
159
-    int id;
160
-    unsigned int flags;
161
-    unsigned int numXSectors;
162
-    unsigned int numZSectors;
163
-    float pos[3];
164
-    vec3_t bbox_min;
165
-    vec3_t bbox_max;
166
-} room_mesh_t;
167
-
168
-// Workout generic entity and a client class from these entities
169
-typedef struct world_entity_s {
170
-    vec3_t pos;
171
-    vec3_t lastPos;
172
-    vec3_t angle;
173
-    vec_t ttl;
174
-
175
-    int type;
176
-    int state;
177
-
178
-    //struct world_entity_s *master;
179
-
180
-} world_entity_t;
181
-
182
-typedef struct {
183
-    vec3_t pos;
184
-    vec3_t lastPos;
185
-    vec3_t angle;
186
-    char clipping;
187
-    float time, eventTime, eventTimer;
188
-    int state, nextState;
189
-    float health;
190
-
191
-    // Client
192
-    unsigned int uid;
193
-    char name[32];
194
-    int actor, enemy;
195
-
196
-    // Render
197
-    unsigned int model;
198
-    unsigned int skin;
199
-    unsigned int animFrame;
200
-
201
-} actor_entity_t;
202
-
203
-enum OpenRaiderEvent {
204
-    eNone = 0,
205
-    eWeaponDischarge,
206
-    eDying,
207
-    eDead,
208
-    eWounded,
209
-    eRunForward,
210
-    eRunBackward,
211
-    eJump,
212
-    eCrouchWalk,
213
-    eIdle,
214
-    eTaunt,
215
-    eTurn,
216
-    eRespawn,
217
-    eLand
218
-};
219
-
220
-/*!
221
- * \brief The game world (model)
222
- */
223
-class World {
224
-public:
225
-
226
-    enum WorldFlag {
227
-        fEnableHopping = 1
228
-    };
229
-
230
-    /*!
231
-     * \brief Constructs an object of World
232
-     */
233
-    World();
234
-
235
-    /*!
236
-     * \brief Deconstructs an object of World
237
-     */
238
-    ~World();
239
-
240
-    /*!
241
-     * \brief Find room a location is in.
242
-     *
243
-     * If it fails to be in a room it gives closest overlapping room.
244
-     * \param index Guessed room index
245
-     * \param x X coordinate
246
-     * \param y Y coordinate
247
-     * \param z Z coordinate
248
-     * \returns correct room index or -1 for unknown
249
-     */
250
-    int getRoomByLocation(int index, float x, float y, float z);
251
-
252
-    /*!
253
-     * \brief Find room a location is in.
254
-     *
255
-     * If it fails to be in a room it gives closest overlapping room.
256
-     * \param x X coordinate
257
-     * \param y Y coordinate
258
-     * \param z Z coordinate
259
-     * \returns correct room index or -1 for unknown
260
-     */
261
-    int getRoomByLocation(float x, float y, float z);
262
-
263
-    /*!
264
-     * \brief Looks for portal crossings from xyz to xyz2 segment
265
-     * from room[index]
266
-     * \param index valid room index
267
-     * \param x X coordinate of first point
268
-     * \param y Y coordinate of first point
269
-     * \param z Z coordinate of first point
270
-     * \param x2 X coordinate of second point
271
-     * \param y2 Y coordinate of second point
272
-     * \param z2 Z coordinate of second point
273
-     * \returns index of adjoined room or -1
274
-     */
275
-    int getAdjoiningRoom(int index,
276
-                            float x, float y, float z,
277
-                            float x2, float y2, float z2);
278
-
279
-    /*!
280
-     * \brief Gets the sector index of the position in room
281
-     * \param room valid room index
282
-     * \param x X coordinate in room
283
-     * \param z Z coordinate in room
284
-     * \returns sector index of position in room
285
-     */
286
-    int getSector(int room, float x, float z);
287
-    int getSector(int room, float x, float z, float *floor, float *ceiling);
288
-
289
-    unsigned int getRoomInfo(int room);
290
-
291
-    /*!
292
-     * \brief Check if sector is a wall
293
-     * \param room valid room index
294
-     * \param sector valid sector index
295
-     * \returns true if this sector is a wall
296
-     */
297
-    bool isWall(int room, int sector);
298
-
299
-    /*!
300
-     * \brief Get the world height at a position
301
-     * \param index valid room index
302
-     * \param x X coordinate
303
-     * \param y will be set to world height in that room
304
-     * \param z Z coordinate
305
-     * \returns true if position is in a room
306
-     */
307
-    bool getHeightAtPosition(int index, float x, float *y, float z);
308
-
309
-#ifdef BAD_BLOOD
310
-    //! \todo Temp methods for rendering use until more refactoring is done
311
-    model_mesh_t *getMesh(int index);
312
-    skeletal_model_t *getModel(int index);
313
-    room_mesh_t *getRoom(int index);
314
-    Vector<entity_t *> *getEntities();
315
-    Vector<sprite_seq_t *> *getSprites();
316
-    Vector<room_mesh_t *> *getRooms();
317
-#endif
318
-
319
-    /*!
320
-     * \brief Set an option flag
321
-     * \param flag flag to set
322
-     */
323
-    void setFlag(WorldFlag flag);
324
-
325
-    /*!
326
-     * \brief Clear an option flag
327
-     * \param flag flag to clear
328
-     */
329
-    void clearFlag(WorldFlag flag);
330
-
331
-    /*!
332
-     * \brief Clears all data in world
333
-     * \todo in future will check if data is in use before clearing
334
-     */
335
-    void destroy();
336
-
337
-    /*!
338
-     * \brief Adds room to world
339
-     * \param room room to add
340
-     */
341
-    void addRoom(room_mesh_t *room);
342
-
343
-    /*!
344
-     * \brief ADds mesh to world
345
-     * \param model mesh to add
346
-     */
347
-    void addMesh(model_mesh_t *model);
348
-
349
-    /*!
350
-     * \brief Adds entity to world
351
-     * \param e entity to add
352
-     */
353
-    void addEntity(entity_t *e);
354
-
355
-    /*!
356
-     * \brief Adds model to world.
357
-     * \param model model to add
358
-     * \returns next model ID or -1 on error
359
-     */
360
-    int addModel(skeletal_model_t *model);
361
-
362
-    /*!
363
-     * \brief Adds sprite to world
364
-     * \param sprite sprite to add
365
-     */
366
-    void addSprite(sprite_seq_t *sprite);
367
-
368
-    /*!
369
-     * \brief Move entity in given direction unless collision occurs
370
-     * \param e entity to move
371
-     * \param movement direction of movement ('f', 'b', 'l' or 'r')
372
-     */
373
-    void moveEntity(entity_t *e, char movement);
374
-
375
-private:
376
-
377
-    /*!
378
-     * \brief Clears all data in world
379
-     */
380
-    void clear();
381
-
382
-    bool mClearLock;
383
-    unsigned int mFlags;                //!< World flags
384
-    Vector<entity_t *> mEntities;       //!< World entities
385
-    Vector<room_mesh_t *> mRooms;       //!< Map data and meshes
386
-    Vector<model_mesh_t *> mMeshes;     //!< Unanimated meshes
387
-    Vector<sprite_seq_t *> mSprites;    //!< Sprites
388
-    Vector<skeletal_model_t *> mModels; //!< Skeletal animation models
389
-};
390
-
391
-#endif

+ 0
- 673
include/games/TombRaider1.h Переглянути файл

@@ -1,673 +0,0 @@
1
-/*!
2
- * \file include/games/TombRaider1.h
3
- * \brief Tomb Raider 1 items and states.
4
- *
5
- * Based on TR Rosetta Stone
6
- *
7
- * \author Mongoose
8
- * \author xythobuz
9
- */
10
-#ifndef _TOMBRAIDER1_H_
11
-#define _TOMBRAIDER1_H_
12
-
13
-/*!
14
- * \brief Tomb Raider 1 items and states
15
- */
16
-class TombRaider1 {
17
-public:
18
-
19
-    /*!
20
-     * \brief States of a Wolf (Item 7)
21
-     */
22
-    enum WolfStates {
23
-        WolfState_Walking       = 1,
24
-        WolfState_Running       = 2,
25
-        WolfState_Jumping       = 3,
26
-        WolfState_Stalking      = 5,
27
-        WolfState_JumpingAttack = 6,
28
-        WolfState_Attacking     = 7,
29
-        WolfState_Lying         = 8,  //!< Lying down
30
-        WolfState_Getting       = 9,  //!< Getting ready to strike
31
-        WolfState_RunningJump   = 10,
32
-        WolfState_Dying         = 11,
33
-        WolfState_Biting        = 12
34
-    };
35
-
36
-    /*!
37
-     * \brief States of a Bear (Item 8)
38
-     */
39
-    enum BearStates {
40
-        BearState_Walking       = 0, //!< Walking on all fours
41
-        BearState_Getting       = 1, //!< Getting back to all fours
42
-        BearState_WalkingHind   = 2, //!< Walking on hind legs
43
-        BearState_Running       = 3, //!< Running on all fours
44
-        BearState_Rearing       = 4, //!< Rearing up on hind legs
45
-        BearState_Growling      = 5, //!< ?
46
-        BearState_RunningAttack = 6, //!< Running and attacking
47
-        BearState_Standing      = 7, //!< Standing on hind legs
48
-        BearState_Biting        = 8,
49
-        BearState_Dying         = 9
50
-    };
51
-
52
-    /*!
53
-     * \brief States of a Bat (Item 9)
54
-     */
55
-    enum BatStates {
56
-        BatState_Starting = 1, //!< Starting to fly
57
-        BatState_Flying   = 2, //!< Flying straight
58
-        BatState_Biting   = 3,
59
-        BatState_Circling = 4,
60
-        BatState_Dying    = 5
61
-    };
62
-
63
-    /*!
64
-     * \brief States of a Crocodile on land (Item 10)
65
-     */
66
-    enum CrocodileLandStates {
67
-        CrocodileLandState_Stationary = 1,
68
-        CrocodileLandState_Walking1   = 2,
69
-        CrocodileLandState_Walking2   = 3,
70
-        CrocodileLandState_Turning    = 4,
71
-        CrocodileLandState_Biting     = 5,
72
-        CrocodileLandState_Dying      = 7
73
-    };
74
-
75
-    /*!
76
-     * \brief States of a Crocodile in water (Item 11)
77
-     */
78
-    enum CrocodileWaterStates {
79
-        CrocodileWaterState_Swimming = 1,
80
-        CrocodileWaterState_Biting   = 2,
81
-        CrocodileWaterState_Dying    = 3
82
-    };
83
-
84
-    /*!
85
-     * \brief States of a Lion (Male & Female) and a Panther (Items 12, 13, 14)
86
-     */
87
-    enum LionStates {
88
-        LionState_Standing = 1,
89
-        LionState_Walking  = 2,
90
-        LionState_Leaping  = 3,
91
-        LionState_LeapBite = 4,
92
-        LionState_Dying    = 5,
93
-        LionState_Biting1  = 6,
94
-        LionState_Biting2  = 7
95
-    };
96
-
97
-    /*!
98
-     * \brief States of a Gorilla (Item 15)
99
-     */
100
-    enum GorillaStates {
101
-        GorillaState_Standing = 1,  //!< Standing on all fours
102
-        GorillaState_Running  = 3,  //!< Running on all fours
103
-        GorillaState_Walking  = 4,  //!< Walking on legs (attacking?)
104
-        GorillaState_Dying    = 5,
105
-        GorillaState_Thumping = 6,  //!< Thumping on chest
106
-        GorillaState_Waving   = 7,  //!< Waving arms
107
-        GorillaState_TurningL = 8,  //!< Turning leftward?
108
-        GorillaState_TurningR = 9,  //!< Turning rightward?
109
-        GorillaState_Jumping  = 10, //!< Jumping up and waving arms
110
-        GorillaState_Climbing = 11
111
-    };
112
-
113
-    /*!
114
-     * \brief States of a Giant Rat on land (Item 16)
115
-     */
116
-    enum GiantRatLandStates {
117
-        GiantRatLandState_Standing  = 1,
118
-        GiantRatLandState_JumpBite  = 2,
119
-        GiantRatLandState_Running   = 3,
120
-        GiantRatLandState_Biting    = 4,
121
-        GiantRatLandState_Dying     = 5,
122
-        GiantRatLandState_RearingUp = 6
123
-    };
124
-
125
-    /*!
126
-     * \brief States of a Giant Rat in the water (Item 17)
127
-     */
128
-    enum GiantRatWaterStates {
129
-        GiantRatWaterState_Swimming = 1,
130
-        GiantRatWaterState_Biting   = 2,
131
-        GiantRatWaterState_Dying    = 3
132
-    };
133
-
134
-    /*!
135
-     * \brief States of a Tyrannosaur (Item 18)
136
-     */
137
-    enum TyrannosaurStates {
138
-        TyrannosaurState_Standing  = 1,
139
-        TyrannosaurState_Walking   = 2,
140
-        TyrannosaurState_Running   = 3,
141
-        TyrannosaurState_Dying     = 5,
142
-        TyrannosaurState_Bellowing = 6,
143
-        TyrannosaurState_Biting    = 7,
144
-        TyrannosaurState_Shaking   = 8  //!< Shaking Head and Spitting Out
145
-    };
146
-
147
-    /*!
148
-     * \brief States of a Raptor (Item 19)
149
-     */
150
-    enum RaptorStates {
151
-        RaptorState_Dying     = 0,
152
-        RaptorState_Standing  = 1,
153
-        RaptorState_Walking   = 2,
154
-        RaptorState_Running   = 3,
155
-        RaptorState_JumpBite  = 4,
156
-        RaptorState_Bellowing = 6,
157
-        RaptorState_RunBellow = 7,
158
-        RaptorState_Biting    = 8
159
-    };
160
-
161
-    /*!
162
-     * \brief States of a Winged Mutant (Item 20)
163
-     */
164
-    enum WingedMutantStates {
165
-        WingedMutantState_Crouching = 1,
166
-        WingedMutantState_Walking   = 2,
167
-        WingedMutantState_Running   = 3,
168
-        WingedMutantState_Biting    = 4,
169
-        WingedMutantState_Looking   = 6,
170
-        WingedMutantState_Jumping   = 7,
171
-        WingedMutantState_Clawing   = 8,
172
-        WingedMutantState_Aiming    = 9,  //!< Aiming Right-Hand Gun
173
-        WingedMutantState_AimFire   = 10, //!< Aiming and Firing Left-Hand Gun
174
-        WingedMutantState_Firing    = 11, //!< Firing Right-Hand Gun
175
-        WingedMutantState_Standing  = 12,
176
-        WingedMutantState_Flying    = 13
177
-    };
178
-
179
-    /*!
180
-     * \brief States of a Centaur Mutant (Item 23)
181
-     */
182
-    enum CentaurMutantStates {
183
-        CentaurMutantState_Standing  = 1,
184
-        CentaurMutantState_Firing    = 2,
185
-        CentaurMutantState_Galloping = 3,
186
-        CentaurMutantState_Aiming    = 4,
187
-        CentaurMutantState_Dying     = 5,
188
-        CentaurMutantState_Rearing   = 6  //!<  Rearing up
189
-    };
190
-
191
-    /*!
192
-     * \brief States of a Mummy (Item 24)
193
-     */
194
-    enum MummyStates {
195
-        MummyState_Standing = 1,
196
-        MummyState_Falling  = 2  //!< Falling forward
197
-    };
198
-
199
-    /*!
200
-     * \brief States of Larson (Item 27)
201
-     */
202
-    enum LarsonStates {
203
-        LarsonState_Walking1    = 0,
204
-        LarsonState_StandingGun = 1,
205
-        LarsonState_Walking2    = 2,
206
-        LarsonState_Running     = 3,
207
-        LarsonState_Aiming      = 4,
208
-        LarsonState_Injured     = 5, //!< Injured by gunshot / Dying
209
-        LarsonState_Standing    = 6,
210
-        LarsonState_Firing      = 7
211
-    };
212
-
213
-    /*!
214
-     * \brief States of Pierre (Item 28)
215
-     */
216
-    enum PierreStates {
217
-        PierreState_Standing   = 1,
218
-        PierreState_Walking    = 2,
219
-        PierreState_Running    = 3,
220
-        PierreState_Aiming     = 4,
221
-        PierreState_Dying      = 5,
222
-        PierreState_Holstering = 6,
223
-        PierreState_Firing     = 7
224
-    };
225
-
226
-    /*!
227
-     * \brief States of the Skateboard (Item 29)
228
-     */
229
-    enum SkateboardStates {
230
-        SkateboardState_BeingTurned = 0,
231
-        SkateboardState_Stationary1 = 1,
232
-        SkateboardState_Stationary2 = 2,
233
-        SkateboardState_Stationary3 = 3,
234
-        SkateboardState_Stationary4 = 4
235
-    };
236
-
237
-    /*!
238
-     * \brief States of the Skateboard Kid (Item 30)
239
-     */
240
-    enum SkateboardKidStates {
241
-        SkateboardKidState_Turning = 0, //!< Turning and Aiming?
242
-        SkateboardKidState_Firing1 = 1,
243
-        SkateboardKidState_Skating = 2,
244
-        SkateboardKidState_Aiming  = 3,
245
-        SkateboardKidState_Firing2 = 4,
246
-        SkateboardKidState_Dying   = 5
247
-    };
248
-
249
-    /*!
250
-     * \brief States of the Cowboy (Item 31)
251
-     */
252
-    enum CowboyStates {
253
-        CowboyState_Aiming1 = 1,
254
-        CowboyState_Walking = 2,
255
-        CowboyState_Running = 3,
256
-        CowboyState_Aiming2 = 4,
257
-        CowboyState_Dying   = 5,
258
-        CowboyState_Firing  = 6
259
-    };
260
-
261
-    /*!
262
-     * \brief States of Mr. T (Item 32)
263
-     */
264
-    enum MrTStates {
265
-        MrTState_Dying    = 0,
266
-        MrTState_Standing = 1,
267
-        MrTState_Walking  = 2,
268
-        MrTState_Running  = 3,
269
-        MrTState_Aiming   = 4,
270
-        MrTState_Firing   = 6
271
-    };
272
-
273
-    /*!
274
-     * \brief States of Winged Natla (Item 33)
275
-     */
276
-    enum WingedNatlaStates {
277
-        WingedNatlaState_Standing1 = 1,
278
-        WingedNatlaState_Flying    = 2,
279
-        WingedNatlaState_Running   = 3,
280
-        WingedNatlaState_Aiming    = 4, //!< Aiming and Firing
281
-        WingedNatlaState_Dying1    = 5, //!< "Dying" the first time
282
-        WingedNatlaState_Spinning  = 7, //!< Spinning around in air
283
-        WingedNatlaState_Standing2 = 8,
284
-        WingedNatlaState_Dying2    = 9  //!< Dying for real
285
-    };
286
-
287
-    /*!
288
-     * \brief States of the Giant Mutant (Item 34)
289
-     */
290
-    enum GiantMutantStates {
291
-        GiantMutantState_Dying         = 0,
292
-        GiantMutantState_Sitting       = 1, //!< Sitting on floor
293
-        GiantMutantState_Pulling       = 2, //!< Pulling self forward
294
-        GiantMutantState_SlappingRight = 4, //!< Slapping with right hand
295
-        GiantMutantState_SlappingBoth  = 5, //!< Slapping with both hands
296
-        GiantMutantState_MakingWave    = 6, //!< Making big wave with right hand
297
-        GiantMutantState_Dropping      = 8, //!< Dropping to floor after hatching
298
-        GiantMutantState_RaisingArms   = 9,
299
-        GiantMutantState_Shaking       = 11 //!< Shaking victim with right hand
300
-    };
301
-
302
-    /*!
303
-     * \brief States of a piece of Collapsible Floor (Item 35)
304
-     */
305
-    enum CollapsibleFloorStates {
306
-        CollapsibleFloorState_Stationary = 0,
307
-        CollapsibleFloorState_Shaking    = 1,
308
-        CollapsibleFloorState_Falling    = 2,
309
-        CollapsibleFloorState_Settling   = 3  //!< Settling down
310
-    };
311
-
312
-    /*!
313
-     * \brief States of a Swinging Blade (Item 36)
314
-     */
315
-    enum SwingingBladeStates {
316
-        SwingingBladeState_Stationary = 0,
317
-        SwingingBladeState_Swinging   = 2
318
-    };
319
-
320
-    /*!
321
-     * \brief States of a Boulder (Item 38)
322
-     */
323
-    enum BoulderStates {
324
-        BoulderState_Stationary = 0,
325
-        BoulderState_Rolling    = 1
326
-    };
327
-
328
-    /*!
329
-     * \brief States of a Dart Gun (Item 40)
330
-     */
331
-    enum DartGunStates {
332
-        DartGunState_Idle   = 0, //!< ?
333
-        DartGunState_Firing = 1  //!< ?
334
-    };
335
-
336
-    /*!
337
-     * \brief States of a Door opening upwards (Item 41)
338
-     */
339
-    enum DoorUpwardStates {
340
-        DoorUpwardState_Upward = 0,
341
-        DoorUpwardState_OnSide = 1
342
-    };
343
-
344
-    /*!
345
-     * \brief States of a Slamming Door (Item 42)
346
-     */
347
-    enum SlammingDoorStates {
348
-        SlammingDoorState_Open   = 0,
349
-        SlammingDoorState_Closed = 1
350
-    };
351
-
352
-    /*!
353
-     * \brief States of the Handle of Thors Hammer (Item 44)
354
-     */
355
-    enum ThorHammerHandleStates {
356
-        ThorHammerHandleState_Stationary = 0, //!< Stationary in up position
357
-        ThorHammerHandleState_Moving1    = 1, //!< Moving down a little and returning
358
-        ThorHammerHandleState_Moving2    = 2, //!< Moving down all the way
359
-        ThorHammerHandleState_Stopped    = 3  //!< Stopped at down position
360
-    };
361
-
362
-    /*!
363
-     * \brief States of the Block of Thors Hammer (Item 45)
364
-     */
365
-    enum ThorHammerBlockStates {
366
-        ThorHammerBlockState_Stationary = 0,
367
-        ThorHammerBlockState_Moving1    = 1, //!< Moving down a little and returning
368
-        ThorHammerBlockState_Moving2    = 2  //!< Moving down all the way
369
-    };
370
-
371
-    /*!
372
-     * \brief States of a Metal Rod (Item 47)
373
-     */
374
-    enum MetalRodStates {
375
-        MetalRodState_Stationary = 0,
376
-        MetalRodState_Moving     = 1
377
-    };
378
-
379
-    /*!
380
-     * \brief States of a Pushable Cubical (Item 48 - 51)
381
-     */
382
-    enum PushableStates {
383
-        PushableState_Stationary = 0,
384
-        PushableState_Pulled     = 1, //!< ?
385
-        PushableState_Pushed     = 2  //!< ?
386
-    };
387
-
388
-    /*!
389
-     * \brief States of a Movable Tall Block (Item 52)
390
-     */
391
-    enum MovableTallBlockStates {
392
-        MovableTallBlockState_Stationary     = 0,
393
-        MovableTallBlockState_MovingForward  = 1, //!< ?
394
-        MovableTallBlockState_MovingBackward = 2  //!< ?
395
-    };
396
-
397
-    /*!
398
-     * \brief States of Falling Pieces (Item 53)
399
-     */
400
-    enum FallingPiecesStates {
401
-        FallingPiecesState_Stationary = 0,
402
-        FallingPiecesState_Falling    = 1,
403
-        FallingPiecesState_Settling   = 2  //!< Settling down
404
-    };
405
-
406
-    /*!
407
-     * \brief States of a Switch (Item 55, 56)
408
-     */
409
-    enum SwitchStates {
410
-        SwitchState_Off = 0,
411
-        SwitchState_On  = 1  //!< States may be reversed
412
-    };
413
-
414
-    /*!
415
-     * \brief States of a Door (Item 57 - 66)
416
-     */
417
-    enum DoorStates {
418
-        DoorState_Closed = 0,
419
-        DoorState_Open   = 1
420
-    };
421
-
422
-    /*!
423
-     * \brief States of a Cog (Item 74 - 76)
424
-     */
425
-    enum CogStates {
426
-        CogState_Stationary = 0,
427
-        CogState_Turning    = 1
428
-    };
429
-
430
-    /*!
431
-     * \brief States of a Shack (Item 162)
432
-     */
433
-    enum ShackStates {
434
-        ShackState_StartingPosition = 0,
435
-        ShackState_DroppingFirst    = 1, //!< Dropping after first fuse
436
-        ShackState_DroppingSecond   = 2, //!< Dropping after second fuse
437
-        ShackState_DroppingThird    = 3, //!< Dropping to ground after third fuse
438
-        ShackState_OnGround         = 4
439
-    };
440
-
441
-    /*!
442
-     * \brief States of a Mutant Egg & Holder (Item 163 & 181)
443
-     */
444
-    enum MutantEggStates {
445
-        MutantEggState_Starting = 0,
446
-        MutantEggState_Hatching = 1  //!< Is the fragmenting hardcoded?
447
-    };
448
-
449
-    /*!
450
-     * \brief States of a Motorboat (Item 182)
451
-     */
452
-    enum MotorboatStates {
453
-        MotorboatState_StationaryInitial = 1,
454
-        MotorboatState_Moving            = 2,
455
-        MotorboatState_StationaryFinal   = 3
456
-    };
457
-
458
-    /*!
459
-     * \brief Items & IDs in Tomb Raider 1
460
-     */
461
-    enum Items {
462
-        Lara             = 0,
463
-        PistolAnimation  = 1,
464
-        ShotgunAnimation = 2,
465
-        MagnumAnimation  = 3,
466
-        LaraAlternate    = 4,  //!< Lara's home appearance, wounded, or turned to gold
467
-        UziAnimation     = 5,
468
-        LaraMutant       = 6,
469
-        Wolf             = 7,
470
-        Bear             = 8,
471
-        Bat              = 9,
472
-        CrocodileLand    = 10,
473
-        CrocodileWater   = 11,
474
-        LionMale         = 12,
475
-        LionFemale       = 13, //!< Same states as Male Lion
476
-        Panther          = 14, //!< Same states as Male and Female Lion
477
-        Gorilla          = 15,
478
-        GiantRatLand     = 16,
479
-        GiantRatWater    = 17,
480
-        Tyrannosaur      = 18,
481
-        Raptor           = 19,
482
-        WingedMutant     = 20, //!< Also winged mummy (unused)
483
-        LaraHips1        = 21,
484
-        LaraHips2        = 22,
485
-        CentaurMutant    = 23,
486
-        Mummy            = 24,
487
-
488
-        Larson           = 27,
489
-        Pierre           = 28,
490
-        Skateboard       = 29,
491
-        SkateboardKid    = 30,
492
-        Cowboy           = 31,
493
-        MrT              = 32,
494
-        WingedNatla      = 33, //!< Actually Natla with a winged mutant
495
-        GiantMutant      = 34,
496
-        CollapsibleFloor = 35,
497
-        SwingingBlade    = 36,
498
-        Spikes           = 37,
499
-        Boulder          = 38,
500
-        Dart             = 39,
501
-        DartGun          = 40,
502
-        DoorUpward       = 41,
503
-        SlammingDoor     = 42,
504
-        SwordOfDamocles1 = 43,
505
-        ThorHammerHandle = 44,
506
-        ThorHammerBlock  = 45,
507
-        HangingBall      = 46, //!< Hanging ball? Some kind of box?
508
-        MetalRod         = 47, //!< Metal rod? / Powered mining cart
509
-        PushableCubical1 = 48,
510
-        PushableCubical2 = 49,
511
-        PushableCubical3 = 50,
512
-        PushableCubical4 = 51,
513
-        MovableTallBlock = 52,
514
-        FallingPieces    = 53,
515
-        SwordOfDamocles2 = 54,
516
-        AboveWaterSwitch = 55,
517
-        UnderWaterSwitch = 56,
518
-        Door1            = 57,
519
-        Door2            = 58,
520
-        Door3            = 59,
521
-        Door4            = 60,
522
-        Door5            = 61,
523
-        Door6            = 62,
524
-        Door7            = 63,
525
-        Door8            = 64,
526
-        Trapdoor1        = 65, //!< Uses DoorStates
527
-        Trapdoor2        = 66, //!< Uses DoorStates
528
-
529
-        BridgeFlat       = 68,
530
-        BridgeSlope1     = 69,
531
-        BridgeSlope2     = 70,
532
-        PassportOpen     = 71, //!< Passport opening up
533
-        Compass          = 72,
534
-
535
-        Cogs1            = 74, //!< animated
536
-        Cogs2            = 75, //!< animated
537
-        Cogs3            = 76, //!< animated
538
-        CS_Lara          = 77, //!< Lara / Scion holder in Cut Scene
539
-        CS_Larson        = 78, //!< Larson / Natla / Scion holder in Cut Scene
540
-        CS_LarsonGun     = 79, //!< Larsons gun / Scion / Natla in Cut Scene
541
-        CS_Scion         = 80, //!< Scion in Cut Scene
542
-        PassportClosed   = 81, //!< Passport closed
543
-        N                = 82, //!< N-thingy, Playstation memory card?
544
-        SaveCrystal      = 83,
545
-        _Pistols         = 84,
546
-        _Shotgun         = 85,
547
-        _Magnums         = 86,
548
-        _Uzis            = 87,
549
-        _PistolAmmo      = 88, //!< ?
550
-        _ShotgunAmmo     = 89,
551
-        _MagnumAmmo      = 90,
552
-        _UziAmmo         = 91,
553
-
554
-        _SmallMedipack   = 93,
555
-        _LargeMedipack   = 94,
556
-        Sunglasses       = 95,
557
-        Cassette         = 96, // Cassette player and headphones
558
-        DirectionKeys    = 97,
559
-
560
-        Pistol           = 99,
561
-        Shotgun          = 100,
562
-        Magnum           = 101,
563
-        Uzi              = 102,
564
-        PistolAmmo       = 103, //!< ?
565
-        ShotgunAmmo      = 104,
566
-        MagnumAmmo       = 105,
567
-        UziAmmo          = 106,
568
-
569
-        SmallMedipack    = 108,
570
-        LargeMedipack    = 109,
571
-        _Puzzle1         = 110,
572
-        _Puzzle2         = 111,
573
-        _Puzzle3         = 112,
574
-        _Puzzle4         = 113,
575
-        Puzzle1          = 114,
576
-        Puzzle2          = 115,
577
-        Puzzle3          = 116,
578
-        Puzzle4          = 117,
579
-        Slot1Empty       = 118,
580
-        Slot2Empty       = 119,
581
-        Slot3Empty       = 120,
582
-        Slot4Empty       = 121,
583
-        Slot1Full        = 122,
584
-        Slot2Full        = 123,
585
-        Slot3Full        = 124,
586
-        Slot4Full        = 125,
587
-        _Pickup1         = 126,
588
-        Pickup1          = 127,
589
-        LaraHips3        = 128,
590
-        _Key1            = 129,
591
-        _Key2            = 130,
592
-        _Key3            = 131,
593
-        _Key4            = 132,
594
-        Key1             = 133,
595
-        Key2             = 134,
596
-        Key3             = 135,
597
-        Key4             = 136,
598
-        Lock1            = 137,
599
-        Lock2            = 138,
600
-        Lock3            = 139,
601
-        Lock4            = 140,
602
-
603
-        _ScionPiece      = 143,
604
-
605
-        CompleteScion    = 146,
606
-        ScionHolder      = 147,
607
-
608
-        ScionPiece       = 150,
609
-        _Flare           = 151, //!< Flare(?) / Explosion
610
-
611
-        _Splash          = 153,
612
-
613
-        _Bubbles1        = 155,
614
-        _Bubbles2        = 156,
615
-
616
-        _BloodSplatter   = 158,
617
-
618
-        _FlyingDisk      = 160,
619
-        CentaurStatue    = 161,
620
-        Shack            = 162, //!< Suspended from wire rope
621
-        MutantEggNormal  = 163, //!< Mutant Egg and Holder (Normal)
622
-        _BulletHit       = 164,
623
-        _Sparkle         = 165,
624
-        Gunflare1        = 166,
625
-
626
-        LaraHips4        = 169,
627
-        LaraHips5        = 170,
628
-
629
-        MutantBullet     = 172,
630
-        MutantGrenade    = 173,
631
-
632
-        _Splatter        = 176,
633
-        LaraHips6        = 177,
634
-        _Fire            = 178,
635
-        LaraHips7        = 179,
636
-        FlowingLava      = 180, //!< Flowing Atlantean Lava
637
-        MutantEggBig     = 181, //!< Mutant Egg and Holder (Big)
638
-        Motorboat        = 182,
639
-        LaraHips8        = 183,
640
-
641
-        ShrinkingWedge   = 189, //!< ?
642
-        _StandardSymbols = 190,
643
-        _Plant1          = 191,
644
-        _Plant2          = 192,
645
-        _Plant3          = 193,
646
-        _Plant4          = 194,
647
-        _Plant5          = 195,
648
-
649
-        _Bag1            = 200,
650
-
651
-        _Bag2            = 204,
652
-
653
-        Gunflare2        = 207,
654
-
655
-        _Rock1           = 212,
656
-        _Rock2           = 213,
657
-        _Rock3           = 214,
658
-        _Bag3            = 215,
659
-        _Pottery1        = 216,
660
-        _Pottery2        = 217,
661
-
662
-        _PaintedPot      = 231,
663
-
664
-        _IncaMummy       = 233,
665
-
666
-        _Pottery3        = 236,
667
-        _Pottery4        = 237,
668
-        _Pottery5        = 238,
669
-        _Pottery6        = 239
670
-    };
671
-};
672
-
673
-#endif

+ 0
- 460
include/templates/List.h Переглянути файл

@@ -1,460 +0,0 @@
1
-/*!
2
- * \file include/templates/List.h
3
- * \brief Template list
4
- *
5
- * UINT_MAX is an error condition, used in place of -1
6
- *
7
- * \author Mongoose
8
- * \author xythobuz
9
- */
10
-
11
-#ifndef _LIST_H_
12
-#define _LIST_H_
13
-
14
-#include <stdlib.h>
15
-#include <limits.h>
16
-#include <stdio.h>
17
-
18
-/*!
19
- * \brief Template class encapsulating a single list node
20
- * \tparam T encapsulated data type
21
- */
22
-template <class T> class ListNode {
23
-public:
24
-
25
-    /*!
26
-     * \brief Create a new ListNode
27
-     * \param data Data to be stored in node
28
-     * \param id node id
29
-     */
30
-    ListNode(T data, unsigned int id) {
31
-        _data  = data;
32
-        _id = id;
33
-        _next = NULL;
34
-    }
35
-
36
-    /*!
37
-     * \brief Destroy a ListNode
38
-     */
39
-    ~ListNode() {
40
-    }
41
-
42
-    /*!
43
-     * \brief Set the id of this ListNode
44
-     * \param id new id
45
-     */
46
-    void Id(unsigned int id) {
47
-        _id = id;
48
-    }
49
-
50
-    /*!
51
-     * \brief Get the id of this ListNode
52
-     * \returns current id
53
-     */
54
-    unsigned int Id() {
55
-        return _id;
56
-    }
57
-
58
-    /*!
59
-     * \brief Set the data of this ListNode
60
-     * \param data new data
61
-     */
62
-    void Data(T data) {
63
-        _data = data;
64
-    }
65
-
66
-    /*!
67
-     * \brief Get the data of this ListNode
68
-     * \returns current data
69
-     */
70
-    T Data() {
71
-        return _data;
72
-    }
73
-
74
-    /*!
75
-     * \brief Get the next ListNode in the List
76
-     * \returns next pointer or NULL
77
-     */
78
-    ListNode<T> *Next() {
79
-        return _next;
80
-    }
81
-
82
-    /*!
83
-     * \brief Set the next ListNode in the List
84
-     * \param next new next pointer
85
-     */
86
-    void Next(ListNode<T> *next) {
87
-        _next = next;
88
-    }
89
-
90
-    /*!
91
-     * \brief Print this ListNode
92
-     */
93
-    void Print() {
94
-        printf("(%u, %p)",  _id, _data);
95
-    }
96
-
97
-private:
98
-
99
-    ListNode<T> *_next; //!< Next Pointer
100
-    unsigned int _id; //!< ListNode ID
101
-    T _data; //!< Encapsulated data
102
-};
103
-
104
-/*!
105
- * \brief Template class representing a linked list
106
- * \tparam T encapsulated data type
107
- */
108
-template <class T> class List {
109
-public:
110
-
111
-    /*!
112
-     * \brief Construct a new linked list
113
-     */
114
-    List() {
115
-        _num_items = 0;
116
-        _head = NULL;
117
-        _current = NULL;
118
-        _last = NULL;
119
-        _cache = NULL;
120
-    }
121
-
122
-    /*!
123
-     * \brief Deconstruct a linked list
124
-     * \sa List::Clear()
125
-     */
126
-    ~List() {
127
-        Clear();
128
-    }
129
-
130
-    /*!
131
-     * \brief Add all data from another list to this one
132
-     * NOTE: this only copies data, the containers aren't the same ids
133
-     * \param list source list where data does come from
134
-     */
135
-    void Copy(List<T> *list) {
136
-        if (!list)
137
-            return;
138
-        for (list->Reset(); list->CurrentExists(); list->Next())
139
-            Add(list->Current());
140
-    }
141
-
142
-    /*!
143
-     * \brief Delete every item in this list
144
-     */
145
-    void Clear() {
146
-        _num_items = 0;
147
-        _last = _cache = NULL;
148
-        while (_head) {
149
-            _current = _head;
150
-            _head = _head->Next();
151
-            delete _current;
152
-        }
153
-    }
154
-
155
-    /*!
156
-     * \brief Searches the list for an id
157
-     * \param id id to be searched
158
-     * \returns data with id, or 0
159
-     */
160
-    T SearchId(unsigned int id) {
161
-        ListNode<T> *current = _head;
162
-        ListNode<T> *last = NULL;
163
-        if (_cache) {
164
-            if (id >= _cache->Id())
165
-                current = _cache;
166
-        }
167
-        while (current) {
168
-            // Found
169
-            if (current->Id() == id) {
170
-                _cache = current;
171
-                return current->Data();
172
-            }
173
-            last = current;
174
-            current = current->Next();
175
-        }
176
-        return 0;
177
-    }
178
-
179
-    /*!
180
-     * \brief Searches the list for specific data
181
-     * \param data data to be searched for
182
-     * \returns id of data, or UINT_MAX
183
-     */
184
-    unsigned int SearchKey(T data) {
185
-        ListNode<T> *current = _head;
186
-        ListNode<T> *last = NULL;
187
-        if (_cache) {
188
-            // Mongoose: 2001-01-31, hhmmm... fixed?
189
-            if (data == _cache->Data())
190
-                return _cache->Id();
191
-        }
192
-        while (current) {
193
-            // Found
194
-            if (current->Data() == data) {
195
-                _cache = current;
196
-                return current->Id();
197
-            }
198
-            last = current;
199
-            current = current->Next();
200
-        }
201
-        return UINT_MAX;
202
-    }
203
-
204
-    /*!
205
-     * \brief Search for an id
206
-     * \param i id to be searched
207
-     * \returns id or 0
208
-     * \sa List::SearchId()
209
-     */
210
-    T operator [] (unsigned int i) {
211
-        if (_head) {
212
-            return SearchId(i);
213
-        } else {
214
-#ifdef DEBUG_INDEX_EMPTY_LIST
215
-            printf("List[%u] = NULL\n", i);
216
-#endif
217
-        }
218
-        return 0;
219
-    }
220
-
221
-    /*!
222
-     * \brief Search for an id and remove the associated item from the list
223
-     * \param id id to be deleted
224
-     */
225
-    void RemoveId(unsigned int id) {
226
-        ListNode<T> *current = _head;
227
-        ListNode<T> *last = NULL;
228
-        _last = _cache = NULL;
229
-        while (current) {
230
-            // Remove
231
-            if (current->Id() == id) {
232
-                if (current == _head)
233
-                    _head = current->Next();
234
-                else
235
-                    last->Next(current->Next());
236
-                if (_current == current)
237
-                    _current = NULL;
238
-                delete current;
239
-                _num_items--;
240
-                return;
241
-            }
242
-            last = current;
243
-            current = current->Next();
244
-        }
245
-    }
246
-
247
-    /*!
248
-     * \brief Search for data and remove the associated item from the list
249
-     * \param data data to be deleted
250
-     */
251
-    void Remove(T data) {
252
-        ListNode<T> *current = _head;
253
-        ListNode<T> *last = NULL;
254
-        _last = _cache = NULL;
255
-        while (current) {
256
-            // Remove
257
-            if (current->Data() == data) {
258
-                if (current == _head)
259
-                    _head = current->Next();
260
-                else
261
-                    last->Next(current->Next());
262
-                if (_current == current)
263
-                    _current = NULL;
264
-                delete current;
265
-                _num_items--;
266
-                return;
267
-            }
268
-            last = current;
269
-            current = current->Next();
270
-        }
271
-    }
272
-
273
-    /*!
274
-     * \brief Is the list empty?
275
-     * \returns true if the list is empty
276
-     */
277
-    bool Empty() {
278
-        return (_head == NULL);
279
-    }
280
-
281
-    /*!
282
-     * \brief Length of the list
283
-     * \returns number of items in the list
284
-     */
285
-    unsigned int NumItems() {
286
-        return _num_items;
287
-    }
288
-
289
-    /*!
290
-     * \brief Print the list
291
-     * \param print_func function that will be called for each item in the list, after its id was printed. Or NULL.
292
-     */
293
-    void Print(void (*print_func)(T)) {
294
-        ListNode<T> *current = _head;
295
-        printf(" [%u] {\n", _num_items);
296
-        while (current) {
297
-            printf("#%u, ", current->Id());
298
-            if (print_func)
299
-                (*print_func)(current->Data());
300
-            current = current->Next();
301
-            fflush(stdout);
302
-        }
303
-        printf(" }\n");
304
-    }
305
-
306
-    /*!
307
-     * \brief Print all IDs in this list
308
-     */
309
-    void Print() {
310
-        ListNode<T> *current = _head;
311
-        printf("List %u {\n", _num_items);
312
-        while (current) {
313
-            //current->Print();
314
-            printf("%u", current->Id());
315
-            current = current->Next();
316
-            if (current)
317
-                printf(", ");
318
-            fflush(stdout);
319
-        }
320
-        printf(" }\n");
321
-    }
322
-
323
-    /*!
324
-     * \brief Reset the iterator
325
-     */
326
-    void Reset() {
327
-        _current = _head;
328
-        _cache = _head;
329
-    }
330
-
331
-    /*!
332
-     * \brief Traverses the list
333
-     * \returns true if there is a new current item, false if the list is at the end
334
-     * \sa List::Next()
335
-     */
336
-    bool operator ++ (int) {
337
-        return Next();
338
-    }
339
-
340
-    /*!
341
-     * \brief Traverses the list
342
-     * \returns true if there is a new current item, false if the list is at the end
343
-     * \sa List::Next()
344
-     */
345
-    bool operator ++ () {
346
-        return Next();
347
-    }
348
-
349
-    /*!
350
-     * \brief Traverses the list
351
-     * \returns true if there is a new current item, false if the list is at the end
352
-     */
353
-    bool Next() {
354
-        if (_current)
355
-            _current = _current->Next();
356
-        return (_current != NULL);
357
-    }
358
-
359
-    /*!
360
-     * \brief Get the id of the current item
361
-     * \returns id of current item or UINT_MAX if there is no current item
362
-     */
363
-    unsigned int CurrentId() {
364
-        if (!_current)
365
-            return UINT_MAX;
366
-
367
-        return _current->Id();
368
-    }
369
-
370
-    /*!
371
-     * \brief Is there a current item?
372
-     * \returns true if there is a current item, false otherwise
373
-     */
374
-    bool CurrentExists() {
375
-        return (_current != 0);
376
-    }
377
-
378
-    /*!
379
-     * \brief Get the current items data
380
-     * \returns data of the current item or 0 if there is no current item
381
-     */
382
-    T Current() {
383
-        if (_current)
384
-            return _current->Data();
385
-        else
386
-            return 0;
387
-    }
388
-
389
-    /*!
390
-     * \brief Add data to the list. Constructs a new ListNode encapsulating the data.
391
-     * \param data data to be stored
392
-     * \returns id of the new ListNode
393
-     */
394
-    unsigned int Add(T data) {
395
-        ListNode<T> *node;
396
-
397
-        node = new ListNode<T>(data, _num_items++);
398
-        return Add(node);
399
-    }
400
-
401
-    /*!
402
-     * \brief Add a ListNode to the end of this List.
403
-     * \param node new node
404
-     * \returns id of the node
405
-     */
406
-    unsigned int Add(ListNode<T> *node) {
407
-        ListNode<T> *current;
408
-        ListNode<T> *last;
409
-        unsigned int i;
410
-
411
-        if (_head) {
412
-            current = _head;
413
-            last = NULL;
414
-            i = 0;
415
-
416
-            //EXP
417
-            if (_last) {
418
-                i = _last->Id();
419
-                current = _last;
420
-            }
421
-
422
-            while (current) {
423
-                // Prepend
424
-                if (current->Id() > i) {
425
-                    node->Id(i);
426
-                    node->Next(current);
427
-
428
-                    if (current == _head)
429
-                        _head = node;
430
-                    else if (last)
431
-                        last->Next(node);
432
-
433
-                    return node->Id();
434
-                }
435
-
436
-                i++;
437
-                last = current;
438
-                current = current->Next();
439
-            }
440
-
441
-            // Append
442
-            last->Next(node);
443
-        } else
444
-            _head = node;
445
-
446
-        _last = node; //EXP
447
-
448
-        return node->Id();
449
-    }
450
-
451
-private:
452
-
453
-    unsigned int _num_items; //!< Number of items in the list
454
-    ListNode<T> *_head; //!< First item in the list
455
-    ListNode<T> *_current; //!< Current item for the list iterator
456
-    ListNode<T> *_last; //!< Last item in the list
457
-    ListNode<T> *_cache; //!< cache used by the search methods
458
-};
459
-
460
-#endif

+ 0
- 409
include/templates/Vector.h Переглянути файл

@@ -1,409 +0,0 @@
1
-/*!
2
- * \file include/templates/Vector.h
3
- * \brief Template Vector
4
- *
5
- * \author Mongoose
6
- */
7
-
8
-#ifndef _VECTOR_H_
9
-#define _VECTOR_H_
10
-
11
-#include <stdlib.h>
12
-#include <stdio.h>
13
-
14
-/*!
15
- * \brief Template class for a (pretty strange) Vector
16
- * \tparam Object datatype the Vector can store
17
- */
18
-template <class Object> class Vector {
19
-public:
20
-
21
-    /*!
22
-     * \brief Construct an empty Vector
23
-     */
24
-    Vector() {
25
-        mData = 0x0;
26
-        mError = 0x0;
27
-        mReserve = 0;
28
-        mStart = 0;
29
-        mEnd = 0;
30
-        mIndex = 0;
31
-    }
32
-
33
-    /*!
34
-     * \brief Construct a Vector from another one
35
-     * \param vector Vector to copy from
36
-     */
37
-    Vector(Vector &vector) {
38
-        mData = 0x0;
39
-        mError = 0x0;
40
-        mReserve = 0;
41
-        mStart = 0;
42
-        mEnd = 0;
43
-        mIndex = 0;
44
-        copy(vector);
45
-    }
46
-
47
-    /*!
48
-     * \brief Construct a Vector with a specific size
49
-     * \param size initial size
50
-     */
51
-    Vector(unsigned int size) {
52
-        mData = 0x0;
53
-        mError = 0x0;
54
-        mReserve = 0;
55
-        mStart = 0;
56
-        mEnd = 0;
57
-        mIndex = 0;
58
-        resize(size);
59
-    }
60
-
61
-    /*!
62
-     * \brief Deconstruct a Vector
63
-     */
64
-    ~Vector() {
65
-        if (!empty() && mData)
66
-            delete [] mData;
67
-        clear();
68
-        mReserve = 0;
69
-    }
70
-
71
-    /*!
72
-     * \brief Clears the Vector, but deletes nothing
73
-     * \sa Vector::erase()
74
-     */
75
-    void clear() {
76
-        mStart = 0;
77
-        mEnd = 0;
78
-        mIndex = 0;
79
-    }
80
-
81
-    /*!
82
-     * \brief Clears the vector and deletes everything contained
83
-     * \sa Vector::clear()
84
-     */
85
-    void erase() {
86
-        for (start(); forward(); next()) {
87
-            if (current())
88
-                delete current();
89
-        }
90
-        clear();
91
-    }
92
-
93
-    /*!
94
-     * \brief Reserve more memory
95
-     * \param count new maximum size
96
-     */
97
-    void reserve(unsigned int count) {
98
-        Object *swap = 0x0;
99
-        if (count > mReserve) {
100
-            swap = mData;
101
-            mReserve = count;
102
-            mData = new Object[count];
103
-        }
104
-        if (swap) {
105
-            for (unsigned int i = begin(); i < end(); ++i)
106
-                mData[i] = swap[i];
107
-            delete [] swap;
108
-        }
109
-    }
110
-
111
-    /*!
112
-     * \brief Resize the Vector
113
-     * \param count new size
114
-     */
115
-    void resize(unsigned int count) {
116
-        resize(count, 0x0);
117
-    }
118
-
119
-    /*!
120
-     * \brief Resize the Vector
121
-     * \param count new size
122
-     * \param object what to put into blank spaces
123
-     */
124
-    void resize(unsigned int count, Object object) {
125
-        reserve(count);
126
-        for (unsigned int i = 0; i < count; ++i) {
127
-            if (i < begin() || i >= end())
128
-                mData[i] = object;
129
-        }
130
-        mEnd = count;
131
-    }
132
-
133
-    /*!
134
-     * \brief Increase size by 1
135
-     */
136
-    void pushBack() {
137
-        pushBack(0x0);
138
-    }
139
-
140
-    /*!
141
-     * \brief Increase size by 1
142
-     * \param object what to put into new space
143
-     */
144
-    void pushBack(Object object) {
145
-        resize(size() + 1);
146
-        mData[size()-1] = object;
147
-    }
148
-
149
-    /*!
150
-     * \brief Check if empty
151
-     * \returns true if begin() equals end()
152
-     */
153
-    bool empty() {
154
-        return (begin() == end());
155
-    }
156
-
157
-    /*!
158
-     * \brief Check maximum capacity
159
-     * \returns reserved memory
160
-     */
161
-    unsigned int capacity() {
162
-        return mReserve;
163
-    }
164
-
165
-    /*!
166
-     * \brief Get start index
167
-     * \returns start index
168
-     */
169
-    unsigned int begin() {
170
-        return mStart;
171
-    }
172
-
173
-    /*!
174
-     * \brief Get end index
175
-     * \returns end index
176
-     */
177
-    unsigned int end() {
178
-        return mEnd;
179
-    }
180
-
181
-    /*!
182
-     * \brief Get size
183
-     * \returns end index
184
-     */
185
-    unsigned int size() {
186
-        return mEnd;
187
-    }
188
-
189
-    /*!
190
-     * \brief Copy a Vector into this one.
191
-     * May increase size.
192
-     * \param vector Vector to copy from
193
-     */
194
-    void copy(Vector<Object> &vector) {
195
-        unsigned int i;
196
-        if (vector.capacity() > capacity()) {
197
-            resize(vector.capacity());
198
-        }
199
-        mStart = vector.begin();
200
-        mEnd = vector.end();
201
-        mError = vector.Error();
202
-        mIndex = vector.getCurrentIndex();
203
-        for (i = vector.begin(); i < vector.end(); ++i) {
204
-            mData[i] = vector[i];
205
-        }
206
-    }
207
-
208
-    /*!
209
-     * \brief Sort the Vector
210
-     * \param compareFunc comparison function for qsort
211
-     */
212
-    void qSort(int (*compareFunc)(const void *, const void *)) {
213
-        qsort(mData, end(), sizeof(Object), compareFunc);
214
-    }
215
-
216
-    /*!
217
-     * \brief Swap two items
218
-     * \param index first index
219
-     * \param index2 second index
220
-     */
221
-    void swap(unsigned int index, unsigned int index2) {
222
-        if (index < begin() || index > end())
223
-            return;
224
-
225
-        if (index2 < begin() || index2 > end())
226
-            return;
227
-
228
-        Object swap = mData[index];
229
-        mData[index] = mData[index2];
230
-        mData[index2] = swap;
231
-    }
232
-
233
-    /*!
234
-     * \brief Set an index to a value
235
-     * \param index index to set
236
-     * \param object object to set it to
237
-     */
238
-    void assign(unsigned int index, Object object) {
239
-        mData[index] = object;
240
-    }
241
-
242
-    /*!
243
-     * \brief Get value at index
244
-     * \param index index to look at
245
-     * \returns data for index, or error object
246
-     */
247
-    Object operator [] (unsigned int index) {
248
-        if (mData == 0x0 || index < begin() || index > end() || index >= size() || empty())
249
-            return mError;
250
-        return mData[index];
251
-    }
252
-
253
-    /*!
254
-     * \brief Print the Vector
255
-     * \param print_func function that can print Objects
256
-     */
257
-    void print(void (*print_func)(Object)) {
258
-        for (unsigned int i = begin(); i < end(); ++i) {
259
-            if (print_func)
260
-                (*print_func)(mData[i]);
261
-            fflush(stdout);
262
-        }
263
-        printf("\n");
264
-    }
265
-
266
-
267
-    /*!
268
-     * \brief Start Iterator at specific index
269
-     * \param index where to start
270
-     */
271
-    void start(unsigned int index) {
272
-        if (mData == 0x0 || index < begin() || index > end() ||
273
-             index >= size() || empty())
274
-            return;
275
-
276
-        mIndex = index;
277
-    }
278
-
279
-    /*!
280
-     * \brief Set Iterator to the first element
281
-     */
282
-    void start() {
283
-        mIndex = begin();
284
-    }
285
-
286
-    /*!
287
-     * \brief Set Iterator to the last element
288
-     */
289
-    void finish() {
290
-        mIndex = end() - 1;
291
-    }
292
-
293
-    /*!
294
-     * \brief Check if the Iterator can go forward
295
-     * \returns true if Iterator is still in range
296
-     */
297
-    bool forward() {
298
-        return (mIndex < end());
299
-    }
300
-
301
-    /*!
302
-     * \brief Check if the Iterator can go backwards
303
-     * \returns true if Iterator is already in range
304
-     */
305
-    bool backward() {
306
-        return (mIndex + 1 > begin());
307
-    }
308
-
309
-    /*!
310
-     * \brief Increment the Iterator
311
-     */
312
-    void next() {
313
-        if (mIndex < end())
314
-            ++mIndex;
315
-    }
316
-
317
-    /*!
318
-     * \brief Decrement the Iterator
319
-     */
320
-    void prev() {
321
-        --mIndex;
322
-    }
323
-
324
-    /*!
325
-     * \brief Set the error object
326
-     * \param object new error object
327
-     */
328
-    void setError(Object object) {
329
-        mError = object;
330
-    }
331
-
332
-    /*!
333
-     * \brief Get Iterator index
334
-     * \returns current Iterator index
335
-     */
336
-    unsigned int getCurrentIndex() {
337
-        return mIndex;
338
-    }
339
-
340
-    /*!
341
-     * \brief Set Iterator index
342
-     * \param index new Iterator index
343
-     */
344
-    void setCurrentIndex(unsigned int index) {
345
-        if (index < end())
346
-            mIndex = index;
347
-    }
348
-
349
-    /*!
350
-     * \brief Get current element
351
-     * \returns element at Iterator index
352
-     */
353
-    Object current() {
354
-        return mData[mIndex];
355
-    }
356
-
357
-    /*!
358
-     * \brief Check if an object is in the Vector.
359
-     * Requires objects to support `==`.
360
-     * \param object object to find
361
-     * \returns true if found, false if not.
362
-     */
363
-    bool find(Object object) {
364
-        for (start(); forward(); next()) {
365
-            if (object == current())
366
-                return true;
367
-        }
368
-        return false;
369
-    }
370
-
371
-    //
372
-    /*!
373
-     * \brief Add an object.
374
-     * Instead of appending objects this attempts replacing 'removed' objects.
375
-     * \param object object to add
376
-     * \returns index of added object
377
-     */
378
-    unsigned int add(Object object) {
379
-        if (begin() > 0) {
380
-            mData[begin() - 1] = object;
381
-            --mStart;
382
-
383
-            return begin();
384
-        }
385
-
386
-        pushBack(object);
387
-        return size();
388
-    }
389
-
390
-
391
-    /*!
392
-     * \brief Remove an object. This will change the index of another element!
393
-     * \param index index to "remove".
394
-     */
395
-    void remove(unsigned int index) {
396
-        mData[index] = mData[begin()];
397
-        ++mStart;
398
-    }
399
-
400
-private:
401
-    Object *mData;         //!< Data array
402
-    Object mError;         //!< Error object
403
-    unsigned int mReserve; //!< Index for reserved space
404
-    unsigned int mStart;   //!< Start index
405
-    unsigned int mEnd;     //!< End index
406
-    unsigned int mIndex;   //!< Iterator index
407
-};
408
-
409
-#endif

+ 0
- 71
include/utils/math.h Переглянути файл

@@ -1,71 +0,0 @@
1
-/*!
2
- *
3
- * \file include/utils/math.h
4
- * \brief Vector and Matrix math
5
- *
6
- * \author Mongoose
7
- */
8
-
9
-#include <math.h>
10
-
11
-#ifndef _UTILS_MATH_H
12
-#define _UTILS_MATH_H
13
-
14
-#define HEL_PI           ((float)M_PI) //!< pi
15
-#define HEL_2_PI         (HEL_PI * 2.0f) //!< pi*2
16
-#define HEL_PI_OVER_4    (HEL_PI / 4.0f) //!< pi/4
17
-#define HEL_PI_OVER_180  (HEL_PI / 180.0f) //!< pi/180
18
-#define HEL_180_OVER_PI  (180.0f / HEL_PI) //!< 180/pi
19
-
20
-#define HEL_RAD_TO_DEG(x) ((x) * HEL_180_OVER_PI) //!< Convert radians to degrees
21
-#define HEL_DEG_TO_RAD(x) ((x) * HEL_PI_OVER_180) //!< Convert degrees to radians
22
-
23
-typedef float vec_t;        //!< 1D Vector, aka float
24
-typedef float vec2_t[2];    //!< 2D Vector
25
-typedef float vec3_t[3];    //!< 3D Vector
26
-typedef float vec4_t[4];    //!< 4D Vector
27
-typedef vec_t matrix_t[16]; //!< Used as _Column_major_ in every class now!
28
-
29
-/*!
30
- * \brief Compare two floats with an Epsilon.
31
- * \param a first float
32
- * \param b second float
33
- * \returns true if a and b are probably the same.
34
- */
35
-bool equalEpsilon(vec_t a, vec_t b);
36
-
37
-/*!
38
- * \brief Calculate Intersection of a line and a polygon
39
- * \param intersect Where the intersection is stored, if it exists
40
- * \param p1 First point of line segment
41
- * \param p2 Second point of line segment
42
- * \param polygon polygon vertex array (0 to 2 are used)
43
- * \returns 0 if there is no intersection
44
- */
45
-int helIntersectionLineAndPolygon(vec3_t intersect, vec3_t p1, vec3_t p2, vec3_t *polygon);
46
-
47
-/*!
48
- * \brief Calculate the length of a line segment / the distance between two points
49
- * \param a First point
50
- * \param b Second point
51
- * \returns distance/length
52
- */
53
-vec_t helDist3v(vec3_t a, vec3_t b);
54
-
55
-/*!
56
- * \brief Calculates the midpoint between two points / of a line segment
57
- * \param a First point
58
- * \param b Second point
59
- * \param mid Midpoint will be stored here
60
- */
61
-void helMidpoint3v(vec3_t a, vec3_t b, vec3_t mid);
62
-
63
-/*!
64
- * \brief Calculates a pseudo-random number
65
- * \param from Lower bound of resulting number
66
- * \param to Upper bound
67
- * \returns random number
68
- */
69
-vec_t helRandomNum(vec_t from, vec_t to);
70
-
71
-#endif

+ 0
- 61
include/utils/strings.h Переглянути файл

@@ -1,61 +0,0 @@
1
-/*!
2
- * \file include/utils/strings.h
3
- * \brief String handling utilities
4
- *
5
- * \author xythobuz
6
- * \author Mongoose
7
- */
8
-
9
-#ifndef _UTILS_STRINGS_H_
10
-#define _UTILS_STRINGS_H_
11
-
12
-/*!
13
- * \brief Check if a string ends with another string.
14
- * \param str string to check
15
- * \param suffix suffix for which to check
16
- * \returns true if str ends with suffix
17
- */
18
-bool stringEndsWith(const char *str, const char *suffix);
19
-
20
-/*!
21
- * \brief Generates a buffered string for the printf call
22
- * \param string format string like for printf
23
- * \param args arguments matching format string
24
- * \returns string in a buffer
25
- */
26
-char *bufferString(const char *string, va_list args) __attribute__((format(printf, 1, 0)));
27
-
28
-/*!
29
- * \brief Generates a buffered string for the printf call
30
- * \param string format string like for printf
31
- * \returns string in a buffer
32
- */
33
-char *bufferString(const char *string, ...) __attribute__((format(printf, 1, 2)));
34
-
35
-/*!
36
- * \brief Expansion of unix home enviroment char.
37
- * Also makes sure string ends in "end" char.
38
- * \param path path string
39
- * \param end end character. 0 appends no additional char
40
- * \returns allocated string of path with expansions
41
- */
42
-char *fullPath(const char *path, char end);
43
-
44
-/*!
45
- * \brief Checks if Command matches Symbol.
46
- * Returns the rest of the argument list back in command buffer, if any
47
- * \param symbol command string
48
- * \param command with arguments
49
- * \returns true if command matches symbol
50
- */
51
-bool rc_command(const char *symbol, char *command);
52
-
53
-/*!
54
- * \brief Interpret a string as a bool
55
- * \param buffer "true" or "false"
56
- * \param val is set to boolean interpretation of buffer
57
- * \returns -1 for null string, -2 if string is not "true" or "false"
58
- */
59
-int rc_get_bool(const char *buffer, bool *val);
60
-
61
-#endif

+ 0
- 89
include/utils/tga.h Переглянути файл

@@ -1,89 +0,0 @@
1
-/*!
2
- * \file include/utils/tga.h
3
- * \brief TGA image reader/writer
4
- *
5
- * \author Mongoose
6
- * \author xythobuz
7
- */
8
-#ifndef _UTILS_TGA_H
9
-#define _UTILS_TGA_H
10
-
11
-/*!
12
- * \brief Possible TGA image types
13
- */
14
-typedef enum {
15
-    TGA_TYPE__NO_DATA    = 0,
16
-    TGA_TYPE__MAPPED     = 1,
17
-    TGA_TYPE__COLOR      = 2,
18
-    TGA_TYPE__GREYSCALE  = 3,
19
-    TGA_TYPE__MAPPED_RLE = 9,
20
-    TGA_TYPE__COLOR_RLE  = 10
21
-    // TGA_TYPE__GREYSCALE_COMPRESSED  = 11,
22
-    // TGA_TYPE__COLOR_HUFFMAN_DELTA_RLE  = 32,
23
-    // TGA_TYPE__COLOR_HUFFMAN_DELTA_RLE_4PASS  = 33
24
-} tga_type_t;
25
-
26
-/*!
27
- * \brief Data structure representing TGA file header
28
- */
29
-typedef struct {
30
-    unsigned char comment_lenght;       //!< Number of bytes in comment
31
-    unsigned char colormap_type;        //!< 0 No colormap; 1 Has colormap
32
-    unsigned char image_type;           //!< 1 Colormapped; 2 Unmapped; 9 Colormapped RLE; 10 Unmapped RLE
33
-    unsigned short colormap_index;      //!< Index of first color map entry
34
-    unsigned short colormap_lenght;     //!< Number of color map entries
35
-    unsigned char colormap_bbp;         //!< 16, 24, or 32 bits per pixel format
36
-    unsigned short origin_x;            //!< X coor of lower-left corner
37
-    unsigned short origin_y;            //!< Y coor of lower-left corner
38
-    unsigned short width;               //!< Width in pixels
39
-    unsigned short height;              //!< Height in pixels
40
-    unsigned char bpp;                  //!< Number of bits in a pixel index
41
-    unsigned char desc_flags;           //!< Various magic bits
42
-} tga_t;
43
-
44
-/*!
45
- * \brief Check if a file is a valid TGA image
46
- * \param f file to be checked
47
- * \returns 0 if valid, else error condition
48
- */
49
-int tgaCheck(FILE *f);
50
-
51
-/*!
52
- * \brief Load a TGA image from file
53
- * \param f valid image file
54
- * \param image Where the pixmap will be stored (or NULL)
55
- * \param width where the width will be stored
56
- * \param height where the height will be stored
57
- * \param type where the type will be stored (tga_type_t)
58
- * \returns 0 on success, else error condition
59
- */
60
-int tgaLoad(FILE *f, unsigned char **image,
61
-                unsigned int *width, unsigned int *height, char *type);
62
-
63
-/*!
64
- * \brief Save a pixel buffer into a file on disk
65
- * \param f file in which image will be saved
66
- * \param image pixmap to be stored
67
- * \param width width of pixmap/image
68
- * \param height height of pixmap/image
69
- * \param type tga type to use
70
- * \returns 0 on success, else error condition
71
- */
72
-int tgaSave(FILE *f, unsigned char *image,
73
-                unsigned int width, unsigned int height, char type);
74
-
75
-/*!
76
- * \brief Save a pixel buffer into a file on disk
77
- * \param image pixmap to be stored
78
- * \param width width of pixmap/image
79
- * \param height height of pixmap/image
80
- * \param type tga type to use
81
- * \param s format string for file path/name
82
- * \returns 0 on success, else error condition
83
- */
84
-int tgaSaveFilename(unsigned char *image,
85
-                        unsigned int width, unsigned int height,
86
-                        char type, const char *s, ...)
87
-    __attribute__((format(printf, 5, 6)));
88
-
89
-#endif

+ 0
- 32
include/utils/time.h Переглянути файл

@@ -1,32 +0,0 @@
1
-/*!
2
- * \file include/utils/time.h
3
- * \brief Time handling utilities
4
- *
5
- * \author xythobuz
6
- * \author Mongoose
7
- */
8
-
9
-#ifndef _UTILS_TIME_H_
10
-#define _UTILS_TIME_H_
11
-
12
-#if defined(linux) || defined(__APPLE__)
13
-#include <time.h>
14
-#include <sys/time.h>
15
-#endif
16
-
17
-extern struct timeval system_timer_start; //!< System timer start time
18
-extern struct timeval system_timer_stop; //!< System timer last read time
19
-extern struct timezone system_timer_tz; //!< System timer timezone info
20
-
21
-/*!
22
- * \brief Read the system timer
23
- * \returns number of ticks
24
- */
25
-unsigned int systemTimerGet();
26
-
27
-/*!
28
- * \brief Reset the system timer
29
- */
30
-void systemTimerReset();
31
-
32
-#endif

+ 3
- 20
src/CMakeLists.txt Переглянути файл

@@ -1,22 +1,5 @@
1 1
 # Set Source files
2
-set (SRCS ${SRCS} "Camera.cpp")
3
-set (SRCS ${SRCS} "Emitter.cpp")
4
-set (SRCS ${SRCS} "GLString.cpp")
5
-set (SRCS ${SRCS} "Matrix.cpp")
6
-set (SRCS ${SRCS} "Mesh.cpp")
7
-set (SRCS ${SRCS} "OpenRaider.cpp")
8
-set (SRCS ${SRCS} "Particle.cpp")
9
-set (SRCS ${SRCS} "Quaternion.cpp")
10
-set (SRCS ${SRCS} "Render.cpp")
11
-set (SRCS ${SRCS} "SDLSystem.cpp")
12
-set (SRCS ${SRCS} "SkeletalModel.cpp")
13
-set (SRCS ${SRCS} "Sound.cpp")
14
-set (SRCS ${SRCS} "System.cpp")
15
-set (SRCS ${SRCS} "Texture.cpp")
16
-set (SRCS ${SRCS} "TombRaider.cpp")
17
-set (SRCS ${SRCS} "Vector3d.cpp")
18
-set (SRCS ${SRCS} "ViewVolume.cpp")
19
-set (SRCS ${SRCS} "World.cpp")
2
+set (SRCS ${SRCS} "main.cpp")
20 3
 
21 4
 #################################################################
22 5
 
@@ -82,7 +65,7 @@ set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${OpenRaider_CXX_FLAGS} ${O
82 65
 set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${OpenRaider_CXX_FLAGS} ${OpenRaider_CXX_FLAGS_RELEASE}")
83 66
 
84 67
 # Add utils directory
85
-add_subdirectory (utils)
68
+# add_subdirectory (utils)
86 69
 
87 70
 # Add Executable
88 71
 add_executable (OpenRaider MACOSX_BUNDLE ${SRCS})
@@ -164,7 +147,7 @@ include_directories (SYSTEM ${ZLIB_INCLUDE_DIRS})
164 147
 set (LIBS ${LIBS} ${ZLIB_LIBRARIES})
165 148
 
166 149
 # Add utils Library
167
-set (LIBS ${LIBS} utilities)
150
+# set (LIBS ${LIBS} utilities)
168 151
 
169 152
 # Link to all found libs
170 153
 target_link_libraries (OpenRaider ${LIBS})

+ 0
- 247
src/Camera.cpp Переглянути файл

@@ -1,247 +0,0 @@
1
-/*!
2
- * \file src/Camera.cpp
3
- * \brief OpenGL camera class
4
- *
5
- * \author Mongoose
6
- */
7
-
8
-#include <stdio.h>
9
-#include <math.h>
10
-
11
-#include "utils/math.h"
12
-#include "Camera.h"
13
-
14
-Camera::Camera() {
15
-    mFlags = 0;
16
-    mViewDistance = 14.0f;
17
-    mTranslateDelta = 256.0f;
18
-    mRotateDelta = HEL_DEG_TO_RAD(15.0f);
19
-    mRotateDelta2 = HEL_DEG_TO_RAD(5.0f);
20
-    mFlags &= Camera_FlyMode;
21
-    reset();
22
-}
23
-
24
-void Camera::getPosition(vec3_t pos) {
25
-    pos[0] = mPos[0];
26
-    pos[1] = mPos[1];
27
-    pos[2] = mPos[2];
28
-}
29
-
30
-void Camera::getUp(vec3_t up) {
31
-    up[0] = mUp[0];
32
-    up[1] = mUp[1];
33
-    up[2] = mUp[2];
34
-}
35
-
36
-void Camera::getTarget(vec3_t target) {
37
-    target[0] = mTarget[0];
38
-    target[1] = mTarget[1];
39
-    target[2] = mTarget[2];
40
-}
41
-
42
-float Camera::getYaw() {
43
-    return HEL_RAD_TO_DEG(mTheta);
44
-}
45
-
46
-vec_t Camera::getRadianYaw() {
47
-    return mTheta;
48
-}
49
-
50
-vec_t Camera::getRadianPitch() {
51
-    return mTheta2;
52
-}
53
-
54
-void Camera::rotate(float angle, float x, float y, float z) {
55
-    Quaternion t, n;
56
-    Matrix matrix;
57
-    vec_t side[4] = { 1.0f, 0.0f,  0.0f, 1.0f };
58
-    vec_t up[4] =   { 0.0f, 1.0f,  0.0f, 1.0f };
59
-    vec_t look[4] = { 0.0f, 0.0f, -1.0f, 1.0f };
60
-    unsigned int i;
61
-    matrix_t m;
62
-
63
-    t.set(angle, x, y, z);
64
-    n = mQ * t;
65
-    n.normalize();
66
-
67
-    n.getMatrix(m);
68
-    matrix.setMatrix(m);
69
-    matrix.multiply4v(side, mSide);
70
-    matrix.multiply4v(look, mTarget);
71
-    matrix.multiply4v(up, mUp);
72
-
73
-    for (i = 0; i < 3; ++i) {
74
-        mSide[i] += mPos[i];
75
-        mTarget[i] += mPos[i];
76
-        mUp[i] += mPos[i];
77
-    }
78
-
79
-    mQ = n;
80
-}
81
-
82
-void Camera::translate(float x, float y, float z) {
83
-    int i;
84
-    vec_t result[4];
85
-    vec_t v[4];
86
-    matrix_t m;
87
-    Matrix matrix;
88
-
89
-    v[0] = x;
90
-    v[1] = y;
91
-    v[2] = -z;
92
-    v[3] = 1;
93
-
94
-    m[0] = mSide[0] - mPos[0];
95
-    m[1] = mUp[0] - mPos[0];
96
-    m[2] = mTarget[0] - mPos[0];
97
-    m[3] = 0;
98
-    m[4] = mSide[1] - mPos[1];
99
-    m[5] = mUp[1] - mPos[1];
100
-    m[6] = mTarget[1] - mPos[1];
101
-    m[7] = 0;
102
-    m[8] = mSide[2] - mPos[2];
103
-    m[9] = mUp[2] - mPos[2];
104
-    m[10] = mTarget[2] - mPos[2];
105
-    m[11] = 0;
106
-    m[12] = 0;
107
-    m[13] = 0;
108
-    m[14] = 0;
109
-    m[15] = 1;
110
-
111
-    matrix.setMatrix(m);
112
-    matrix.multiply4v(v, result);
113
-
114
-    for (i = 0; i < 3; ++i) {
115
-        mSide[i] += result[i];
116
-        mUp[i] += result[i];
117
-        mTarget[i] += result[i];
118
-        mPos[i] += result[i];
119
-    }
120
-
121
-    mPos[0] = x;
122
-    mPos[1] = y;
123
-    mPos[2] = z;
124
-}
125
-
126
-void Camera::reset() {
127
-    mTheta = 0.0f;
128
-    mTheta2 = 0.0f;
129
-
130
-    mPos[0] = 0.0f;
131
-    mPos[1] = 0.0f;
132
-    mPos[2] = 0.0f;
133
-
134
-    mTarget[0] = 0.0f;
135
-    mTarget[1] = 0.0f;
136
-    mTarget[2] = mViewDistance;
137
-
138
-    mSide[0] = 1.0f;
139
-    mSide[1] = 0.0f;
140
-    mSide[2] = 0.0f;
141
-
142
-    mUp[0] = 0.0f;
143
-    mUp[1] = 1.0f;
144
-    mUp[2] = 0.0f;
145
-
146
-    mQ.setIdentity();
147
-    translate(0.0f, 0.0f, 0.0f);
148
-}
149
-
150
-void Camera::setSensitivityY(float angle) {
151
-    mRotateDelta2 = HEL_DEG_TO_RAD(angle);
152
-}
153
-
154
-void Camera::setSensitivityX(float angle) {
155
-    mRotateDelta = HEL_DEG_TO_RAD(angle);
156
-}
157
-
158
-void Camera::command(enum camera_command cmd) {
159
-    switch (cmd) {
160
-        case CAMERA_MOVE_FORWARD:
161
-            if (mFlags & Camera_FlyMode)
162
-                mPos[2] += (mTranslateDelta * cosf(mTheta));
163
-
164
-            mPos[0] += (mTranslateDelta * sinf(mTheta));
165
-            mPos[1] += (mTranslateDelta * sinf(mTheta2));
166
-            break;
167
-        case CAMERA_MOVE_BACKWARD:
168
-            if (mFlags & Camera_FlyMode)
169
-                mPos[2] -= (mTranslateDelta * cosf(mTheta));
170
-
171
-            mPos[0] -= (mTranslateDelta * sinf(mTheta));
172
-            mPos[1] -= (mTranslateDelta * sinf(mTheta2));
173
-            break;
174
-        case CAMERA_MOVE_LEFT:
175
-            mPos[0] -= (mTranslateDelta * sinf(mTheta - 90.0f));
176
-            mPos[2] -= (mTranslateDelta * cosf(mTheta - 90.0f));
177
-            break;
178
-        case CAMERA_MOVE_RIGHT:
179
-            mPos[0] -= (mTranslateDelta * sinf(mTheta + 90.0f));
180
-            mPos[2] -= (mTranslateDelta * cosf(mTheta + 90.0f));
181
-            break;
182
-        case CAMERA_ROTATE_UP:
183
-            if (mTheta2 < (M_PI / 2)) {
184
-                mTheta2 += mRotateDelta2;
185
-                rotate(mTheta2, 1.0f, 0.0f, 0.0f);
186
-            }
187
-            break;
188
-        case CAMERA_ROTATE_DOWN:
189
-            if (mTheta2 > -(M_PI / 2)) {
190
-                mTheta2 -= mRotateDelta2;
191
-                rotate(mTheta2, 1.0f, 0.0f, 0.0f);
192
-            }
193
-            break;
194
-        case CAMERA_ROTATE_RIGHT:
195
-            mTheta += mRotateDelta;
196
-            rotate(mTheta, 0.0f, 1.0f, 0.0f);
197
-            break;
198
-        case CAMERA_ROTATE_LEFT:
199
-            mTheta -= mRotateDelta;
200
-            rotate(mTheta, 0.0f, 1.0f, 0.0f);
201
-            break;
202
-        case CAMERA_MOVE_UP:
203
-            mPos[1] -= mTranslateDelta / 2.0f;
204
-            mTarget[1] -= mTranslateDelta / 2.0f;
205
-            break;
206
-        case CAMERA_MOVE_DOWN:
207
-            mPos[1] += mTranslateDelta / 2.0f;
208
-            mTarget[1] += mTranslateDelta / 2.0f;
209
-            break;
210
-        case CAMERA_SPEED_UP:
211
-            ++mTranslateDelta;
212
-            break;
213
-        case CAMERA_SPEED_DOWN:
214
-            if (--mTranslateDelta < 0.0f)
215
-                mTranslateDelta = 1.0f;
216
-            break;
217
-    }
218
-}
219
-
220
-void Camera::setSpeed(float s) {
221
-    mTranslateDelta = s;
222
-}
223
-
224
-void Camera::update() {
225
-    mTarget[2] = (mViewDistance * cosf(mTheta)) + mPos[2];
226
-    mTarget[0] = (mViewDistance * sinf(mTheta)) + mPos[0];
227
-    mTarget[1] = (mViewDistance * sinf(mTheta2)) + mPos[1]; // + height_offset;
228
-}
229
-
230
-void Camera::setPosition(vec3_t pos) {
231
-    mPos[0] = pos[0];
232
-    mPos[1] = pos[1];
233
-    mPos[2] = pos[2];
234
-}
235
-
236
-void Camera::setUp(vec3_t up) {
237
-    mUp[0] = up[0];
238
-    mUp[1] = up[1];
239
-    mUp[2] = up[2];
240
-}
241
-
242
-void Camera::setTarget(vec3_t target) {
243
-    mTarget[0] = target[0];
244
-    mTarget[1] = target[1];
245
-    mTarget[2] = target[2];
246
-}
247
-

+ 0
- 245
src/Emitter.cpp Переглянути файл

@@ -1,245 +0,0 @@
1
-/*!
2
- * \file src/Emitter.cpp
3
- * \brief Particle emitter class.
4
- *
5
- * \author Mongoose
6
- */
7
-
8
-#include <stdlib.h>
9
-#include <string.h>
10
-#include <stdio.h>
11
-
12
-#ifdef __APPLE__
13
-#include <OpenGL/gl.h>
14
-#include <OpenGL/glu.h>
15
-#else
16
-#include <GL/gl.h>
17
-#include <GL/glu.h>
18
-#endif
19
-
20
-#include "Emitter.h"
21
-
22
-vec_t Emitter::mFrustum[6][4];
23
-
24
-int Emitter::compareParticleDist(const void *voidA, const void *voidB) {
25
-    Particle *a = const_cast<Particle *>(static_cast<const Particle *>(voidA));
26
-    Particle *b = const_cast<Particle *>(static_cast<const Particle *>(voidB));
27
-    float x, y, z, distA, distB;
28
-
29
-    if (!a || !b)
30
-        return -1; // error really
31
-
32
-    a->Pos(&x, &y, &z);
33
-    distA = (Emitter::mFrustum[5][0] * x +
34
-            Emitter::mFrustum[5][1] * y +
35
-            Emitter::mFrustum[5][2] * z +
36
-            Emitter::mFrustum[5][3]);
37
-
38
-    b->Pos(&x, &y, &z);
39
-    distB = (Emitter::mFrustum[5][0] * x +
40
-            Emitter::mFrustum[5][1] * y +
41
-            Emitter::mFrustum[5][2] * z +
42
-            Emitter::mFrustum[5][3]);
43
-
44
-    // reverse less/greater than
45
-    // less than
46
-    if (distA > distB)
47
-        return -1;
48
-
49
-    // greater than ( no need for equal )
50
-    return 1;
51
-}
52
-
53
-Emitter::Emitter(const char *name, int n) {
54
-    _name = NULL;
55
-    _flags = 0;
56
-    _particle = NULL;
57
-    _count = 0;
58
-    _pos[0] = _pos[1] = _pos[2] = 0.0;
59
-    _mangle[0] = _mangle[1] = _mangle[2] = 0.0;
60
-
61
-    Name(name);
62
-    ParticleArray(n);
63
-}
64
-
65
-Emitter::~Emitter() {
66
-    if (_name)
67
-        delete [] _name;
68
-
69
-    if (_particle)
70
-        delete [] _particle;
71
-
72
-    _count = 0;
73
-}
74
-
75
-Particle *Emitter::Particles() {
76
-    return _particle;
77
-}
78
-
79
-
80
-int Emitter::Count() {
81
-    return _count;
82
-}
83
-
84
-void Emitter::Pos(float *x, float *y, float *z) {
85
-    *x = _pos[0];
86
-    *y = _pos[1];
87
-    *z = _pos[2];
88
-}
89
-
90
-void Emitter::Pos(float x, float y, float z) {
91
-    _pos[0] = x;
92
-    _pos[1] = y;
93
-    _pos[2] = z;
94
-}
95
-
96
-void Emitter::Orientation(float *x, float *y, float *z) {
97
-    *x = _mangle[0];
98
-    *y = _mangle[1];
99
-    *z = _mangle[2];
100
-}
101
-
102
-void Emitter::Orientation(float x, float y, float z) {
103
-    _mangle[0] = x;
104
-    _mangle[1] = y;
105
-    _mangle[2] = z;
106
-}
107
-
108
-unsigned int Emitter::Flags() {
109
-    return _flags;
110
-}
111
-
112
-void Emitter::Flags(unsigned int flag, bool op) {
113
-    _flags |= flag;
114
-
115
-    if (!op)
116
-        _flags ^= flag;
117
-}
118
-
119
-void Emitter::ParticleArray(int n) {
120
-    if (n) {
121
-        if (_particle) {
122
-            _count = 0;
123
-            delete [] _particle;
124
-        }
125
-
126
-        _count = n;
127
-        _particle = new Particle[_count];
128
-    }
129
-}
130
-
131
-void Emitter::Name(const char *name) {
132
-    if (name && name[0]) {
133
-        if (_name)
134
-            delete [] _name;
135
-
136
-        int l = strlen(name);
137
-        _name = new char[l+1];
138
-
139
-        // Mongoose 2002.01.09, Mongoose says 'Only you can prevent overflows'
140
-        strncpy(_name, name, l);
141
-        _name[l] = 0;
142
-    }
143
-}
144
-
145
-void Emitter::SetTextureId(int id) {
146
-    for (unsigned int i = 0; i < _count; i++)
147
-        _particle[i].TextureId(id);
148
-}
149
-
150
-void Emitter::TextureId(unsigned int particle_start, unsigned int particle_end, int id) {
151
-    if ((particle_start < _count) && (particle_end > 0 && particle_end <= _count) && (particle_start < particle_end)) {
152
-        for (unsigned int i = particle_start; i < particle_end; i++)
153
-            _particle[i].TextureId(id);
154
-    }
155
-}
156
-
157
-void Emitter::Color(unsigned int particle_start, unsigned int particle_end, float r, float g, float b) {
158
-    if ((particle_start < _count) && (particle_end > 0 && particle_end <= _count) && (particle_start < particle_end)) {
159
-        for (unsigned int i = particle_start; i < particle_end; i++)
160
-            _particle[i].Color(r, g, b);
161
-    }
162
-}
163
-
164
-void Emitter::Speed(unsigned int particle_start, unsigned int particle_end, float x, float y, float z) {
165
-    if ((particle_start < _count) && (particle_end > 0 && particle_end <= _count) && (particle_start < particle_end)) {
166
-        for (unsigned int i = particle_start; i < particle_end; i++)
167
-            _particle[i].Speed(x, y, z);
168
-    }
169
-}
170
-
171
-void Emitter::Force(unsigned int particle_start, unsigned int particle_end, float x, float y, float z) {
172
-    if ((particle_start < _count) && (particle_end > 0 && particle_end <= _count) && (particle_start < particle_end)) {
173
-        for (unsigned int i = particle_start; i < particle_end; i++)
174
-            _particle[i].Force(x, y, z);
175
-    }
176
-}
177
-
178
-void Emitter::Draw() {
179
-    unsigned int i, p;
180
-    float x, y, z;
181
-    float r, g, b;
182
-    float life;
183
-
184
-    if (!_count || !_particle) {
185
-        printf("Emitter::Draw> No particles!\n");
186
-        return;
187
-    }
188
-
189
-    glPushMatrix();
190
-
191
-    //glRotatef(_mangle[0], 1.0, 0.0, 0.0);
192
-    //glRotatef(_mangle[1], 0.0, 1.0, 0.0);
193
-    //glRotatef(_mangle[2], 0.0, 0.0, 1.0);
194
-    //glTranslatef(_pos[0], _pos[1], _pos[2]);
195
-
196
-    if (_flags & fUseDepthSorting)
197
-        qsort(_particle, _count, sizeof(Particle), compareParticleDist);
198
-
199
-    for (i = 0; i < _count; i++) {
200
-        if (_particle[i].isActive()) {
201
-            _particle[i].Pos(&x, &y, &z);
202
-
203
-            if (_flags & fUseFrustumCulling) {
204
-                for (p = 0; p < 6; ++p) {
205
-                    if (((mFrustum[p][0] * x) + (mFrustum[p][1] * y) + (mFrustum[p][2] * z) + mFrustum[p][3]) < 0) {
206
-                        _particle[i].setActive(false);
207
-                        break;
208
-                    }
209
-                }
210
-
211
-                if (!_particle[i].isActive())
212
-                    continue;
213
-            }
214
-
215
-            _particle[i].Color(&r, &g, &b);
216
-            life = _particle[i].Life();
217
-
218
-            // Mongoose 2002.01.01, Removed Texture agent dep
219
-            glBindTexture(GL_TEXTURE_2D, _particle[i].Texture());
220
-
221
-            // Alpha is determined by life, which is affected by blend amount
222
-            glColor4f(r, g, b, life);
223
-
224
-            // Render tristrip quad
225
-            glBegin(GL_TRIANGLE_STRIP);
226
-            glTexCoord2d(1.0, 1.0);
227
-            glVertex3f(x + 0.5f, y + 0.5f, z);
228
-
229
-            glTexCoord2d(0.0, 1.0);
230
-            glVertex3f(x - 0.5f, y + 0.5f, z);
231
-
232
-            glTexCoord2d(1.0, 0.0);
233
-            glVertex3f(x + 0.5f, y - 0.5f, z);
234
-
235
-            glTexCoord2d(0.0, 0.0);
236
-            glVertex3f(x - 0.5f, y - 0.5f, z);
237
-            glEnd();
238
-
239
-            // Update particle's attributes for it's life cycle
240
-            _particle[i].Update();
241
-        }
242
-    }
243
-
244
-    glPopMatrix();
245
-}

+ 0
- 142
src/GLString.cpp Переглянути файл

@@ -1,142 +0,0 @@
1
-/*!
2
- * \file src/GLString.cpp
3
- * \brief Open GL rendering font/string class
4
- *
5
- * \author Mongoose
6
- * \author xythobuz
7
- */
8
-
9
-#include <string.h>
10
-#include <stdio.h>
11
-#include <stdlib.h>
12
-#include <stdarg.h>
13
-#include <assert.h>
14
-
15
-#ifdef __APPLE__
16
-#include <OpenGL/gl.h>
17
-#else
18
-#include <GL/gl.h>
19
-#endif
20
-
21
-#include "Texture.h"
22
-#include "utils/strings.h"
23
-#include "GLString.h"
24
-
25
-GLString::GLString() {
26
-    _num_string_max = 0;
27
-    _num_string = 0;
28
-    _scale = 1.0;
29
-    _string = NULL;
30
-}
31
-
32
-
33
-GLString::~GLString() {
34
-    if (_string) {
35
-        for (unsigned int i = 0; i < _num_string; ++i) {
36
-            if (_string[i].text)
37
-                delete [] _string[i].text;
38
-        }
39
-        delete [] _string;
40
-    }
41
-}
42
-
43
-
44
-void GLString::Init(unsigned int max_strings) {
45
-    assert(max_strings > 0);
46
-
47
-    _num_string_max = max_strings;
48
-    _string = new gl_string_t[max_strings];
49
-}
50
-
51
-
52
-void GLString::SetChar(unsigned int string, unsigned int pos, char c) {
53
-    gl_string_t *str = GetString(string);
54
-    assert(str != NULL);
55
-    if (pos < str->len)
56
-        str->text[pos] = c;
57
-}
58
-
59
-
60
-unsigned int GLString::GetStringLen(unsigned int string) {
61
-    gl_string_t *str = GetString(string);
62
-    assert(str != NULL);
63
-    return str->len;
64
-}
65
-
66
-
67
-char *GLString::GetBuffer(unsigned int string) {
68
-    gl_string_t *str = GetString(string);
69
-    assert(str != NULL);
70
-    return str->text;
71
-}
72
-
73
-
74
-void GLString::setActive(unsigned int string, bool active) {
75
-    gl_string_t *str = GetString(string);
76
-    assert(str != NULL);
77
-    str->active = active;
78
-}
79
-
80
-
81
-void GLString::SetString(unsigned int string, const char *s, ...) {
82
-    va_list args;
83
-    gl_string_t *str = GetString(string);
84
-
85
-    assert(s != NULL);
86
-    assert(s[0] != '\0');
87
-    assert(str != NULL);
88
-
89
-    delete [] str->text;
90
-
91
-    va_start(args, s);
92
-    str->text = bufferString(s, args);
93
-    va_end(args);
94
-
95
-    str->active = true;
96
-    str->len = (unsigned short)strlen(str->text);
97
-}
98
-
99
-void GLString::Scale(float scale) {
100
-    _scale = scale;
101
-}
102
-
103
-int GLString::glPrintf(int x, int y, const char *string, ...) {
104
-    va_list args;
105
-
106
-    assert(string != NULL);
107
-    assert(string[0] != '\0');
108
-
109
-    if (_num_string > _num_string_max)
110
-        return -2;
111
-
112
-    va_start(args, string);
113
-
114
-    _string[_num_string].active = true;
115
-    _string[_num_string].scale = _scale;
116
-    _string[_num_string].x = x;
117
-    _string[_num_string].y = y;
118
-    _string[_num_string].text = bufferString(string, args);
119
-
120
-    //! \fixme All this is really unnecessary complex!
121
-    _string[_num_string].len = (unsigned short)strlen(_string[_num_string].text);
122
-
123
-    ++_num_string;
124
-
125
-    va_end(args);
126
-
127
-    return 0;
128
-}
129
-
130
-void GLString::Render() {
131
-    for (unsigned int i = 0; i < _num_string; ++i) {
132
-        if (_string[i].active)
133
-            glPrint2d(_string[i].x, _string[i].y, _string[i].scale, _string[i].text);
134
-    }
135
-}
136
-
137
-gl_string_t *GLString::GetString(unsigned int id) {
138
-    assert(id < _num_string);
139
-
140
-    return _string + id;
141
-}
142
-

+ 0
- 406
src/Matrix.cpp Переглянути файл

@@ -1,406 +0,0 @@
1
-/*!
2
- * \file src/Matrix.cpp
3
- * \brief 3D Matrix
4
- *
5
- * \author Mongoose
6
- */
7
-
8
-#include <stdio.h>
9
-#include <math.h>
10
-
11
-#include "Matrix.h"
12
-
13
-Matrix::Matrix() {
14
-    setIdentity();
15
-}
16
-
17
-Matrix::Matrix(matrix_t m) {
18
-    setMatrix(m);
19
-}
20
-
21
-Matrix::Matrix(Quaternion &q) {
22
-    matrix_t m;
23
-    q.getMatrix(m);
24
-    setMatrix(m);
25
-}
26
-
27
-bool Matrix::getInvert(matrix_t out) {
28
-    matrix_t m;
29
-
30
-#ifdef COLUMN_ORDER
31
-    getMatrix(m);
32
-#else
33
-    getTransposeMatrix(m);
34
-#endif
35
-
36
-    /* Mongoose: This code was from a Jeff Lander tutorial which was based
37
-       on MESA GL's InvertMatrix */
38
-
39
-    /* NB. OpenGL Matrices are COLUMN major. */
40
-#define SWAP_ROWS(a, b) { float *_tmp = a; (a)=(b); (b)=_tmp; }
41
-#define MAT(m,r,c) (m)[(c)*4+(r)]
42
-
43
-    float wtmp[4][8];
44
-    float m0, m1, m2, m3, s;
45
-    float *r0, *r1, *r2, *r3;
46
-
47
-    r0 = wtmp[0], r1 = wtmp[1], r2 = wtmp[2], r3 = wtmp[3];
48
-
49
-    r0[0] = MAT(m,0,0), r0[1] = MAT(m,0,1),
50
-    r0[2] = MAT(m,0,2), r0[3] = MAT(m,0,3),
51
-    r0[4] = 1.0f, r0[5] = r0[6] = r0[7] = 0.0f,
52
-
53
-    r1[0] = MAT(m,1,0), r1[1] = MAT(m,1,1),
54
-    r1[2] = MAT(m,1,2), r1[3] = MAT(m,1,3),
55
-    r1[5] = 1.0f, r1[4] = r1[6] = r1[7] = 0.0f,
56
-
57
-    r2[0] = MAT(m,2,0), r2[1] = MAT(m,2,1),
58
-    r2[2] = MAT(m,2,2), r2[3] = MAT(m,2,3),
59
-    r2[6] = 1.0f, r2[4] = r2[5] = r2[7] = 0.0f,
60
-
61
-    r3[0] = MAT(m,3,0), r3[1] = MAT(m,3,1),
62
-    r3[2] = MAT(m,3,2), r3[3] = MAT(m,3,3),
63
-    r3[7] = 1.0f, r3[4] = r3[5] = r3[6] = 0.0f;
64
-
65
-    /* choose pivot - or die */
66
-    if (fabs(r3[0])>fabs(r2[0])) SWAP_ROWS(r3, r2);
67
-    if (fabs(r2[0])>fabs(r1[0])) SWAP_ROWS(r2, r1);
68
-    if (fabs(r1[0])>fabs(r0[0])) SWAP_ROWS(r1, r0);
69
-    if (0.0f == r0[0])  return false;
70
-
71
-    /* eliminate first variable     */
72
-    m1 = r1[0]/r0[0]; m2 = r2[0]/r0[0]; m3 = r3[0]/r0[0];
73
-    s = r0[1]; r1[1] -= m1 * s; r2[1] -= m2 * s; r3[1] -= m3 * s;
74
-    s = r0[2]; r1[2] -= m1 * s; r2[2] -= m2 * s; r3[2] -= m3 * s;
75
-    s = r0[3]; r1[3] -= m1 * s; r2[3] -= m2 * s; r3[3] -= m3 * s;
76
-    s = r0[4];
77
-    if (s != 0.0f) { r1[4] -= m1 * s; r2[4] -= m2 * s; r3[4] -= m3 * s; }
78
-    s = r0[5];
79
-    if (s != 0.0f) { r1[5] -= m1 * s; r2[5] -= m2 * s; r3[5] -= m3 * s; }
80
-    s = r0[6];
81
-    if (s != 0.0f) { r1[6] -= m1 * s; r2[6] -= m2 * s; r3[6] -= m3 * s; }
82
-    s = r0[7];
83
-    if (s != 0.0f) { r1[7] -= m1 * s; r2[7] -= m2 * s; r3[7] -= m3 * s; }
84
-
85
-    /* choose pivot - or die */
86
-    if (fabs(r3[1])>fabs(r2[1])) SWAP_ROWS(r3, r2);
87
-    if (fabs(r2[1])>fabs(r1[1])) SWAP_ROWS(r2, r1);
88
-    if (0.0f == r1[1])  return false;
89
-
90
-    /* eliminate second variable */
91
-    m2 = r2[1]/r1[1]; m3 = r3[1]/r1[1];
92
-    r2[2] -= m2 * r1[2]; r3[2] -= m3 * r1[2];
93
-    r2[3] -= m2 * r1[3]; r3[3] -= m3 * r1[3];
94
-    s = r1[4]; if (0.0f != s) { r2[4] -= m2 * s; r3[4] -= m3 * s; }
95
-    s = r1[5]; if (0.0f != s) { r2[5] -= m2 * s; r3[5] -= m3 * s; }
96
-    s = r1[6]; if (0.0f != s) { r2[6] -= m2 * s; r3[6] -= m3 * s; }
97
-    s = r1[7]; if (0.0f != s) { r2[7] -= m2 * s; r3[7] -= m3 * s; }
98
-
99
-    /* choose pivot - or die */
100
-    if (fabs(r3[2])>fabs(r2[2])) SWAP_ROWS(r3, r2);
101
-    if (0.0f == r2[2])  return false;
102
-
103
-    /* eliminate third variable */
104
-    m3 = r3[2]/r2[2];
105
-    r3[3] -= m3 * r2[3], r3[4] -= m3 * r2[4],
106
-    r3[5] -= m3 * r2[5], r3[6] -= m3 * r2[6],
107
-    r3[7] -= m3 * r2[7];
108
-
109
-    /* last check */
110
-    if (0.0f == r3[3]) return false;
111
-
112
-    s = 1.0f/r3[3];              /* now back substitute row 3 */
113
-    r3[4] *= s; r3[5] *= s; r3[6] *= s; r3[7] *= s;
114
-
115
-    m2 = r2[3];                 /* now back substitute row 2 */
116
-    s  = 1.0f/r2[2];
117
-    r2[4] = s * (r2[4] - r3[4] * m2), r2[5] = s * (r2[5] - r3[5] * m2),
118
-    r2[6] = s * (r2[6] - r3[6] * m2), r2[7] = s * (r2[7] - r3[7] * m2);
119
-    m1 = r1[3];
120
-    r1[4] -= r3[4] * m1, r1[5] -= r3[5] * m1,
121
-    r1[6] -= r3[6] * m1, r1[7] -= r3[7] * m1;
122
-    m0 = r0[3];
123
-    r0[4] -= r3[4] * m0, r0[5] -= r3[5] * m0,
124
-    r0[6] -= r3[6] * m0, r0[7] -= r3[7] * m0;
125
-
126
-    m1 = r1[2];                 /* now back substitute row 1 */
127
-    s  = 1.0f/r1[1];
128
-    r1[4] = s * (r1[4] - r2[4] * m1), r1[5] = s * (r1[5] - r2[5] * m1),
129
-    r1[6] = s * (r1[6] - r2[6] * m1), r1[7] = s * (r1[7] - r2[7] * m1);
130
-    m0 = r0[2];
131
-    r0[4] -= r2[4] * m0, r0[5] -= r2[5] * m0,
132
-    r0[6] -= r2[6] * m0, r0[7] -= r2[7] * m0;
133
-
134
-    m0 = r0[1];                 /* now back substitute row 0 */
135
-    s  = 1.0f/r0[0];
136
-    r0[4] = s * (r0[4] - r1[4] * m0), r0[5] = s * (r0[5] - r1[5] * m0),
137
-    r0[6] = s * (r0[6] - r1[6] * m0), r0[7] = s * (r0[7] - r1[7] * m0);
138
-
139
-    MAT(out,0,0) = r0[4];
140
-    MAT(out,0,1) = r0[5], MAT(out,0,2) = r0[6];
141
-    MAT(out,0,3) = r0[7], MAT(out,1,0) = r1[4];
142
-    MAT(out,1,1) = r1[5], MAT(out,1,2) = r1[6];
143
-    MAT(out,1,3) = r1[7], MAT(out,2,0) = r2[4];
144
-    MAT(out,2,1) = r2[5], MAT(out,2,2) = r2[6];
145
-    MAT(out,2,3) = r2[7], MAT(out,3,0) = r3[4];
146
-    MAT(out,3,1) = r3[5], MAT(out,3,2) = r3[6];
147
-    MAT(out,3,3) = r3[7];
148
-
149
-    return true;
150
-#undef MAT
151
-#undef SWAP_ROWS
152
-}
153
-
154
-void Matrix::getMatrix(matrix_t mat) {
155
-    copy(mMatrix, mat);
156
-}
157
-
158
-void Matrix::getTransposeMatrix(matrix_t m) {
159
-    m[ 0]= mMatrix[0]; m[ 1]= mMatrix[4]; m[ 2]= mMatrix[ 8]; m[ 3]=mMatrix[12];
160
-    m[ 4]= mMatrix[1]; m[ 5]= mMatrix[5]; m[ 6]= mMatrix[ 9]; m[ 7]=mMatrix[13];
161
-    m[ 8]= mMatrix[2]; m[ 9]= mMatrix[6]; m[10]= mMatrix[10]; m[11]=mMatrix[14];
162
-    m[12]= mMatrix[3]; m[13]= mMatrix[7]; m[14]= mMatrix[11]; m[15]=mMatrix[15];
163
-}
164
-
165
-Matrix Matrix::multiply(const Matrix &a, const Matrix &b) {
166
-    Matrix c;
167
-    multiply(a.mMatrix, b.mMatrix, c.mMatrix);
168
-    return c;
169
-}
170
-
171
-Matrix Matrix::operator *(const Matrix &a) {
172
-    return multiply(a, *this);
173
-}
174
-
175
-Vector3d Matrix::operator *(Vector3d v) {
176
-    vec_t x = v.mVec[0], y = v.mVec[1], z = v.mVec[2];
177
-
178
-#ifdef COLUMN_ORDER
179
-    return Vector3d(mMatrix[0]*x + mMatrix[4]*y + mMatrix[ 8]*z + mMatrix[12],
180
-            mMatrix[1]*x + mMatrix[5]*y + mMatrix[ 9]*z + mMatrix[13],
181
-            mMatrix[2]*x + mMatrix[6]*y + mMatrix[10]*z + mMatrix[14]);
182
-#else
183
-    return Vector3d(mMatrix[0]*x + mMatrix[1]*y + mMatrix[ 2]*z + mMatrix[ 3],
184
-            mMatrix[4]*x + mMatrix[5]*y + mMatrix[ 6]*z + mMatrix[ 7],
185
-            mMatrix[8]*x + mMatrix[9]*y + mMatrix[10]*z + mMatrix[11]);
186
-#endif
187
-}
188
-
189
-void Matrix::multiply3v(vec3_t v, vec3_t result) {
190
-    vec_t x = v[0], y = v[1], z = v[2];
191
-
192
-    result[0] = mMatrix[0]*x + mMatrix[1]*y + mMatrix[ 2]*z + mMatrix[ 3];
193
-    result[1] = mMatrix[4]*x + mMatrix[5]*y + mMatrix[ 6]*z + mMatrix[ 7];
194
-    result[2] = mMatrix[8]*x + mMatrix[9]*y + mMatrix[10]*z + mMatrix[11];
195
-}
196
-
197
-void Matrix::multiply4v(vec4_t v, vec4_t result) {
198
-    vec_t x = v[0], y = v[1], z = v[2], w = v[3];
199
-
200
-    result[0] = mMatrix[ 0]*x + mMatrix[ 1]*y + mMatrix[ 2]*z + mMatrix[ 3]*w;
201
-    result[1] = mMatrix[ 4]*x + mMatrix[ 5]*y + mMatrix[ 6]*z + mMatrix[ 7]*w;
202
-    result[2] = mMatrix[ 8]*x + mMatrix[ 9]*y + mMatrix[10]*z + mMatrix[11]*w;
203
-    result[3] = mMatrix[12]*x + mMatrix[13]*y + mMatrix[14]*z + mMatrix[15]*w;
204
-}
205
-
206
-void Matrix::print() {
207
-    printf("{\n%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n}\n",
208
-#ifdef COLUMN_ORDER
209
-            mMatrix[0], mMatrix[4], mMatrix[ 8], mMatrix[12],
210
-            mMatrix[1], mMatrix[5], mMatrix[ 9], mMatrix[13],
211
-            mMatrix[2], mMatrix[6], mMatrix[10], mMatrix[14],
212
-            mMatrix[3], mMatrix[7], mMatrix[11], mMatrix[15]);
213
-#else
214
-            mMatrix[ 0], mMatrix[ 1], mMatrix[ 2], mMatrix[ 3],
215
-            mMatrix[ 4], mMatrix[ 5], mMatrix[ 6], mMatrix[ 7],
216
-            mMatrix[ 8], mMatrix[ 9], mMatrix[10], mMatrix[11],
217
-            mMatrix[12], mMatrix[13], mMatrix[14], mMatrix[15]);
218
-#endif
219
-}
220
-
221
-bool Matrix::isIdentity() {
222
-    // Hhhmm... floating point using direct comparisons
223
-    /*
224
-    if (mMatrix[ 0] == 1 && mMatrix[ 1] == 0 && mMatrix[ 2] == 0 &&
225
-            mMatrix[ 3] == 0 &&    mMatrix[ 4] == 0 && mMatrix[ 5] == 1 &&
226
-            mMatrix[ 6] == 0 && mMatrix[ 7] == 0 && mMatrix[ 8] == 0 &&
227
-            mMatrix[ 9] == 0 && mMatrix[10] == 1 && mMatrix[11] == 0 &&
228
-            mMatrix[12] == 0 && mMatrix[13] == 0 && mMatrix[14] == 0 &&
229
-            mMatrix[15] == 1)
230
-        return true;
231
-    */
232
-    if (equalEpsilon(mMatrix[ 0], 1.0) && equalEpsilon(mMatrix[ 1], 0.0) && equalEpsilon(mMatrix[ 2], 0.0) &&
233
-        equalEpsilon(mMatrix[ 3], 0.0) && equalEpsilon(mMatrix[ 4], 0.0) && equalEpsilon(mMatrix[ 5], 1.0) &&
234
-        equalEpsilon(mMatrix[ 6], 0.0) && equalEpsilon(mMatrix[ 7], 0.0) && equalEpsilon(mMatrix[ 8], 0.0) &&
235
-        equalEpsilon(mMatrix[ 9], 0.0) && equalEpsilon(mMatrix[10], 1.0) && equalEpsilon(mMatrix[11], 0.0) &&
236
-        equalEpsilon(mMatrix[12], 0.0) && equalEpsilon(mMatrix[13], 0.0) && equalEpsilon(mMatrix[14], 0.0) &&
237
-        equalEpsilon(mMatrix[15], 1.0))
238
-        return true;
239
-
240
-    return false;
241
-}
242
-
243
-void Matrix::setMatrix(matrix_t mat) {
244
-    copy(mat, mMatrix);
245
-}
246
-
247
-void Matrix::setIdentity() {
248
-    mMatrix[ 0] = 1; mMatrix[ 1] = 0; mMatrix[ 2] = 0; mMatrix[ 3] = 0;
249
-    mMatrix[ 4] = 0; mMatrix[ 5] = 1; mMatrix[ 6] = 0; mMatrix[ 7] = 0;
250
-    mMatrix[ 8] = 0; mMatrix[ 9] = 0; mMatrix[10] = 1; mMatrix[11] = 0;
251
-    mMatrix[12] = 0; mMatrix[13] = 0; mMatrix[14] = 0; mMatrix[15] = 1;
252
-}
253
-
254
-void Matrix::scale(const vec_t *xyz) {
255
-    scale(xyz[0], xyz[1], xyz[2]);
256
-}
257
-
258
-void Matrix::scale(vec_t sx, vec_t sy, vec_t sz) {
259
-    matrix_t smatrix;
260
-    matrix_t tmp;
261
-
262
-    smatrix[ 0] = sx; smatrix[ 1] = 0;  smatrix[ 2] = 0;  smatrix[ 3] = 0;
263
-    smatrix[ 4] = 0;  smatrix[ 5] = sy; smatrix[ 6] = 0;  smatrix[ 7] = 0;
264
-    smatrix[ 8] = 0;  smatrix[ 9] = 0;  smatrix[10] = sz; smatrix[11] = 0;
265
-    smatrix[12] = 0;  smatrix[13] = 0;  smatrix[14] = 0;  smatrix[15] = 1;
266
-
267
-    copy(mMatrix, tmp);
268
-    multiply(tmp, smatrix, mMatrix);
269
-}
270
-
271
-void Matrix::rotate(const vec_t *xyz) {
272
-    rotate(xyz[0], xyz[1], xyz[2]);
273
-}
274
-
275
-void Matrix::rotate(vec_t ax, vec_t ay, vec_t az) {
276
-    matrix_t xmat, ymat, zmat, tmp, tmp2;
277
-
278
-    xmat[ 0]=1;         xmat[ 1]=0;         xmat[ 2]=0;         xmat[ 3]=0;
279
-    xmat[ 4]=0;         xmat[ 5]=cosf(ax);  xmat[ 6]=sinf(ax);  xmat[ 7]=0;
280
-    xmat[ 8]=0;         xmat[ 9]=-sinf(ax); xmat[10]=cosf(ax);  xmat[11]=0;
281
-    xmat[12]=0;         xmat[13]=0;         xmat[14]=0;         xmat[15]=1;
282
-
283
-    ymat[ 0]=cosf(ay);  ymat[ 1]=0;         ymat[ 2]=-sinf(ay); ymat[ 3]=0;
284
-    ymat[ 4]=0;         ymat[ 5]=1;         ymat[ 6]=0;         ymat[ 7]=0;
285
-    ymat[ 8]=sinf(ay);  ymat[ 9]=0;         ymat[10]=cosf(ay);  ymat[11]=0;
286
-    ymat[12]=0;         ymat[13]=0;         ymat[14]=0;         ymat[15]=1;
287
-
288
-    zmat[ 0]=cosf(az);  zmat[ 1]=sinf(az);  zmat[ 2]=0;         zmat[ 3]=0;
289
-    zmat[ 4]=-sinf(az); zmat[ 5]=cosf(az);  zmat[ 6]=0;         zmat[ 7]=0;
290
-    zmat[ 8]=0;         zmat[ 9]=0;         zmat[10]=1;         zmat[11]=0;
291
-    zmat[12]=0;         zmat[13]=0;         zmat[14]=0;         zmat[15]=1;
292
-
293
-    multiply(mMatrix, ymat, tmp);
294
-    multiply(tmp, xmat, tmp2);
295
-    multiply(tmp2, zmat, mMatrix);
296
-}
297
-
298
-void Matrix::translate(const vec_t *xyz) {
299
-    translate(xyz[0], xyz[1], xyz[2]);
300
-}
301
-
302
-void Matrix::translate(vec_t tx, vec_t ty, vec_t tz) {
303
-    matrix_t tmat, tmp;
304
-
305
-    tmat[ 0]=1;  tmat[ 1]=0;  tmat[ 2]=0;  tmat[ 3]=0;
306
-    tmat[ 4]=0;  tmat[ 5]=1;  tmat[ 6]=0;  tmat[ 7]=0;
307
-    tmat[ 8]=0;  tmat[ 9]=0;  tmat[10]=1;  tmat[11]=0;
308
-    tmat[12]=tx; tmat[13]=ty; tmat[14]=tz; tmat[15]=1;
309
-
310
-    copy(mMatrix, tmp);
311
-    multiply(tmp, tmat, mMatrix);
312
-}
313
-
314
-void Matrix::copy(matrix_t source, matrix_t dest) {
315
-    for (int i = 0; i < 16; i++)
316
-        dest[i] = source[i];
317
-}
318
-
319
-void Matrix::multiply(const matrix_t a, const matrix_t b, matrix_t result) {
320
-    /* Generated code for matrix mult
321
-     * Code used:
322
-
323
-    // char order is argument
324
-    int i, j, k;
325
-    if (order == 'r') {
326
-        printf("// Row order\n");
327
-    } else {
328
-        printf("// Column order\n");
329
-    }
330
-    for (i = 0; i < 4; ++i) {
331
-        for (j = 0; j < 4; ++j) {
332
-            if (order == 'r') {
333
-                printf("result[%2i] = ", j+i*4);
334
-            } else {
335
-                printf("result[%2i] = ", j+i*4);
336
-            }
337
-            for (k = 0; k < 4; ++k) {
338
-                if (order == 'r') {
339
-                    printf("a[%2i] * b[%2i]%s",
340
-                    k+i*4, j+k*4, (k == 3) ? ";\n" : " + ");
341
-                } else {
342
-                    printf("a[%2i] * b[%2i]%s",
343
-                    i+k*4, k+j*4, (k == 3) ? ";\n" : " + ");
344
-                }
345
-                //sum+=(elements[i+k*4]*m.elements[k+j*4]);
346
-            }
347
-            //result.elements[i+j*4]=sum;
348
-        }
349
-        printf("\n");
350
-    }
351
-    printf("\n");
352
-    printf("// Transpose\n");
353
-    for(i = 0; i < 4; ++i) {
354
-        for (j = 0; j < 4; ++j) {
355
-            printf("a[%2i] = b[%2i]%s",
356
-            j+i*4, i+j*4, (j == 3) ? ";\n" : "; ");
357
-        }
358
-    }
359
-
360
-     * was in test/Matrix.cpp
361
-     */
362
-#ifdef COLUMN_ORDER
363
-    /* Column order */
364
-    result[ 0] = a[ 0] * b[ 0] + a[ 4] * b[ 1] + a[ 8] * b[ 2] + a[12] * b[ 3];
365
-    result[ 1] = a[ 0] * b[ 4] + a[ 4] * b[ 5] + a[ 8] * b[ 6] + a[12] * b[ 7];
366
-    result[ 2] = a[ 0] * b[ 8] + a[ 4] * b[ 9] + a[ 8] * b[10] + a[12] * b[11];
367
-    result[ 3] = a[ 0] * b[12] + a[ 4] * b[13] + a[ 8] * b[14] + a[12] * b[15];
368
-
369
-    result[ 4] = a[ 1] * b[ 0] + a[ 5] * b[ 1] + a[ 9] * b[ 2] + a[13] * b[ 3];
370
-    result[ 5] = a[ 1] * b[ 4] + a[ 5] * b[ 5] + a[ 9] * b[ 6] + a[13] * b[ 7];
371
-    result[ 6] = a[ 1] * b[ 8] + a[ 5] * b[ 9] + a[ 9] * b[10] + a[13] * b[11];
372
-    result[ 7] = a[ 1] * b[12] + a[ 5] * b[13] + a[ 9] * b[14] + a[13] * b[15];
373
-
374
-    result[ 8] = a[ 2] * b[ 0] + a[ 6] * b[ 1] + a[10] * b[ 2] + a[14] * b[ 3];
375
-    result[ 9] = a[ 2] * b[ 4] + a[ 6] * b[ 5] + a[10] * b[ 6] + a[14] * b[ 7];
376
-    result[10] = a[ 2] * b[ 8] + a[ 6] * b[ 9] + a[10] * b[10] + a[14] * b[11];
377
-    result[11] = a[ 2] * b[12] + a[ 6] * b[13] + a[10] * b[14] + a[14] * b[15];
378
-
379
-    result[12] = a[ 3] * b[ 0] + a[ 7] * b[ 1] + a[11] * b[ 2] + a[15] * b[ 3];
380
-    result[13] = a[ 3] * b[ 4] + a[ 7] * b[ 5] + a[11] * b[ 6] + a[15] * b[ 7];
381
-    result[14] = a[ 3] * b[ 8] + a[ 7] * b[ 9] + a[11] * b[10] + a[15] * b[11];
382
-    result[15] = a[ 3] * b[12] + a[ 7] * b[13] + a[11] * b[14] + a[15] * b[15];
383
-#else
384
-    /* Row order */
385
-    result[ 0] = a[ 0] * b[ 0] + a[ 1] * b[ 4] + a[ 2] * b[ 8] + a[ 3] * b[12];
386
-    result[ 1] = a[ 0] * b[ 1] + a[ 1] * b[ 5] + a[ 2] * b[ 9] + a[ 3] * b[13];
387
-    result[ 2] = a[ 0] * b[ 2] + a[ 1] * b[ 6] + a[ 2] * b[10] + a[ 3] * b[14];
388
-    result[ 3] = a[ 0] * b[ 3] + a[ 1] * b[ 7] + a[ 2] * b[11] + a[ 3] * b[15];
389
-
390
-    result[ 4] = a[ 4] * b[ 0] + a[ 5] * b[ 4] + a[ 6] * b[ 8] + a[ 7] * b[12];
391
-    result[ 5] = a[ 4] * b[ 1] + a[ 5] * b[ 5] + a[ 6] * b[ 9] + a[ 7] * b[13];
392
-    result[ 6] = a[ 4] * b[ 2] + a[ 5] * b[ 6] + a[ 6] * b[10] + a[ 7] * b[14];
393
-    result[ 7] = a[ 4] * b[ 3] + a[ 5] * b[ 7] + a[ 6] * b[11] + a[ 7] * b[15];
394
-
395
-    result[ 8] = a[ 8] * b[ 0] + a[ 9] * b[ 4] + a[10] * b[ 8] + a[11] * b[12];
396
-    result[ 9] = a[ 8] * b[ 1] + a[ 9] * b[ 5] + a[10] * b[ 9] + a[11] * b[13];
397
-    result[10] = a[ 8] * b[ 2] + a[ 9] * b[ 6] + a[10] * b[10] + a[11] * b[14];
398
-    result[11] = a[ 8] * b[ 3] + a[ 9] * b[ 7] + a[10] * b[11] + a[11] * b[15];
399
-
400
-    result[12] = a[12] * b[ 0] + a[13] * b[ 4] + a[14] * b[ 8] + a[15] * b[12];
401
-    result[13] = a[12] * b[ 1] + a[13] * b[ 5] + a[14] * b[ 9] + a[15] * b[13];
402
-    result[14] = a[12] * b[ 2] + a[13] * b[ 6] + a[14] * b[10] + a[15] * b[14];
403
-    result[15] = a[12] * b[ 3] + a[13] * b[ 7] + a[14] * b[11] + a[15] * b[15];
404
-#endif
405
-}
406
-

+ 0
- 625
src/Mesh.cpp Переглянути файл

@@ -1,625 +0,0 @@
1
-/*!
2
- * \file src/Mesh.cpp
3
- * \brief OpenGL Mesh
4
- *
5
- * \author Mongoose
6
- */
7
-
8
-#include <stdlib.h>
9
-#include <assert.h>
10
-
11
-#ifdef __APPLE__
12
-#include <OpenGL/gl.h>
13
-#else
14
-#include <GL/gl.h>
15
-#endif
16
-
17
-#include "Mesh.h"
18
-
19
-
20
-////////////////////////////////////////////////////////////
21
-// Constructors
22
-////////////////////////////////////////////////////////////
23
-
24
-Mesh::Mesh()
25
-{
26
-    mNumVertices = 0;
27
-    mVertices = 0x0;
28
-
29
-    mNumNormals = 0;
30
-    mNormals = 0x0;
31
-
32
-    mNumColors = 0;
33
-    mColors = 0x0;
34
-
35
-    mNumTris = 0;
36
-    mTris = 0x0;
37
-
38
-    mNumQuads = 0;
39
-    mQuads = 0x0;
40
-
41
-    mVertexArray = 0x0;
42
-    mNormalArray = 0x0;
43
-    mColorArray = 0x0;
44
-
45
-    mTriangleCount = 0;
46
-    mTriangleTextures = 0x0;
47
-    mTriangleIndices = 0x0;
48
-    mTriangleFlags = 0x0;
49
-    mTriangleTexCoordArray = 0x0;
50
-
51
-    mFlags = 0;
52
-    mMode = MeshModeTexture;
53
-}
54
-
55
-
56
-Mesh::~Mesh()
57
-{
58
-    unsigned int i;
59
-
60
-
61
-    if (mVertices)
62
-    {
63
-        delete [] mVertices;
64
-    }
65
-
66
-    if (mNormals)
67
-    {
68
-        delete [] mNormals;
69
-    }
70
-
71
-    if (mColors)
72
-    {
73
-        delete [] mColors;
74
-    }
75
-
76
-    if (mTris)
77
-    {
78
-        for (i = 0; i < mNumTris; ++i)
79
-        {
80
-            if (mTris[i].triangles)
81
-                delete [] mTris[i].triangles;
82
-
83
-            if (mTris[i].alpha_triangles)
84
-                delete [] mTris[i].alpha_triangles;
85
-
86
-            if (mTris[i].texcoors)
87
-                delete [] mTris[i].texcoors;
88
-
89
-            if (mTris[i].texcoors2)
90
-                delete [] mTris[i].texcoors2;
91
-        }
92
-
93
-        delete [] mTris;
94
-    }
95
-
96
-    if (mQuads)
97
-    {
98
-        for (i = 0; i < mNumQuads; ++i)
99
-        {
100
-            if (mQuads[i].quads)
101
-                delete [] mQuads[i].quads;
102
-
103
-            if (mQuads[i].alpha_quads)
104
-                delete [] mQuads[i].alpha_quads;
105
-
106
-            if (mQuads[i].texcoors)
107
-                delete [] mQuads[i].texcoors;
108
-
109
-            if (mQuads[i].texcoors2)
110
-                delete [] mQuads[i].texcoors2;
111
-        }
112
-
113
-        delete [] mQuads;
114
-    }
115
-
116
-    if (mVertexArray)
117
-    {
118
-        delete [] mVertexArray;
119
-    }
120
-
121
-    if (mNormalArray)
122
-    {
123
-        delete [] mNormalArray;
124
-    }
125
-
126
-    if (mColorArray)
127
-    {
128
-        delete [] mColorArray;
129
-    }
130
-
131
-    if (mTriangleTextures)
132
-    {
133
-        delete [] mTriangleTextures;
134
-    }
135
-
136
-    if (mTriangleIndices)
137
-    {
138
-        delete [] mTriangleIndices;
139
-    }
140
-
141
-    if (mTriangleFlags)
142
-    {
143
-        delete [] mTriangleFlags;
144
-    }
145
-
146
-    if (mTriangleTexCoordArray)
147
-    {
148
-        delete [] mTriangleTexCoordArray;
149
-    }
150
-}
151
-
152
-
153
-////////////////////////////////////////////////////////////
154
-// Public Accessors
155
-////////////////////////////////////////////////////////////
156
-
157
-void Mesh::drawAlpha()
158
-{
159
-    unsigned int i, j, k, index;
160
-
161
-
162
-    // Render quadralaterals
163
-    for (mQuads ? i = 0 : i = mNumQuads; i < mNumQuads; ++i)
164
-    {
165
-        switch (mMode)
166
-        {
167
-            case MeshModeWireframe:
168
-                glColor3f(0.0, 0.0, 1.0);
169
-                glBindTexture(GL_TEXTURE_2D, 0);
170
-                break;
171
-            case MeshModeSolid:
172
-                // Bind WHITE texture for solid colors
173
-                glBindTexture(GL_TEXTURE_2D, 0);
174
-                break;
175
-            case MeshModeTexture:
176
-            case MeshModeMultiTexture:
177
-                // Bind texture id for textures
178
-                glBindTexture(GL_TEXTURE_2D, mQuads[i].texture+1);
179
-                break;
180
-        }
181
-
182
-        glBegin(GL_QUADS);
183
-
184
-        for (j = 0; j < mQuads[i].num_alpha_quads; ++j)
185
-        {
186
-            for (k = 0; k < 4; ++k)
187
-            {
188
-                index = mQuads[i].alpha_quads[j*4+k];
189
-
190
-                glTexCoord2fv(mQuads[i].texcoors2[j*4+k]);
191
-                glColor4fv(mColors[index]);
192
-                glVertex3fv(mVertices[index]);
193
-            }
194
-        }
195
-
196
-        glEnd();
197
-    }
198
-
199
-    // Render triangles
200
-    for (mTris ? i = 0 : i = mNumTris; i < mNumTris; ++i)
201
-    {
202
-        switch (mMode)
203
-        {
204
-            case MeshModeWireframe:
205
-                glColor3f(0.0, 1.0, 0.0);
206
-                glBindTexture(GL_TEXTURE_2D, 0);
207
-                break;
208
-            case MeshModeSolid:
209
-                // Bind WHITE texture for solid colors
210
-                glBindTexture(GL_TEXTURE_2D, 0);
211
-                break;
212
-            case MeshModeTexture:
213
-            case MeshModeMultiTexture:
214
-                // Bind texture id for textures
215
-                glBindTexture(GL_TEXTURE_2D, mTris[i].texture+1);
216
-                break;
217
-        }
218
-
219
-        glBegin(GL_TRIANGLES);
220
-
221
-        for (j = 0; j < mTris[i].num_alpha_triangles; ++j)
222
-        {
223
-            for (k = 0; k < 3; ++k)
224
-            {
225
-                index = mTris[i].alpha_triangles[j*3+k];
226
-
227
-                glTexCoord2fv(mTris[i].texcoors2[j*3+k]);
228
-                glColor4fv(mColors[index]);
229
-                glVertex3fv(mVertices[index]);
230
-            }
231
-        }
232
-
233
-        glEnd();
234
-    }
235
-}
236
-
237
-
238
-void Mesh::drawSolid()
239
-{
240
-    unsigned int i, j, k, index;
241
-
242
-
243
-    if (mFlags & fMesh_UseVertexArray)
244
-    {
245
-        //glEnableClientState(GL_VERTEX_ARRAY);
246
-        //glVertexPointer(3, GL_FLOAT, 0, mVertexArray);
247
-
248
-        glPointSize(2.0f);
249
-        glColor3f(1.0f, 1.0f, 1.0f);
250
-        glBegin(GL_TRIANGLES);
251
-
252
-        for (i = 0; i < mTriangleCount*3; ++i)
253
-        {
254
-            //glArrayElement(mTriangleIndices[i]);
255
-            glVertex3fv(mVertexArray+mTriangleIndices[i]);
256
-        }
257
-
258
-        glEnd();
259
-
260
-        glPointSize(1.0f);
261
-
262
-        //! \fixme
263
-        /*
264
-        for (j = 0; j < mQuads[i].num_quads; ++j)
265
-        {
266
-            for (k = 0; k < 4; ++k)
267
-            {
268
-                index = mQuads[i].quads[j*4+k];
269
-
270
-                glTexCoord2fv(mQuads[i].texcoors[j*4+k]);
271
-                glArrayElement(mQuads[i].quads[j*4+k]);
272
-            }
273
-        }
274
-        */
275
-
276
-        return;
277
-    }
278
-
279
-    // Render quadralaterals
280
-    for (mQuads ? i = 0 : i = mNumQuads; i < mNumQuads; ++i)
281
-    {
282
-        switch (mMode)
283
-        {
284
-            case MeshModeSolid:
285
-                glColor3f(0.0, 0.0, 0.0);
286
-                break;
287
-            case MeshModeWireframe:
288
-                // Bind WHITE texture for solid colors
289
-                glBindTexture(GL_TEXTURE_2D, 0);
290
-                break;
291
-#ifdef MULTITEXTURE
292
-            case MeshModeMultiTexture:
293
-                glActiveTextureARB(GL_TEXTURE0_ARB);
294
-                glEnable(GL_TEXTURE_2D);
295
-                glBindTexture(GL_TEXTURE_2D, mQuads[i].texture+1);
296
-
297
-                glActiveTextureARB(GL_TEXTURE1_ARB);
298
-                glEnable(GL_TEXTURE_2D);
299
-                glBindTexture(GL_TEXTURE_2D, mQuads[i].bumpmap+1);
300
-                break;
301
-#else
302
-            case MeshModeMultiTexture:
303
-#endif
304
-            case MeshModeTexture:
305
-                // Bind texture id for textures
306
-                glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
307
-                glBindTexture(GL_TEXTURE_2D, mQuads[i].texture+1);
308
-                break;
309
-        }
310
-
311
-        glBegin(GL_QUADS);
312
-
313
-        for (j = 0; j < mQuads[i].num_quads; ++j)
314
-        {
315
-            for (k = 0; k < 4; ++k)
316
-            {
317
-                index = mQuads[i].quads[j*4+k];
318
-
319
-                glColor4fv(mColors[index]);
320
-
321
-#ifdef MULTITEXTURE
322
-                if (mMode == MeshModeMultiTexture)
323
-                {
324
-                    glMultiTexCoord2fvARB(GL_TEXTURE0_ARB,
325
-                            mQuads[i].texcoors[j*4+k]);
326
-                    glMultiTexCoord2fvARB(GL_TEXTURE1_ARB,
327
-                            mQuads[i].texcoors[j*4+k]);
328
-                }
329
-                else
330
-#endif
331
-                    glTexCoord2fv(mQuads[i].texcoors[j*4+k]);
332
-
333
-                glVertex3fv(mVertices[index]);
334
-            }
335
-        }
336
-
337
-        glEnd();
338
-    }
339
-
340
-    // Render triangles
341
-    for (mTris ? i = 0 : i = mNumTris; i < mNumTris; ++i)
342
-    {
343
-        switch (mMode)
344
-        {
345
-            case MeshModeSolid:
346
-                glColor3f(1.0, 0.0, 0.0);
347
-                break;
348
-            case MeshModeWireframe:
349
-                // Bind WHITE texture for solid colors
350
-                glBindTexture(GL_TEXTURE_2D, 0);
351
-                break;
352
-#ifdef MULTITEXTURE
353
-            case MeshModeMultiTexture:
354
-                glActiveTextureARB(GL_TEXTURE0_ARB);
355
-                glEnable(GL_TEXTURE_2D);
356
-                glBindTexture(GL_TEXTURE_2D, mTris[i].texture+1);
357
-
358
-                glActiveTextureARB(GL_TEXTURE1_ARB);
359
-                glEnable(GL_TEXTURE_2D);
360
-                glBindTexture(GL_TEXTURE_2D, mTris[i].bumpmap+1);
361
-                break;
362
-#else
363
-            case MeshModeMultiTexture:
364
-#endif
365
-            case MeshModeTexture:
366
-                // Bind texture id for textures
367
-                glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
368
-                glBindTexture(GL_TEXTURE_2D, mTris[i].texture+1);
369
-                break;
370
-        }
371
-
372
-        glBegin(GL_TRIANGLES);
373
-
374
-        for (j = 0; j < mTris[i].num_triangles; ++j)
375
-        {
376
-            for (k = 0; k < 3; ++k)
377
-            {
378
-                index = mTris[i].triangles[j*3+k];
379
-
380
-#ifdef MULTITEXTURE
381
-                if (mMode == MeshModeMultiTexture)
382
-                {
383
-                    glMultiTexCoord2fvARB(GL_TEXTURE0_ARB,
384
-                            mTris[i].texcoors[j*3+k]);
385
-                    glMultiTexCoord2fvARB(GL_TEXTURE1_ARB,
386
-                            mTris[i].texcoors[j*3+k]);
387
-                }
388
-                else
389
-#endif
390
-                    glTexCoord2fv(mTris[i].texcoors[j*3+k]);
391
-
392
-                glColor4fv(mColors[index]);
393
-                glVertex3fv(mVertices[index]);
394
-            }
395
-        }
396
-
397
-        glEnd();
398
-    }
399
-
400
-#ifdef MULTITEXTURE
401
-    if (mMode == MeshModeMultiTexture)
402
-    {
403
-        glDisable(GL_TEXTURE_2D);
404
-        glActiveTextureARB(GL_TEXTURE0_ARB);
405
-    }
406
-#endif
407
-}
408
-
409
-
410
-////////////////////////////////////////////////////////////
411
-// Public Mutators
412
-////////////////////////////////////////////////////////////
413
-
414
-void Mesh::allocateColors(unsigned int n)
415
-{
416
-    if (mColors)
417
-    {
418
-        mNumColors = 0;
419
-        delete [] mColors;
420
-    }
421
-
422
-    if (!n)
423
-    {
424
-        return;
425
-    }
426
-
427
-    mNumColors = n;
428
-    mColors = new vec4_t[mNumColors];
429
-}
430
-
431
-
432
-void Mesh::allocateNormals(unsigned int n)
433
-{
434
-    if (mNormals)
435
-    {
436
-        mNumNormals = 0;
437
-        delete [] mNormals;
438
-    }
439
-
440
-    if (!n)
441
-    {
442
-        return;
443
-    }
444
-
445
-    mNumNormals = n;
446
-    mNormals = new vec3_t[mNumNormals];
447
-}
448
-
449
-
450
-void Mesh::allocateRectangles(unsigned int n)
451
-{
452
-    if (mQuads)
453
-    {
454
-        mNumQuads = 0;
455
-        delete [] mQuads;
456
-    }
457
-
458
-    if (!n)
459
-    {
460
-        return;
461
-    }
462
-
463
-    mNumQuads = n;
464
-    mQuads = new rect_t[mNumQuads];
465
-}
466
-
467
-
468
-void Mesh::allocateTriangles(unsigned int n)
469
-{
470
-    if (mTris)
471
-    {
472
-        mNumTris = 0;
473
-        delete [] mTris;
474
-    }
475
-
476
-    if (!n)
477
-    {
478
-        return;
479
-    }
480
-
481
-    mNumTris = n;
482
-    mTris = new tris_t[mNumTris];
483
-}
484
-
485
-
486
-void Mesh::allocateVertices(unsigned int n)
487
-{
488
-    if (mVertices)
489
-    {
490
-        mNumVertices = 0;
491
-        delete [] mVertices;
492
-    }
493
-
494
-    if (!n)
495
-    {
496
-        return;
497
-    }
498
-
499
-    mNumVertices = n;
500
-    mVertices = new vec3_t[mNumVertices];
501
-}
502
-
503
-
504
-void Mesh::bufferColorArray(unsigned int colorCount, vec_t *colors)
505
-{
506
-    if (mColors)
507
-    {
508
-        mNumColors = 0;
509
-        delete [] mColors;
510
-    }
511
-
512
-    if (!colorCount)
513
-    {
514
-        return;
515
-    }
516
-
517
-    mNumColors = colorCount;
518
-    mColorArray = colors;
519
-}
520
-
521
-
522
-void Mesh::bufferNormalArray(unsigned int normalCount, vec_t *normals)
523
-{
524
-    if (mNormals)
525
-    {
526
-        mNumNormals = 0;
527
-        delete [] mNormals;
528
-    }
529
-
530
-    if (!normalCount)
531
-    {
532
-        return;
533
-    }
534
-
535
-    mNumNormals = normalCount;
536
-    mNormalArray = normals;
537
-}
538
-
539
-
540
-void Mesh::bufferTriangles(unsigned int count,
541
-        unsigned int *indices, vec_t *texCoords,
542
-        int *textures, unsigned int *flags)
543
-{
544
-
545
-    mTriangleCount = count;
546
-    mTriangleTextures = textures;
547
-    mTriangleIndices = indices;
548
-    mTriangleFlags = flags;
549
-    mTriangleTexCoordArray = texCoords;
550
-
551
-    //! \fixme sortTrianglesByTexture();
552
-}
553
-
554
-
555
-void Mesh::bufferVertexArray(unsigned int vertexCount, vec_t *vertices)
556
-{
557
-    if (mVertices)
558
-    {
559
-        mNumVertices = 0;
560
-        delete [] mVertices;
561
-    }
562
-
563
-    if (!vertexCount)
564
-    {
565
-        return;
566
-    }
567
-
568
-    mNumVertices = vertexCount;
569
-    mVertexArray = vertices;
570
-    mFlags |= fMesh_UseVertexArray;
571
-}
572
-
573
-
574
-void Mesh::setColor(unsigned int index,
575
-        float r, float g, float b, float a)
576
-{
577
-    assert(index < mNumColors);
578
-
579
-    mColors[index][0] = r;
580
-    mColors[index][1] = g;
581
-    mColors[index][2] = b;
582
-    mColors[index][3] = a;
583
-}
584
-
585
-
586
-void Mesh::setColor(unsigned int index, float rgba[4])
587
-{
588
-    assert(index < mNumColors);
589
-
590
-    mColors[index][0] = rgba[0];
591
-    mColors[index][1] = rgba[1];
592
-    mColors[index][2] = rgba[2];
593
-    mColors[index][3] = rgba[3];
594
-}
595
-
596
-
597
-void Mesh::setNormal(unsigned int index, float i, float j, float k)
598
-{
599
-    assert(index < mNumNormals);
600
-
601
-    mNormals[index][0] = i;
602
-    mNormals[index][1] = j;
603
-    mNormals[index][2] = k;
604
-}
605
-
606
-
607
-void Mesh::setVertex(unsigned int index, float x, float y, float z)
608
-{
609
-    assert(index < mNumVertices);
610
-
611
-    mVertices[index][0] = x;
612
-    mVertices[index][1] = y;
613
-    mVertices[index][2] = z;
614
-}
615
-
616
-
617
-////////////////////////////////////////////////////////////
618
-// Private Accessors
619
-////////////////////////////////////////////////////////////
620
-
621
-
622
-////////////////////////////////////////////////////////////
623
-// Private Mutators
624
-////////////////////////////////////////////////////////////
625
-

+ 0
- 3423
src/OpenRaider.cpp
Різницю між файлами не показано, бо вона завелика
Переглянути файл


+ 0
- 162
src/Particle.cpp Переглянути файл

@@ -1,162 +0,0 @@
1
-/*!
2
- * \file src/Particle.cpp
3
- * \brief Particle system base implementation
4
- *
5
- * \author Mongoose
6
- */
7
-
8
-#include <stdlib.h>
9
-#include <stdio.h>
10
-#include <assert.h>
11
-
12
-#include "Particle.h"
13
-
14
-Particle::Particle()
15
-{
16
-    setActive(true);
17
-    TextureId(0);
18
-    Speed(2000.0f, 2000.0f, 2000.0f);
19
-    Color(1.0f, 1.0f, 1.0f);
20
-    Force(0.0f, 0.8f, 0.0f);
21
-
22
-    Reset();
23
-}
24
-
25
-
26
-void Particle::TextureId(int id)
27
-{
28
-    _texture = id;
29
-}
30
-
31
-
32
-void Particle::setActive(bool active)
33
-{
34
-    _active = active;
35
-}
36
-
37
-
38
-void Particle::Speed(float x, float y, float z)
39
-{
40
-    _speed[0] = x;
41
-    _speed[1] = y;
42
-    _speed[2] = z;
43
-}
44
-
45
-
46
-void Particle::Color(float r, float g, float b)
47
-{
48
-    _color[0] = r;
49
-    _color[1] = g;
50
-    _color[2] = b;
51
-}
52
-
53
-
54
-void Particle::Force(float x, float y, float z)
55
-{
56
-    _force[0] = x;
57
-    _force[1] = y;
58
-    _force[2] = z;
59
-}
60
-
61
-
62
-void Particle::Reset()
63
-{
64
-    // Mongoose 2002.01.01, Ah, how old is that code?
65
-#ifdef OBSOLETE
66
-    _active = true;
67
-    _life = 1.0;
68
-    _blend = (float)(rand() % 100) / 1000.0 + 0.003;
69
-
70
-    _pos[0] = _pos[1] = _pos[2] = 0.0;
71
-
72
-    _dir[0] = (float)((rand() % 50) - 26.0) * 10.0;
73
-    _dir[1] = (float)((rand() % 50) - 25.0) * 10.0;
74
-    _dir[2] = _dir[1];
75
-
76
-    _force[0] = 0.0;
77
-    _force[1] = -0.8;
78
-    _force[2] = 0.0;
79
-#else
80
-    //! \fixme _blend prob should have nonstatic range
81
-    _blend = (float)(0.003 + (0.1 * rand() / (RAND_MAX + 1.0))); // high order
82
-    //_blend = (float)(rand() % 100) / 1000.0 + 0.003;
83
-
84
-    //! \fixme Reset these using some nonstatic functions and values later
85
-    _life = 1.0;
86
-
87
-    _pos[0] = _pos[1] = _pos[2] = 0.0;
88
-
89
-    _dir[0] = (float)(-26.0 + (50.0 * rand() / (RAND_MAX + 1.0))); // high order
90
-    _dir[0] *= 10.0;
91
-    //_dir[0] = (float)((rand() % 50) - 26.0) * 10.0;
92
-    _dir[1] = (float)(-25.0 + (50.0 * rand() / (RAND_MAX + 1.0))); // high order
93
-    _dir[1] *= 10.0;
94
-    //_dir[1] = (float)((rand() % 50) - 25.0) * 10.0;
95
-    _dir[2] = _dir[1];
96
-#endif
97
-}
98
-
99
-
100
-void Particle::Pos(float *x, float *y, float *z)
101
-{
102
-    assert(x != NULL);
103
-    assert(y != NULL);
104
-    assert(z != NULL);
105
-
106
-    *x = _pos[0];
107
-    *y = _pos[1];
108
-    *z = _pos[2];
109
-}
110
-
111
-
112
-void Particle::Color(float *r, float *g, float *b)
113
-{
114
-    assert(r != NULL);
115
-    assert(g != NULL);
116
-    assert(b != NULL);
117
-
118
-    *r = _color[0];
119
-    *g = _color[1];
120
-    *b = _color[2];
121
-}
122
-
123
-
124
-float Particle::Life()
125
-{
126
-    return _life;
127
-}
128
-
129
-
130
-void Particle::Update()
131
-{
132
-    // Adjust particle position
133
-    _pos[0] += _dir[0] / _speed[0];
134
-    _pos[1] += _dir[1] / _speed[1];
135
-    _pos[2] += _dir[2] / _speed[2];
136
-
137
-    // Adjust particle direction
138
-    _dir[0] += _force[0];
139
-    _dir[1] += _force[1];
140
-    _dir[2] += _force[2];
141
-
142
-    // Adjust particle blending/life
143
-    _life -= _blend;
144
-
145
-    // Reset 'dead' OR fully blended particles
146
-    if (_life < 0.0)
147
-    {
148
-        Reset();
149
-    }
150
-}
151
-
152
-
153
-int Particle::Texture()
154
-{
155
-    return _texture;
156
-}
157
-
158
-
159
-bool Particle::isActive()
160
-{
161
-    return _active;
162
-}

+ 0
- 289
src/Quaternion.cpp Переглянути файл

@@ -1,289 +0,0 @@
1
-/*!
2
- * \file src/Quaternion.cpp
3
- * \brief Quaternion
4
- *
5
- * \author Mongoose
6
- */
7
-
8
-#include <math.h>
9
-
10
-#include "Quaternion.h"
11
-
12
-Quaternion::Quaternion() {
13
-    mW = 0;
14
-    mX = 0;
15
-    mY = 0;
16
-    mZ = 0;
17
-}
18
-
19
-Quaternion::Quaternion(vec_t w, vec_t x, vec_t y, vec_t z) {
20
-    mW = w;
21
-    mX = x;
22
-    mY = y;
23
-    mZ = z;
24
-}
25
-
26
-Quaternion::Quaternion(vec4_t v) {
27
-    mW = v[0];
28
-    mX = v[1];
29
-    mY = v[2];
30
-    mZ = v[3];
31
-}
32
-
33
-void Quaternion::getMatrix(matrix_t m) {
34
-    m[ 0] = 1.0f - 2.0f * (mY*mY + mZ*mZ);
35
-    m[ 1] = 2.0f * (mX*mY - mW*mZ);
36
-    m[ 2] = 2.0f * (mX*mZ + mW*mY);
37
-    m[ 3] = 0.0f;
38
-
39
-    m[ 4] = 2.0f * (mX*mY + mW*mZ);
40
-    m[ 5] = 1.0f - 2.0f * (mX*mX + mZ*mZ);
41
-    m[ 6] = 2.0f * (mY*mZ - mW*mX);
42
-    m[ 7] = 0.0f;
43
-
44
-    m[ 8] = 2.0f * (mX*mZ - mW*mY);
45
-    m[ 9] = 2.0f * (mY*mZ + mW*mX);
46
-    m[10] = 1.0f - 2.0f * (mX*mX + mY*mY);
47
-    m[11] = 0.0f;
48
-
49
-    m[12] = 0.0f;
50
-    m[13] = 0.0f;
51
-    m[14] = 0.0f;
52
-    m[15] = 1.0f;
53
-}
54
-
55
-Quaternion Quaternion::operator *(const Quaternion &q) {
56
-    return multiply(*this, q);
57
-}
58
-
59
-Quaternion Quaternion::operator /(const Quaternion &q) {
60
-    return divide(*this, q);
61
-}
62
-
63
-Quaternion Quaternion::operator +(const Quaternion &q) {
64
-    return add(*this, q);
65
-}
66
-
67
-Quaternion Quaternion::operator -(const Quaternion &q) {
68
-    return subtract(*this, q);
69
-}
70
-
71
-bool Quaternion::operator ==(const Quaternion &q) {
72
-    //return (mX == q.mX && mY == q.mY && mZ == q.mZ && mW == q.mW);
73
-    return (equalEpsilon(mX, q.mX) && equalEpsilon(mY, q.mY) &&
74
-            equalEpsilon(mZ, q.mZ) && equalEpsilon(mW, q.mW));
75
-}
76
-
77
-Quaternion Quaternion::conjugate() {
78
-    return Quaternion(mW, -mX, -mY, -mZ);
79
-}
80
-
81
-Quaternion Quaternion::scale(vec_t s) {
82
-    return Quaternion(mW * s, mX * s, mY * s, mZ * s);
83
-}
84
-
85
-Quaternion Quaternion::inverse() {
86
-    return conjugate().scale(1/magnitude());
87
-}
88
-
89
-vec_t Quaternion::dot(Quaternion a, Quaternion b) {
90
-    return ((a.mW * b.mW) + (a.mX * b.mX) + (a.mY * b.mY) + (a.mZ * b.mZ));
91
-}
92
-
93
-vec_t Quaternion::magnitude() {
94
-    return sqrtf(dot(*this, *this));
95
-}
96
-
97
-void Quaternion::setIdentity() {
98
-    mW = 1.0;
99
-    mX = 0.0;
100
-    mY = 0.0;
101
-    mZ = 0.0;
102
-}
103
-
104
-void Quaternion::set(vec_t angle, vec_t x, vec_t y, vec_t z) {
105
-    vec_t temp, dist;
106
-
107
-    // Normalize
108
-    temp = x*x + y*y + z*z;
109
-
110
-    dist = 1.0f / sqrtf(temp);
111
-
112
-    x *= dist;
113
-    y *= dist;
114
-    z *= dist;
115
-
116
-    mX = x;
117
-    mY = y;
118
-    mZ = z;
119
-
120
-    mW = cosf(angle / 2.0f);
121
-}
122
-
123
-void Quaternion::normalize() {
124
-    vec_t dist, square;
125
-
126
-    square = mX * mX + mY * mY + mZ * mZ + mW * mW;
127
-
128
-    if (square > 0.0) {
129
-        dist = 1.0f / sqrtf(square);
130
-    } else {
131
-        dist = 1;
132
-    }
133
-
134
-    mX *= dist;
135
-    mY *= dist;
136
-    mZ *= dist;
137
-    mW *= dist;
138
-}
139
-
140
-void Quaternion::copy(Quaternion q) {
141
-    mW = q.mW;
142
-    mX = q.mX;
143
-    mY = q.mY;
144
-    mZ = q.mZ;
145
-}
146
-
147
-Quaternion Quaternion::slerp(Quaternion a, Quaternion b, vec_t time) {
148
-    /*******************************************************************
149
-     * Spherical Linear Interpolation algorthim
150
-     *-----------------------------------------------------------------
151
-     *
152
-     * Interpolate between A and B rotations ( Find qI )
153
-     *
154
-     * qI = (((qB . qA)^ -1)^ Time) qA
155
-     *
156
-     * http://www.magic-software.com/Documentation/quat.pdf
157
-     *
158
-     * Thanks to digiben for algorithms and basis of the notes in
159
-     * this func
160
-     *
161
-     *******************************************************************/
162
-
163
-    vec_t result, scaleA, scaleB;
164
-    Quaternion i;
165
-
166
-
167
-    // Don't bother if it's the same rotation, it's the same as the result
168
-    if (a == b)
169
-        return a;
170
-
171
-    // A . B
172
-    result = dot(a, b);
173
-
174
-    // If the dot product is less than 0, the angle is greater than 90 degrees
175
-    if (result < 0.0f) {
176
-        // Negate quaternion B and the result of the dot product
177
-        b = Quaternion(-b.mW, -b.mX, -b.mY, -b.mZ);
178
-        result = -result;
179
-    }
180
-
181
-    // Set the first and second scale for the interpolation
182
-    scaleA = 1 - time;
183
-    scaleB = time;
184
-
185
-    // Next, we want to actually calculate the spherical interpolation.  Since this
186
-    // calculation is quite computationally expensive, we want to only perform it
187
-    // if the angle between the 2 quaternions is large enough to warrant it.  If the
188
-    // angle is fairly small, we can actually just do a simpler linear interpolation
189
-    // of the 2 quaternions, and skip all the complex math.  We create a "delta" value
190
-    // of 0.1 to say that if the cosine of the angle (result of the dot product) between
191
-    // the 2 quaternions is smaller than 0.1, then we do NOT want to perform the full on
192
-    // interpolation using.  This is because you won't really notice the difference.
193
-
194
-    // Check if the angle between the 2 quaternions was big enough
195
-    // to warrant such calculations
196
-    if (1 - result > 0.1f) {
197
-        // Get the angle between the 2 quaternions, and then
198
-        // store the sin() of that angle
199
-        vec_t theta = (float)acos(result);
200
-        vec_t sinTheta = (float)sin(theta);
201
-
202
-        // Calculate the scale for qA and qB, according to
203
-        // the angle and it's sine value
204
-        scaleA = (float)sin((1 - time) * theta) / sinTheta;
205
-        scaleB = (float)sin((time * theta)) / sinTheta;
206
-    }
207
-
208
-    // Calculate the x, y, z and w values for the quaternion by using a special
209
-    // form of linear interpolation for quaternions.
210
-    return (a.scale(scaleA) + b.scale(scaleB));
211
-}
212
-
213
-void Quaternion::setByMatrix(matrix_t matrix) {
214
-    float diagonal = matrix[0] + matrix[5] + matrix[10] + 1.0f;
215
-    float scale = 0.0f;
216
-    float w = 0.0f, x = 0.0f, y = 0.0f, z = 0.0f;
217
-
218
-    if (diagonal > 0.00000001) {
219
-        // Calculate the scale of the diagonal
220
-        scale = (float)(sqrt(diagonal) * 2);
221
-
222
-        w = 0.25f * scale;
223
-        x = (matrix[9] - matrix[6]) / scale;
224
-        y = (matrix[2] - matrix[8]) / scale;
225
-        z = (matrix[4] - matrix[1]) / scale;
226
-    } else {
227
-        // If the first element of the diagonal is the greatest value
228
-        if (matrix[0] > matrix[5] && matrix[0] > matrix[10]) {
229
-            // Find the scale according to the first element, and double it
230
-            scale = (float)sqrt(1.0f + matrix[0] - matrix[5] - matrix[10])*2.0f;
231
-
232
-            // Calculate the quaternion
233
-            w = (matrix[9] - matrix[6]) / scale;
234
-            x = 0.25f * scale;
235
-            y = (matrix[4] + matrix[1]) / scale;
236
-            z = (matrix[2] + matrix[8]) / scale;
237
-        } else if (matrix[5] > matrix[10]) {
238
-            // The second element of the diagonal is the greatest value
239
-            // Find the scale according to the second element, and double it
240
-            scale = (float)sqrt(1.0f + matrix[5] - matrix[0] - matrix[10])*2.0f;
241
-
242
-            // Calculate the quaternion
243
-            w = (matrix[2] - matrix[8]) / scale;
244
-            x = (matrix[4] + matrix[1]) / scale;
245
-            y = 0.25f * scale;
246
-            z = (matrix[9] + matrix[6]) / scale;
247
-        } else { // The third element of the diagonal is the greatest value
248
-            // Find the scale according to the third element, and double it
249
-            scale = (float)sqrt(1.0f + matrix[10] - matrix[0] - matrix[5])*2.0f;
250
-
251
-            // Calculate the quaternion
252
-            w = (matrix[4] - matrix[1]) / scale;
253
-            x = (matrix[2] + matrix[8]) / scale;
254
-            y = (matrix[9] + matrix[6]) / scale;
255
-            z = 0.25f * scale;
256
-        }
257
-    }
258
-
259
-    mW = w;
260
-    mX = x;
261
-    mY = y;
262
-    mZ = z;
263
-}
264
-
265
-Quaternion Quaternion::multiply(Quaternion a, Quaternion b) {
266
-    return Quaternion(a.mW * b.mW - a.mX * b.mX - a.mY * b.mY - a.mZ * b.mZ,
267
-            a.mW * b.mX + a.mX * b.mW + a.mY * b.mZ - a.mZ * b.mY,
268
-            a.mW * b.mY + a.mY * b.mW + a.mZ * b.mX - a.mX * b.mZ,
269
-            a.mW * b.mZ + a.mZ * b.mW + a.mX * b.mY - a.mY * b.mX);
270
-}
271
-
272
-Quaternion Quaternion::divide(Quaternion a, Quaternion b) {
273
-    return (a * (b.inverse()));
274
-}
275
-
276
-Quaternion Quaternion::add(Quaternion a, Quaternion b) {
277
-    return Quaternion(a.mW + b.mW,
278
-            a.mX + b.mX,
279
-            a.mY + b.mY,
280
-            a.mZ + b.mZ);
281
-}
282
-
283
-Quaternion Quaternion::subtract(Quaternion a, Quaternion b) {
284
-    return Quaternion(a.mW - b.mW,
285
-            a.mX - b.mX,
286
-            a.mY - b.mY,
287
-            a.mZ - b.mZ);
288
-}
289
-

+ 0
- 2236
src/Render.cpp
Різницю між файлами не показано, бо вона завелика
Переглянути файл


+ 0
- 352
src/SDLSystem.cpp Переглянути файл

@@ -1,352 +0,0 @@
1
-/*!
2
- * \file src/SDLSystem.cpp
3
- * \brief SDL System interface implementation
4
- *
5
- * \author Mongoose
6
- */
7
-
8
-#include <stdlib.h>
9
-#include <stdio.h>
10
-#include <string.h>
11
-#include <cmath>
12
-#include <assert.h>
13
-
14
-#include "SDL_opengl.h"
15
-
16
-#include "utils/math.h"
17
-#include "SDLSystem.h"
18
-
19
-SDLSystem::SDLSystem() : System() {
20
-    mWindow = 0x0;
21
-    mFullscreen = false;
22
-}
23
-
24
-SDLSystem::~SDLSystem() {
25
-}
26
-
27
-#ifdef FIXME
28
-void SDLSystem::bindKeyCommand(const char *cmd, int key, int event) {
29
-    if (key > 255) {
30
-        printf("Currently key event mapping only handles ASCII characters\n");
31
-        return;
32
-    }
33
-
34
-    printf("Bound command '%s' -> event %i (0x%x key)\n", cmd, event, key);
35
-
36
-    keyEvents[key] = event;
37
-}
38
-#endif
39
-
40
-void SDLSystem::setGrabMouse(bool on) {
41
-    SDL_SetRelativeMouseMode(on ? SDL_TRUE : SDL_FALSE);
42
-    if (!on)
43
-        SDL_ShowCursor(1);
44
-}
45
-
46
-void SDLSystem::initVideo(unsigned int width, unsigned int height, bool fullscreen) {
47
-    int flags = 0; //, x, y;
48
-
49
-    assert(width > 0);
50
-    assert(height > 0);
51
-
52
-    // Create GL context
53
-    SDL_Init(SDL_INIT_VIDEO);
54
-    printf("Created OpenGL Context\n");
55
-    atexit(SDL_Quit);
56
-
57
-    m_width = width;
58
-    m_height = height;
59
-
60
-#ifndef __APPLE__
61
-    if (!m_driver || !m_driver[0] || SDL_GL_LoadLibrary(m_driver) < 0) {
62
-        SDL_ClearError();
63
-
64
-        // Fallback 1
65
-        if (SDL_GL_LoadLibrary("libGL.so") < 0) {
66
-            SDL_ClearError();
67
-
68
-            // Fallback 2
69
-            if (SDL_GL_LoadLibrary("libGL.so.1") < 0) {
70
-                fprintf(stderr, "initVideo> SDL_GL_LoadLibrary failed!\n");
71
-                fprintf(stderr, "initVideo> Error is [%s].\n", SDL_GetError());
72
-                shutdown(1);
73
-            }
74
-        }
75
-    }
76
-#endif
77
-
78
-    flags |= SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE;
79
-
80
-    mFullscreen = fullscreen;
81
-    if (mFullscreen)
82
-        flags |= SDL_WINDOW_FULLSCREEN;
83
-
84
-    setGrabMouse(true); // Always grab mouse!
85
-
86
-    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
87
-    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
88
-    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
89
-    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
90
-    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
91
-
92
-    mWindow = SDL_CreateWindow(VERSION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
93
-            width, height, flags);
94
-    mGLContext = SDL_GL_CreateContext(mWindow);
95
-
96
-    // Resize context
97
-    resizeGL(width, height);
98
-}
99
-
100
-void SDLSystem::resize(unsigned int width, unsigned int height) {
101
-    assert(width > 0);
102
-    assert(height > 0);
103
-
104
-    m_width = width;
105
-    m_height = height;
106
-
107
-    SDL_SetWindowSize(mWindow, width, height);
108
-
109
-    // Resize context
110
-    resizeGL(width, height);
111
-}
112
-
113
-void SDLSystem::runGame() {
114
-    SDL_Event event;
115
-    unsigned int mkeys, mod, key;
116
-    int btn = 0;
117
-    bool specialKey;
118
-
119
-    for (;;) {
120
-        // Pause for 10-20 ms
121
-        SDL_Delay(10);
122
-
123
-        while (SDL_PollEvent(&event)) {
124
-            switch (event.type) {
125
-                case SDL_QUIT:
126
-                    shutdown(0);
127
-                    break;
128
-                case SDL_MOUSEMOTION:
129
-                    // Wrap motion
130
-                    handleMouseMotionEvent(event.motion.xrel / 2, event.motion.yrel / 2);
131
-                    break;
132
-                case SDL_MOUSEBUTTONDOWN:
133
-                case SDL_MOUSEBUTTONUP:
134
-                    //handleMouseEvent(event.button.button, event.button.state,
135
-                    //                    event.button.x, event.button.y);
136
-
137
-                    switch (event.button.button) {
138
-                        case SDL_BUTTON_LEFT:
139
-                            btn = SYS_MOUSE_LEFT;
140
-                            break;
141
-                        case SDL_BUTTON_RIGHT:
142
-                            btn = SYS_MOUSE_RIGHT;
143
-                            break;
144
-                        case SDL_BUTTON_MIDDLE:
145
-                            btn = SYS_MOUSE_MIDDLE;
146
-                            break;
147
-                    }
148
-
149
-                    if (event.button.state == SDL_PRESSED) {
150
-                        handleKeyPressEvent(btn, 0); //! \fixme mod not used
151
-                    } else {
152
-                        handleKeyReleaseEvent(btn, 0); //! \fixme mod not used
153
-                    }
154
-                    break;
155
-                case SDL_KEYUP:
156
-                case SDL_KEYDOWN:
157
-                    //SDL_GetMouseState(&x, &y); // Get cursor pos
158
-
159
-                    mkeys = (unsigned int)SDL_GetModState();
160
-                    mod = 0;
161
-
162
-                    if (mkeys & KMOD_LSHIFT)
163
-                        mod |= SYS_MOD_KEY_LSHIFT;
164
-
165
-                    if (mkeys & KMOD_RSHIFT)
166
-                        mod |= SYS_MOD_KEY_RSHIFT;
167
-
168
-                    if (mkeys & KMOD_LCTRL)
169
-                        mod |= SYS_MOD_KEY_LCTRL;
170
-
171
-                    if (mkeys & KMOD_RCTRL)
172
-                        mod |= SYS_MOD_KEY_RCTRL;
173
-
174
-                    if (mkeys & KMOD_LALT)
175
-                        mod |= SYS_MOD_KEY_LALT;
176
-
177
-                    if (mkeys & KMOD_RALT)
178
-                        mod |= SYS_MOD_KEY_RALT;
179
-
180
-                    if (mkeys & KMOD_LGUI)
181
-                        mod |= SYS_MOD_KEY_LMETA;
182
-
183
-                    if (mkeys & KMOD_RGUI)
184
-                        mod |= SYS_MOD_KEY_RMETA;
185
-
186
-                    key = event.key.keysym.sym;
187
-                    specialKey = false;
188
-
189
-                    switch (key) {
190
-                        case SDLK_F1:
191
-                            key = SYS_KEY_F1;
192
-                            specialKey = true;
193
-                            break;
194
-                        case SDLK_F2:
195
-                            key = SYS_KEY_F2;
196
-                            specialKey = true;
197
-                            break;
198
-                        case SDLK_F3:
199
-                            key = SYS_KEY_F3;
200
-                            specialKey = true;
201
-                            break;
202
-                        case SDLK_F4:
203
-                            key = SYS_KEY_F4;
204
-                            specialKey = true;
205
-                            break;
206
-                        case SDLK_F5:
207
-                            key = SYS_KEY_F5;
208
-                            specialKey = true;
209
-                            break;
210
-                        case SDLK_F6:
211
-                            key = SYS_KEY_F6;
212
-                            specialKey = true;
213
-                            break;
214
-                        case SDLK_F7:
215
-                            key = SYS_KEY_F7;
216
-                            specialKey = true;
217
-                            break;
218
-                        case SDLK_F8:
219
-                            key = SYS_KEY_F8;
220
-                            specialKey = true;
221
-                            break;
222
-                        case SDLK_F9:
223
-                            key = SYS_KEY_F9;
224
-                            specialKey = true;
225
-                            break;
226
-                        case SDLK_F10:
227
-                            key = SYS_KEY_F10;
228
-                            specialKey = true;
229
-                            break;
230
-                        case SDLK_F11:
231
-                            key = SYS_KEY_F11;
232
-                            specialKey = true;
233
-                            break;
234
-                        case SDLK_F12:
235
-                            key = SYS_KEY_F12;
236
-                            specialKey = true;
237
-                            break;
238
-                        case SDLK_UP:
239
-                            key = SYS_KEY_UP;
240
-                            specialKey = true;
241
-                            break;
242
-                        case SDLK_DOWN:
243
-                            key = SYS_KEY_DOWN;
244
-                            specialKey = true;
245
-                            break;
246
-                        case SDLK_RIGHT:
247
-                            key = SYS_KEY_RIGHT;
248
-                            specialKey = true;
249
-                            break;
250
-                        case SDLK_LEFT:
251
-                            key = SYS_KEY_LEFT;
252
-                            specialKey = true;
253
-                            break;
254
-                        case SDLK_PAGEDOWN:
255
-                            key = SYS_KEY_PAGEDOWN;
256
-                            specialKey = true;
257
-                            break;
258
-                        case SDLK_PAGEUP:
259
-                            key = SYS_KEY_PAGEUP;
260
-                            specialKey = true;
261
-                            break;
262
-                    }
263
-
264
-#ifdef __APPLE__
265
-                    // Handle CMD+Q to quit in all circumstances
266
-                    if (key == 'q') {
267
-                        if (mod & SYS_MOD_KEY_LMETA) {
268
-                            shutdown(0);
269
-                        }
270
-                    }
271
-#endif
272
-
273
-                    /*! \fixme Avoid passing modifers as a key, since the
274
-                     * consoles using this expect text characters, add unicode
275
-                     * support later when they're able to handle it
276
-                     */
277
-                    if (key > 255 && key < 1000) {
278
-                        key = 0;
279
-                    }
280
-
281
-                    if (key == mConsoleKey) {
282
-                        if (event.type == SDL_KEYDOWN) {
283
-                            mConsoleMode = !mConsoleMode;
284
-                            // Tmp hack
285
-                            handleConsoleKeyPressEvent(mConsoleKey, 0);
286
-                        }
287
-                    } else if (mConsoleMode) { // Console keying (text input)
288
-                        switch (event.type) {
289
-                            case SDL_KEYDOWN:
290
-                                handleConsoleKeyPressEvent(key, mod);
291
-                                break;
292
-                            default:
293
-                                ;
294
-                        }
295
-                    } else if (mKeyEvents[key] != 0) { // Bound key
296
-                        //if (key < 255 && mKeyEvents[key] != 0)
297
-                        key = mKeyEvents[key];
298
-
299
-                        switch (event.type) {
300
-                            case SDL_KEYDOWN:
301
-                                handleBoundKeyPressEvent(key);
302
-                                break;
303
-                            default:
304
-                                handleBoundKeyReleaseEvent(key);
305
-                        }
306
-                    } else { // 'Classic' key event handlers
307
-                        switch (event.type) {
308
-                            case SDL_KEYDOWN:
309
-                                handleKeyPressEvent(key, mod);
310
-                                break;
311
-                            default:
312
-                                handleKeyReleaseEvent(key, mod);
313
-                        }
314
-                    }
315
-                    break;
316
-                case SDL_WINDOWEVENT:
317
-                    switch(event.window.event) {
318
-                        case SDL_WINDOWEVENT_RESIZED:
319
-                            resize(event.window.data1, event.window.data2);
320
-                            break;
321
-                    }
322
-                    break;
323
-            }
324
-        }
325
-
326
-        // Game frame
327
-        gameFrame();
328
-    }
329
-}
330
-
331
-void SDLSystem::shutdown(int i) {
332
-    //SDL_QuitSubSystem(SDL_OPENGL);
333
-    //SDL_Quit(); // Moved to atexit() call
334
-
335
-    exit(i);
336
-}
337
-
338
-void SDLSystem::toggleFullscreen() {
339
-    if (mWindow) {
340
-        mFullscreen = !mFullscreen;
341
-
342
-        if (mFullscreen)
343
-            SDL_SetWindowFullscreen(mWindow, SDL_WINDOW_FULLSCREEN_DESKTOP);
344
-        else
345
-            SDL_SetWindowFullscreen(mWindow, 0);
346
-    }
347
-}
348
-
349
-void SDLSystem::swapBuffersGL() {
350
-    SDL_GL_SwapWindow(mWindow);
351
-}
352
-

+ 0
- 161
src/SkeletalModel.cpp Переглянути файл

@@ -1,161 +0,0 @@
1
-/*!
2
- * \file src/SkeletalModel.cpp
3
- * \brief This is the factored out skeletal model class
4
- *
5
- * \author Mongoose
6
- */
7
-
8
-#include "SkeletalModel.h"
9
-
10
-////////////////////////////////////////////////////////////
11
-// Constructors
12
-////////////////////////////////////////////////////////////
13
-
14
-SkeletalModel::SkeletalModel()
15
-{
16
-    model = 0x0;
17
-    flags = 0;
18
-    mBoneFrame = 0;
19
-    mAnimationFrame = 0;
20
-    mIdleAnimation = 0;
21
-    time = 0.0f;
22
-    lastTime = 0.0f;
23
-    rate = 0.0f;
24
-}
25
-
26
-
27
-SkeletalModel::~SkeletalModel()
28
-{
29
-    if (model)
30
-    {
31
-        for (model->animation.start();
32
-                model->animation.forward();
33
-                model->animation.next())
34
-        {
35
-            animation_frame_t *af = model->animation.current();
36
-
37
-            if (!af)
38
-                continue;
39
-
40
-            for (af->frame.start(); af->frame.forward(); af->frame.next())
41
-            {
42
-                bone_frame_t *bf = af->frame.current();
43
-
44
-                if (!bf)
45
-                    continue;
46
-
47
-                bf->tag.erase();
48
-
49
-                //for (bf->tag.start(); bf->tag.forward(); bf->tag.next())
50
-                //{
51
-                //  if (bf->tag.current())
52
-                //      delete bf->tag.current();
53
-                //}
54
-
55
-                delete bf;
56
-            }
57
-
58
-            af->frame.clear();
59
-
60
-            delete af;
61
-        }
62
-
63
-        model->animation.clear();
64
-
65
-        //! \fixme Causes "freeing already freed pointer" exception
66
-        //delete model;
67
-    }
68
-}
69
-
70
-
71
-////////////////////////////////////////////////////////////
72
-// Public Accessors
73
-////////////////////////////////////////////////////////////
74
-
75
-int SkeletalModel::getAnimation()
76
-{
77
-    return mAnimationFrame;
78
-}
79
-
80
-
81
-int SkeletalModel::getFrame()
82
-{
83
-    return mBoneFrame;
84
-}
85
-
86
-
87
-int SkeletalModel::getIdleAnimation()
88
-{
89
-    return mIdleAnimation;
90
-}
91
-
92
-
93
-////////////////////////////////////////////////////////////
94
-// Public Mutators
95
-////////////////////////////////////////////////////////////
96
-
97
-void SkeletalModel::setModel(skeletal_model_t *mdl)
98
-{
99
-    if (mdl)
100
-        model = mdl;
101
-}
102
-
103
-
104
-void SkeletalModel::setAnimation(int index)
105
-{
106
-    if (!model) // index > (int)model->animation.size())
107
-        return;
108
-
109
-    animation_frame_t *a = model->animation[index];
110
-
111
-    if (a)
112
-    {
113
-        mAnimationFrame = index;
114
-        mBoneFrame = 0;
115
-        rate = a->rate;
116
-    }
117
-}
118
-
119
-
120
-void SkeletalModel::setFrame(int index)
121
-{
122
-    if (!model)
123
-        return;
124
-
125
-    animation_frame_t *a = model->animation[mAnimationFrame];
126
-
127
-    if (a) // index > (int)a->frame.size())
128
-    {
129
-        bone_frame_t *b = a->frame[index];
130
-
131
-        if (b)
132
-        {
133
-            mBoneFrame = index;
134
-        }
135
-    }
136
-}
137
-
138
-
139
-void SkeletalModel::setIdleAnimation(int index)
140
-{
141
-    if (!model)
142
-        return;
143
-
144
-    animation_frame_t *a = model->animation[index];
145
-
146
-    if (a)
147
-    {
148
-        mIdleAnimation = index;
149
-    }
150
-}
151
-
152
-
153
-////////////////////////////////////////////////////////////
154
-// Private Accessors
155
-////////////////////////////////////////////////////////////
156
-
157
-
158
-////////////////////////////////////////////////////////////
159
-// Private Mutators
160
-////////////////////////////////////////////////////////////
161
-

+ 0
- 262
src/Sound.cpp Переглянути файл

@@ -1,262 +0,0 @@
1
-/*!
2
- * \file src/Sound.cpp
3
- * \brief This is the audio manager Implementation
4
- *
5
- * \author Mongoose
6
- * \author xythobuz
7
- */
8
-
9
-#ifdef __APPLE__
10
-#include <OpenAL/al.h>
11
-#else
12
-#include <AL/al.h>
13
-#endif
14
-
15
-#include <AL/alut.h>
16
-
17
-#include <time.h>
18
-#include <stdio.h>
19
-#include <stdlib.h>
20
-#include <sys/time.h>
21
-#include <sys/types.h>
22
-#include <sys/stat.h>
23
-#include <fcntl.h>
24
-#include <unistd.h>
25
-#include <assert.h>
26
-
27
-#include "Sound.h"
28
-
29
-Sound::Sound()
30
-{
31
-    mSource[0] = 0;
32
-    mBuffer[0] = 0;
33
-    mNext = 0;
34
-    mInit = false;
35
-}
36
-
37
-
38
-Sound::~Sound()
39
-{
40
-    if (mInit)
41
-    {
42
-        alutExit();
43
-    }
44
-}
45
-
46
-
47
-int Sound::init()
48
-{
49
-#ifndef __APPLE__
50
-    int fd;
51
-
52
-    fd = open("/dev/dsp", O_RDWR);
53
-
54
-    if (fd < 0)
55
-    {
56
-        perror("Sound::Init> Could not open /dev/dsp : ");
57
-        return -1;
58
-    }
59
-
60
-    close(fd);
61
-#endif
62
-
63
-    ALCdevice *Device = alcOpenDevice("OSS");
64
-    ALCcontext *Context = alcCreateContext(Device, NULL);
65
-    alcMakeContextCurrent(Context);
66
-
67
-    if (alutInitWithoutContext(NULL, NULL) == AL_FALSE) {
68
-        printf("Sound::Init> Could not initialize alut (%s)\n", alutGetErrorString(alutGetError()));
69
-        return -2;
70
-    }
71
-
72
-    mInit = true;
73
-    printf("Created OpenAL Context\n");
74
-
75
-    return 0;
76
-}
77
-
78
-
79
-int Sound::registeredSources() {
80
-    return mNext;
81
-}
82
-
83
-
84
-void Sound::listenAt(float pos[3], float angle[3])
85
-{
86
-    assert(mInit == true);
87
-    assert(pos != NULL);
88
-    assert(angle != NULL);
89
-
90
-    alListenerfv(AL_POSITION, pos);
91
-    alListenerfv(AL_ORIENTATION, angle);
92
-}
93
-
94
-
95
-void Sound::sourceAt(int source, float pos[3])
96
-{
97
-    assert(mInit == true);
98
-    assert(source >= 0);
99
-    assert(source < mNext);
100
-    assert(pos != NULL);
101
-
102
-    alSourcefv(mSource[source], AL_POSITION, pos);
103
-}
104
-
105
-
106
-//! \fixme Seperate sourcing and buffering, Mongoose 2002.01.04
107
-int Sound::addFile(const char *filename, int *source, unsigned int flags)
108
-{
109
-    ALsizei size;
110
-    ALfloat freq;
111
-    ALenum format;
112
-    ALvoid *data;
113
-
114
-    assert(mInit == true);
115
-    assert(filename != NULL);
116
-    assert(filename[0] != '\0');
117
-    assert(source != NULL);
118
-
119
-    *source = -1;
120
-
121
-    alGetError();
122
-
123
-    alGenBuffers(1, &mBuffer[mNext]);
124
-
125
-    if (alGetError() != AL_NO_ERROR)
126
-    {
127
-        fprintf(stderr, "Sound::AddFile> alGenBuffers call failed\n");
128
-        return -1;
129
-    }
130
-
131
-    alGetError();
132
-
133
-    alGenSources(1, &mSource[mNext]);
134
-
135
-    if (alGetError() != AL_NO_ERROR)
136
-    {
137
-        fprintf(stderr, "Sound::AddFile> alGenSources call failed\n");
138
-        return -2;
139
-    }
140
-
141
-    // err = alutLoadWAV(filename, &data, &format, &size, &bits, &freq);
142
-    // is deprecated!
143
-    data = alutLoadMemoryFromFile(filename, &format, &size, &freq);
144
-
145
-    if (alutGetError() != ALUT_ERROR_NO_ERROR)
146
-    {
147
-        fprintf(stderr, "Could not load %s\n", filename);
148
-        return -3;
149
-    }
150
-
151
-    alBufferData(mBuffer[mNext], format, data, size, static_cast<ALsizei>(freq));
152
-
153
-    alSourcei(mSource[mNext], AL_BUFFER, mBuffer[mNext]);
154
-
155
-    if (flags & SoundFlagsLoop)
156
-    {
157
-        alSourcei(mSource[mNext], AL_LOOPING, 1);
158
-    }
159
-
160
-    *source = mNext++;
161
-
162
-    return 0;
163
-}
164
-
165
-int Sound::addWave(unsigned char *wav, unsigned int length, int *source, unsigned int flags)
166
-{
167
-    ALsizei size;
168
-    ALfloat freq;
169
-    ALenum format;
170
-    ALvoid *data;
171
-    int error = 0;
172
-
173
-    assert(mInit == true);
174
-    assert(wav != NULL);
175
-    assert(source != NULL);
176
-
177
-    *source = -1;
178
-
179
-    data = wav;
180
-
181
-    alGetError();
182
-
183
-    alGenBuffers(1, &mBuffer[mNext]);
184
-
185
-    if (alGetError() != AL_NO_ERROR)
186
-    {
187
-        fprintf(stderr, "Sound::AddWave> alGenBuffers call failed\n");
188
-        return -1;
189
-    }
190
-
191
-    alGetError();
192
-
193
-    alGenSources(1, &mSource[mNext]);
194
-
195
-    if (alGetError() != AL_NO_ERROR)
196
-    {
197
-        fprintf(stderr, "Sound::AddWave> alGenSources call failed\n");
198
-        return -2;
199
-    }
200
-
201
-    //AL_FORMAT_WAVE_EXT does not exist on Mac!"
202
-    // alBufferData(mBuffer[mNext], AL_FORMAT_WAVE_EXT, data, size, freq);
203
-    // Idea: Fill Buffer with
204
-    // alutLoadMemoryFromFileImage
205
-    //     (const ALvoid *data, ALsizei length, ALenum *format, ALsizei *size, ALfloat *frequency)
206
-
207
-    data = alutLoadMemoryFromFileImage(wav, length, &format, &size, &freq);
208
-
209
-    if (((error = alutGetError()) != ALUT_ERROR_NO_ERROR) || (data == NULL)) {
210
-        fprintf(stderr, "Could not load wav buffer (%s)\n", alutGetErrorString(error));
211
-        return -3;
212
-    }
213
-
214
-
215
-    alBufferData(mBuffer[mNext], format, data, size, static_cast<ALsizei>(freq));
216
-
217
-    alSourcei(mSource[mNext], AL_BUFFER, mBuffer[mNext]);
218
-
219
-    if (flags & SoundFlagsLoop)
220
-    {
221
-        alSourcei(mSource[mNext], AL_LOOPING, 1);
222
-    }
223
-
224
-    *source = mNext++;
225
-
226
-    //! \fixme Should free alut buffer?
227
-
228
-    return 0;
229
-}
230
-
231
-
232
-void Sound::remove(int source) {
233
-    assert(source >= 0);
234
-    assert(source < mNext);
235
-
236
-    alDeleteSources(1, &mSource[source]);
237
-    alDeleteBuffers(1, &mBuffer[source]);
238
-
239
-    if (source == (mNext - 1))
240
-        mNext--;
241
-}
242
-
243
-
244
-void Sound::play(int source)
245
-{
246
-    assert(mInit == true);
247
-    assert(source >= 0);
248
-    assert(source < mNext);
249
-
250
-    alSourcePlay(mSource[source]);
251
-}
252
-
253
-
254
-void Sound::stop(int source)
255
-{
256
-    assert(mInit == true);
257
-    assert(source >= 0);
258
-    assert(source < mNext);
259
-
260
-    alSourceStop(mSource[source]);
261
-}
262
-

+ 0
- 217
src/System.cpp Переглянути файл

@@ -1,217 +0,0 @@
1
-/*!
2
- * \file src/System.cpp
3
- * \brief Mostly defines the interface of System implementations.
4
- *
5
- * Currently only SDL is used, but there was a GLUT implementation.
6
- *
7
- * \author Mongoose
8
- */
9
-
10
-#include <stdlib.h>
11
-#include <stdio.h>
12
-#include <sys/stat.h>
13
-#include <sys/types.h>
14
-#include <string.h>
15
-#include <stdarg.h>
16
-#include <cmath>
17
-#include <assert.h>
18
-
19
-#ifdef __APPLE__
20
-#include <OpenGL/gl.h>
21
-#include <OpenGL/glu.h>
22
-#else
23
-#include <GL/gl.h>
24
-#include <GL/glu.h>
25
-#endif
26
-
27
-#include "utils/math.h"
28
-#include "utils/time.h"
29
-#include "System.h"
30
-
31
-System::System() {
32
-    m_width = 800;
33
-    m_height = 600;
34
-
35
-    m_driver = NULL;
36
-
37
-    m_clipFar  = 4000.0f;
38
-    m_clipNear = 4.0f;
39
-    m_fovY     = 45.0f;
40
-
41
-    mConsoleMode = false;
42
-    mCommandMode = 0;
43
-
44
-    printf("[System.Core]\n");
45
-
46
-    // Hack for bad Map class, as well as reserved commands
47
-    addCommandMode("[System.Console]");
48
-    mConsoleKey = '`';
49
-    bindKeyCommand("+console", mConsoleKey, 0);
50
-
51
-#ifdef WIN32
52
-    setDriverGL("libGL32.dll");
53
-#else
54
-    setDriverGL("/usr/lib/libGL.so.1");
55
-#endif
56
-}
57
-
58
-System::~System() {
59
-}
60
-
61
-unsigned int System::addCommandMode(const char *command) {
62
-    assert(command != NULL);
63
-    assert(command[0] == '[');
64
-
65
-    mCmdModes.pushBack(command);
66
-    return (mCmdModes.size() - 1);
67
-}
68
-
69
-//! \fixme Modifer support later
70
-void System::bindKeyCommand(const char *cmd, unsigned int key, int event) {
71
-    assert(cmd != NULL);
72
-    assert(cmd[0] != '\0');
73
-
74
-    printf("Bound command '%s' -> event %i (0x%x key)\n", cmd, event, key);
75
-    mKeyEvents[key] = event;
76
-}
77
-
78
-void System::command(const char *cmd) {
79
-    bool modeFound = false;
80
-    char *cmdbuf;
81
-
82
-    assert(cmd != NULL);
83
-    assert(cmd[0] != '\0');
84
-
85
-    if (cmd[0] == '[') { // Set a mode, eg "[Engine.OpenGL.Driver]"
86
-        for (mCmdModes.start(); mCmdModes.forward(); mCmdModes.next()) {
87
-            if (strcmp(cmd, mCmdModes.current()) == 0) {
88
-                mCommandMode = mCmdModes.getCurrentIndex();
89
-                modeFound = true;
90
-            }
91
-        }
92
-
93
-        if (!modeFound) {
94
-            //  mCommandMode = 0;
95
-            printf("Command> Unknown mode '%s'\n", cmd);
96
-        }
97
-    } else { // Execute a command in current mode, eg "stat fps"
98
-        cmdbuf = new char[strlen(cmd) + 1];
99
-        strncpy(cmdbuf, cmd, strlen(cmd) + 1);
100
-        handleCommand(cmdbuf, mCommandMode);
101
-    }
102
-}
103
-
104
-int System::loadResourceFile(const char *filename) {
105
-    char buffer[256];
106
-    bool line_comment = false;
107
-    FILE *f;
108
-    char c;
109
-    int i, j;
110
-
111
-    assert(filename != NULL);
112
-    assert(filename[0] != '\0');
113
-
114
-    f = fopen(filename, "r");
115
-
116
-    if (!f) {
117
-        perror(filename);
118
-        return -1;
119
-    }
120
-
121
-    printf("Loading %s...\n", filename);
122
-
123
-    i = 0;
124
-    buffer[0] = 0;
125
-
126
-    // Strip out whitespace and comments
127
-    while (fscanf(f, "%c", &c) != EOF) {
128
-        if (line_comment && c != '\n')
129
-            continue;
130
-
131
-        if (i > 254) {
132
-            printf("loadResourceFile> Overflow handled\n");
133
-            i = 254;
134
-        }
135
-
136
-        switch (c) {
137
-            case '\v':
138
-            case '\t':
139
-                break;
140
-            case '#':
141
-                buffer[i++] = 0;
142
-                line_comment = true;
143
-                break;
144
-            case '\n':
145
-                if (line_comment)
146
-                    line_comment = false;
147
-
148
-                if (buffer[0] == 0) {
149
-                    i = 0;
150
-                    continue;
151
-                }
152
-
153
-                buffer[i] = 0;
154
-                //printf("'%s'\n", buffer);
155
-
156
-                // 'Preprocessor' commands
157
-                if (buffer[0] == '@') {
158
-                    if (strncmp((buffer + 1), "include ", 8) == 0) {
159
-                        for (j = 9; j < i; ++j) {
160
-                            buffer[j-9] = buffer[j];
161
-                            buffer[j-8] = 0;
162
-                        }
163
-
164
-                        printf("Importing '%s'\n", buffer);
165
-
166
-                        loadResourceFile(fullPath(buffer, 0));
167
-                    }
168
-                } else {
169
-                    command(buffer);
170
-                }
171
-
172
-                i = 0;
173
-                buffer[0] = 0;
174
-                break;
175
-            default:
176
-                buffer[i++] = c;
177
-        }
178
-    }
179
-
180
-    fclose(f);
181
-
182
-    return 0;
183
-}
184
-
185
-void System::setDriverGL(const char *driver) {
186
-    assert(driver != NULL);
187
-    assert(driver[0] != '\0');
188
-
189
-    if (m_driver)
190
-        delete [] m_driver;
191
-
192
-    unsigned int len = strlen(driver);
193
-    m_driver = new char[len + 1];
194
-    strncpy(m_driver, driver, len);
195
-    m_driver[len] = 0;
196
-}
197
-
198
-void System::resizeGL(unsigned int w, unsigned int h) {
199
-    assert(w > 0);
200
-    assert(h > 0);
201
-
202
-    glViewport(0, 0, w, h);
203
-    glMatrixMode(GL_PROJECTION);
204
-    glLoadIdentity();
205
-
206
-    // Adjust clipping
207
-    // gluPerspective is deprecated!
208
-    // gluPerspective(m_fovY, ((GLdouble)w)/((GLdouble)h), m_clipNear, m_clipFar);
209
-    // Fix: http://stackoverflow.com/a/2417756
210
-    GLfloat fH = tanf(m_fovY * HEL_PI / 360.0f) * m_clipNear;
211
-    GLfloat fW = fH * ((GLfloat)w)/((GLfloat)h);
212
-    glFrustum(-fW, fW, -fH, fH, m_clipNear, m_clipFar);
213
-
214
-    glMatrixMode(GL_MODELVIEW);
215
-    glLoadIdentity();
216
-}
217
-

+ 0
- 1125
src/Texture.cpp
Різницю між файлами не показано, бо вона завелика
Переглянути файл


+ 0
- 6281
src/TombRaider.cpp
Різницю між файлами не показано, бо вона завелика
Переглянути файл


+ 0
- 135
src/Vector3d.cpp Переглянути файл

@@ -1,135 +0,0 @@
1
-/*!
2
- * \file src/Vector3d.cpp
3
- * \brief 3D Math vector
4
- *
5
- * \author Mongoose
6
- */
7
-
8
-#include <math.h>
9
-
10
-#include "Vector3d.h"
11
-
12
-Vector3d::Vector3d() {
13
-    mVec[0] = mVec[1] = mVec[2] = 0.0f;
14
-}
15
-
16
-Vector3d::Vector3d(vec3_t v) {
17
-    mVec[0] = v[0];
18
-    mVec[1] = v[1];
19
-    mVec[2] = v[2];
20
-}
21
-
22
-Vector3d::Vector3d(vec_t x, vec_t y, vec_t z) {
23
-    mVec[0] = x;
24
-    mVec[1] = y;
25
-    mVec[2] = z;
26
-}
27
-
28
-Vector3d::Vector3d(const Vector3d &v) {
29
-    mVec[0] = v.mVec[0];
30
-    mVec[1] = v.mVec[1];
31
-    mVec[2] = v.mVec[2];
32
-}
33
-
34
-vec_t Vector3d::dot(const Vector3d &u, const Vector3d &v) {
35
-    return (u.mVec[0]*v.mVec[0] + u.mVec[1]*v.mVec[1] + u.mVec[2]*v.mVec[2]);
36
-}
37
-
38
-Vector3d Vector3d::cross(const Vector3d &u, const Vector3d &v) {
39
-    return Vector3d(u.mVec[1] * v.mVec[2] - u.mVec[2] * v.mVec[1],
40
-            u.mVec[2] * v.mVec[0] - u.mVec[0] * v.mVec[2],
41
-            u.mVec[0] * v.mVec[1] - u.mVec[1] * v.mVec[0]);
42
-}
43
-
44
-vec_t Vector3d::magnitude() {
45
-    return sqrtf(mVec[0]*mVec[0] + mVec[1]*mVec[1] + mVec[2]*mVec[2]);
46
-}
47
-
48
-Vector3d Vector3d::unit() {
49
-    vec_t norm = magnitude();
50
-
51
-    return Vector3d(mVec[0] / norm,
52
-            mVec[1] / norm,
53
-            mVec[2] / norm);
54
-}
55
-
56
-Vector3d Vector3d::zeroVector() {
57
-    return Vector3d(0, 0, 0);
58
-}
59
-
60
-Vector3d Vector3d::operator +(const Vector3d &v) {
61
-    return Vector3d(mVec[0] + v.mVec[0],
62
-            mVec[1] + v.mVec[1],
63
-            mVec[2] + v.mVec[2]);
64
-}
65
-
66
-Vector3d Vector3d::operator -(const Vector3d &v) {
67
-    return Vector3d(mVec[0] - v.mVec[0],
68
-            mVec[1] - v.mVec[1],
69
-            mVec[2] - v.mVec[2]);
70
-}
71
-
72
-Vector3d Vector3d::operator -() {
73
-    return Vector3d(-mVec[0],
74
-            -mVec[1],
75
-            -mVec[2]);
76
-}
77
-
78
-Vector3d Vector3d::operator *(vec_t s) {
79
-    return Vector3d(s * mVec[0],
80
-            s * mVec[1],
81
-            s * mVec[2]);
82
-}
83
-
84
-Vector3d Vector3d::operator /(vec_t s) {
85
-    return Vector3d(mVec[0] / s,
86
-            mVec[1] / s,
87
-            mVec[2] / s);
88
-}
89
-
90
-vec_t Vector3d::operator *(const Vector3d &v) {
91
-    return dot(*this, v);
92
-}
93
-
94
-void Vector3d::normalize() {
95
-    vec_t norm = magnitude();
96
-
97
-    mVec[0] /= norm;
98
-    mVec[1] /= norm;
99
-    mVec[2] /= norm;
100
-}
101
-
102
-void Vector3d::zero() {
103
-    mVec[0] = 0;
104
-    mVec[1] = 0;
105
-    mVec[2] = 0;
106
-}
107
-
108
-Vector3d &Vector3d::operator =(const Vector3d &v) {
109
-    mVec[0] = v.mVec[0];
110
-    mVec[1] = v.mVec[1];
111
-    mVec[2] = v.mVec[2];
112
-    return *this;
113
-}
114
-
115
-Vector3d &Vector3d::operator +=(const Vector3d &v) {
116
-    mVec[0] += v.mVec[0];
117
-    mVec[1] += v.mVec[1];
118
-    mVec[2] += v.mVec[2];
119
-    return *this;
120
-}
121
-
122
-Vector3d &Vector3d::operator -=(const Vector3d &v) {
123
-    mVec[0] -= v.mVec[0];
124
-    mVec[1] -= v.mVec[1];
125
-    mVec[2] -= v.mVec[2];
126
-    return *this;
127
-}
128
-
129
-Vector3d &Vector3d::operator *=(vec_t s) {
130
-    mVec[0] *= s;
131
-    mVec[1] *= s;
132
-    mVec[2] *= s;
133
-    return *this;
134
-}
135
-

+ 0
- 270
src/ViewVolume.cpp Переглянути файл

@@ -1,270 +0,0 @@
1
-/*!
2
- * \file include/ViewVolume.h
3
- * \brief Viewing Volume for culling use
4
- *
5
- * Thanks Mark Morley for the article I used to get several algorithms.
6
- *
7
- * \author Mongoose
8
- */
9
-
10
-#include <math.h>
11
-
12
-#include "ViewVolume.h"
13
-
14
-ViewVolume::ViewVolume() {
15
-    mFrustum[0][0] = mFrustum[0][1] = mFrustum[0][2] = mFrustum[0][3] = 0.0f;
16
-    mFrustum[1][0] = mFrustum[1][1] = mFrustum[1][2] = mFrustum[1][3] = 0.0f;
17
-    mFrustum[2][0] = mFrustum[2][1] = mFrustum[2][2] = mFrustum[2][3] = 0.0f;
18
-    mFrustum[3][0] = mFrustum[3][1] = mFrustum[3][2] = mFrustum[3][3] = 0.0f;
19
-    mFrustum[4][0] = mFrustum[4][1] = mFrustum[4][2] = mFrustum[4][3] = 0.0f;
20
-    mFrustum[5][0] = mFrustum[5][1] = mFrustum[5][2] = mFrustum[5][3] = 0.0f;
21
-}
22
-
23
-bool ViewVolume::isBoundingVolumeInFrustum(BoundingVolume bvol) {
24
-    return (isBoundingSphereInFrustum(bvol.mSphere) &&
25
-            isBoundingBoxInFrustum(bvol.mBox));
26
-}
27
-
28
-bool ViewVolume::isBoundingSphereInFrustum(BoundingSphere bvol) {
29
-    return (isSphereInFrustum(bvol.mCenter[0],
30
-                bvol.mCenter[1],
31
-                bvol.mCenter[2],
32
-                bvol.mRadius));
33
-}
34
-
35
-bool ViewVolume::isBoundingBoxInFrustum(BoundingBox bvol) {
36
-    return (isBboxInFrustum(bvol.mMin, bvol.mMax));
37
-}
38
-
39
-bool ViewVolume::isPointInFrustum(vec_t x, vec_t y, vec_t z) {
40
-    for (unsigned int p = 0; p < 6; ++p) {
41
-        if (mFrustum[p][0] * x + mFrustum[p][1] * y + mFrustum[p][2] * z +
42
-                mFrustum[p][3] <= 0) {
43
-            return false;
44
-        }
45
-    }
46
-    return true;
47
-}
48
-
49
-bool ViewVolume::isSphereInFrustum(vec_t x, vec_t y, vec_t z, vec_t radius) {
50
-    vec_t d;
51
-    for (unsigned int p = 0; p < 6; ++p) {
52
-        d = mFrustum[p][0] * x + mFrustum[p][1] * y + mFrustum[p][2] * z + mFrustum[p][3];
53
-        if (d <= -radius)
54
-            return false;
55
-    }
56
-    return true;
57
-}
58
-
59
-bool ViewVolume::isBboxInFrustum(vec3_t min, vec3_t max) {
60
-    for (unsigned int p = 0; p < 6; ++p) {
61
-        if (mFrustum[p][0] * min[0] +
62
-                mFrustum[p][1] * min[1] +
63
-                mFrustum[p][2] * min[2] + mFrustum[p][3] > 0)
64
-            continue;
65
-
66
-        if (mFrustum[p][0] * max[0] +
67
-                mFrustum[p][1] * max[1] +
68
-                mFrustum[p][2] * max[2] + mFrustum[p][3] > 0)
69
-            continue;
70
-
71
-        if (mFrustum[p][0] * min[0] +
72
-                mFrustum[p][1] * max[1] +
73
-                mFrustum[p][2] * max[2] + mFrustum[p][3] > 0)
74
-            continue;
75
-
76
-        if (mFrustum[p][0] * min[0] +
77
-                mFrustum[p][1] * min[1] +
78
-                mFrustum[p][2] * max[2] + mFrustum[p][3] > 0)
79
-            continue;
80
-
81
-        if (mFrustum[p][0] * min[0] +
82
-                mFrustum[p][1] * max[1] +
83
-                mFrustum[p][2] * min[2] + mFrustum[p][3] > 0)
84
-            continue;
85
-
86
-        if (mFrustum[p][0] * max[0] +
87
-                mFrustum[p][1] * min[1] +
88
-                mFrustum[p][2] * min[2] + mFrustum[p][3] > 0)
89
-            continue;
90
-
91
-        if (mFrustum[p][0] * max[0] +
92
-                mFrustum[p][1] * max[1] +
93
-                mFrustum[p][2] * min[2] + mFrustum[p][3] > 0)
94
-            continue;
95
-
96
-        if (mFrustum[p][0] * max[0] +
97
-                mFrustum[p][1] * min[1] +
98
-                mFrustum[p][2] * max[2] + mFrustum[p][3] > 0)
99
-            continue;
100
-
101
-        return false;
102
-    }
103
-    return true;
104
-}
105
-
106
-vec_t ViewVolume::getDistToSphereFromNear(vec_t x, vec_t y, vec_t z, vec_t radius) {
107
-    vec_t d = 0.0;
108
-    for (unsigned int p = 0; p < 6; ++p) {
109
-        d = mFrustum[p][0] * x + mFrustum[p][1] * y + mFrustum[p][2] * z + mFrustum[p][3];
110
-        if (d <= -radius)
111
-            return 0;
112
-    }
113
-    return d + radius;
114
-}
115
-
116
-vec_t ViewVolume::getDistToBboxFromNear(vec3_t min, vec3_t max) {
117
-    vec3_t center;
118
-    vec_t d, radius;
119
-
120
-    helMidpoint3v(min, max, center);
121
-
122
-    // 5 should be near plane
123
-    d = (mFrustum[5][0] * center[0] +
124
-            mFrustum[5][1] * center[1] +
125
-            mFrustum[5][2] * center[2] +
126
-            mFrustum[5][3]);
127
-
128
-    radius = helDist3v(max, center);
129
-
130
-    if (d <= -radius)
131
-        return 0;
132
-
133
-    return d + radius;
134
-}
135
-
136
-void ViewVolume::getFrustum(vec_t frustum[6][4]) {
137
-    for (unsigned int p = 0; p < 6; ++p) {
138
-        for (unsigned int i = 0; i < 4; ++i) {
139
-            frustum[p][i] = mFrustum[p][i];
140
-        }
141
-    }
142
-}
143
-
144
-void ViewVolume::getPlane(ViewVolumeSide p, vec4_t plane) {
145
-    for (unsigned int i = 0; i < 4; ++i) {
146
-        plane[i] =  mFrustum[p][i];
147
-    }
148
-}
149
-
150
-void ViewVolume::updateFrame(matrix_t proj, matrix_t mdl) {
151
-    setModel(mdl);
152
-    setProjection(proj);
153
-    updateClip();
154
-    updateFrustum();
155
-}
156
-
157
-void ViewVolume::updateFrame() {
158
-    updateClip();
159
-    updateFrustum();
160
-}
161
-
162
-void ViewVolume::setModel(matrix_t mdl) {
163
-    mModel.setMatrix(mdl);
164
-}
165
-
166
-void ViewVolume::setProjection(matrix_t proj) {
167
-    mProjection.setMatrix(proj);
168
-}
169
-
170
-void ViewVolume::updateClip() {
171
-    mClip = mProjection * mModel;
172
-}
173
-
174
-void ViewVolume::updateFrustum() {
175
-    matrix_t clip;
176
-    vec_t t;
177
-
178
-    mClip.getMatrix(clip);
179
-
180
-    /* Extract the numbers for the RIGHT plane */
181
-    mFrustum[0][0] = clip[ 3] - clip[ 0];
182
-    mFrustum[0][1] = clip[ 7] - clip[ 4];
183
-    mFrustum[0][2] = clip[11] - clip[ 8];
184
-    mFrustum[0][3] = clip[15] - clip[12];
185
-
186
-    /* Normalize the result */
187
-    t = sqrtf(mFrustum[0][0] * mFrustum[0][0] +
188
-            mFrustum[0][1] * mFrustum[0][1] +
189
-            mFrustum[0][2] * mFrustum[0][2]);
190
-    mFrustum[0][0] /= t;
191
-    mFrustum[0][1] /= t;
192
-    mFrustum[0][2] /= t;
193
-    mFrustum[0][3] /= t;
194
-
195
-    /* Extract the numbers for the LEFT plane */
196
-    mFrustum[1][0] = clip[ 3] + clip[ 0];
197
-    mFrustum[1][1] = clip[ 7] + clip[ 4];
198
-    mFrustum[1][2] = clip[11] + clip[ 8];
199
-    mFrustum[1][3] = clip[15] + clip[12];
200
-
201
-    /* Normalize the result */
202
-    t = sqrtf(mFrustum[1][0] * mFrustum[1][0] +
203
-            mFrustum[1][1] * mFrustum[1][1] +
204
-            mFrustum[1][2] * mFrustum[1][2]);
205
-    mFrustum[1][0] /= t;
206
-    mFrustum[1][1] /= t;
207
-    mFrustum[1][2] /= t;
208
-    mFrustum[1][3] /= t;
209
-
210
-    /* Extract the BOTTOM plane */
211
-    mFrustum[2][0] = clip[ 3] + clip[ 1];
212
-    mFrustum[2][1] = clip[ 7] + clip[ 5];
213
-    mFrustum[2][2] = clip[11] + clip[ 9];
214
-    mFrustum[2][3] = clip[15] + clip[13];
215
-
216
-    /* Normalize the result */
217
-    t = sqrtf(mFrustum[2][0] * mFrustum[2][0] +
218
-            mFrustum[2][1] * mFrustum[2][1] +
219
-            mFrustum[2][2] * mFrustum[2][2]);
220
-    mFrustum[2][0] /= t;
221
-    mFrustum[2][1] /= t;
222
-    mFrustum[2][2] /= t;
223
-    mFrustum[2][3] /= t;
224
-
225
-    /* Extract the TOP plane */
226
-    mFrustum[3][0] = clip[ 3] - clip[ 1];
227
-    mFrustum[3][1] = clip[ 7] - clip[ 5];
228
-    mFrustum[3][2] = clip[11] - clip[ 9];
229
-    mFrustum[3][3] = clip[15] - clip[13];
230
-
231
-    /* Normalize the result */
232
-    t = sqrtf(mFrustum[3][0] * mFrustum[3][0] +
233
-            mFrustum[3][1] * mFrustum[3][1] +
234
-            mFrustum[3][2] * mFrustum[3][2]);
235
-    mFrustum[3][0] /= t;
236
-    mFrustum[3][1] /= t;
237
-    mFrustum[3][2] /= t;
238
-    mFrustum[3][3] /= t;
239
-
240
-    /* Extract the FAR plane */
241
-    mFrustum[4][0] = clip[ 3] - clip[ 2];
242
-    mFrustum[4][1] = clip[ 7] - clip[ 6];
243
-    mFrustum[4][2] = clip[11] - clip[10];
244
-    mFrustum[4][3] = clip[15] - clip[14];
245
-
246
-    /* Normalize the result */
247
-    t = sqrtf(mFrustum[4][0] * mFrustum[4][0] +
248
-            mFrustum[4][1] * mFrustum[4][1] +
249
-            mFrustum[4][2] * mFrustum[4][2]);
250
-    mFrustum[4][0] /= t;
251
-    mFrustum[4][1] /= t;
252
-    mFrustum[4][2] /= t;
253
-    mFrustum[4][3] /= t;
254
-
255
-    /* Extract the NEAR plane */
256
-    mFrustum[5][0] = clip[ 3] + clip[ 2];
257
-    mFrustum[5][1] = clip[ 7] + clip[ 6];
258
-    mFrustum[5][2] = clip[11] + clip[10];
259
-    mFrustum[5][3] = clip[15] + clip[14];
260
-
261
-    /* Normalize the result */
262
-    t = sqrtf(mFrustum[5][0] * mFrustum[5][0] +
263
-            mFrustum[5][1] * mFrustum[5][1] +
264
-            mFrustum[5][2] * mFrustum[5][2]);
265
-    mFrustum[5][0] /= t;
266
-    mFrustum[5][1] /= t;
267
-    mFrustum[5][2] /= t;
268
-    mFrustum[5][3] /= t;
269
-}
270
-

+ 0
- 762
src/World.cpp Переглянути файл

@@ -1,762 +0,0 @@
1
-/*!
2
- * \file src/World.cpp
3
- * \brief The game world (model)
4
- *
5
- * \author Mongoose
6
- */
7
-
8
-#include <math.h>
9
-
10
-#include "World.h"
11
-
12
-
13
-////////////////////////////////////////////////////////////
14
-// Constructors
15
-////////////////////////////////////////////////////////////
16
-
17
-World::World()
18
-{
19
-    mClearLock = false;
20
-    mFlags = 0;
21
-    mEntities.setError(0x0);
22
-    mRooms.setError(0x0);
23
-    mMeshes.setError(0x0);
24
-    mSprites.setError(0x0);
25
-    mModels.setError(0x0);
26
-}
27
-
28
-
29
-World::~World()
30
-{
31
-    destroy();
32
-}
33
-
34
-
35
-////////////////////////////////////////////////////////////
36
-// Public Accessors
37
-////////////////////////////////////////////////////////////
38
-
39
-int World::getRoomByLocation(int index, float x, float y, float z)
40
-{
41
-    room_mesh_t *room = mRooms[index];
42
-
43
-    if (room)
44
-    {
45
-        if (x > room->bbox_min[0] && x < room->bbox_max[0] &&
46
-                z > room->bbox_min[2] && z < room->bbox_max[2])
47
-        {
48
-            if (y > room->bbox_min[1] && y < room->bbox_max[1])
49
-                return index;
50
-        }
51
-    }
52
-
53
-    return getRoomByLocation(x, y, z);
54
-}
55
-
56
-
57
-int World::getRoomByLocation(float x, float y, float z)
58
-{
59
-    room_mesh_t *room;
60
-    int hop = -1;
61
-
62
-
63
-    for (mRooms.start(); mRooms.forward(); mRooms.next())
64
-    {
65
-        room = mRooms.current();
66
-
67
-        if (!room)
68
-            continue;
69
-
70
-        if (x > room->bbox_min[0] && x < room->bbox_max[0] &&
71
-                z > room->bbox_min[2] && z < room->bbox_max[2])
72
-        {
73
-            // This room contains current position
74
-            if (y > room->bbox_min[1] && y < room->bbox_max[1])
75
-                return mRooms.getCurrentIndex();
76
-
77
-            // This room is above or below current position
78
-            hop = mRooms.getCurrentIndex();
79
-        }
80
-    }
81
-
82
-    // Room is -1?  Must be in void, try to hop to room with same X,Z
83
-    if (mFlags & fEnableHopping)
84
-        return hop;
85
-
86
-    return -1;
87
-}
88
-
89
-
90
-int World::getAdjoiningRoom(int index,
91
-        float x, float y, float z,
92
-        float x2, float y2, float z2)
93
-{
94
-    room_mesh_t *room = mRooms[index];
95
-    portal_t * portal;
96
-    vec3_t intersect, p1, p2;
97
-
98
-
99
-    p1[0] = x;  p1[1] = y;  p1[2] = z;
100
-    p2[0] = x2; p2[1] = y2; p2[2] = z2;
101
-
102
-    if (room)
103
-    {
104
-        for (room->portals.start(); room->portals.forward();
105
-                room->portals.next())
106
-        {
107
-            portal = room->portals.current();
108
-
109
-            if (!portal)
110
-                continue;
111
-
112
-            if (helIntersectionLineAndPolygon(intersect, p1, p2, // 4,
113
-                        portal->vertices))
114
-            {
115
-                return portal->adjoining_room;
116
-            }
117
-        }
118
-    }
119
-
120
-    return -1;
121
-}
122
-
123
-
124
-int World::getSector(int room, float x, float z, float *floor, float *ceiling)
125
-{
126
-    room_mesh_t *r;
127
-    sector_t * s;
128
-    int sector;
129
-
130
-
131
-    r = mRooms[room];
132
-
133
-    if (!r)
134
-        return -1;
135
-
136
-    sector = (((((int)x - (int)r->pos[0]) / 1024) * r->numZSectors) +
137
-            (((int)z - (int)r->pos[2]) / 1024));
138
-
139
-    if (sector > -1)
140
-    {
141
-        s = r->sectors[sector];
142
-
143
-        if (!s)
144
-            return -1;
145
-
146
-        *floor = s->floor;
147
-        *ceiling = s->ceiling;
148
-    }
149
-
150
-    return sector;
151
-}
152
-
153
-
154
-int World::getSector(int room, float x, float z)
155
-{
156
-    int sector;
157
-    room_mesh_t *r;
158
-
159
-
160
-    r = mRooms[room];
161
-
162
-    if (!r)
163
-    {
164
-        return -1;
165
-    }
166
-
167
-    sector = (((((int)x - (int)r->pos[0]) / 1024) * r->numZSectors) +
168
-            (((int)z - (int)r->pos[2]) / 1024));
169
-
170
-    if (sector < 0)
171
-    {
172
-        return -1;
173
-    }
174
-
175
-    return sector;
176
-}
177
-
178
-
179
-unsigned int World::getRoomInfo(int room)
180
-{
181
-    room_mesh_t *r;
182
-
183
-
184
-    r = mRooms[room];
185
-
186
-    if (!r)
187
-    {
188
-        return 0;
189
-    }
190
-
191
-    return r->flags;
192
-}
193
-
194
-
195
-bool World::isWall(int room, int sector)
196
-{
197
-    room_mesh_t *r;
198
-    sector_t *sect;
199
-
200
-
201
-    r = mRooms[room];
202
-
203
-    if (!r)
204
-    {
205
-        return true;
206
-    }
207
-
208
-    sect = r->sectors[sector];
209
-
210
-    if (!sect)
211
-    {
212
-        return true;
213
-    }
214
-
215
-    return (sector > 0 && sect->wall);
216
-}
217
-
218
-
219
-bool World::getHeightAtPosition(int index, float x, float *y, float z)
220
-{
221
-    room_mesh_t *room = mRooms[index];
222
-
223
-#ifdef OBSOLETE_USING_BOXES
224
-    unsigned int i;
225
-    float zmax, xmax, zmin, xmin;
226
-
227
-
228
-    if (!room)
229
-    {
230
-        return false;
231
-    }
232
-
233
-    // Mongoose 2002.08.14, It's 0302 - give me a fucking break --
234
-    //   this works albeit poorly  =)
235
-    for (i = 0; (int)i < room->num_boxes; ++i)
236
-    {
237
-        xmax = room->boxes[i].c.pos[0];
238
-        xmin = room->boxes[i].a.pos[0];
239
-        zmax = room->boxes[i].c.pos[2];
240
-        zmin = room->boxes[i].a.pos[2];
241
-
242
-        if (x < xmax && x > xmin && z < zmax && z > zmin)
243
-        {
244
-            //printf("%f %f %f %f\n", xmax, xmin, zmax, zmin);
245
-
246
-            *y =  room->boxes[i].a.pos[1]; // hhmm...room->pos[1] +
247
-            return true;
248
-        }
249
-    }
250
-
251
-    return false;
252
-#else
253
-    int sector;
254
-    sector_t *sect;
255
-
256
-
257
-    if (!room)
258
-    {
259
-        return false;
260
-    }
261
-
262
-    // Mongoose 2002.08.14, Remember sector_z is width of sector array
263
-    sector = getSector(index, x, z);
264
-
265
-    sect = room->sectors[sector];
266
-
267
-    if (!sect)
268
-    {
269
-        return true;
270
-    }
271
-
272
-    *y = sect->floor;
273
-
274
-    return true;
275
-#endif
276
-}
277
-
278
-
279
-// Temp methods for rendering use until more refactoring is done
280
-#ifdef BAD_BLOOD
281
-model_mesh_t *World::getMesh(int index)
282
-{
283
-    return mMeshes[index];
284
-}
285
-
286
-skeletal_model_t *World::getModel(int index)
287
-{
288
-    return mModels[index];
289
-}
290
-
291
-room_mesh_t *World::getRoom(int index)
292
-{
293
-    return mRooms[index];
294
-}
295
-
296
-Vector<entity_t *> *World::getEntities()
297
-{
298
-    return &mEntities;
299
-}
300
-
301
-Vector<sprite_seq_t *> *World::getSprites()
302
-{
303
-    return &mSprites;
304
-}
305
-
306
-Vector<room_mesh_t *> *World::getRooms()
307
-{
308
-    return &mRooms;
309
-}
310
-#endif
311
-
312
-
313
-////////////////////////////////////////////////////////////
314
-// Public Mutators
315
-////////////////////////////////////////////////////////////
316
-
317
-void World::setFlag(WorldFlag flag)
318
-{
319
-    mFlags |= flag;
320
-}
321
-
322
-
323
-
324
-void World::clearFlag(WorldFlag flag)
325
-{
326
-    mFlags |= flag;
327
-    mFlags ^= flag;
328
-}
329
-
330
-
331
-void World::destroy()
332
-{
333
-    // Add some locking to check use state first
334
-    if (!mClearLock)
335
-    {
336
-        clear();
337
-    }
338
-}
339
-
340
-
341
-void World::addRoom(room_mesh_t *room)
342
-{
343
-    mClearLock = false;
344
-    mRooms.pushBack(room);
345
-}
346
-
347
-
348
-void World::addMesh(model_mesh_t *mesh)
349
-{
350
-    if (mesh)
351
-    {
352
-        mClearLock = false;
353
-        mMeshes.pushBack(mesh);
354
-    }
355
-}
356
-
357
-
358
-void World::addEntity(entity_t *e)
359
-{
360
-    if (e)
361
-    {
362
-        mClearLock = false;
363
-        e->master = 0x0;
364
-        e->moveType = worldMoveType_walk; // Walk
365
-        e->room = getRoomByLocation(e->pos[0], e->pos[1], e->pos[2]);
366
-        mEntities.pushBack(e);
367
-    }
368
-}
369
-
370
-
371
-int World::addModel(skeletal_model_t *model)
372
-{
373
-    if (model)
374
-    {
375
-        mClearLock = false;
376
-        mModels.pushBack(model);
377
-        return mModels.end();
378
-    }
379
-
380
-    return -1;
381
-}
382
-
383
-
384
-void World::addSprite(sprite_seq_t *sprite)
385
-{
386
-    if (sprite)
387
-    {
388
-        mClearLock = false;
389
-        mSprites.pushBack(sprite);
390
-    }
391
-}
392
-
393
-
394
-void World::moveEntity(entity_t *e, char movement)
395
-{
396
-    const float moved = 180.0f;
397
-    const float testd = 220.0f;
398
-    const float camHeight = 8.0f;
399
-    float x, y, z, pitch, h, floor, ceiling;
400
-    int room, sector;
401
-    bool wall;
402
-    unsigned int roomFlags;
403
-
404
-
405
-    if (!e)
406
-    {
407
-        return;
408
-    }
409
-
410
-    switch (e->moveType)
411
-    {
412
-        case worldMoveType_walkNoSwim:
413
-        case worldMoveType_walk:
414
-            pitch = 0.0f;  // in the future pitch could control jump up blocks here
415
-            break;
416
-
417
-        case worldMoveType_noClipping:
418
-        case worldMoveType_fly:
419
-        case worldMoveType_swim:
420
-            pitch = e->angles[2];
421
-            break;
422
-    }
423
-
424
-    switch (movement)
425
-    {
426
-        case 'f':
427
-            x = e->pos[0] + (testd * sinf(e->angles[1]));
428
-            y = e->pos[1] + (testd * sinf(pitch));
429
-            z = e->pos[2] + (testd * cosf(e->angles[1]));
430
-            break;
431
-        case 'b':
432
-            x = e->pos[0] - (testd * sinf(e->angles[1]));
433
-            y = e->pos[1] - (testd * sinf(pitch));
434
-            z = e->pos[2] - (testd * cosf(e->angles[1]));
435
-            break;
436
-        case 'l':
437
-            x = e->pos[0] - (testd * sinf(e->angles[1] + 90.0f));
438
-            y = e->pos[1];
439
-            z = e->pos[2] - (testd * cosf(e->angles[1] + 90.0f));
440
-            break;
441
-        case 'r':
442
-            x = e->pos[0] + (testd * sinf(e->angles[1] + 90.0f));
443
-            y = e->pos[1];
444
-            z = e->pos[2] + (testd * cosf(e->angles[1] + 90.0f));
445
-            break;
446
-        default:
447
-            return;
448
-    }
449
-
450
-    //room = getRoomByLocation(x, y, z);
451
-    room = getRoomByLocation(e->room, x, y, z);
452
-
453
-    if (room == -1) // Will we hit a portal?
454
-    {
455
-#define ADJ_ROOM_CHECK
456
-#ifdef ADJ_ROOM_CHECK
457
-        room = getAdjoiningRoom(e->room,
458
-                e->pos[0],  e->pos[1], e->pos[2],
459
-                x, y, z);
460
-#else
461
-        if (!mFlags & fEnableHopping)
462
-        {
463
-            mFlags |= fEnableHopping;
464
-            room = getRoomByLocation(e->room, x, y, z);
465
-            printf("Hopped\n");
466
-            mFlags ^= fEnableHopping;
467
-        }
468
-
469
-        //room = getRoomByLocation(x, y, z);
470
-#endif
471
-
472
-        if (room > -1)
473
-        {
474
-            printf("Crossing from room %i to %i\n", e->room, room);
475
-        }
476
-    }
477
-
478
-    roomFlags = getRoomInfo(room);
479
-    sector = getSector(room, x, z, &floor, &ceiling);
480
-    wall = isWall(room, sector);
481
-
482
-    // If you're underwater you may want to swim  =)
483
-    // ...if you're worldMoveType_walkNoSwim, you better hope it's shallow
484
-    if (roomFlags & roomFlag_underWater && e->moveType == worldMoveType_walk)
485
-    {
486
-        e->moveType = worldMoveType_swim;
487
-    }
488
-
489
-    // Don't swim on land
490
-    if (!(roomFlags & roomFlag_underWater) && e->moveType == worldMoveType_swim)
491
-    {
492
-        e->moveType = worldMoveType_walk;
493
-    }
494
-
495
-    // Mongoose 2002.09.02, Add check for room -> room transition
496
-    //   ( Only allow by movement between rooms by using portals )
497
-    if (((e->moveType == worldMoveType_noClipping) ||
498
-                (e->moveType == worldMoveType_fly) ||
499
-                (e->moveType == worldMoveType_swim)) ||
500
-            ((room > -1) && (!wall)))
501
-    {
502
-        e->room = room;
503
-
504
-        switch (movement)
505
-        {
506
-            case 'f':
507
-                x = e->pos[0] + (moved * sinf(e->angles[1]));
508
-                y = e->pos[1] + (moved * sinf(pitch));
509
-                z = e->pos[2] + (moved * cosf(e->angles[1]));
510
-                break;
511
-            case 'b':
512
-                x = e->pos[0] - (moved * sinf(e->angles[1]));
513
-                y = e->pos[1] - (moved * sinf(pitch));
514
-                z = e->pos[2] - (moved * cosf(e->angles[1]));
515
-                break;
516
-            case 'l':
517
-                x = e->pos[0] - (moved * sinf(e->angles[1] + 90.0f));
518
-                z = e->pos[2] - (moved * cosf(e->angles[1] + 90.0f));
519
-                break;
520
-            case 'r':
521
-                x = e->pos[0] + (moved * sinf(e->angles[1] + 90.0f));
522
-                z = e->pos[2] + (moved * cosf(e->angles[1] + 90.0f));
523
-                break;
524
-        }
525
-
526
-        /*! \fixme Test for vector (move vector) / plane (portal) collision here
527
-         * to see if we need to switch rooms... man...
528
-         */
529
-
530
-        h = y;
531
-        getHeightAtPosition(room, x, &h, z);
532
-
533
-        switch (e->moveType)
534
-        {
535
-            case worldMoveType_fly:
536
-            case worldMoveType_swim:
537
-#ifdef DIVE_GAP
538
-                // Clips to top of water, waiting for DIVE event
539
-                if (h < floor)
540
-                    e->pos[1] = floor;
541
-                else if (h > ceiling)
542
-                    e->pos[1] = ceiling;
543
-                else
544
-                    e->pos[1] = y;
545
-#endif
546
-
547
-                // Don't fall out of world, avoid a movement that does
548
-                if (h > y - camHeight)
549
-                {
550
-                    e->pos[0] = x;
551
-                    e->pos[1] = y;
552
-                    e->pos[2] = z;
553
-                }
554
-                break;
555
-            case worldMoveType_walk:
556
-            case worldMoveType_walkNoSwim:
557
-                y = e->pos[1];  // Override vector movement walking ( er, not pretty )
558
-
559
-                // Now fake gravity
560
-                // Mongoose 2002.08.14, Remember TR is upside down ( you fall 'up' )
561
-
562
-                //ddist = h - e->pos[1];
563
-
564
-                // This is to force false gravity, by making camera stay on ground
565
-                e->pos[1] = h; //roomFloor->bbox_min[1];
566
-
567
-                // Check for camera below terrian and correct
568
-                if (e->pos[1] < h - camHeight)
569
-                {
570
-                    e->pos[1] = h - camHeight;
571
-                }
572
-
573
-                e->pos[0] = x;
574
-                e->pos[2] = z;
575
-                break;
576
-            case worldMoveType_noClipping:
577
-                e->pos[0] = x;
578
-                e->pos[1] = y;
579
-                e->pos[2] = z;
580
-        }
581
-
582
-#ifdef OBSOLETE
583
-        m_text->SetString(1,"Room %2i  Sector %2i %sPos %.0f %.0f %.0f Yaw %.0f",
584
-                room, sector,
585
-                wall ? " Wall " : " ",
586
-                e->pos[0], e->pos[1], e->pos[2], e->angles[1]);
587
-#endif
588
-    }
589
-    else
590
-    {
591
-        e->moving = false;
592
-        return;
593
-    }
594
-
595
-    e->room = room;
596
-    e->moving = true;
597
-}
598
-
599
-
600
-////////////////////////////////////////////////////////////
601
-// Private Accessors
602
-////////////////////////////////////////////////////////////
603
-
604
-
605
-////////////////////////////////////////////////////////////
606
-// Private Mutators
607
-////////////////////////////////////////////////////////////
608
-
609
-void World::clear()
610
-{
611
-    room_mesh_t *room;
612
-    model_mesh_t *mesh;
613
-    sprite_seq_t *sprite;
614
-    skeletal_model_t *model;
615
-    bone_frame_t *boneframe;
616
-    bone_tag_t *tag;
617
-    animation_frame_t *animation;
618
-    List<skeletal_model_t *> cache;
619
-
620
-
621
-    mClearLock = true;
622
-
623
-    mEntities.erase();
624
-
625
-    for (mRooms.start(); mRooms.forward(); mRooms.next())
626
-    {
627
-        room = mRooms.current();
628
-
629
-        if (room)
630
-        {
631
-            room->portals.erase();
632
-            room->models.erase();
633
-            room->sprites.erase();
634
-            room->sectors.erase();
635
-            room->boxes.erase();
636
-        }
637
-    }
638
-
639
-    mRooms.erase();
640
-
641
-    for (mMeshes.start(); mMeshes.forward(); mMeshes.next())
642
-    {
643
-        mesh = mMeshes.current();
644
-
645
-        if (!mesh)
646
-            continue;
647
-
648
-        for (mesh->texturedTriangles.start();
649
-                mesh->texturedTriangles.forward();
650
-                mesh->texturedTriangles.next())
651
-        {
652
-            if (mesh->texturedTriangles.current())
653
-                delete mesh->texturedTriangles.current();
654
-        }
655
-
656
-        for (mesh->coloredTriangles.start(); mesh->coloredTriangles.forward();
657
-                mesh->coloredTriangles.next())
658
-        {
659
-            if (mesh->coloredTriangles.current())
660
-                delete mesh->coloredTriangles.current();
661
-        }
662
-
663
-        for (mesh->texturedRectangles.start();
664
-                mesh->texturedRectangles.forward();
665
-                mesh->texturedRectangles.next())
666
-        {
667
-            if (mesh->texturedRectangles.current())
668
-                delete mesh->texturedRectangles.current();
669
-        }
670
-
671
-        for (mesh->coloredRectangles.start(); mesh->coloredRectangles.forward();
672
-                mesh->coloredRectangles.next())
673
-        {
674
-            if (mesh->coloredRectangles.current())
675
-                delete mesh->coloredRectangles.current();
676
-        }
677
-
678
-        if (mesh->vertices)
679
-            delete [] mesh->vertices;
680
-
681
-        if (mesh->colors)
682
-            delete [] mesh->colors;
683
-
684
-        if (mesh->normals)
685
-            delete [] mesh->normals;
686
-
687
-        delete mesh;
688
-    }
689
-
690
-    mMeshes.clear();
691
-
692
-    for (mSprites.start(); mSprites.forward(); mSprites.next())
693
-    {
694
-        sprite = mSprites.current();
695
-
696
-        if (!sprite)
697
-            continue;
698
-
699
-        if (sprite->sprite)
700
-            delete [] sprite->sprite;
701
-
702
-        delete sprite;
703
-    }
704
-
705
-    mSprites.clear();
706
-
707
-    for (mModels.start(); mModels.forward(); mModels.next())
708
-    {
709
-        model = mModels.current();
710
-
711
-        if (!model)
712
-            continue;
713
-
714
-        // No smart pointers, so skip if deleted once  =)
715
-        if (!cache.SearchKey(model))
716
-        {
717
-            cache.Add(model);
718
-        }
719
-        else
720
-        {
721
-            continue;
722
-        }
723
-
724
-        for (model->animation.start(); model->animation.forward();
725
-                model->animation.next())
726
-        {
727
-            animation  = model->animation.current();
728
-
729
-            if (!animation)
730
-                continue;
731
-
732
-            for (animation->frame.start(); animation->frame.forward();
733
-                    animation->frame.next())
734
-            {
735
-                boneframe = animation->frame.current();
736
-
737
-                if (!boneframe)
738
-                    continue;
739
-
740
-                for (boneframe->tag.start(); boneframe->tag.forward();
741
-                        boneframe->tag.next())
742
-                {
743
-                    tag = boneframe->tag.current();
744
-
745
-                    if (!tag)
746
-                        continue;
747
-
748
-                    delete tag;
749
-                }
750
-
751
-                delete boneframe;
752
-            }
753
-
754
-            delete animation;
755
-        }
756
-
757
-        delete model;
758
-    }
759
-
760
-    mModels.clear();
761
-}
762
-

+ 30
- 0
src/main.cpp Переглянути файл

@@ -0,0 +1,30 @@
1
+/*!
2
+ * \file src/main.cpp
3
+ * \brief Where main() is
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#include <stdlib.h>
9
+#include <stdio.h>
10
+
11
+#include "config.h"
12
+
13
+void cleanupHandler() {
14
+
15
+}
16
+
17
+int main(int argc, char *argv[]) {
18
+    if (argc == 1) {
19
+        // Use default rc file path
20
+    } else if (argc == 2) {
21
+        // Use provided rc file
22
+    } else {
23
+        printf("Usage:\n%s [/path/to/config.file]\n", argv[0]);
24
+        return 1;
25
+    }
26
+
27
+    atexit(cleanupHandler);
28
+
29
+    return 0;
30
+}

+ 0
- 11
src/utils/CMakeLists.txt Переглянути файл

@@ -1,11 +0,0 @@
1
-# Source files
2
-set (UTIL_SRCS ${UTIL_SRCS} "math.cpp")
3
-set (UTIL_SRCS ${UTIL_SRCS} "strings.cpp")
4
-set (UTIL_SRCS ${UTIL_SRCS} "tga.cpp")
5
-set (UTIL_SRCS ${UTIL_SRCS} "time.cpp")
6
-
7
-# Include directory
8
-include_directories ("${PROJECT_SOURCE_DIR}/include")
9
-
10
-# Add library
11
-add_library (utilities ${UTIL_SRCS})

+ 0
- 137
src/utils/math.cpp Переглянути файл

@@ -1,137 +0,0 @@
1
-/*!
2
- *
3
- * \file src/utils/math.cpp
4
- * \brief Vector and Matrix math
5
- *
6
- * \author Mongoose
7
- */
8
-
9
-#include <stdlib.h>
10
-#include <math.h>
11
-#include <float.h>
12
-#include <assert.h>
13
-
14
-#include "Vector3d.h"
15
-#include "Matrix.h"
16
-#include "utils/math.h"
17
-
18
-bool equalEpsilon(vec_t a, vec_t b) {
19
-    vec_t epsilon = FLT_EPSILON;
20
-    if (fabs(a - b) <= (fmax(fabs(a), fabs(b)) * epsilon))
21
-        return true;
22
-    return false;
23
-}
24
-
25
-
26
-inline vec_t square(vec_t a)
27
-{
28
-    return a * a;
29
-}
30
-
31
-
32
-int helIntersectionLineAndPolygon(vec3_t intersect,
33
-        vec3_t p1, vec3_t p2,
34
-        vec3_t *polygon)
35
-{
36
-    assert(polygon != NULL);
37
-
38
-    //  vec3_t normal, a, b;
39
-    Vector3d a, b, normal, pA, pB;
40
-    vec_t d, denominator, mu;
41
-
42
-
43
-    pA = Vector3d(p1);
44
-    pB = Vector3d(p2);
45
-
46
-    // Find normal
47
-    a = Vector3d(polygon[1]) - Vector3d(polygon[0]);
48
-    b = Vector3d(polygon[2]) - Vector3d(polygon[0]);
49
-    normal = Vector3d::cross(a, b);
50
-    normal.normalize();
51
-
52
-    // find D
53
-    //d = (normal[0] * polygon[0][0] -
54
-    //    normal[1] * polygon[0][1] -
55
-    //    normal[2] * polygon[0][2]);
56
-    d = (normal.mVec[0] * polygon[0][0] -
57
-            normal.mVec[1] * polygon[0][1] -
58
-            normal.mVec[2] * polygon[0][2]);
59
-
60
-    // line segment parallel to plane?
61
-    a = pB - pA;
62
-
63
-    //denominator = (normal[0] * a[0] +
64
-    //                  normal[1] * a[1] +
65
-    //                  normal[2] * a[2]);
66
-    denominator = Vector3d::dot(normal, a);
67
-
68
-    if (denominator > 0.0)
69
-        return 0;
70
-
71
-    // Line segment contains intercept point?
72
-    //mu = - ((d + normal[0] * p1[0] + normal[1] * p1[1] + normal[2] * p1[2]) /
73
-    //        denominator);
74
-    mu = -((d + Vector3d::dot(normal, pA)) / denominator);
75
-
76
-    if (mu < 0.0 || mu > 1.0)
77
-        return 0;
78
-
79
-    //intersect[0] = p1[0] + mu * a[0];
80
-    //intersect[1] = p1[1] + mu * a[1];
81
-    //intersect[2] = p1[2] + mu * a[2];
82
-    b = pA + (a * mu);
83
-    intersect[0] = b.mVec[0];
84
-    intersect[1] = b.mVec[1];
85
-    intersect[2] = b.mVec[2];
86
-
87
-
88
-    // See if the intercept is bound by polygon by winding number
89
-    // assume convex polygons here for sure
90
-    double theta = Vector3d::dot(b - Vector3d(polygon[0]), normal); // b = intersect
91
-
92
-    if (theta >= 90.0) // Yeah I know
93
-        return 0;
94
-
95
-    return 1;
96
-}
97
-
98
-
99
-vec_t helDist3v(vec3_t a, vec3_t b)
100
-{
101
-    return (sqrtf( ((b[0] - a[0]) * (b[0] - a[0])) +
102
-                ((b[1] - a[1]) * (b[1] - a[1])) +
103
-                ((b[2] - a[2]) * (b[2] - a[2]))));
104
-}
105
-
106
-
107
-void helMidpoint3v(vec3_t a, vec3_t b, vec3_t mid)
108
-{
109
-    mid[0] = (a[0] + b[0]) / 2.0f;
110
-    mid[1] = (a[1] + b[1]) / 2.0f;
111
-    mid[2] = (a[2] + b[2]) / 2.0f;
112
-}
113
-
114
-
115
-vec_t helNorm4v(vec4_t v)
116
-{
117
-    return (sqrtf(v[0]*v[0] + v[1]*v[1] + v[2]*v[2] + v[3]*v[3]));
118
-}
119
-
120
-
121
-vec_t helNorm3v(vec3_t v)
122
-{
123
-    return (sqrtf(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]));
124
-}
125
-
126
-
127
-vec_t helNorm2v(vec2_t v)
128
-{
129
-    return (sqrtf(v[0]*v[0] + v[1]*v[1]));
130
-}
131
-
132
-
133
-vec_t helRandomNum(vec_t from, vec_t to)
134
-{
135
-    return from + ((to - from) * rand() / (RAND_MAX + 1.0f));
136
-}
137
-

+ 0
- 171
src/utils/strings.cpp Переглянути файл

@@ -1,171 +0,0 @@
1
-/*!
2
- * \file include/utils/strings.h
3
- * \brief String handling utilities
4
- *
5
- * \author xythobuz
6
- * \author Mongoose
7
- */
8
-
9
-#include <cstdarg>
10
-#include <cstdlib>
11
-#include <stdio.h>
12
-#include <string.h>
13
-#include <assert.h>
14
-
15
-#if defined(unix) || defined(__APPLE__)
16
-#include <wordexp.h>
17
-#endif
18
-
19
-#include "utils/strings.h"
20
-
21
-bool stringEndsWith(const char *str, const char *suffix) {
22
-    assert(str != NULL);
23
-    assert(suffix != NULL);
24
-
25
-    size_t lenstr = strlen(str);
26
-    size_t lensuffix = strlen(suffix);
27
-
28
-    if (lensuffix > lenstr)
29
-        return false;
30
-
31
-    return strncmp(str + lenstr - lensuffix, suffix, lensuffix) == 0;
32
-}
33
-
34
-char *bufferString(const char *string, va_list args) {
35
-    int sz = 60;
36
-    int n;
37
-    char *text;
38
-
39
-    assert(string != NULL);
40
-    assert(string[0] != '\0');
41
-
42
-    text = new char[sz];
43
-
44
-    n = vsnprintf(text, sz, string, args);
45
-
46
-    if (n < 0) {
47
-        delete [] text;
48
-        return NULL; // encoding error
49
-    } else if (n >= sz) {
50
-        sz = n + 1; // buffer too small
51
-        delete [] text;
52
-        text = new char[sz];
53
-        n = vsnprintf(text, sz, string, args);
54
-    }
55
-
56
-    return text;
57
-}
58
-
59
-char *bufferString(const char *string, ...) {
60
-    va_list args;
61
-    va_start(args, string);
62
-    char *text = bufferString(string, args);
63
-    va_end(args);
64
-    return text;
65
-}
66
-
67
-char *fullPath(const char *path, char end) {
68
-    unsigned int lenPath, offset;
69
-    wordexp_t word;
70
-    char *dir;
71
-
72
-    assert(path != NULL);
73
-    assert(path[0] != '\0');
74
-
75
-    if (path[0] == '~') {
76
-#if defined(unix) || defined(__APPLE__)
77
-#ifdef __APPLE__
78
-        // Workaround for Mac OS X. See:
79
-        // http://stackoverflow.com/questions/20534788/why-does-wordexp-fail-with-wrde-syntax-on-os-x
80
-        signal(SIGCHLD, SIG_DFL);
81
-#endif
82
-        // Expand string into segments
83
-        int res = wordexp(path, &word, 0);
84
-#ifdef __APPLE__
85
-        signal(SIGCHLD, SIG_IGN);
86
-#endif
87
-        if (res != 0) {
88
-            printf("fullPath> wordexp() failed: %d\n", res);
89
-            return NULL;
90
-        }
91
-
92
-        // Get length of complete string
93
-        lenPath = 0;
94
-        for (unsigned int i = 0; i < word.we_wordc; i++) {
95
-            lenPath += strlen(word.we_wordv[i]);
96
-        }
97
-
98
-        // Allocate new string
99
-        dir = new char[lenPath + 2]; // space for end char
100
-
101
-        // Copy segments into new string
102
-        offset = 0;
103
-        for (unsigned int i = 0; i < word.we_wordc; i++) {
104
-            unsigned int len = strlen(word.we_wordv[i]);
105
-            strncpy(dir + offset, word.we_wordv[i], len);
106
-            offset += len;
107
-        }
108
-
109
-        wordfree(&word);
110
-#else
111
-        printf("WARNING: Tilde expansion not supported on this platform!\n");
112
-        lenPath = strlen(path);
113
-        dir = new char[lenPath + 2]; // space for end char
114
-        strncpy(dir, path, lenPath);
115
-#endif
116
-    } else {
117
-        lenPath = strlen(path);
118
-        dir = new char[lenPath + 2]; // space for end char
119
-        strncpy(dir, path, lenPath);
120
-    }
121
-
122
-    // Make sure ends in "end" char
123
-    if ((lenPath > 0) && (end != 0) && (dir[lenPath - 1] != end)) {
124
-        dir[lenPath] = end;
125
-        dir[lenPath + 1] = 0;
126
-    } else {
127
-        dir[lenPath] = 0;
128
-    }
129
-
130
-    return dir;
131
-}
132
-
133
-bool rc_command(const char *symbol, char *command) {
134
-    assert(symbol != NULL);
135
-    assert(symbol[0] != '\0');
136
-    assert(command != NULL);
137
-    assert(command[0] != '\0');
138
-
139
-    int lens = strlen(symbol);
140
-
141
-    if (strncmp(command, symbol, lens) == 0) {
142
-        int lenc = strlen(command);
143
-
144
-        //! \fixme Should ignore whitespace, but only if it is really there...?
145
-        // lens+1 skips '=' or ' '
146
-        for (int i = 0, j = lens+1; j < lenc; ++i, ++j) {
147
-            command[i] = command[j];
148
-            command[i+1] = 0;
149
-        }
150
-
151
-        return true;
152
-    }
153
-
154
-    return false;
155
-}
156
-
157
-int rc_get_bool(const char *buffer, bool *val) {
158
-    assert(buffer != NULL);
159
-    assert(buffer[0] != '\0');
160
-    assert(val != NULL);
161
-
162
-    if ((buffer[0] == '1') || (strncmp(buffer, "true", 4) == 0))
163
-        *val = true;
164
-    else if ((buffer[0] == '0') || (strncmp(buffer, "false", 5) == 0))
165
-        *val = false;
166
-    else
167
-        return -2;
168
-
169
-    return 0;
170
-}
171
-

+ 0
- 382
src/utils/tga.cpp Переглянути файл

@@ -1,382 +0,0 @@
1
-/*!
2
- * \file src/utils/tga.cpp
3
- * \brief TGA image reader/writer
4
- *
5
- * \todo type should pass more info (2 bits for RGBA|RGB|GREY; val for depth)
6
- *
7
- * \author Mongoose
8
- * \author xythobuz
9
- */
10
-
11
-#include <stdio.h>
12
-#include <string.h>
13
-#include <stdarg.h>
14
-#include <assert.h>
15
-
16
-#include "utils/tga.h"
17
-
18
-int tgaCheck(FILE *f) {
19
-    char buffer[10];
20
-
21
-    assert(f != NULL);
22
-
23
-    /* Read the header */
24
-    fseek(f, 0, SEEK_SET);
25
-    fread(buffer, 8, 1, f);
26
-
27
-    // buffer[1] = 0 - Means not color mapped (1 would mean mapped)
28
-    if (!(buffer[1] == 0 && (buffer[2] == TGA_TYPE__COLOR ||
29
-                    //buffer[2] == TGA_TYPE__GREYSCALE ||
30
-                    buffer[2] == TGA_TYPE__COLOR_RLE))) {
31
-        printf("tgaCheck> Inavlid or unknown TGA format.\n");
32
-        return -2;
33
-    }
34
-    return 0;
35
-}
36
-
37
-int tgaLoad(FILE *f, unsigned char **image, unsigned int *width, unsigned int *height, char *type) {
38
-    tga_t header;
39
-    char comment[256];
40
-    unsigned char pixel[4];
41
-    unsigned char *swap_row = NULL;
42
-    unsigned char tmp, packet;
43
-    bool must_flip = 0;
44
-    unsigned int size;
45
-    unsigned int i, j;
46
-
47
-    assert(f != NULL);
48
-    assert(image != NULL);
49
-    assert(width != NULL);
50
-    assert(height != NULL);
51
-    assert(type != NULL);
52
-
53
-    fseek(f, 0, SEEK_SET);
54
-
55
-    // Read TGA header
56
-    fread(&header.comment_lenght, 1, 1, f);
57
-    fread(&header.colormap_type, 1, 1, f);
58
-    fread(&header.image_type, 1, 1, f);
59
-    fread(&header.colormap_index, 2, 1, f);
60
-    fread(&header.colormap_lenght, 2, 1, f);
61
-    fread(&header.colormap_bbp, 1, 1, f);
62
-
63
-    fread(&tmp, 1, 1, f);
64
-    header.origin_x = tmp;
65
-    fread(&tmp, 1, 1, f);
66
-    header.origin_x += tmp * 256;
67
-
68
-    fread(&tmp, 1, 1, f);
69
-    header.origin_y = tmp;
70
-    fread(&tmp, 1, 1, f);
71
-    header.origin_y += tmp * 256;
72
-
73
-    fread(&tmp, 1, 1, f);
74
-    header.width = tmp;
75
-    fread(&tmp, 1, 1, f);
76
-    header.width += tmp * 256;
77
-
78
-    fread(&tmp, 1, 1, f);
79
-    header.height = tmp;
80
-    fread(&tmp, 1, 1, f);
81
-    header.height += tmp * 256;
82
-
83
-    fread(&header.bpp, 1, 1, f);
84
-    fread(&header.desc_flags, 1, 1, f);
85
-
86
-    *width = header.width;
87
-    *height = header.height;
88
-
89
-    switch (header.bpp) {
90
-        case 32:
91
-            *type = 2; //32;
92
-            break;
93
-        case 24:
94
-            *type = 1; //24;
95
-            break;
96
-        case 8:
97
-        default:
98
-            *type = 0; //8;
99
-            break;
100
-    }
101
-
102
-#ifdef DEBUG_TGA
103
-    printf("TGA [%ix%i@%ibpp, %it, %ix, %iy, %uf]\n",
104
-            header.width, header.height, header.bpp, header.image_type,
105
-            header.origin_x, header.origin_y,
106
-            header.desc_flags);
107
-#endif
108
-
109
-    // Comments can be 0 - 255
110
-    if (header.comment_lenght) {
111
-        fread(&comment, 1, header.comment_lenght, f);
112
-        for (i = 0; i < 255; ++i) {
113
-            if (!(comment[i] > 32 && comment[i] < 127))
114
-                comment[i] = 183; // print a dot for invalid text
115
-        }
116
-        comment[255] = 0;
117
-        printf("Comment: '%s'\n", comment);
118
-    }
119
-
120
-    *image = NULL;
121
-    size = header.width * header.height;
122
-
123
-    if (!size || (!(header.colormap_type == 0 && (header.image_type == 2 || header.image_type == 10)))) {
124
-        fprintf(stderr, "tgaLoad> Unknown image format.\n");
125
-        return -2;
126
-    }
127
-
128
-    // Mongoose: Added 'screen origin bit' support back here
129
-    if (!(header.desc_flags & 32)) {
130
-        must_flip = true;
131
-    }
132
-
133
-    switch (header.bpp) {
134
-        case 32:
135
-            size *= 4;
136
-            *image = new unsigned char [size];
137
-            switch (header.image_type) {
138
-                case TGA_TYPE__COLOR_RLE:
139
-                    for (i = 0; i < size;) {
140
-                        fread(&packet, 1, 1, f);
141
-                        if (packet & 0x80) { // Run Length
142
-                            packet = (packet &0x7F) + 1;
143
-                            fread(&pixel, 4, 1, f);
144
-                            for (j = 0; j < packet; j++) {
145
-                                (*image)[i++] = pixel[2];
146
-                                (*image)[i++] = pixel[1];
147
-                                (*image)[i++] = pixel[0];
148
-                                (*image)[i++] = pixel[3];
149
-                            }
150
-                        } else { // RAW
151
-                            packet = (packet &0x7F) + 1;
152
-                            for (j = 0; j < packet; j++) {
153
-                                fread(&pixel, 4, 1, f);
154
-                                (*image)[i++] = pixel[2];
155
-                                (*image)[i++] = pixel[1];
156
-                                (*image)[i++] = pixel[0];
157
-                                (*image)[i++] = pixel[3];
158
-                            }
159
-                        }
160
-                    }
161
-                    break;
162
-                case TGA_TYPE__COLOR:
163
-                    if (fread((*image), size, 1, f) < 1) {
164
-                        fprintf(stderr, "tgaLoad> Image fread failed.\n");
165
-                        delete [] *image;
166
-                        return -4;
167
-                    }
168
-                    for (i = 0; i < size; i += 4) {
169
-                        tmp = (*image)[i];
170
-                        (*image)[i] = (*image)[i + 2];
171
-                        (*image)[i + 2] = tmp;
172
-                    }
173
-                    break;
174
-                default:
175
-                    ;
176
-            }
177
-            if (must_flip) {
178
-                swap_row = new unsigned char [header.width * 4];
179
-                for (i = 0, j = header.height-1; (int)i < header.height/2; i++, j--) {
180
-                    memcpy(swap_row, &(*image)[i*header.width*4], header.width*4);
181
-                    memcpy(&(*image)[i*header.width*4], &(*image)[j*header.width*4],
182
-                            header.width*4);
183
-                    memcpy(&(*image)[j*header.width*4], swap_row, header.width*4);
184
-                }
185
-                delete [] swap_row;
186
-            }
187
-            break;
188
-        case 24:
189
-            size *= 3;
190
-            *image = new unsigned char [size];
191
-            switch (header.image_type) {
192
-                case TGA_TYPE__COLOR_RLE:
193
-                    for (i = 0; i < size;) {
194
-                        fread(&packet, 1, 1, f);
195
-                        if (packet & 0x80) { // Run Length
196
-                            packet = (packet &0x7F) + 1;
197
-                            fread(&pixel, 3, 1, f);
198
-                            for (j = 0; j < packet; j++) {
199
-                                (*image)[i++] = pixel[2];
200
-                                (*image)[i++] = pixel[1];
201
-                                (*image)[i++] = pixel[0];
202
-                            }
203
-                        } else { // RAW
204
-                            packet = (packet &0x7F) + 1;
205
-                            for (j = 0; j < packet; j++) {
206
-                                fread(&pixel, 3, 1, f);
207
-                                (*image)[i++] = pixel[2];
208
-                                (*image)[i++] = pixel[1];
209
-                                (*image)[i++] = pixel[0];
210
-                            }
211
-                        }
212
-                    }
213
-                    break;
214
-                case TGA_TYPE__COLOR:
215
-                    if (fread((*image), size, 1, f) < 1) {
216
-                        fprintf(stderr, "tgaLoad> Image fread failed.\n");
217
-                        delete [] *image;
218
-                        return -4;
219
-                    }
220
-                    for (i = 0; i < size; i += 3) {
221
-                        tmp = (*image)[i];
222
-                        (*image)[i] = (*image)[i + 2];
223
-                        (*image)[i + 2] = tmp;
224
-                    }
225
-                    break;
226
-                default:
227
-                    ;
228
-            }
229
-            if (must_flip) {
230
-                swap_row = new unsigned char [header.width * 3];
231
-                for (i = 0, j = header.height - 1; (int)i < header.height / 2; i++, j--) {
232
-                    memcpy(swap_row, &(*image)[i*header.width*3], header.width*3);
233
-                    memcpy(&(*image)[i*header.width*3], &(*image)[j*header.width*3],
234
-                            header.width*3);
235
-                    memcpy(&(*image)[j*header.width*3], swap_row, header.width*3);
236
-                }
237
-                delete [] swap_row;
238
-            }
239
-            break;
240
-        case 8:
241
-            printf("tgaLoad> 8bpp Not implemented\n");
242
-            break;
243
-        default:
244
-            ;
245
-    }
246
-
247
-#ifdef DEBUG_TGA
248
-    char c;
249
-    printf("TGA Comment: ");
250
-    while (fread(&c, 1, 1, f) == 1) {
251
-        printf("%c", c);
252
-    }
253
-    printf("\n");
254
-#endif
255
-
256
-    return 0;
257
-}
258
-
259
-int tgaSave(FILE *f, unsigned char *image, unsigned int width, unsigned int height, char type) {
260
-    tga_t header;
261
-    unsigned int size;
262
-    char comment[64];
263
-    //unsigned int i;
264
-    //unsigned char tmp;
265
-
266
-    assert(f != NULL);
267
-    assert(image != NULL);
268
-    assert(width > 0);
269
-    assert(height > 0);
270
-
271
-    strncpy(comment, "OpenRaider TGA", 63);
272
-    comment[63] = 0;
273
-
274
-    header.comment_lenght = (unsigned char)strlen(comment);
275
-    header.colormap_type = 0;
276
-
277
-    // No colormaps
278
-    header.colormap_index = 0;
279
-    header.colormap_lenght = 0;
280
-    header.colormap_bbp = 0;
281
-
282
-    header.origin_x = header.origin_y = 0;
283
-    header.width = (unsigned short)width;
284
-    header.height = (unsigned short)height;
285
-
286
-    header.desc_flags = 0;
287
-
288
-    switch (type) {
289
-        case 4:
290
-            header.image_type = TGA_TYPE__COLOR;
291
-            header.desc_flags = 32;
292
-            header.bpp = 32;
293
-            break;
294
-        case 2:
295
-            header.bpp = 32;
296
-            break;
297
-        case 1:
298
-            header.image_type = TGA_TYPE__GREYSCALE;
299
-            header.bpp = 8;
300
-            break;
301
-        default:
302
-            header.image_type = TGA_TYPE__COLOR;
303
-            header.bpp = 24;
304
-    }
305
-
306
-    // Write TGA header
307
-    fwrite(&header.comment_lenght, 1, 1, f);
308
-    fwrite(&header.colormap_type, 1, 1, f);
309
-    fwrite(&header.image_type, 1, 1, f);
310
-    fwrite(&header.colormap_index, 2, 1, f);
311
-    fwrite(&header.colormap_lenght, 2, 1, f);
312
-    fwrite(&header.colormap_bbp, 1, 1, f);
313
-    fwrite(&header.origin_x, 2, 1, f);
314
-    fwrite(&header.origin_y, 2, 1, f);
315
-    fwrite(&header.width, 2, 1, f);
316
-    fwrite(&header.height, 2, 1, f);
317
-    fwrite(&header.bpp, 1, 1, f);
318
-    fwrite(&header.desc_flags, 1, 1, f);
319
-
320
-    // Write comment
321
-    fwrite(&comment, 1, header.comment_lenght, f);
322
-
323
-    switch (header.bpp) {
324
-        case 32:
325
-            size = header.width * header.height * 4;
326
-
327
-            //for (i = 0; i < size; i += 4)
328
-            //{
329
-            //  tmp = image[i];
330
-            //  image[i] = image[i + 2];
331
-            //  image[i + 2] = tmp;
332
-            //}
333
-            break;
334
-        case 24:
335
-            size = header.width * header.height * 3;
336
-
337
-            //for (i = 0; i < size; i += 3)
338
-            //{
339
-            //  tmp = image[i];
340
-            //  image[i] = image[i + 2];
341
-            //  image[i + 2] = tmp;
342
-            //}
343
-            break;
344
-        case 8:
345
-        default:
346
-            size = header.width * header.height;
347
-            break;
348
-    }
349
-
350
-    // Write image data
351
-    if (fwrite(image, size, 1, f) < 1) {
352
-        perror("tgaSave> Disk write failed.\n");
353
-        return -2;
354
-    }
355
-    return 0;
356
-}
357
-
358
-int tgaSaveFilename(unsigned char *image, unsigned int width, unsigned int height, char type, const char *s, ...) {
359
-    char buffer[1024];
360
-    FILE *f;
361
-    int v;
362
-    va_list args;
363
-
364
-    assert(image != NULL);
365
-    assert(width > 0);
366
-    assert(height > 0);
367
-    assert(s != NULL);
368
-    assert(s[0] != '\0');
369
-
370
-    va_start(args, s);
371
-    vsnprintf(buffer, 1023, s, args);
372
-    va_end(args);
373
-    f = fopen(buffer, "wb");
374
-    if (!f) {
375
-        perror(buffer);
376
-        return -1;
377
-    }
378
-    v = tgaSave(f, image, width, height, type);
379
-    fclose(f);
380
-    return v;
381
-}
382
-

+ 0
- 33
src/utils/time.cpp Переглянути файл

@@ -1,33 +0,0 @@
1
-/*!
2
- * \file include/utils/time.h
3
- * \brief Time handling utilities
4
- *
5
- * \author xythobuz
6
- * \author Mongoose
7
- */
8
-
9
-#include "utils/time.h"
10
-
11
-struct timeval system_timer_start;
12
-struct timeval system_timer_stop;
13
-struct timezone system_timer_tz;
14
-
15
-unsigned int systemTimerGet() {
16
-    gettimeofday(&system_timer_stop, &system_timer_tz);
17
-
18
-    if (system_timer_start.tv_usec > system_timer_stop.tv_usec) {
19
-        system_timer_stop.tv_usec += 1000000;
20
-        system_timer_stop.tv_sec--;
21
-    }
22
-
23
-    system_timer_stop.tv_usec -= system_timer_start.tv_usec;
24
-    system_timer_stop.tv_sec -= system_timer_start.tv_sec;
25
-
26
-    return ((system_timer_stop.tv_sec - system_timer_start.tv_sec) * 1000)
27
-        + ((system_timer_stop.tv_usec - system_timer_start.tv_usec) / 1000);
28
-}
29
-
30
-void systemTimerReset() {
31
-    gettimeofday(&system_timer_start, &system_timer_tz);
32
-}
33
-

Завантаження…
Відмінити
Зберегти