Pārlūkot izejas kodu

Moving to OpenGL 3.3 core. Depending on GLM. Removed old level reader, old math lib.

Thomas Buck 10 gadus atpakaļ
vecāks
revīzija
c2db7bcfbd
77 mainītis faili ar 1206 papildinājumiem un 12457 dzēšanām
  1. 11
    0
      ChangeLog.md
  2. 6
    2
      README.md
  3. 63
    0
      cmake/FindGLM.cmake
  4. 1
    1
      cmake/travis_install_linux.sh
  5. 1
    1
      cmake/travis_install_mac.sh
  6. 16
    71
      include/Camera.h
  7. 0
    5
      include/Entity.h
  8. 0
    3
      include/Game.h
  9. 10
    9
      include/Mesh.h
  10. 17
    161
      include/Render.h
  11. 0
    5
      include/Room.h
  12. 3
    12
      include/RoomData.h
  13. 0
    12
      include/SkeletalModel.h
  14. 0
    16
      include/Sprite.h
  15. 0
    3
      include/StaticMesh.h
  16. 16
    13
      include/TextureManager.h
  17. 0
    728
      include/TombRaider.h
  18. 0
    1139
      include/TombRaiderData.h
  19. 0
    152
      include/ViewVolume.h
  20. 0
    22
      include/commands/CommandAnimate.h
  21. 0
    11
      include/commands/CommandRender.h
  22. 2
    23
      include/global.h
  23. 0
    202
      include/math/Matrix.h
  24. 0
    202
      include/math/Quaternion.h
  25. 0
    46
      include/math/Vec3.h
  26. 0
    65
      include/math/math.h
  27. 5
    2
      include/system/FontTRLE.h
  28. 48
    23
      include/system/Window.h
  29. 4
    1
      include/utils/pcx.h
  30. 6
    2
      include/utils/png.h
  31. 1
    1
      include/utils/tga.h
  32. 8
    6
      src/CMakeLists.txt
  33. 46
    79
      src/Camera.cpp
  34. 1
    1
      src/Console.cpp
  35. 7
    46
      src/Entity.cpp
  36. 13
    294
      src/Game.cpp
  37. 2
    0
      src/Menu.cpp
  38. 7
    9
      src/MenuFolder.cpp
  39. 94
    54
      src/Mesh.cpp
  40. 63
    511
      src/Render.cpp
  41. 25
    388
      src/Room.cpp
  42. 7
    66
      src/RoomData.cpp
  43. 2
    254
      src/SkeletalModel.cpp
  44. 14
    47
      src/Sprite.cpp
  45. 14
    141
      src/StaticMesh.cpp
  46. 45
    81
      src/TextureManager.cpp
  47. 0
    5631
      src/TombRaider.cpp
  48. 116
    74
      src/UI.cpp
  49. 0
    254
      src/ViewVolume.cpp
  50. 0
    1
      src/commands/CMakeLists.txt
  51. 0
    3
      src/commands/Command.cpp
  52. 0
    82
      src/commands/CommandAnimate.cpp
  53. 1
    1
      src/commands/CommandEngine.cpp
  54. 13
    80
      src/commands/CommandRender.cpp
  55. 6
    4
      src/commands/CommandSet.cpp
  56. 1
    1
      src/loader/Loader.cpp
  57. 38
    27
      src/loader/LoaderTR2.cpp
  58. 11
    23
      src/main.cpp
  59. 0
    9
      src/math/CMakeLists.txt
  60. 0
    515
      src/math/Matrix.cpp
  61. 0
    290
      src/math/Quaternion.cpp
  62. 0
    118
      src/math/Vec3.cpp
  63. 0
    94
      src/math/math.cpp
  64. 18
    11
      src/system/FontImGui.cpp
  65. 59
    53
      src/system/FontSDL.cpp
  66. 40
    34
      src/system/FontTRLE.cpp
  67. 2
    2
      src/system/SoundAL.cpp
  68. 264
    127
      src/system/Window.cpp
  69. 4
    2
      src/system/WindowGLUT.cpp
  70. 17
    10
      src/system/WindowSDL.cpp
  71. 1
    1
      src/utils/filesystem.cpp
  72. 14
    13
      src/utils/pcx.cpp
  73. 3
    3
      src/utils/pixel.cpp
  74. 30
    31
      src/utils/png.cpp
  75. 10
    10
      src/utils/tga.cpp
  76. 0
    9
      test/CMakeLists.txt
  77. 0
    34
      test/math.cpp

+ 11
- 0
ChangeLog.md Parādīt failu

@@ -2,6 +2,17 @@
2 2
 
3 3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4 4
 
5
+    [ 20141215 ]
6
+    * Rewrote GL code for the Font implementations, ImGUI and the Main Menu
7
+
8
+    [ 20141214 ]
9
+    * Removed math, Matrix, Quaternion, Vec3, ViewVolume
10
+
11
+    [ 20141213 ]
12
+    * Completely removed old TombRaider level reader (so only unfinished TR2 compatibility now)
13
+    * Now creating OpenGL 3.3 Core Profile Context, so absolutely _nothing_ works right now!
14
+    * Now depending on GLM lib
15
+
5 16
     [ 20141207 ]
6 17
     * LoaderTR2 now also loads all important parts of the Room structures
7 18
     * Started work on new Mesh implementation used with LoaderTR2

+ 6
- 2
README.md Parādīt failu

@@ -1,6 +1,8 @@
1 1
 # OpenRaider
2 2
 
3
-[![Build Status](https://travis-ci.org/xythobuz/OpenRaider.svg?branch=master)](https://travis-ci.org/xythobuz/OpenRaider)
3
+[![Build Status](https://travis-ci.org/xythobuz/OpenRaider.svg?branch=loader)](https://travis-ci.org/xythobuz/OpenRaider)
4
+
5
+__This is the development branch of OpenRaider! Currently in the process of moving to OpenGL 3.3...__
4 6
 
5 7
 This is a fork of the [OpenRaider](http://openraider.sourceforge.net) Open Source implementation of the classic Tomb Raider Game Engine. The original project was abandoned in 2003.
6 8
 
@@ -39,6 +41,7 @@ Basically, OpenRaider depends on the following:
39 41
 * C++11 compiler
40 42
 * cmake
41 43
 * OpenGL
44
+* GLM
42 45
 * zlib
43 46
 * SDL2
44 47
 * SDL2-TTF (optional, needed if you want to use TTF fonts)
@@ -47,7 +50,7 @@ Basically, OpenRaider depends on the following:
47 50
 
48 51
 On Mac OS X 10.9 with [XCode](https://developer.apple.com/xcode/) and [MacPorts](http://www.macports.org) installed, the following should be enough to get all dependencies that are available as port:
49 52
 
50
-    sudo port install cmake zlib libsdl2 libsdl2_ttf
53
+    sudo port install cmake zlib glm libsdl2 libsdl2_ttf
51 54
 
52 55
 A similar command for the package manager of your favorite Linux Distribution should do the trick.
53 56
 
@@ -178,6 +181,7 @@ There are some included cmake scripts:
178 181
 * [GetGitRevisionDescription.cmake](https://github.com/rpavlik/cmake-modules/blob/master/GetGitRevisionDescription.cmake)
179 182
 * [GetGitRevisionDescription.cmake.in](https://github.com/rpavlik/cmake-modules/blob/master/GetGitRevisionDescription.cmake.in)
180 183
 * [FindFreeGLUT](https://github.com/PDAL/PDAL/blob/master/cmake/modules/FindFreeGLUT.cmake)
184
+* [FindGLM] (https://github.com/g-truc/glm/blob/master/util/FindGLM.cmake)
181 185
 
182 186
 See the respective files in `cmake` for their licensing.
183 187
 

+ 63
- 0
cmake/FindGLM.cmake Parādīt failu

@@ -0,0 +1,63 @@
1
+# FindGLM - attempts to locate the glm matrix/vector library.
2
+#
3
+# This module defines the following variables (on success):
4
+#   GLM_INCLUDE_DIRS  - where to find glm/glm.hpp
5
+#   GLM_FOUND         - if the library was successfully located
6
+#
7
+# It is trying a few standard installation locations, but can be customized
8
+# with the following variables:
9
+#   GLM_ROOT_DIR      - root directory of a glm installation
10
+#                       Headers are expected to be found in either:
11
+#                       <GLM_ROOT_DIR>/glm/glm.hpp           OR
12
+#                       <GLM_ROOT_DIR>/include/glm/glm.hpp
13
+#                       This variable can either be a cmake or environment
14
+#                       variable. Note however that changing the value
15
+#                       of the environment varible will NOT result in
16
+#                       re-running the header search and therefore NOT
17
+#                       adjust the variables set by this module.
18
+
19
+#=============================================================================
20
+# Copyright 2012 Carsten Neumann
21
+#
22
+# Distributed under the OSI-approved BSD License (the "License");
23
+# see accompanying file Copyright.txt for details.
24
+#
25
+# This software is distributed WITHOUT ANY WARRANTY; without even the
26
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
27
+# See the License for more information.
28
+#=============================================================================
29
+# (To distribute this file outside of CMake, substitute the full
30
+#  License text for the above reference.)
31
+
32
+# default search dirs
33
+SET(_glm_HEADER_SEARCH_DIRS
34
+    "/usr/include"
35
+    "/usr/local/include")
36
+
37
+# check environment variable
38
+SET(_glm_ENV_ROOT_DIR "$ENV{GLM_ROOT_DIR}")
39
+
40
+IF(NOT GLM_ROOT_DIR AND _glm_ENV_ROOT_DIR)
41
+    SET(GLM_ROOT_DIR "${_glm_ENV_ROOT_DIR}")
42
+ENDIF(NOT GLM_ROOT_DIR AND _glm_ENV_ROOT_DIR)
43
+
44
+# put user specified location at beginning of search
45
+IF(GLM_ROOT_DIR)
46
+    SET(_glm_HEADER_SEARCH_DIRS "${GLM_ROOT_DIR}"
47
+                                "${GLM_ROOT_DIR}/include"
48
+                                 ${_glm_HEADER_SEARCH_DIRS})
49
+ENDIF(GLM_ROOT_DIR)
50
+
51
+# locate header
52
+FIND_PATH(GLM_INCLUDE_DIR "glm/glm.hpp"
53
+    PATHS ${_glm_HEADER_SEARCH_DIRS})
54
+
55
+INCLUDE(FindPackageHandleStandardArgs)
56
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLM DEFAULT_MSG
57
+    GLM_INCLUDE_DIR)
58
+
59
+IF(GLM_FOUND)
60
+    SET(GLM_INCLUDE_DIRS "${GLM_INCLUDE_DIR}")
61
+
62
+    MESSAGE(STATUS "GLM_INCLUDE_DIR = ${GLM_INCLUDE_DIR}")
63
+ENDIF(GLM_FOUND)

+ 1
- 1
cmake/travis_install_linux.sh Parādīt failu

@@ -1,6 +1,6 @@
1 1
 #!/bin/bash
2 2
 
3
-sudo apt-get -qq -y install libsdl2-dev libsdl2-ttf-dev libalut-dev libpng12-dev zlib1g-dev cmake
3
+sudo apt-get -qq -y install libsdl2-dev libsdl2-ttf-dev libalut-dev libpng12-dev zlib1g-dev cmake glm
4 4
 
5 5
 if [ "$CC" = "gcc" ]; then sudo apt-get install gcc-4.8; fi
6 6
 if [ "$CXX" = "g++" ]; then sudo apt-get install g++-4.8; fi

+ 1
- 1
cmake/travis_install_mac.sh Parādīt failu

@@ -1,4 +1,4 @@
1 1
 #!/bin/bash
2 2
 
3
-brew install sdl2 sdl2_ttf freealut
3
+brew install sdl2 sdl2_ttf freealut glm
4 4
 

+ 16
- 71
include/Camera.h Parādīt failu

@@ -2,92 +2,37 @@
2 2
  * \file include/Camera.h
3 3
  * \brief Camera class
4 4
  *
5
- * \author Mongoose
6 5
  * \author xythobuz
7 6
  */
8 7
 
9 8
 #ifndef _CAMERA_H_
10 9
 #define _CAMERA_H_
11 10
 
12
-#include "math/Quaternion.h"
11
+#include "glm/vec3.hpp"
12
+#include "glm/mat4x4.hpp"
13 13
 
14
-/*!
15
- * \brief Commands for interactive camera control
16
- */
17
-enum camera_command {
18
-    CAMERA_ROTATE_RIGHT,
19
-    CAMERA_ROTATE_LEFT,
20
-    CAMERA_ROTATE_UP,
21
-    CAMERA_ROTATE_DOWN
22
-};
23
-
24
-/*!
25
- * \brief Camera class
26
- */
27 14
 class Camera {
28 15
   public:
29
-    /*!
30
-     * \brief Constructs an object of Camera
31
-     */
32
-    Camera();
33
-
34
-    /*!
35
-     * \brief Get the target currently looked at
36
-     * \param target where the target will be stored
37
-     */
38
-    void getTarget(float target[3]);
39
-
40
-    /*!
41
-     * \brief Get angle/yaw of camera
42
-     * \returns theta angle/yaw of camera
43
-     */
44
-    float getRadianYaw() { return mTheta; }
16
+    static void handleMouseMotion(int x, int y);
17
+    static glm::mat4 getViewMatrix();
45 18
 
46
-    /*!
47
-     * \brief Get angle/pitch of camera
48
-     * \returns phi angle/pitch of camera
49
-     */
50
-    float getRadianPitch() { return mTheta2; }
19
+    static float getRadianPitch() { return thetaX; }
20
+    static float getRadianYaw() { return thetaY; }
51 21
 
52
-    /*!
53
-     * \brief Set current position
54
-     * \param pos new position
55
-     */
56
-    void setPosition(float pos[3]);
22
+    static void setPosition(glm::vec3 p) { pos = p; }
23
+    static glm::vec3 getPosition() { return pos; }
57 24
 
58
-    void setSensitivityX(float sens) { mRotationDeltaX = sens; }
25
+    static void setSensitivityX(float sens) { rotationDeltaX = sens; }
26
+    static float getSensitivityX() { return rotationDeltaX; }
59 27
 
60
-    float getSensitivityX() { return mRotationDeltaX; }
61
-
62
-    void setSensitivityY(float sens) { mRotationDeltaY = sens; }
63
-
64
-    float getSensitivityY() { return mRotationDeltaY; }
65
-
66
-    /*!
67
-     * \brief Updates view target
68
-     */
69
-    void update();
70
-
71
-    /*!
72
-     * \brief Sends interactive command to camera
73
-     * \param cmd valid camera command
74
-     */
75
-    void command(enum camera_command cmd);
28
+    static void setSensitivityY(float sens) { rotationDeltaY = sens; }
29
+    static float getSensitivityY() { return rotationDeltaY; }
76 30
 
77 31
   private:
78
-
79
-    void rotate(float angle, float x, float y, float z);
80
-
81
-    Quaternion mQ;         //!< Quaternion for rotation
82
-    float mPos[4];         //!< Location in 3 space (aka eye)
83
-    float mTarget[4];      //!< Postition we're looking at
84
-    float mViewDistance;   //!< Distance from target
85
-    float mTheta;          //!< View angle Y
86
-    float mTheta2;         //!< View angle Z
87
-    float mRotationDeltaX; //!< Horizontal mouse sensitivity
88
-    float mRotationDeltaY; //!< Vertical mouse sensitivity
32
+    static glm::vec3 pos;
33
+    static float thetaX, thetaY;
34
+    static float rotationDeltaX, rotationDeltaY;
89 35
 };
90 36
 
91
-Camera& getCamera();
92
-
93 37
 #endif
38
+

+ 0
- 5
include/Entity.h Parādīt failu

@@ -9,7 +9,6 @@
9 9
 #define _ENTITY_H_
10 10
 
11 11
 #include "SkeletalModel.h"
12
-#include "TombRaider.h"
13 12
 
14 13
 class Entity {
15 14
   public:
@@ -23,10 +22,6 @@ class Entity {
23 22
 
24 23
     Entity(float p[3], float a[3], int id, long r, unsigned int model);
25 24
 
26
-    Entity(TombRaider& tr, unsigned int index, unsigned int i, unsigned int model);
27
-
28
-    bool operator<(Entity& o);
29
-    static bool compare(Entity* a, Entity* b);
30 25
     void display();
31 26
     void move(char movement);
32 27
     void print();

+ 0
- 3
include/Game.h Parādīt failu

@@ -12,7 +12,6 @@
12 12
 #include <vector>
13 13
 
14 14
 #include "Entity.h"
15
-#include "TombRaider.h"
16 15
 
17 16
 class Game {
18 17
   public:
@@ -48,8 +47,6 @@ class Game {
48 47
     std::string levelName;
49 48
     bool mLoaded;
50 49
 
51
-    TombRaider mTombRaider;
52
-
53 50
     long mLara;
54 51
 };
55 52
 

+ 10
- 9
include/Mesh.h Parādīt failu

@@ -10,7 +10,7 @@
10 10
 #ifndef _MESH_H_
11 11
 #define _MESH_H_
12 12
 
13
-#include "math/Vec3.h"
13
+#include "glm/vec3.hpp"
14 14
 
15 15
 /*!
16 16
  * \brief OpenGL Mesh
@@ -19,11 +19,11 @@ class Mesh {
19 19
   public:
20 20
 
21 21
     struct rectangle_t {
22
-        Vec3 a, b, c, d;
22
+        glm::vec3 a, b, c, d;
23 23
         uint16_t texture;
24 24
         float red, green, blue;
25 25
 
26
-        rectangle_t(Vec3 _a, Vec3 _b, Vec3 _c, Vec3 _d, uint16_t t,
26
+        rectangle_t(glm::vec3 _a, glm::vec3 _b, glm::vec3 _c, glm::vec3 _d, uint16_t t,
27 27
                     float re = 0.0f, float gr = 0.0f, float bl = 0.0f)
28 28
             : a(_a), b(_b), c(_c), d(_d), texture(t), red(re), green(gr), blue(bl) { }
29 29
     };
@@ -34,19 +34,20 @@ class Mesh {
34 34
     void drawAlpha();
35 35
     void drawSolid();
36 36
 
37
-    void addTexturedRectangle(Vec3 a, Vec3 b, Vec3 c, Vec3 d, uint16_t textile);
38
-    void addTexturedTriangle(Vec3 a, Vec3 b, Vec3 c, uint16_t textile);
37
+    void addTexturedRectangle(glm::vec3 a, glm::vec3 b, glm::vec3 c, glm::vec3 d, uint16_t textile);
38
+    void addTexturedTriangle(glm::vec3 a, glm::vec3 b, glm::vec3 c, uint16_t textile);
39 39
 
40
-    void addColoredRectangle(Vec3 a, Vec3 b, Vec3 c, Vec3 d, float re, float gr, float bl);
41
-    void addColoredTriangle(Vec3 a, Vec3 b, Vec3 c, float re, float gr, float bl);
40
+    void addColoredRectangle(glm::vec3 a, glm::vec3 b, glm::vec3 c, glm::vec3 d, float re, float gr,
41
+                             float bl);
42
+    void addColoredTriangle(glm::vec3 a, glm::vec3 b, glm::vec3 c, float re, float gr, float bl);
42 43
 
43
-    void addNormal(Vec3 n);
44
+    void addNormal(glm::vec3 n);
44 45
 
45 46
     std::vector<rectangle_t> texturedRectangles;
46 47
     std::vector<rectangle_t> coloredRectangles;
47 48
     std::vector<rectangle_t> texturedTriangles;
48 49
     std::vector<rectangle_t> coloredTriangles;
49
-    std::vector<Vec3> normals;
50
+    std::vector<glm::vec3> normals;
50 51
 
51 52
 
52 53
     // Old API

+ 17
- 161
include/Render.h Parādīt failu

@@ -9,177 +9,33 @@
9 9
 #ifndef _RENDER_H_
10 10
 #define _RENDER_H_
11 11
 
12
-#include <vector>
12
+#include "glm/vec4.hpp"
13 13
 
14
-#include "Room.h"
15 14
 #include "TextureManager.h"
16
-#include "ViewVolume.h"
17 15
 
18
-/*!
19
- * \brief OpenRaider Renderer class
20
- */
16
+enum class RenderMode {
17
+    Disabled,
18
+    LoadScreen,
19
+    Solid,
20
+    Wireframe,
21
+    Texture
22
+};
23
+
21 24
 class Render {
22 25
   public:
26
+    static RenderMode getMode();
27
+    static void setMode(RenderMode m);
23 28
 
24
-    typedef enum {
25
-        modeDisabled,
26
-        modeLoadScreen,
27
-        modeVertexLight,
28
-        modeSolid,
29
-        modeWireframe,
30
-        modeTexture
31
-    } RenderMode;
32
-
33
-    typedef enum {
34
-        fRoomAlpha              = (1 << 0),
35
-        fEntityModels           = (1 << 1),
36
-        fFog                    = (1 << 2),
37
-        fGL_Lights              = (1 << 3),
38
-        fRenderPonytail         = (1 << 4),
39
-        fAnimateAllModels       = (1 << 5),
40
-        // fMultiTexture           = (1 << 6), //! \todo Whats up with Multitexture stuff? Where is it needed?
41
-    } RenderFlags;
42
-
43
-    /*!
44
-     * \brief Constructs an object of Render
45
-     */
46
-    Render();
47
-
48
-    /*!
49
-     * \brief Deconstructs an object of Render
50
-     */
51
-    ~Render();
52
-
53
-    /*!
54
-     * \brief Makes a screenshot, writes to disk
55
-     * \param filenameBase basename of file to be written
56
-     */
57
-    void screenShot(const char* filenameBase);
58
-
59
-    /*!
60
-     * \brief Gets current rendering mode
61
-     * \returns current RenderMode
62
-     * \fixme Don't return enum as int?!
63
-     */
64
-    int getMode();
65
-
66
-    /*!
67
-     * Removes current world/entity/etc geometry
68
-     */
69
-    void ClearWorld();
70
-
71
-    /*!
72
-     * \brief Clears bitflags, changes state of renderer in some way
73
-     * \param flags RenderFlags to clear (ORed)
74
-     * \fixme use enum not integer as parameter?!
75
-     */
76
-    void clearFlags(unsigned int flags);
77
-
78
-    /*!
79
-     * \brief Sets bitflags, changes state of renderer in some way
80
-     * \param flags RenderFlags to set (ORed)
81
-     * \fixme use enum not integer as parameter?!
82
-     */
83
-    void setFlags(unsigned int flags);
84
-
85
-    void setMode(int n);
86
-
87
-    /*!
88
-     * \brief Renders a single game frame
89
-     */
90
-    void display();
91
-
92
-    void setSkyMesh(int index, bool rot);
93
-
94
-    unsigned int getFlags();
95
-
96
-    /*!
97
-     * \brief Check if a point is in the View Volume
98
-     * \param x X coordinate
99
-     * \param y Y coordinate
100
-     * \param z Z coordinate
101
-     * \returns true if point is visible
102
-     */
103
-    bool isVisible(float x, float y, float z);
104
-
105
-    /*!
106
-     * \brief Check if a sphere is in the View Volume
107
-     * \param x X coordinate of center of sphere
108
-     * \param y Y coordinate of center of sphere
109
-     * \param z Z coordinate of center of sphere
110
-     * \param radius radius of sphere
111
-     * \returns true if sphere is visible
112
-     */
113
-    bool isVisible(float x, float y, float z, float radius);
29
+    static void display();
114 30
 
115
-    bool isVisible(BoundingBox& box);
31
+    static void screenShot(const char* filenameBase);
116 32
 
117
-    float getDistToSphereFromNear(float x, float y, float z, float radius);
118
-
119
-    void debugDisplayTexture(int texture = -1,
120
-                             TextureManager::TextureStorage s = TextureManager::TextureStorage::GAME,
121
-                             float x = 0.0f, float y = 0.0f, float w = 256.0f, float h = 256.0f);
122
-
123
-    void debugDisplayTextile(int texture = -1,
124
-                             float x = 0.0f, float y = 0.0f, float w = 64.0f, float h = 64.0f);
125
-
126
-    void debugDisplaySprite(int sprite = -1, int offset = 0,
127
-                            float x = 0.0f, float y = 0.0f, float w = 128.0f, float h = 128.0f);
33
+    static void drawTexture(float x, float y, float w, float h, glm::vec4 color,
34
+                            unsigned int texture, TextureManager::TextureStorage s);
128 35
 
129 36
   private:
130
-
131
-    void drawTexture(float x, float y, float w, float h,
132
-                     unsigned int texture, TextureManager::TextureStorage s);
133
-
134
-    void drawTextile(float x, float y, float w, float h, unsigned int textile);
135
-
136
-    void drawSprite(float x, float y, float w, float h, unsigned int sprite, unsigned int offset);
137
-
138
-    static void lightRoom(Room& room);
139
-
140
-    void drawLoadScreen();
141
-
142
-    /*!
143
-     * \brief Build a visible room list starting at index
144
-     * \param index valid room index where to start the list
145
-     */
146
-    void newRoomRenderList(int index);
147
-
148
-    /*!
149
-     * \brief Build a visible room list starting from room and
150
-     * only considers its linked rooms and their linked rooms.
151
-     * \param room First room in list
152
-     */
153
-    void buildRoomRenderList(Room& room);
154
-
155
-    /*!
156
-     * \brief Renders Sky domes/boxes/etc by scaling factor.
157
-     *
158
-     * Texture must be initialized.
159
-     * \param scale correct scale for map size
160
-     */
161
-    void drawSkyMesh(float scale);
162
-
163
-    /*!
164
-     * \brief Updates View Volume. Call once per render frame.
165
-     */
166
-    void updateViewVolume();
167
-
168
-    std::vector<Room*> mRoomRenderList;
169
-
170
-    ViewVolume mViewVolume; //!< View Volume for frustum culling
171
-
172
-    unsigned int mFlags;                  //!< Rendering flags
173
-    unsigned int mMode;                   //!< Rendering mode
174
-    int mLock;
175
-    int mSkyMesh;                         //!< Skymesh model id
176
-    bool mSkyMeshRotation;                //!< Should Skymesh be rotated?
177
-
178
-    int debugTexture, debugTextile, debugSprite, debugSpriteOffset;
179
-    TextureManager::TextureStorage debugTextureStorage;
180
-    float debugX, debugY, debugW, debugH;
37
+    static RenderMode mode;
181 38
 };
182 39
 
183
-Render& getRender();
184
-
185 40
 #endif
41
+

+ 0
- 5
include/Room.h Parādīt failu

@@ -11,7 +11,6 @@
11 11
 #include <vector>
12 12
 #include "Mesh.h"
13 13
 #include "Sprite.h"
14
-#include "TombRaider.h"
15 14
 #include "RoomData.h"
16 15
 
17 16
 typedef enum {
@@ -20,8 +19,6 @@ typedef enum {
20 19
 
21 20
 class Room {
22 21
   public:
23
-    Room(TombRaider& tr, unsigned int index);
24
-
25 22
     Room(float p[3] = nullptr, unsigned int f = 0, unsigned int x = 0, unsigned int z = 0);
26 23
     ~Room();
27 24
 
@@ -73,8 +70,6 @@ class Room {
73 70
     void addSprite(Sprite* s);
74 71
 
75 72
   private:
76
-    void sortModels();
77
-
78 73
     unsigned int flags;
79 74
     unsigned int numXSectors;
80 75
     unsigned int numZSectors;

+ 3
- 12
include/RoomData.h Parādīt failu

@@ -8,10 +8,10 @@
8 8
 #ifndef _ROOM_DATA_H_
9 9
 #define _ROOM_DATA_H_
10 10
 
11
+#include "glm/vec3.hpp"
12
+
11 13
 #include <vector>
12 14
 #include <memory>
13
-#include "math/Matrix.h"
14
-#include "TombRaider.h"
15 15
 
16 16
 class BoundingBox {
17 17
   public:
@@ -37,8 +37,6 @@ class Light {
37 37
         typeDirectional = 3  //!< Directional light
38 38
     } LightType;
39 39
 
40
-    Light(TombRaider& tr, unsigned int room, unsigned int index);
41
-
42 40
     void getPos(float p[4]);
43 41
     void getDir(float d[3]);
44 42
     float getAtt();
@@ -57,13 +55,8 @@ class Light {
57 55
 
58 56
 class StaticModel {
59 57
   public:
60
-    StaticModel(TombRaider& tr, unsigned int room, unsigned int i);
61 58
     void display();
62 59
 
63
-    // Compares distance to ViewVolume for depth sorting
64
-    bool operator<(const StaticModel& other);
65
-    static bool compare(StaticModel* a, StaticModel* b);
66
-
67 60
   private:
68 61
     int index;
69 62
     float yaw;
@@ -75,8 +68,7 @@ class StaticModel {
75 68
 
76 69
 class Portal {
77 70
   public:
78
-    Portal(float vert[4][3], float norm[3], int adj);
79
-    Portal(TombRaider& tr, unsigned int room, unsigned int index, Matrix& transform);
71
+    Portal(glm::vec3 vert[4], float norm[3], int adj);
80 72
 
81 73
     void getVertices(float vert[4][3]);
82 74
     int getAdjoiningRoom();
@@ -90,7 +82,6 @@ class Portal {
90 82
 class Sector {
91 83
   public:
92 84
     Sector(float f, float c, bool w) : floor(f), ceiling(c), wall(w) { }
93
-    Sector(TombRaider& tr, unsigned int room, unsigned int index);
94 85
     float getFloor();
95 86
     float getCeiling();
96 87
     bool isWall();

+ 0
- 12
include/SkeletalModel.h Parādīt failu

@@ -11,14 +11,9 @@
11 11
 
12 12
 #include <vector>
13 13
 
14
-#include "TombRaider.h"
15
-
16 14
 class BoneTag {
17 15
   public:
18 16
     BoneTag(int m, float o[3], float r[3], char f);
19
-
20
-    BoneTag(TombRaider& tr, unsigned int index, unsigned int j, unsigned int* l,
21
-            unsigned int frame_offset);
22 17
     void display();
23 18
 
24 19
     void getOffset(float o[3]);
@@ -35,8 +30,6 @@ class BoneTag {
35 30
 class BoneFrame {
36 31
   public:
37 32
     BoneFrame(float p[3]);
38
-
39
-    BoneFrame(TombRaider& tr, unsigned int index, unsigned int frame_offset);
40 33
     ~BoneFrame();
41 34
 
42 35
     void getPosition(float p[3]);
@@ -53,9 +46,6 @@ class BoneFrame {
53 46
 class AnimationFrame {
54 47
   public:
55 48
     AnimationFrame(char r);
56
-
57
-    AnimationFrame(TombRaider& tr, unsigned int index, int a, unsigned int* frame_offset,
58
-                   int frame_step);
59 49
     ~AnimationFrame();
60 50
 
61 51
     unsigned long size();
@@ -70,8 +60,6 @@ class AnimationFrame {
70 60
 class SkeletalModel {
71 61
   public:
72 62
     SkeletalModel(int i);
73
-
74
-    SkeletalModel(TombRaider& tr, unsigned int index, int objectId);
75 63
     ~SkeletalModel();
76 64
     void display(unsigned long aframe, unsigned long bframe);
77 65
 

+ 0
- 16
include/Sprite.h Parādīt failu

@@ -11,21 +11,10 @@
11 11
 #include <cstdint>
12 12
 
13 13
 #include "loader/Loader.h"
14
-#include "TombRaider.h"
15 14
 
16 15
 class Sprite {
17 16
   public:
18 17
     Sprite(uint16_t tile, uint8_t x, uint8_t y, uint16_t width, uint16_t height);
19
-
20
-    Sprite(TombRaider& tr, unsigned int room, unsigned int index);
21
-
22
-    Sprite(TombRaider& tr, unsigned int item, unsigned int sequence, unsigned int index) :
23
-        Sprite((tr.Sprite() + ((tr.SpriteSequence() + sequence)->offset) + index)->tile,
24
-               (tr.Sprite() + ((tr.SpriteSequence() + sequence)->offset) + index)->x,
25
-               (tr.Sprite() + ((tr.SpriteSequence() + sequence)->offset) + index)->y,
26
-               (tr.Sprite() + ((tr.SpriteSequence() + sequence)->offset) + index)->width,
27
-               (tr.Sprite() + ((tr.SpriteSequence() + sequence)->offset) + index)->height) { }
28
-
29 18
     void display();
30 19
     void display(float x, float y, float w, float h);
31 20
 
@@ -42,17 +31,12 @@ class SpriteSequence {
42 31
     SpriteSequence(int32_t objectID);
43 32
     void add(Sprite s);
44 33
 
45
-    SpriteSequence(TombRaider& tr, unsigned int item, unsigned int sequence);
46
-    ~SpriteSequence();
47
-
48 34
     unsigned long size();
49 35
     Sprite& get(unsigned long index);
50 36
 
51 37
   private:
52 38
     int32_t id;
53 39
     std::vector<Sprite> sprites;
54
-
55
-    std::vector<Sprite*> oldsprites;
56 40
 };
57 41
 
58 42
 #endif

+ 0
- 3
include/StaticMesh.h Parādīt failu

@@ -9,7 +9,6 @@
9 9
 #define _STATIC_MODEL_H_
10 10
 
11 11
 #include <vector>
12
-#include "TombRaider.h"
13 12
 
14 13
 class TexturedTriangle {
15 14
   public:
@@ -26,8 +25,6 @@ class TexturedTriangle {
26 25
 class StaticMesh {
27 26
   public:
28 27
     StaticMesh(int id, int mesh);
29
-
30
-    StaticMesh(TombRaider& tr, unsigned int index);
31 28
     ~StaticMesh();
32 29
     void display();
33 30
     float getRadius();

+ 16
- 13
include/TextureManager.h Parādīt failu

@@ -12,8 +12,6 @@
12 12
 #include <cstdint>
13 13
 #include <vector>
14 14
 
15
-#include "math/Vec3.h"
16
-
17 15
 // These are loaded into TextureStorage::SYSTEM by initialize()!
18 16
 #define TEXTURE_WHITE 0
19 17
 #define TEXTURE_SPLASH 1
@@ -32,16 +30,11 @@ class TextureTile {
32 30
     ~TextureTile();
33 31
 
34 32
     void add(TextureTileVertex* t);
35
-    bool isTriangle();
36
-    void display(float x, float y, float w, float h, float z);
37 33
 
38
-    void displayTriangle(Vec3 a, Vec3 b, Vec3 c);
39
-    void displayRectangle(Vec3 a, Vec3 b, Vec3 c, Vec3 d);
34
+    void displayTriangle(float a[3], float b[3], float c[3]);
35
+    void displayRectangle(float a[3], float b[3], float c[3], float d[3]);
40 36
 
41 37
   private:
42
-    void displayTriangle(float x, float y, float w, float h, float z);
43
-    void displayRectangle(float x, float y, float w, float h, float z);
44
-
45 38
     uint16_t attribute;
46 39
     uint16_t texture;
47 40
     std::vector<TextureTileVertex*> vertices;
@@ -53,6 +46,14 @@ class TextureTile {
53 46
 class TextureManager {
54 47
   public:
55 48
 
49
+    enum class ColorMode {
50
+        RGB,
51
+        RGBA,
52
+        ARGB,
53
+        BGR,
54
+        BGRA
55
+    };
56
+
56 57
     enum class TextureStorage {
57 58
         GAME,
58 59
         SYSTEM
@@ -61,6 +62,7 @@ class TextureManager {
61 62
     ~TextureManager();
62 63
 
63 64
     int initialize();
65
+    int initializeSplash();
64 66
 
65 67
     void clear();
66 68
 
@@ -70,8 +72,9 @@ class TextureManager {
70 72
      * \brief Binds the texture for use in GL
71 73
      * \param n valid texture index
72 74
      * \param s Which TextureStorage should be accessed
75
+     * \param unit Which GL texture unit should be used
73 76
      */
74
-    void bindTextureId(unsigned int n, TextureStorage s = TextureStorage::GAME);
77
+    void bindTextureId(unsigned int n, TextureStorage s = TextureStorage::GAME, unsigned int unit = 0);
75 78
 
76 79
     /*!
77 80
      * \brief Loads Buffer as texture
@@ -85,9 +88,9 @@ class TextureManager {
85 88
      * \param filter if the texture should be mipmap filtered
86 89
      * \returns texture ID or < 0 on error
87 90
      */
88
-    int loadBufferSlot(unsigned char* image,
89
-                       unsigned int width, unsigned int height,
90
-                       ColorMode mode, unsigned int bpp,
91
+    int loadBufferSlot(unsigned char* image = nullptr,
92
+                       unsigned int width = 256, unsigned int height = 256,
93
+                       ColorMode mode = ColorMode::RGBA, unsigned int bpp = 32,
91 94
                        TextureStorage s = TextureStorage::GAME,
92 95
                        int slot = -1, bool filter = true);
93 96
 

+ 0
- 728
include/TombRaider.h Parādīt failu

@@ -1,728 +0,0 @@
1
-/*!
2
- * \file include/TombRaider.h
3
- * \brief Loads maps, meshes, textures...
4
- *
5
- * \todo WARNING: No endian routines as of yet
6
- * \author Mongoose
7
- */
8
-
9
-#ifndef _TOMBRAIDER_H_
10
-#define _TOMBRAIDER_H_
11
-
12
-#include <cstdint>
13
-#include <cstdio>
14
-
15
-#include "TombRaiderData.h"
16
-
17
-/*!
18
- * \brief Loads maps, meshes, textures...
19
- */
20
-class TombRaider {
21
-  public:
22
-
23
-    /*!
24
-     * \brief Constructs an object of TombRaider
25
-     */
26
-    TombRaider();
27
-
28
-    /*!
29
-     * \brief Deconstructs an object of TombRaider
30
-     */
31
-    ~TombRaider();
32
-
33
-    ////////////////////////////////////////
34
-    // Wash me -- not part of cleaned API //
35
-    ////////////////////////////////////////
36
-
37
-    int NumRooms();
38
-
39
-    int NumMoveables();
40
-
41
-    int NumTextures();
42
-
43
-    /*!
44
-     * \brief Get number of _special_ textures/images
45
-     * \returns number of special textures/images
46
-     */
47
-    int NumSpecialTextures();
48
-
49
-    int NumAnimations();
50
-
51
-    unsigned int NumFrames();
52
-
53
-    int NumStaticMeshes();
54
-
55
-    int NumSpriteSequences();
56
-
57
-    int NumItems();
58
-
59
-    tr2_version_type Engine();
60
-
61
-    unsigned short* Frame();
62
-
63
-    tr2_animation_t* Animation();
64
-
65
-    tr2_item_t* Item();
66
-
67
-    tr2_box_t* Box();
68
-
69
-    tr2_mesh_t* Mesh();
70
-
71
-    /*!
72
-     * \brief Get number of animations for a moveable
73
-     * \param moveable_index valid moveable id
74
-     * \returns number of animations for specified moveable
75
-     */
76
-    int getNumAnimsForMoveable(int moveable_index);
77
-
78
-    tr2_staticmesh_t* StaticMesh();
79
-
80
-    tr2_moveable_t* Moveable();
81
-
82
-    tr2_meshtree_t* MeshTree();
83
-
84
-    /*!
85
-     * \brief Get the sprites
86
-     * \returns the sprite array
87
-     */
88
-    tr2_sprite_texture_t* Sprite();
89
-
90
-    tr2_sprite_sequence_t* SpriteSequence();
91
-
92
-    /*!
93
-     * \brief Get copies of texture and it's bumpmap
94
-     * \param texture valid textile index
95
-     * \param image will be set to texture if found, or NULL
96
-     * \param bumpmap will be set to bumpmap if found, or NULL
97
-     */
98
-    void Texture(int texture, unsigned char** image, unsigned char** bumpmap);
99
-
100
-    //unsigned int* Palette16();
101
-    //unsigned char* Palette8();
102
-
103
-    tr2_room_t* Room();
104
-
105
-    /*!
106
-     * \brief Loads TombRaider 1-5 pak into memory
107
-     * and does some processing.
108
-     * \param filename points to valid TombRaider pak
109
-     * \returns 0 on success, < 0 on error
110
-     * \sa TombRaider::loadTR5()
111
-     */
112
-    int Load(const char* filename);
113
-
114
-    /*!
115
-     * \brief Compute rotation angles from moveable animation data
116
-     * \param frame moveable animation data
117
-     * \param frame_offset moveable animation data
118
-     * \param angle_offset moveable animation data
119
-     * \param x will be set to computed angle
120
-     * \param y will be set to computed angle
121
-     * \param z will be set to computed angle
122
-     */
123
-    void computeRotationAngles(unsigned short** frame,
124
-                               unsigned int* frame_offset,
125
-                               unsigned int* angle_offset,
126
-                               float* x, float* y, float* z);
127
-
128
-    /*!
129
-     * \brief Returns computed UV in u and v
130
-     * \param st object texture vert, its coordinates are added to the pixels and divided by 255.0
131
-     * \param u will contain calculated x value
132
-     * \param v will contain calculated y value
133
-     */
134
-    void computeUV(tr2_object_texture_vert_t* st, float* u, float* v);
135
-
136
-    void getColor(int index, float color[4]);
137
-
138
-    tr2_version_type getEngine();
139
-
140
-    /*!
141
-     * \brief Get the collision sphere for a mesh
142
-     * \param meshIndex mesh index
143
-     * \param center will be filled with center coordinates, not NULL
144
-     * \param radius will be filled with radius, not NULL
145
-     */
146
-    void getMeshCollisionInfo(unsigned int meshIndex,
147
-                              float center[3], float* radius);
148
-
149
-    /*!
150
-     * \brief Get SIGNED mesh count (TR encoded < 0 errors)
151
-     * \returns signed mesh count
152
-     */
153
-    int getMeshCount();
154
-
155
-    /*!
156
-     * \brief This method is made to let you fill arrays or
157
-     * create single faces. There may be an allocatin version that
158
-     * passes back arrays later.
159
-     * Returns Quads/Rects as 2 triangles,
160
-     * because returning quads would be too trivial :)
161
-     * \param meshIndex mesh index
162
-     * \param faceIndex face index
163
-     * \param index allocated RGBA
164
-     * \param color allocated RGBA
165
-     * \fixme This method interface may change later
166
-     */
167
-    void getMeshColoredRectangle(unsigned int meshIndex,
168
-                                 unsigned int faceIndex,
169
-                                 int index[6], float color[4]);
170
-
171
-    /*!
172
-     * \brief This method is made to let you fill arrays or
173
-     * create single faces. There may be an allocating version that
174
-     * passes back arrays later.
175
-     * \param meshIndex mesh index
176
-     * \param faceIndex face index
177
-     * \param index allocated RGBA
178
-     * \param color allocated RGBA
179
-     * \fixme This method interface may change later
180
-     */
181
-    void getMeshColoredTriangle(unsigned int meshIndex,
182
-                                unsigned int faceIndex,
183
-                                int index[3], float color[4]);
184
-
185
-    /*!
186
-     * \brief This method is made to let you fill arrays or
187
-     * create single faces. There may be an allocatin version that
188
-     * passes back arrays later.
189
-     * Returns Quads/Rects as 2 triangles,
190
-     * because returning quads would be too trivial :)
191
-     * \param meshIndex mesh index
192
-     * \param faceIndex face index
193
-     * \param index allocated
194
-     * \param st allocated
195
-     * \param texture allocated
196
-     * \param transparency allocated
197
-     * \fixme This method interface may change later
198
-     */
199
-    void getMeshTexturedRectangle(unsigned int meshIndex,
200
-                                  unsigned int faceIndex,
201
-                                  int index[6], float st[12], int* texture,
202
-                                  unsigned short* transparency);
203
-
204
-    /*!
205
-     * \brief This method is made to let you fill arrays or
206
-     * create single faces. There may be an allocatin version that
207
-     * passes back arrays later.
208
-     * \param meshIndex mesh index
209
-     * \param faceIndex face index
210
-     * \param index allocated
211
-     * \param st allocated
212
-     * \param texture allocated
213
-     * \param transparency allocated
214
-     * \fixme This method interface may change later
215
-     */
216
-    void getMeshTexturedTriangle(unsigned int meshIndex,
217
-                                 unsigned int faceIndex,
218
-                                 int index[3], float st[6], int* texture,
219
-                                 unsigned short* transparency);
220
-
221
-    /*!
222
-     * \brief Get face counts for a given mesh.
223
-     *
224
-     * \todo This method interface may change later...
225
-     * \param meshIndex mesh index
226
-     * \returns number of textured triangles in mesh
227
-     */
228
-    int getMeshTexturedTriangleCount(unsigned int meshIndex);
229
-
230
-    /*!
231
-     * \brief Get face counts for a given mesh.
232
-     * \param meshIndex mesh index
233
-     * \returns number of colored triangles in mesh
234
-     */
235
-    int getMeshColoredTriangleCount(unsigned int meshIndex);
236
-
237
-    /*!
238
-     * \brief Get face counts for a given mesh.
239
-     * \param meshIndex mesh index
240
-     * \returns number of textured rectangles in mesh
241
-     */
242
-    int getMeshTexturedRectangleCount(unsigned int meshIndex);
243
-
244
-    /*!
245
-     * \brief Get face counts for a given mesh.
246
-     * \returns number if colored rectangles in mesh
247
-     */
248
-    int getMeshColoredRectangleCount(unsigned int meshIndex);
249
-
250
-    /*!
251
-     * \brief Get vertex, normal and color arrays for a mesh
252
-     * \param meshIndex mesh index
253
-     * \param vertexCount will be set to length of vertex array
254
-     * \param verts will be set to allocated vertex array (XYX)
255
-     * \param normalCount will be set to length of normal array
256
-     * \param norms will be set to allocated normal array (IJK)
257
-     * \param colorCount will be set to length of color array
258
-     * \param colors will be set to allocated color array (I)
259
-     */
260
-    void getMeshVertexArrays(unsigned int meshIndex,
261
-                             unsigned int* vertexCount, float** verts,
262
-                             unsigned int* normalCount, float** norms,
263
-                             unsigned int* colorCount, float** colors);
264
-
265
-    /*!
266
-     * \brief Get a single collision box from room (unified)
267
-     * \param roomIndex room index
268
-     * \param index index of box in room
269
-     * \param xyzA will contain first corner of box
270
-     * \param xyzB will contain second corner of box
271
-     * \param xyzC will contain third corner of box
272
-     * \param xyzD will contain fourth corner of box
273
-     * \returns 0 on success, < 0 on error
274
-     */
275
-    int getRoomBox(unsigned int roomIndex, unsigned int index,
276
-                   float* xyzA, float* xyzB, float* xyzC, float* xyzD);
277
-
278
-    /*!
279
-     * \brief Get number of collision boxes in room (unified)
280
-     * \param roomIndex room index
281
-     * \returns number of collision boxes in room
282
-     */
283
-    unsigned int getRoomBoxCount(unsigned int roomIndex);
284
-
285
-    void getRoomInfo(unsigned int index,
286
-                     unsigned int* flags, float pos[3],
287
-                     float bboxMin[3], float bboxMax[3]);
288
-
289
-    /*!
290
-     * \brief Get a single light from a room (unified)
291
-     * \param roomIndex valid room index
292
-     * \param index valid light index in room
293
-     * \param pos allocated, will contain position
294
-     * \param color allocated, will contain color
295
-     * \param dir allocated, will contain direction
296
-     * \param attenuation will contain attenuation
297
-     * \param cutoffAngle will contain cutoff angle
298
-     * \param type will contain type
299
-     * \param flags will contain flags
300
-     * \returns 0 on success, < 0 on error
301
-     */
302
-    int getRoomLight(unsigned int roomIndex, unsigned int index,
303
-                     float pos[4], float color[4], float dir[3],
304
-                     float* attenuation, float* cutoffAngle,
305
-                     unsigned int* type, unsigned int* flags);
306
-
307
-    /*!
308
-     * \brief Get number of lights in room (unified)
309
-     * \param roomIndex room index
310
-     * \returns number of lights in room
311
-     */
312
-    unsigned int getRoomLightCount(unsigned int roomIndex);
313
-
314
-    /*!
315
-     * \brief Get a single model info from a room
316
-     * \param roomIndex valid room index
317
-     * \param index valid model index in room
318
-     * \param modelIndex will contain starting mesh
319
-     * \param pos will contain pos
320
-     * \param yaw will contain yaw angle
321
-     * \returns 0 on success, < 0 on error
322
-     */
323
-    int getRoomModel(unsigned int roomIndex, unsigned int index,
324
-                     int* modelIndex, float pos[3], float* yaw);
325
-
326
-    /*!
327
-     * \brief Get number of room models in room (unified)
328
-     * \param roomIndex room index
329
-     * \returns number of room models in room
330
-     */
331
-    unsigned int getRoomModelCount(unsigned int roomIndex);
332
-
333
-    /*!
334
-     * \brief Get a single portal from room (unified)
335
-     * \param roomIndex valid room index
336
-     * \param index valid portal index in room
337
-     * \param adjoiningRoom will contain adjoining room index
338
-     * \param normal allocated, will contain normal vector
339
-     * \param vertices allocated, will contain vertices
340
-     * \returns 0 on success, < 0 on error
341
-     */
342
-    int getRoomPortal(unsigned int roomIndex, unsigned int index,
343
-                      int* adjoiningRoom, float normal[3], float vertices[12]);
344
-
345
-    /*!
346
-     * \brief Get number of portals from room (unified)
347
-     * \param roomIndex room index
348
-     * \returns number of portals from room
349
-     */
350
-    unsigned int getRoomPortalCount(unsigned int roomIndex);
351
-
352
-    /*!
353
-     * \brief Get rectangle data with texCoords for non-matching
354
-     * vertex/uv for each vertex in TombRaider room (unified)
355
-     * \param roomIndex valid room index
356
-     * \param rectangleIndex rectangle index in room
357
-     * \param indices will contain indices
358
-     * \param texCoords will contain texCoords
359
-     * \param texture will contain texture
360
-     * \param flags will contain flags
361
-     */
362
-    void getRoomRectangle(unsigned int roomIndex, unsigned int rectangleIndex,
363
-                          unsigned int* indices, float* texCoords, int* texture,
364
-                          unsigned int* flags);
365
-
366
-    /*!
367
-     * \brief Get number of rectangles from room (unified)
368
-     * \param roomIndex room index
369
-     * \returns number of rectangles from room
370
-     */
371
-    unsigned int getRoomRectangleCount(unsigned int roomIndex);
372
-
373
-    /*!
374
-     * \brief Get a single sector from room (unified)
375
-     * \param roomIndex room index
376
-     * \param index sector index
377
-     * \param flags will contain flags
378
-     * \param ceiling will contain ceiling
379
-     * \param floor will contain floor
380
-     * \param floorDataIndex will contain floor data index
381
-     * \param boxIndex will contain boxIndex
382
-     * \param roomBelow will contain roomBelow
383
-     * \param roomAbove will contain roomAbove
384
-     * \return 0 on success, < 0 on error
385
-     */
386
-    int getRoomSector(unsigned int roomIndex, unsigned int index,
387
-                      unsigned int* flags, float* ceiling, float* floor,
388
-                      int* floorDataIndex, int* boxIndex,
389
-                      int* roomBelow, int* roomAbove);
390
-
391
-    /*!
392
-     * \brief Get number of sectors in room (unified)
393
-     * \param roomIndex room index
394
-     * \param zSectorsCount will contain width of sector list
395
-     * \param xSectorsCount will contain height of sector list
396
-     * \returns number of sectors in room
397
-     */
398
-    unsigned int getRoomSectorCount(unsigned int roomIndex,
399
-                                    unsigned int* zSectorsCount,
400
-                                    unsigned int* xSectorsCount);
401
-
402
-    void getRoomSprite(unsigned int roomIndex, unsigned int index,
403
-                       float scale, int* texture,
404
-                       float* pos, float* vertices, float* texcoords);
405
-
406
-    /*!
407
-     * \brief Get number of sprites in room (unified)
408
-     * \param roomIndex room index
409
-     * \returns number of sprites in room
410
-     */
411
-    unsigned int getRoomSpriteCount(unsigned int roomIndex);
412
-
413
-    /*!
414
-     * \brief Gets triangle data with texCoords for non-matching
415
-     * vertex/uv for each vertex in TombRaider room (unified)
416
-     * \param roomIndex room index
417
-     * \param triangleIndex triangle index
418
-     * \param indices will contain indices
419
-     * \param texCoords will contain texCoords
420
-     * \param texture will contain texture
421
-     * \param flags will contain flags
422
-     */
423
-    void getRoomTriangle(unsigned int roomIndex, unsigned int triangleIndex,
424
-                         unsigned int* indices, float* texCoords, int* texture,
425
-                         unsigned int* flags);
426
-
427
-    /*!
428
-     * \brief Gets triangle data with texCoords for non-matching
429
-     * vertex/uv for each vertex in TombRaider room.
430
-     *
431
-     * This is used with vertices, colors, etc. to do partial array
432
-     * rendering, since the texcoords will never match vertives
433
-     * (Tomb Raider is textile based).
434
-     * \param index room index
435
-     * \param textureOffset texture offset
436
-     * \param count will contain count
437
-     * \param indices will contain indices
438
-     * \param texCoords will contain texCoords
439
-     * \param textures will contain textures
440
-     * \param flags will contain flags
441
-     */
442
-    void getRoomTriangles(unsigned int index, int textureOffset,
443
-                          unsigned int* count, unsigned int** indices,
444
-                          float** texCoords, int** textures,
445
-                          unsigned int** flags);
446
-
447
-    /*!
448
-     * \brief Gets triangle data with duplicated vertex/color/normal
449
-     * data for each face vertex to match the textile based texcoords.
450
-     *
451
-     * This uses more memory, but lets you do direct array rendering
452
-     * with OpenGL, D3D, etc.
453
-     * \param roomIndex room index
454
-     * \param textureOffset texture offset
455
-     * \param count will contain count
456
-     * \param indices will contain indices
457
-     * \param vertices will contain vertices
458
-     * \param texCoords will contain texCoords
459
-     * \param colors will contain colors
460
-     * \param textures will contain textures
461
-     * \param flags will contain flags
462
-     */
463
-    void getRoomTriangles(unsigned int roomIndex, int textureOffset,
464
-                          unsigned int* count,
465
-                          unsigned int** indices, float** vertices,
466
-                          float** texCoords, float** colors,
467
-                          int** textures, unsigned int** flags);
468
-
469
-    /*!
470
-     * \brief Get number of triangles from room (unified)
471
-     * \param roomIndex room index
472
-     * \returns number of triangles from room
473
-     */
474
-    unsigned int getRoomTriangleCount(unsigned int roomIndex);
475
-
476
-    /*!
477
-     * \brief Gets vertex position and color
478
-     * \param roomIndex room index
479
-     * \param vertexIndex vertex index
480
-     * \param xyz will contain vertex position, has to be allocated
481
-     * \param rgba will contain vertex color, has to be allocated
482
-     */
483
-    void getRoomVertex(unsigned int roomIndex, unsigned int vertexIndex,
484
-                       float* xyz, float* rgba);
485
-
486
-    /*!
487
-     * \brief Get allocated vertex and color arrays and their element counts (unified)
488
-     * \param roomIndex valid room index
489
-     * \param vertexCount will contain vertex array length
490
-     * \param vertices will contain vertex array
491
-     * \param normalCount will contain normal array length
492
-     * \param normals will contain normal array
493
-     * \param colorCount will contain color array length
494
-     * \param colors will contain color array
495
-     */
496
-    void getRoomVertexArrays(unsigned int roomIndex,
497
-                             unsigned int* vertexCount, float** vertices,
498
-                             unsigned int* normalCount, float** normals,
499
-                             unsigned int* colorCount, float** colors);
500
-
501
-    /*!
502
-     * \brief Get number of lights in room (unified)
503
-     * \param roomIndex room index
504
-     * \returns number of lights in room
505
-     */
506
-    unsigned int getRoomVertexCount(unsigned int roomIndex);
507
-
508
-    /*!
509
-     * \brief Get sky mesh ID
510
-     * \returns moveable id of sky mesh or -1 if none
511
-     */
512
-    int getSkyModelId();
513
-
514
-    /*!
515
-     * \brief Get a copy of a sound sample and its byte size
516
-     * \param index sound sample index
517
-     * \param bytes will contain byte size of sound sample
518
-     * \param data will contain sound sample
519
-     */
520
-    void getSoundSample(unsigned int index,
521
-                        unsigned int* bytes, unsigned char** data);
522
-
523
-    /*!
524
-     * \brief Get number of loaded sound samples
525
-     * \returns number of sound samples loaded
526
-     */
527
-    unsigned int getSoundSamplesCount();
528
-
529
-    /*!
530
-     * \brief Check if a mesh is valid
531
-     * \param index mesh index (?)
532
-     * \returns true if mesh is valid
533
-     */
534
-    bool isMeshValid(int index);
535
-
536
-    /*!
537
-     * \brief Check if a room is valid (TRC support)
538
-     * \param index room index
539
-     * \returns true if room is valid
540
-     */
541
-    bool isRoomValid(int index);
542
-
543
-    /*!
544
-     * \brief Load an external sound pak for TR2 and TR3
545
-     * \param filename pak to load
546
-     * \returns < 0 on error
547
-     */
548
-    int loadSFX(const char* filename);
549
-
550
-    void reset();
551
-
552
-  private:
553
-
554
-    void extractMeshes(unsigned char* mesh_data,
555
-                       unsigned int num_mesh_pointers,
556
-                       unsigned int* mesh_pointers);
557
-
558
-    int Fread(void* buffer, size_t size, size_t count, FILE* f);
559
-
560
-    /*!
561
-     * \brief Get a copy of the sound samples
562
-     * \param bytes will contain size of sound samples
563
-     * \param data will contain sound samples themselves
564
-     */
565
-    void getRiffData(unsigned int* bytes, unsigned char** data);
566
-
567
-    /*!
568
-     * \brief Get a copy of a TR4 sound sample
569
-     * \param index sound sample index
570
-     * \param bytes will contain length of sound sample
571
-     * \param data will contain sound sample itself
572
-     */
573
-    void getRiffDataTR4(unsigned int index,
574
-                        unsigned int* bytes, unsigned char** data);
575
-
576
-    /*!
577
-     * \brief Get an array of offsets for a contiguous RIFF data stream in chunks.
578
-     *
579
-     * Offsets will be allocated with enough space to hold expected
580
-     * number of offsets. (Should be known number, otherwise not all RIFFs
581
-     * will be parsed.)
582
-     * \param riffData riff data
583
-     * \param riffDataBytes length of riff data
584
-     * \param offsets will contain offsets
585
-     * \param numOffsets known number
586
-     * \returns number of RIFFs found
587
-     */
588
-    int getRiffOffsets(unsigned char* riffData, unsigned int riffDataBytes,
589
-                       unsigned int** offsets, unsigned int numOffsets);
590
-
591
-    /*!
592
-     * \brief Makes a 32bit RGBA image from a textile.
593
-     *
594
-     * This handles all selection and conversion, including
595
-     * alpha layering flags, now.
596
-     * \param texture valid index into textile list
597
-     * \returns 32bit RGBA image or NULL on error
598
-     */
599
-    unsigned char* getTexTile(int texture);
600
-
601
-    /*!
602
-     * \brief Loads a TR5 pak into memory.
603
-     * \param f valid FILE
604
-     * \returns 0 on success, < 0 on error
605
-     */
606
-    int loadTR5(FILE* f);
607
-
608
-    static void print(const char* methodName, const char* s, ...) __attribute__((format(printf, 2, 3)));
609
-
610
-    void printDebug(const char* methodName, const char* s, ...) __attribute__((format(printf, 3, 4)));
611
-
612
-    bool mDebug;                           //!< Debug output toggle
613
-    unsigned int mPakVersion;              //!< TombRaider pak file header version
614
-    tr2_version_type mEngineVersion;       //!< TombRaider engine version
615
-    tr2_colour_t _palette8[256];           //!< 8-bit palette
616
-    unsigned int _palette16[256];          //!< 16-bit palette
617
-    unsigned int _num_textiles;            //!< Total number of texture tiles
618
-    unsigned short  _num_room_textures;    //!< Num textures only for room use?
619
-    unsigned short _num_misc_textures;     //!< Num of textures for misc use?
620
-    unsigned short _num_bump_map_textures; //!< Num of textures that are bump map, texture pairs
621
-    tr2_textile8_t* _textile8;             //!< 8-bit (palettised) textiles
622
-    tr2_textile16_t* _textile16;           //!< 16-bit (ARGB) textiles
623
-    tr2_textile32_t* _textile32;           //!< 32-bit (BGRA) textiles
624
-    unsigned int _num_tex_special;         //!< Special textures and bump maps count
625
-    unsigned char* _tex_special;           //!< Special textures and bump maps
626
-    unsigned int _unknown_t;               //!< 32-bit unknown (always 0 in real TR2 levels)
627
-    unsigned short _num_rooms;             //!< Number of rooms in this level
628
-    tr2_room_t* _rooms;                    //!< List of rooms (TR1,TR2,TR3,TR4)
629
-    tr5_room_t* mRoomsTR5;                 //!< Rooms ( TR5 / TRC ) Only
630
-    unsigned int _num_floor_data;          //!< Num of words of floor data this level
631
-    unsigned short* _floor_data;           //!< Floor data
632
-    int mMeshCount;                        //!< Number of meshes this level
633
-    tr2_mesh_t* mMeshes;                   //!< list of meshes
634
-    unsigned int _num_animations;          //!< number of animations this level
635
-    tr2_animation_t* _animations;          //!< list of animations
636
-    unsigned int _num_state_changes;       //!< number of structures(?) this level
637
-    tr2_state_change_t* _state_changes;    //!< list of structures
638
-    unsigned int _num_anim_dispatches;     //!< number of ranges(?) this level
639
-    tr2_anim_dispatch_t* _anim_dispatches; //!< list of ranges
640
-    unsigned int _num_anim_commands;       //!< number of Bone1s this level
641
-    tr2_anim_command_t* _anim_commands;    //!< list of Bone1s
642
-    unsigned int _num_mesh_trees;          //!< number of Bone2s this level
643
-    tr2_meshtree_t* _mesh_trees;           //!< list of Bone2s
644
-    unsigned int _num_frames;              //!< num of words of frame data this level
645
-    unsigned short* _frames;               //!< frame data
646
-    unsigned int _num_moveables;           //!< number of moveables this level
647
-    tr2_moveable_t* _moveables;            //!< list of moveables
648
-
649
-    uint32_t numMoveablesTR5;
650
-    tr5_moveable_t* moveablesTR5;
651
-
652
-    uint32_t numAnimationsTR5;
653
-    tr5_animation_t* animationsTR5;
654
-
655
-    uint32_t numObjectTexturesTR5;
656
-    tr5_object_texture_t* objectTexturesTR5;
657
-
658
-    uint32_t numCinematicFramesTR5;
659
-    tr5_cinematic_frame_t* cinematicFramesTR5;
660
-
661
-    uint32_t numFlyByCamerasTR5;
662
-    tr5_flyby_camera_t* flyByCamerasTR5;
663
-
664
-    unsigned int _num_static_meshes;        //!< number of static meshes this level
665
-    tr2_staticmesh_t* _static_meshes;       //!< static meshes
666
-    unsigned int _num_object_textures;      //!< number of object textures this level
667
-    tr2_object_texture_t* _object_textures; //!< list of object textures
668
-
669
-    unsigned int _num_sprite_textures;        //!< num of sprite textures this level
670
-    tr2_sprite_texture_t* _sprite_textures;   //!< list of sprite textures
671
-    unsigned int _num_sprite_sequences;       //!< num of sprite sequences this level
672
-    tr2_sprite_sequence_t* _sprite_sequences; //!< sprite sequence data
673
-    int  _num_cameras;                        //!< Number of Cameras
674
-    tr2_camera_t*  _cameras;                  //!< cameras
675
-    int  _num_sound_sources;                  //!< Number of Sounds
676
-    tr2_sound_source_t* _sound_sources;       //!< sounds
677
-    int  _num_boxes;                          //!< Number of Boxes
678
-    tr2_box_t* _boxes;                        /*!< boxes - looks like
679
-                                               * struct { unsigned short value[4]; }
680
-                                               * - value[0..2] might be a vector;
681
-                                               * value[3] seems to be index into
682
-                                               * Overlaps[] */
683
-    int  _num_overlaps;                       //!< Number of Overlaps
684
-    short*  _overlaps;                        /*!< Overlaps -
685
-                                               * looks like ushort; 0x8000 is flag
686
-                                               * of some sort appears to be an
687
-                                               * offset into Boxes[] and/or
688
-                                               * Boxes2[] */
689
-    short*  _zones;                           //!< Boxes2
690
-    int  _num_animated_textures;              //!< Number of AnimTextures
691
-    short*  _animated_textures;               //!< Animtextures
692
-    int  _num_items;                          //!< Number of Items
693
-    tr2_item_t* _items;                       //!< Items
694
-    unsigned char*  _light_map;               //!< Colour-light maps
695
-    unsigned int _num_cinematic_frames;       //!< Number of cut-scene frames
696
-    tr2_cinematic_frame_t* _cinematic_frames; //!< Cut-scene frames
697
-    short  _num_demo_data;                    //!< Number of Demo Data
698
-    unsigned char*  _demo_data;               //!< Demo data
699
-    float mRoomVertexLightingFactor;
700
-    float mTexelScale;
701
-
702
-    // Sound data
703
-    short*  mSoundMap;                   //!< Sound map
704
-    int  mNumSoundDetails;               //!< Number of SampleModifiers
705
-    tr2_sound_details_t* mSoundDetails;  //!< Sample modifiers
706
-    int  mNumSampleIndices;              //!< Number of Sample Indices
707
-    int*  mSampleIndices;                //!< Sample indices
708
-    unsigned int* mSampleIndicesTR5;
709
-    bool mRiffAlternateLoaded;           //!< Is a TR2,TR3 SFX loaded?
710
-    unsigned int* mRiffAlternateOffsets; //!< After parsing this will
711
-    //!< hold byte offsets for TR2,TR3
712
-    //!< RIFFs in the buffered SFX
713
-    int mRiffDataSz;                     //!< Byte size of a loaded SFX
714
-    unsigned char* mRiffData;            //!< SFX RIFF data in chunks
715
-    unsigned int mNumTR4Samples;
716
-    unsigned char** mTR4Samples;
717
-    unsigned int* mTR4SamplesSz;
718
-
719
-    // For packed Fread emu/wrapper
720
-    unsigned char*
721
-    mCompressedLevelData;     //!< Buffer used to emulate fread with uncompressed libz data
722
-    unsigned int mCompressedLevelDataOffset; //!< Offset into buffer
723
-    unsigned int mCompressedLevelSize;       //!< Size of buffer
724
-    tr_fread_mode_t mFreadMode;              //!< Fread mode file|buffer
725
-};
726
-
727
-#endif
728
-

+ 0
- 1139
include/TombRaiderData.h
Failā izmaiņas netiks attēlotas, jo tās ir par lielu
Parādīt failu


+ 0
- 152
include/ViewVolume.h Parādīt failu

@@ -1,152 +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 "math/Matrix.h"
12
-
13
-/*!
14
- * \brief Viewing Volume for culling use
15
- */
16
-class ViewVolume {
17
-  public:
18
-
19
-    /*!
20
-     * \brief Sides of the view volume
21
-     */
22
-    enum ViewVolumeSide {
23
-        rightSide  = 0, //!< Right
24
-        leftSide   = 1, //!< Left
25
-        bottomSide = 2, //!< Bottom
26
-        topSide    = 3, //!< Top
27
-        farSide    = 4, //!< Back
28
-        nearSide   = 5  //!< Front
29
-    };
30
-
31
-    /*!
32
-     * \brief Planes of the view volume
33
-     */
34
-    enum ViewVolumePlane {
35
-        planeA = 0, //!< X value of normal
36
-        planeB = 1, //!< Y value of normal
37
-        planeC = 2, //!< Z value of normal
38
-        planeD = 3  //!< Distance to origin
39
-    };
40
-
41
-    /*!
42
-     * \brief Constructs an object of ViewVolume
43
-     */
44
-    ViewVolume();
45
-
46
-    /*!
47
-     * \brief Check if point is in view volume
48
-     * \param x X coordinate of point
49
-     * \param y Y coordinate of point
50
-     * \param z Z coordinate of point
51
-     * \returns true if point in view volume
52
-     */
53
-    bool isPointInFrustum(float x, float y, float z);
54
-
55
-    /*!
56
-     * \brief Check if bounding sphere is in view volume
57
-     * \param x X coordinate of a valid abstract sphere
58
-     * \param y Y coordinate of a valid abstract sphere
59
-     * \param z Z coordinate of a valid abstract sphere
60
-     * \param radius radius of a valid abstract sphere
61
-     * \returns true if abstract sphere in view volume
62
-     */
63
-    bool isSphereInFrustum(float x, float y, float z, float radius);
64
-
65
-    /*!
66
-     * \brief Check if bounding box is in view volume
67
-     * \param min minimum point of valid abstract bounding box
68
-     * \param max maximum point of valid abstract bounding box
69
-     * \returns true if abstract bounding box in view volume
70
-     */
71
-    bool isBboxInFrustum(float min[3], float max[3]);
72
-
73
-    /*!
74
-     * \brief Distance to Bounding sphere
75
-     * \param x X coordinate of a valid abstract sphere
76
-     * \param y Y coordinate of a valid abstract sphere
77
-     * \param z Z coordinate of a valid abstract sphere
78
-     * \param radius radius of a valid abstract sphere
79
-     * \returns distance to abstract sphere bounding volume
80
-     */
81
-    float getDistToSphereFromNear(float x, float y, float z, float radius);
82
-
83
-    /*!
84
-     * \brief Distance to Bounding box
85
-     * \param min minimum point of a valid abstract bounding box
86
-     * \param max maximum point of a valid abstract bounding box
87
-     * \returns distance to abstract box bounding volume
88
-     */
89
-    float getDistToBboxFromNear(const float min[3], const float max[3]);
90
-
91
-    /*!
92
-     * \brief Get a copy of the view volume
93
-     * \param frustum where frustum will be stored
94
-     */
95
-    void getFrustum(float frustum[6][4]);
96
-
97
-    /*!
98
-     * \brief Get a copy of a given plane in view volume
99
-     * \param p side
100
-     * \param plane wher plane will be stored
101
-     */
102
-    void getPlane(ViewVolumeSide p, float plane[4]);
103
-
104
-    /*!
105
-     * \brief Updates view volume for this frame.
106
-     * \param proj new projection matrix
107
-     * \param mdl new model matrix
108
-     */
109
-    void updateFrame(float proj[16], float mdl[16]);
110
-
111
-    /*!
112
-     * \brief Updates view volume for this frame.
113
-     *
114
-     * Model & Projection Matrices must be set.
115
-     */
116
-    void updateFrame();
117
-
118
-    /*!
119
-     * \brief Set this class' model matrix
120
-     * \param mdl new model matrix
121
-     */
122
-    void setModel(float mdl[16]);
123
-
124
-    /*!
125
-     * \brief Set this class' projection matrix
126
-     * \param proj new projection matrix
127
-     */
128
-    void setProjection(float proj[16]);
129
-
130
-  private:
131
-
132
-    /*!
133
-     * \brief Computes clipping matrix.
134
-     *
135
-     * Model & Projection matrices must be set!
136
-     */
137
-    void updateClip();
138
-
139
-    /*!
140
-     * \brief Computes planes of frustum.
141
-     *
142
-     * Model, Projection & Clip matrices must be set!
143
-     */
144
-    void updateFrustum();
145
-
146
-    Matrix mProjection;   //!< Projection matrix
147
-    Matrix mModel;        //!< Model matrix
148
-    Matrix mClip;         //!< Clipping matrix
149
-    float mFrustum[6][4]; //!< View volume
150
-};
151
-
152
-#endif

+ 0
- 22
include/commands/CommandAnimate.h Parādīt failu

@@ -1,22 +0,0 @@
1
-/*!
2
- * \file include/commands/CommandAnimate.h
3
- * \brief Animate Command interface
4
- *
5
- * \author xythobuz
6
- */
7
-
8
-#ifndef _COMMAND_ANIMATE_H_
9
-#define _COMMAND_ANIMATE_H_
10
-
11
-#include "commands/Command.h"
12
-
13
-class CommandAnimate : public Command {
14
-  public:
15
-    virtual std::string name();
16
-    virtual std::string brief();
17
-    virtual void printHelp();
18
-    virtual int execute(std::istream& args);
19
-};
20
-
21
-#endif
22
-

+ 0
- 11
include/commands/CommandRender.h Parādīt failu

@@ -18,16 +18,5 @@ class CommandMode : public Command {
18 18
     virtual int execute(std::istream& args);
19 19
 };
20 20
 
21
-class CommandRenderflag : public Command {
22
-  public:
23
-    virtual std::string name();
24
-    virtual std::string brief();
25
-    virtual void printHelp();
26
-    virtual int execute(std::istream& args);
27
-
28
-  private:
29
-    int stringToFlag(std::string flag);
30
-};
31
-
32 21
 #endif
33 22
 

+ 2
- 23
include/global.h Parādīt failu

@@ -11,16 +11,6 @@
11 11
 
12 12
 void renderFrame();
13 13
 
14
-// Supported pixelmap color formats
15
-enum ColorMode {
16
-    GREYSCALE,
17
-    RGB,
18
-    RGBA,
19
-    ARGB,
20
-    BGR,
21
-    BGRA
22
-};
23
-
24 14
 // Colors used where ever needed
25 15
 const unsigned char BLACK[]  = {   0,   0,   0, 255 };
26 16
 const unsigned char GREY[]   = { 128, 128, 128, 255 };
@@ -77,25 +67,14 @@ typedef enum {
77 67
     unknownKey // Should always be at the end
78 68
 } KeyboardButton;
79 69
 
80
-// Visual C++ does not understand __attribute__
81
-#ifdef _MSC_VER
82
-#define __attribute__(x)
83
-#endif
84
-
85
-//! \todo Replace NULL usage with nullptr
86
-#ifndef NULL
87
-#define NULL nullptr
88
-#endif
89
-
90 70
 // Globally include OpenGL header
91 71
 #ifdef __APPLE__
92
-#include <OpenGL/gl.h>
72
+#include <OpenGL/gl3.h>
93 73
 #else
94 74
 #ifdef _WIN32
95 75
 #include <windows.h>
96 76
 #endif
97
-#include <GL/gl.h>
98
-#include <GL/glext.h>
77
+#include <GL/gl3.h>
99 78
 #endif
100 79
 
101 80
 // If available, use our own assert that prints the call stack

+ 0
- 202
include/math/Matrix.h Parādīt failu

@@ -1,202 +0,0 @@
1
-/*!
2
- * \file include/math/Matrix.h
3
- * \brief 3D Matrix
4
- *
5
- * \author Mongoose
6
- */
7
-
8
-#ifndef _MATH_MATRIX_H_
9
-#define _MATH_MATRIX_H_
10
-
11
-#include "math/math.h"
12
-#include "math/Quaternion.h"
13
-#include "math/Vec3.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(float mat[16]);
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(float mat[16]);
62
-
63
-    /*!
64
-     * \brief Returns this matrix transposed
65
-     * \param mat target
66
-     */
67
-    void getTransposeMatrix(float mat[16]);
68
-
69
-    /*!
70
-     * \brief Returns this matrix inverted
71
-     * \param mat target
72
-     */
73
-    bool getInvert(float mat[16]);
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(float v[4], float result[4]);
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(float v[3], float result[3]);
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
-    Vec3 operator *(Vec3 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(float mat[16]);
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(float x, float y, float z);
141
-
142
-    /*!
143
-     * \brief Rotate object in 3D space
144
-     * \param xyz rotation in radians
145
-     */
146
-    void rotate(const float* 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(float x, float y, float z);
155
-
156
-    /*!
157
-     * \brief Scale object in 3D space
158
-     * \param xyz scaling factors
159
-     */
160
-    void scale(const float* 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(float x, float y, float z);
169
-
170
-    /*!
171
-     * \brief Translate (move) object in 3D space
172
-     * \param xyz translations
173
-     */
174
-    void translate(const float* xyz);
175
-
176
-    /*!
177
-     * \brief Transpose this matrix
178
-     */
179
-    void transpose();
180
-
181
-  private:
182
-
183
-    /*!
184
-     * \brief Copys value from source to dest
185
-     * \param source source
186
-     * \param dest destination
187
-     */
188
-    static void copy(float source[16], float dest[16]);
189
-
190
-    /*!
191
-     * \brief Multiplies matrices a and b. Neither a or b is also the result.
192
-     * \param a first matrix
193
-     * \param b second matrix
194
-     * \param result wil be set to resultant matrix value
195
-     */
196
-    static void multiply(const float a[16], const float b[16], float result[16]);
197
-
198
-    float mMatrix[16];
199
-};
200
-
201
-#endif
202
-

+ 0
- 202
include/math/Quaternion.h Parādīt failu

@@ -1,202 +0,0 @@
1
-/*!
2
- * \file include/math/Quaternion.h
3
- * \brief Quaternion
4
- *
5
- * \author Mongoose
6
- */
7
-
8
-#ifndef _MATH_QUATERNION_H_
9
-#define _MATH_QUATERNION_H_
10
-
11
-#include "math/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(float w, float x, float y, float z);
32
-
33
-    /*!
34
-     * \brief Constructs an object of Quaternion
35
-     * \param v contents of new Quaternion
36
-     */
37
-    Quaternion(float v[4]);
38
-
39
-    /*!
40
-     * \brief Get column order matrix equivalent of this quaternion
41
-     * \param m where matrix will be stored
42
-     */
43
-    void getMatrix(float m[16]);
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(float 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 float dot(Quaternion a, Quaternion b);
110
-
111
-    /*!
112
-     * \brief Magnitude of this quaternion
113
-     * \returns Magnitude of this quaternion
114
-     */
115
-    float 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, float 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(float angle, float x, float y, float 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(float m[16]);
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
-    float mW; //!< Quaternion, W part
196
-    float mX; //!< Quaternion, X part
197
-    float mY; //!< Quaternion, Y part
198
-    float mZ; //!< Quaternion, Z part
199
-};
200
-
201
-#endif
202
-

+ 0
- 46
include/math/Vec3.h Parādīt failu

@@ -1,46 +0,0 @@
1
-/*!
2
- * \file include/math/Vec3.h
3
- * \brief 3D Math vector
4
- *
5
- * \author xythobuz
6
- * \author Mongoose
7
- */
8
-
9
-#ifndef _MATH_VEC3_H_
10
-#define _MATH_VEC3_H_
11
-
12
-#include "math/math.h"
13
-
14
-class Vec3 {
15
-  public:
16
-    Vec3(float _x = 0.0f, float _y = 0.0f, float _z = 0.0f);
17
-    Vec3(float v[3]);
18
-
19
-    float magnitude();
20
-    void normalize();
21
-    Vec3 unit();
22
-
23
-    Vec3 operator +(const Vec3& v);
24
-    Vec3 operator -(const Vec3& v);
25
-    Vec3 operator -();
26
-    Vec3 operator *(float s);
27
-    Vec3 operator /(float s);
28
-    float operator *(const Vec3& v);
29
-
30
-    Vec3& operator +=(const Vec3& v);
31
-    Vec3& operator -=(const Vec3& v);
32
-    Vec3& operator *=(float s);
33
-
34
-    bool operator ==(const Vec3& v);
35
-    bool operator !=(const Vec3& v);
36
-
37
-    float x, y, z;
38
-
39
-    // ----------------------------------------------------------
40
-
41
-    static float dot(const Vec3& u, const Vec3& v);
42
-    static Vec3 cross(const Vec3& u, const Vec3& v);
43
-};
44
-
45
-#endif
46
-

+ 0
- 65
include/math/math.h Parādīt failu

@@ -1,65 +0,0 @@
1
-/*!
2
- *
3
- * \file include/math/math.h
4
- * \brief Vector and Matrix math
5
- *
6
- * \author Mongoose
7
- * \author xythobuz
8
- */
9
-
10
-#ifndef _MATH_MATH_H
11
-#define _MATH_MATH_H
12
-
13
-#ifndef M_PI
14
-#define OR_PI (3.14159265358979323846f) //!< pi
15
-#else
16
-#define OR_PI ((float)M_PI) //!< pi
17
-#endif
18
-
19
-#define OR_RAD_TO_DEG(x) ((x) * (180.0f / OR_PI)) //!< Convert radians to degrees
20
-#define OR_DEG_TO_RAD(x) ((x) * (OR_PI / 180.0f)) //!< Convert degrees to radians
21
-
22
-/*!
23
- * \brief Compare two floats with an Epsilon.
24
- * \param a first float
25
- * \param b second float
26
- * \returns true if a and b are probably the same.
27
- */
28
-bool equalEpsilon(float a, float b);
29
-
30
-/*!
31
- * \brief Calculate Intersection of a line and a polygon
32
- * \param intersect Where the intersection is stored, if it exists
33
- * \param p1 First point of line segment
34
- * \param p2 Second point of line segment
35
- * \param polygon polygon vertex array (0 to 2 are used)
36
- * \returns 0 if there is no intersection
37
- */
38
-int intersectionLinePolygon(float intersect[3], float p1[3], float p2[3], float polygon[3][3]);
39
-
40
-/*!
41
- * \brief Calculate the length of a line segment / the distance between two points
42
- * \param a First point
43
- * \param b Second point
44
- * \returns distance/length
45
- */
46
-float distance(const float a[3], const float b[3]);
47
-
48
-/*!
49
- * \brief Calculates the midpoint between two points / of a line segment
50
- * \param a First point
51
- * \param b Second point
52
- * \param mid Midpoint will be stored here
53
- */
54
-void midpoint(const float a[3], const float b[3], float mid[3]);
55
-
56
-/*!
57
- * \brief Calculates a pseudo-random number
58
- * \param from Lower bound of resulting number
59
- * \param to Upper bound
60
- * \returns random number
61
- */
62
-float randomNum(float from, float to);
63
-
64
-#endif
65
-

+ 5
- 2
include/system/FontTRLE.h Parādīt failu

@@ -8,6 +8,9 @@
8 8
 #ifndef _FONT_TRLE_H_
9 9
 #define _FONT_TRLE_H_
10 10
 
11
+#include "glm/vec2.hpp"
12
+#include <vector>
13
+
11 14
 /*!
12 15
  * \brief Tomb Raider Level Editor Font loader
13 16
  */
@@ -30,8 +33,8 @@ class FontTRLE {
30 33
   private:
31 34
     static void setDefaultOffsets();
32 35
     static void loadLPS(std::string f);
33
-    static void writeChar(unsigned int index, unsigned int xDraw, unsigned int yDraw,
34
-                          float scale, const unsigned char color[4]);
36
+    static void writeChar(unsigned int index, unsigned int xDraw, unsigned int yDraw, float scale,
37
+                          std::vector<glm::vec2>& vertices, std::vector<glm::vec2>& uvs);
35 38
 
36 39
     static bool mFontInit;
37 40
     static unsigned int mFontTexture;

+ 48
- 23
include/system/Window.h Parādīt failu

@@ -8,49 +8,61 @@
8 8
 #ifndef _WINDOW_H_
9 9
 #define _WINDOW_H_
10 10
 
11
-/*!
12
- * \brief Windowing interface
13
- */
11
+#include "glm/vec2.hpp"
12
+#include "glm/vec4.hpp"
13
+
14
+#include <vector>
15
+
16
+class Shader {
17
+  public:
18
+    Shader() : programID(-1) { }
19
+    ~Shader();
20
+
21
+    int compile(const char* vertex, const char* fragment);
22
+    void use();
23
+
24
+    int addUniform(const char* name);
25
+    unsigned int getUniform(int n);
26
+
27
+    void addBuffer(int n = 1);
28
+    unsigned int getBuffer(int n);
29
+
30
+  private:
31
+    int programID;
32
+    std::vector<unsigned int> uniforms;
33
+    std::vector<unsigned int> buffers;
34
+};
35
+
14 36
 class Window {
15 37
   public:
16 38
 
17 39
     virtual ~Window() {}
18 40
 
19 41
     virtual void setSize(unsigned int width, unsigned int height) = 0;
42
+    virtual unsigned int getWidth();
43
+    virtual unsigned int getHeight();
20 44
 
21 45
     virtual void setFullscreen(bool fullscreen) = 0;
22
-
23
-    virtual bool getFullscreen() { return mFullscreen; }
46
+    virtual bool getFullscreen();
24 47
 
25 48
     virtual void setMousegrab(bool grab) = 0;
26
-
27
-    virtual bool getMousegrab() { return mMousegrab; }
49
+    virtual bool getMousegrab();
28 50
 
29 51
     virtual int initialize() = 0;
30 52
 
31 53
     virtual void eventHandling() = 0;
32 54
 
33 55
     virtual void setTextInput(bool on) = 0;
34
-
35
-    virtual bool getTextInput() { return mTextInput; }
56
+    virtual bool getTextInput();
36 57
 
37 58
     virtual void swapBuffersGL() = 0;
38 59
 
39
-    virtual unsigned int getWidth() { return mWidth; }
40
-
41
-    virtual unsigned int getHeight() { return mHeight; }
42
-
43
-    virtual int initializeGL();
44
-
45
-    virtual void resizeGL();
60
+    static int initializeGL();
61
+    static void shutdownGL();
62
+    static void resizeGL();
46 63
 
47
-    virtual void glEnter2D();
48
-
49
-    virtual void glExit2D();
50
-
51
-    static void lookAt(float eyeX, float eyeY, float eyeZ,
52
-                       float lookAtX, float lookAtY, float lookAtZ,
53
-                       float upX, float upY, float upZ);
64
+    static void drawTextGL(std::vector<glm::vec2>& vertices, std::vector<glm::vec2>& uvs,
65
+                           glm::vec4 color, unsigned int texture);
54 66
 
55 67
   protected:
56 68
     bool mInit;
@@ -59,6 +71,19 @@ class Window {
59 71
     bool mTextInput;
60 72
     unsigned int mWidth;
61 73
     unsigned int mHeight;
74
+
75
+  private:
76
+    static Shader textShader;
77
+    static const char* textShaderVertex;
78
+    static const char* textShaderFragment;
79
+
80
+    static Shader imguiShader;
81
+    static const char* imguiShaderVertex;
82
+    static const char* imguiShaderFragment;
83
+
84
+    static unsigned int vertexArrayID;
85
+
86
+    friend class UI;
62 87
 };
63 88
 
64 89
 Window& getWindow();

+ 4
- 1
include/utils/pcx.h Parādīt failu

@@ -11,6 +11,8 @@
11 11
 #ifndef _UTILS_PCX_H_
12 12
 #define _UTILS_PCX_H_
13 13
 
14
+#include "TextureManager.h"
15
+
14 16
 /*!
15 17
  * \brief Check if a file is a valid PCX image
16 18
  * \param filename path of file to read
@@ -29,7 +31,8 @@ int pcxCheck(const char* filename);
29 31
  * \returns 0 on success
30 32
  */
31 33
 int pcxLoad(const char* filename, unsigned char** image,
32
-            unsigned int* width, unsigned int* height, ColorMode* mode, unsigned int* bpp);
34
+            unsigned int* width, unsigned int* height,
35
+            TextureManager::ColorMode* mode, unsigned int* bpp);
33 36
 
34 37
 #endif
35 38
 

+ 6
- 2
include/utils/png.h Parādīt failu

@@ -8,6 +8,8 @@
8 8
 #ifndef _UTILS_PNG_H_
9 9
 #define _UTILS_PNG_H_
10 10
 
11
+#include "TextureManager.h"
12
+
11 13
 /*!
12 14
  * \brief Check if a file is a valid PNG image
13 15
  * \param filename path of file to read
@@ -26,7 +28,8 @@ int pngCheck(const char* filename);
26 28
  * \returns 0 on success
27 29
  */
28 30
 int pngLoad(const char* filename, unsigned char** image,
29
-            unsigned int* width, unsigned int* height, ColorMode* mode, unsigned int* bpp);
31
+            unsigned int* width, unsigned int* height,
32
+            TextureManager::ColorMode* mode, unsigned int* bpp);
30 33
 
31 34
 /*!
32 35
  * \brief Create a PNG image file from an RGBA buffer
@@ -39,7 +42,8 @@ int pngLoad(const char* filename, unsigned char** image,
39 42
  * \returns 0 on success
40 43
  */
41 44
 int pngSave(const char* filename, unsigned char* image,
42
-            unsigned int width, unsigned int height, ColorMode mode, unsigned int bpp);
45
+            unsigned int width, unsigned int height,
46
+            TextureManager::ColorMode mode, unsigned int bpp);
43 47
 
44 48
 #endif
45 49
 

+ 1
- 1
include/utils/tga.h Parādīt failu

@@ -18,7 +18,7 @@ int tgaCheck(const char* filename);
18 18
 /*!
19 19
  * \brief Load a TGA image from file
20 20
  * \param filename path to file
21
- * \param image Where the pixmap will be stored (or NULL)
21
+ * \param image Where the pixmap will be stored (or nullptr)
22 22
  * \param width where the width will be stored
23 23
  * \param height where the height will be stored
24 24
  * \param type where the type will be stored (tga_type_t)

+ 8
- 6
src/CMakeLists.txt Parādīt failu

@@ -55,6 +55,12 @@ if (PNG_FOUND)
55 55
     add_definitions (${PNG_DEFINITIONS})
56 56
 endif (PNG_FOUND)
57 57
 
58
+# Add GLM Library
59
+find_package (GLM REQUIRED)
60
+if (GLM_FOUND)
61
+    include_directories (SYSTEM  ${GLM_INCLUDE_DIRS})
62
+endif (GLM_FOUND)
63
+
58 64
 #################################################################
59 65
 
60 66
 # Set Source files
@@ -78,9 +84,7 @@ set (SRCS ${SRCS} "SoundManager.cpp")
78 84
 set (SRCS ${SRCS} "Sprite.cpp")
79 85
 set (SRCS ${SRCS} "StaticMesh.cpp")
80 86
 set (SRCS ${SRCS} "TextureManager.cpp")
81
-set (SRCS ${SRCS} "TombRaider.cpp")
82 87
 set (SRCS ${SRCS} "UI.cpp")
83
-set (SRCS ${SRCS} "ViewVolume.cpp")
84 88
 set (SRCS ${SRCS} "World.cpp")
85 89
 
86 90
 # Select available Sound library
@@ -219,7 +223,6 @@ set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${OpenRaider_CXX_FLAGS}
219 223
 add_subdirectory ("commands")
220 224
 add_subdirectory ("deps")
221 225
 add_subdirectory ("loader")
222
-add_subdirectory ("math")
223 226
 add_subdirectory ("system")
224 227
 add_subdirectory ("utils")
225 228
 
@@ -227,9 +230,8 @@ add_subdirectory ("utils")
227 230
 add_library (OpenRaider_all OBJECT ${SRCS})
228 231
 add_executable (OpenRaider MACOSX_BUNDLE ${RESRCS}
229 232
     $<TARGET_OBJECTS:OpenRaider_all> $<TARGET_OBJECTS:OpenRaider_commands>
230
-    $<TARGET_OBJECTS:OpenRaider_deps> $<TARGET_OBJECTS:OpenRaider_math>
231
-    $<TARGET_OBJECTS:OpenRaider_utils> $<TARGET_OBJECTS:OpenRaider_loader>
232
-    $<TARGET_OBJECTS:OpenRaider_system>
233
+    $<TARGET_OBJECTS:OpenRaider_deps> $<TARGET_OBJECTS:OpenRaider_loader>
234
+    $<TARGET_OBJECTS:OpenRaider_utils> $<TARGET_OBJECTS:OpenRaider_system>
233 235
 )
234 236
 
235 237
 #################################################################

+ 46
- 79
src/Camera.cpp Parādīt failu

@@ -6,89 +6,56 @@
6 6
  * \author xythobuz
7 7
  */
8 8
 
9
+#include "glm/gtc/matrix_transform.hpp"
10
+
9 11
 #include "global.h"
10
-#include <cmath>
11
-#include "math/Matrix.h"
12 12
 #include "Camera.h"
13 13
 
14
-Camera::Camera() {
15
-    mViewDistance = 14.0f;
16
-    mRotationDeltaX = 1.0f;
17
-    mRotationDeltaY = 1.0f;
18
-    mTheta = 0.0f;
19
-    mTheta2 = 0.0f;
20
-
21
-    mPos[0] = 0.0f;
22
-    mPos[1] = 0.0f;
23
-    mPos[2] = 0.0f;
24
-
25
-    mTarget[0] = 0.0f;
26
-    mTarget[1] = 0.0f;
27
-    mTarget[2] = mViewDistance;
28
-
29
-    mQ.setIdentity();
30
-}
31
-
32
-void Camera::getTarget(float target[3]) {
33
-    target[0] = mTarget[0];
34
-    target[1] = mTarget[1];
35
-    target[2] = mTarget[2];
36
-}
37
-
38
-void Camera::setPosition(float pos[3]) {
39
-    mPos[0] = pos[0];
40
-    mPos[1] = pos[1];
41
-    mPos[2] = pos[2];
42
-}
43
-
44
-void Camera::update() {
45
-    mTarget[0] = (mViewDistance * std::sin(mTheta)) + mPos[0];
46
-    mTarget[1] = (mViewDistance * std::sin(mTheta2)) + mPos[1]; // + height_offset;
47
-    mTarget[2] = (mViewDistance * std::cos(mTheta)) + mPos[2];
48
-}
49
-
50
-void Camera::rotate(float angle, float x, float y, float z) {
51
-    Quaternion t, n;
52
-    float look[4] = { 0.0f, 0.0f, -1.0f, 1.0f };
53
-
54
-    t.set(angle, x, y, z);
55
-    n = mQ * t;
56
-    n.normalize();
57
-
58
-    Matrix matrix(n);
59
-    matrix.multiply4v(look, mTarget);
60
-
61
-    for (int i = 0; i < 3; ++i)
62
-        mTarget[i] += mPos[i];
63
-
64
-    mQ = n;
14
+glm::vec3 Camera::pos(0.0f, 0.0f, 0.0f);
15
+float Camera::thetaX = glm::pi<float>();
16
+float Camera::thetaY = 0.0f;
17
+float Camera::rotationDeltaX = 0.75f;
18
+float Camera::rotationDeltaY = 0.75f;
19
+
20
+void Camera::handleMouseMotion(int x, int y) {
21
+    while (x > 0) {
22
+        if (thetaX < (glm::pi<float>() / 2.0f)) {
23
+            thetaX += rotationDeltaX;
24
+        }
25
+        x--;
26
+    }
27
+    while (x < 0) {
28
+        if (thetaX > -(glm::pi<float>() / 2.0f)) {
29
+            thetaX -= rotationDeltaX;
30
+        }
31
+        x++;
32
+    }
33
+    while (y > 0) {
34
+        if (thetaY < (glm::pi<float>() / 2.0f)) {
35
+            thetaY += rotationDeltaY;
36
+        }
37
+        y--;
38
+    }
39
+    while (y < 0) {
40
+        if (thetaY > -(glm::pi<float>() / 2.0f)) {
41
+            thetaY -= rotationDeltaY;
42
+        }
43
+        y++;
44
+    }
65 45
 }
66 46
 
67
-void Camera::command(enum camera_command cmd) {
68
-    switch (cmd) {
69
-        case CAMERA_ROTATE_UP:
70
-            if (mTheta2 < (OR_PI / 2)) {
71
-                mTheta2 += mRotationDeltaY;
72
-                rotate(mTheta2, 1.0f, 0.0f, 0.0f);
73
-            }
74
-            break;
75
-
76
-        case CAMERA_ROTATE_DOWN:
77
-            if (mTheta2 > -(OR_PI / 2)) {
78
-                mTheta2 -= mRotationDeltaY;
79
-                rotate(mTheta2, 1.0f, 0.0f, 0.0f);
80
-            }
81
-            break;
82
-
83
-        case CAMERA_ROTATE_RIGHT:
84
-            mTheta += mRotationDeltaX;
85
-            rotate(mTheta, 0.0f, 1.0f, 0.0f);
86
-            break;
87
-
88
-        case CAMERA_ROTATE_LEFT:
89
-            mTheta -= mRotationDeltaX;
90
-            rotate(mTheta, 0.0f, 1.0f, 0.0f);
91
-            break;
92
-    }
47
+glm::mat4 Camera::getViewMatrix() {
48
+    glm::vec3 dir(
49
+        glm::cos(thetaY) * glm::sin(thetaX),
50
+        glm::sin(thetaY),
51
+        glm::cos(thetaY) * glm::cos(thetaX)
52
+    );
53
+    glm::vec3 right(
54
+        glm::sin(thetaX - glm::pi<float>() / 2.0f),
55
+        0.0f,
56
+        glm::cos(thetaX - glm::pi<float>() / 2.0f)
57
+    );
58
+    glm::vec3 up = glm::cross(right, dir);
59
+    return glm::lookAt(pos, pos + dir, up);
93 60
 }
94 61
 

+ 1
- 1
src/Console.cpp Parādīt failu

@@ -69,7 +69,7 @@ void Console::callback(ImGuiTextEditCallbackData* data) {
69 69
 }
70 70
 
71 71
 void Console::display() {
72
-    if (ImGui::Begin("Console", NULL, ImVec2(600, 400), -1.0f)) {
72
+    if (ImGui::Begin("Console", nullptr, ImVec2(600, 400), -1.0f)) {
73 73
         if (lastLogLength != getLog().size()) {
74 74
             lastLogLength = getLog().size();
75 75
             scrollToBottom = true;

+ 7
- 46
src/Entity.cpp Parādīt failu

@@ -5,16 +5,13 @@
5 5
  * \author xythobuz
6 6
  */
7 7
 
8
-#include <cmath>
8
+#include "glm/glm.hpp"
9 9
 
10 10
 #include "global.h"
11 11
 #include "Log.h"
12
-#include "Render.h"
13 12
 #include "World.h"
14 13
 #include "Entity.h"
15 14
 
16
-#include "games/TombRaider1.h"
17
-
18 15
 Entity::Entity(float p[3], float a[3], int id, long r, unsigned int model) {
19 16
     for (int i = 0; i < 3; i++) {
20 17
         pos[i] = p[i];
@@ -30,52 +27,16 @@ Entity::Entity(float p[3], float a[3], int id, long r, unsigned int model) {
30 27
     state = 0;
31 28
 }
32 29
 
33
-Entity::Entity(TombRaider& tr, unsigned int index, unsigned int i, unsigned int model) {
34
-    tr2_moveable_t* moveable = tr.Moveable();
35
-    tr2_item_t* item = tr.Item();
36
-
37
-    pos[0] = item[i].x;
38
-    pos[1] = item[i].y;
39
-    pos[2] = item[i].z;
40
-    angles[0] = 0;
41
-    angles[1] = OR_DEG_TO_RAD(((item[i].angle >> 14) & 0x03) * 90.0f);
42
-    angles[2] = 0;
43
-    objectId = moveable[index].object_id;
44
-    moveType = MoveTypeWalk;
45
-    room = getWorld().getRoomByLocation(pos[0], pos[1], pos[2]);
46
-    skeletalModel = model;
47
-    boneFrame = 0;
48
-    animationFrame = 0;
49
-    idleAnimation = 0;
50
-    state = 0;
51
-}
52
-
53
-bool Entity::operator<(Entity& o) {
54
-    float distA = getRender().getDistToSphereFromNear(pos[0], pos[1], pos[2], 1.0f);
55
-    float distB = getRender().getDistToSphereFromNear(o.pos[0], o.pos[1], o.pos[2], 1.0f);
56
-    return (distA < distB);
57
-}
58
-
59
-bool Entity::compare(Entity* a, Entity* b) {
60
-    return (*b) < (*a);
61
-}
62
-
63 30
 void Entity::display() {
31
+    /*
64 32
     glPushMatrix();
65 33
     glTranslatef(pos[0], pos[1], pos[2]);
66
-    glRotatef(OR_RAD_TO_DEG(angles[1]), 0, 1, 0);
67
-    glRotatef(OR_RAD_TO_DEG(angles[0]), 1, 0, 0);
68
-    //glRotatef(OR_RAD_TO_DEG(angles[2]), 0, 0, 1);
34
+    glRotatef(glm::degrees(angles[1]), 0, 1, 0);
35
+    glRotatef(glm::degrees(angles[0]), 1, 0, 0);
36
+    //glRotatef(glm::degrees(angles[2]), 0, 0, 1);
69 37
     getWorld().getSkeletalModel(skeletalModel).display(animationFrame, boneFrame);
70 38
     glPopMatrix();
71
-
72
-    // Cycle frames
73
-    if (getRender().getFlags() & Render::fAnimateAllModels) {
74
-        if (boneFrame < (getModel().get(animationFrame).size() - 1))
75
-            boneFrame++;
76
-        else
77
-            boneFrame = 0;
78
-    }
39
+    */
79 40
 }
80 41
 
81 42
 void Entity::move(char movement) {
@@ -233,7 +194,7 @@ void Entity::print() {
233 194
              << ")" << Log::endl
234 195
              << "  " << pos[0] << "x " << pos[1] << "y " << pos[2] << "z"
235 196
              << Log::endl
236
-             << "  " << OR_RAD_TO_DEG(angles[1]) << " Yaw" << Log::endl;
197
+             << "  " << glm::degrees(angles[1]) << " Yaw" << Log::endl;
237 198
 }
238 199
 
239 200
 SkeletalModel& Entity::getModel() {

+ 13
- 294
src/Game.cpp Parādīt failu

@@ -24,12 +24,6 @@
24 24
 #include "World.h"
25 25
 #include "utils/strings.h"
26 26
 
27
-#include "games/TombRaider1.h"
28
-
29
-#ifdef MULTITEXTURE
30
-std::map<int, int> gMapTex2Bump;
31
-#endif
32
-
33 27
 Game::Game() {
34 28
     mLoaded = false;
35 29
     mLara = -1;
@@ -40,22 +34,21 @@ Game::~Game() {
40 34
 
41 35
 int Game::initialize() {
42 36
     // Enable Renderer
43
-    getRender().setMode(Render::modeLoadScreen);
37
+    Render::setMode(RenderMode::LoadScreen);
44 38
 
45 39
     return 0;
46 40
 }
47 41
 
48 42
 void Game::display() {
49
-    getRender().display();
43
+    Render::display();
50 44
 }
51 45
 
52 46
 void Game::destroy() {
53 47
     mLoaded = false;
54 48
     mLara = -1;
55
-    getRender().setMode(Render::modeLoadScreen);
49
+    Render::setMode(RenderMode::LoadScreen);
56 50
 
57 51
     getWorld().destroy();
58
-    getRender().ClearWorld();
59 52
     Sound::clear(); // Remove all previously loaded sounds
60 53
     SoundManager::clear();
61 54
     getTextureManager().clear();
@@ -67,20 +60,17 @@ bool Game::isLoaded() {
67 60
 
68 61
 int Game::loadLevel(const char* level) {
69 62
     destroy();
70
-
71 63
     levelName = level;
72
-
73 64
     getLog() << "Loading " << levelName << Log::endl;
74
-
75
-    int error = 0;
76 65
     auto loader = Loader::createLoader(level);
77 66
     if (loader) {
78 67
         // First Loader test
79 68
         getLog() << "Trying to load using new loader..." << Log::endl;
80
-        error = loader->load(level);
69
+        int error = loader->load(level);
81 70
         if (error != 0) {
82 71
             getLog() << "Error while trying new loader (" << error << ")..." << Log::endl;
83 72
             destroy();
73
+            return -2;
84 74
         } else {
85 75
             SoundManager::prepareSources();
86 76
 
@@ -88,54 +78,16 @@ int Game::loadLevel(const char* level) {
88 78
                 getLog() << "Can't find Lara entity in level?!" << Log::endl;
89 79
             } else {
90 80
                 mLoaded = true;
91
-                //getRender().setMode(Render::modeVertexLight);
81
+                //Render::setMode(RenderMode::Texture);
92 82
             }
93 83
 
94 84
             UI::setVisible(true);
85
+            return 0;
95 86
         }
87
+    } else {
88
+        getLog() << "No suitable loader for this level!" << Log::endl;
89
+        return -1;
96 90
     }
97
-
98
-    if ((!loader) || (error != 0)) {
99
-        getLog() << "Falling back to old level loader..." << Log::endl;
100
-        error = mTombRaider.Load(levelName.c_str());
101
-        if (error != 0)
102
-            return error;
103
-
104
-        // If required, load the external sound effect file MAIN.SFX into TombRaider
105
-        if ((mTombRaider.getEngine() == TR_VERSION_2) || (mTombRaider.getEngine() == TR_VERSION_3)) {
106
-            std::string tmp(levelName);
107
-            size_t pos = tmp.rfind('/');
108
-            tmp.erase(pos + 1);
109
-            tmp += "MAIN.SFX";
110
-            error = mTombRaider.loadSFX(tmp.c_str());
111
-            if (error != 0)
112
-                getLog() << "Could not load SFX " << tmp << Log::endl;
113
-            else
114
-                getLog() << "Loaded external SFX file!" << Log::endl;
115
-        }
116
-
117
-        // Process data
118
-        processTextures();
119
-        processRooms();
120
-        processModels();
121
-        processSprites();
122
-        processMoveables();
123
-        processPakSounds();
124
-
125
-        mTombRaider.reset();
126
-
127
-        if (mLara == -1) {
128
-            //! \todo Cutscene support
129
-            getLog() << "Can't find Lara entity in level pak!" << Log::endl;
130
-            //destroy();
131
-            return -1;
132
-        } else {
133
-            mLoaded = true;
134
-            getRender().setMode(Render::modeVertexLight);
135
-        }
136
-    }
137
-
138
-    return 0;
139 91
 }
140 92
 
141 93
 void Game::handleAction(ActionEvents action, bool isFinished) {
@@ -164,25 +116,12 @@ void Game::handleAction(ActionEvents action, bool isFinished) {
164 116
 
165 117
 void Game::handleMouseMotion(int xrel, int yrel, int xabs, int yabs) {
166 118
     if (mLoaded) {
167
-        // Move Camera on X Axis
168
-        if (xrel > 0)
169
-            while (xrel-- > 0)
170
-                getCamera().command(CAMERA_ROTATE_RIGHT);
171
-        else if (xrel < 0)
172
-            while (xrel++ < 0)
173
-                getCamera().command(CAMERA_ROTATE_LEFT);
174
-
175
-        // Move Camera on Y Axis
176
-        if (yrel > 0)
177
-            while (yrel-- > 0)
178
-                getCamera().command(CAMERA_ROTATE_UP);
179
-        else if (yrel < 0)
180
-            while (yrel++ < 0)
181
-                getCamera().command(CAMERA_ROTATE_DOWN);
119
+        Camera::handleMouseMotion(xrel, yrel);
182 120
 
183
-        // Fix Laras rotation
121
+        /*
184 122
         float angles[3] = { 0.0f, getCamera().getRadianYaw(), getCamera().getRadianPitch() };
185 123
         getLara().setAngles(angles);
124
+        */
186 125
     }
187 126
 }
188 127
 
@@ -198,223 +137,3 @@ void Game::setLara(long lara) {
198 137
     mLara = lara;
199 138
 }
200 139
 
201
-void Game::processSprites() {
202
-    for (int i = 0; i < (mTombRaider.NumItems() - 1); i++) {
203
-        if ((mTombRaider.Engine() == TR_VERSION_1) && (mTombRaider.Item()[i].intensity1 == -1))
204
-            continue;
205
-
206
-        for (int j = 0; j < mTombRaider.NumSpriteSequences(); j++) {
207
-            if (mTombRaider.SpriteSequence()[j].object_id == mTombRaider.Item()[i].object_id)
208
-                getWorld().addSprite(new SpriteSequence(mTombRaider, i, j));
209
-        }
210
-    }
211
-
212
-    getLog() << "Found " << mTombRaider.NumSpriteSequences() << " sprites." << Log::endl;
213
-}
214
-
215
-void Game::processRooms() {
216
-    for (int index = 0; index < mTombRaider.NumRooms(); index++)
217
-        getWorld().addRoom(new Room(mTombRaider, index));
218
-
219
-    getLog() << "Found " << mTombRaider.NumRooms() << " rooms." << Log::endl;
220
-}
221
-
222
-void Game::processModels() {
223
-    for (int index = 0; index < mTombRaider.getMeshCount(); index++)
224
-        getWorld().addStaticMesh(new StaticMesh(mTombRaider, index));
225
-
226
-    getLog() << "Found " << mTombRaider.getMeshCount() << " meshes." << Log::endl;
227
-}
228
-
229
-void Game::processPakSounds() {
230
-    unsigned char* riff;
231
-    unsigned int riffSz;
232
-    //tr2_sound_source_t *sound;
233
-    //tr2_sound_details_t *detail;
234
-    //float pos[3];
235
-    unsigned int i;
236
-    unsigned long id;
237
-
238
-    /* detail
239
-       short sample;
240
-       short volume;
241
-       short sound_range;
242
-       short flags;         // bits 8-15: priority?, 2-7: number of sound samples
243
-    // in this group, bits 0-1: channel number
244
-    */
245
-
246
-    for (i = 0; i < mTombRaider.getSoundSamplesCount(); ++i) {
247
-        mTombRaider.getSoundSample(i, &riffSz, &riff);
248
-
249
-        id = Sound::loadBuffer(riff, riffSz);
250
-
251
-        //if (((i + 1) == TR_SOUND_F_PISTOL) && (id > 0))
252
-        //{
253
-        //m_testSFX = id;
254
-        //}
255
-
256
-        delete [] riff;
257
-
258
-        // sound[i].sound_id; // internal sound index
259
-        // sound[i].flags;  // 0x40, 0x80, or 0xc0
260
-        //pos[0] = sound[i].x;
261
-        //pos[1] = sound[i].y;
262
-        //pos[2] = sound[i].z;
263
-        //getSound().SourceAt(id, pos);
264
-    }
265
-
266
-    getLog() << "Found " << mTombRaider.getSoundSamplesCount() << " sound samples." << Log::endl;
267
-}
268
-
269
-void Game::processTextures() {
270
-    unsigned char* image;
271
-    unsigned char* bumpmap;
272
-    int i;
273
-
274
-    //if ( mTombRaider.getNumBumpMaps())
275
-    //  gBumpMapStart = mTombRaider.NumTextures();
276
-
277
-    for (i = 0; i < mTombRaider.NumTextures(); ++i) {
278
-        mTombRaider.Texture(i, &image, &bumpmap);
279
-
280
-        // Overwrite any previous level textures on load
281
-        getTextureManager().loadBufferSlot(image, 256, 256,
282
-                                           RGBA, 32, TextureManager::TextureStorage::GAME, i);
283
-
284
-#ifdef MULTITEXTURE
285
-        gMapTex2Bump[i] = -1;
286
-#endif
287
-
288
-        if (bumpmap) {
289
-#ifdef MULTITEXTURE
290
-            gMapTex2Bump[i] = i + mTombRaider.NumTextures();
291
-#endif
292
-            getTextureManager().loadBufferSlot(bumpmap, 256, 256,
293
-                                               RGBA, 32, TextureManager::TextureStorage::GAME,
294
-                                               i + mTombRaider.NumTextures());
295
-        }
296
-
297
-        if (image)
298
-            delete [] image;
299
-
300
-        if (bumpmap)
301
-            delete [] bumpmap;
302
-    }
303
-
304
-    getLog() << "Found " << mTombRaider.NumTextures() << " textures." << Log::endl;
305
-}
306
-
307
-void Game::processMoveables() {
308
-    unsigned int statCount = 0;
309
-
310
-    tr2_moveable_t* moveable = mTombRaider.Moveable();
311
-    tr2_item_t* item = mTombRaider.Item();
312
-    tr2_sprite_sequence_t* sprite_sequence = mTombRaider.SpriteSequence();
313
-
314
-    for (int i = 0; i < mTombRaider.NumItems(); ++i) {
315
-        int j;
316
-        int object_id = item[i].object_id;
317
-
318
-        // It may not be a moveable, test for sprite
319
-        if (!(mTombRaider.Engine() == TR_VERSION_1 && item[i].intensity1 == -1)) {
320
-            for (j = 0; j < (int)mTombRaider.NumSpriteSequences(); ++j) {
321
-                if (sprite_sequence[j].object_id == object_id)
322
-                    break;
323
-            }
324
-
325
-            // It's not a moveable, skip sprite
326
-            if (j < (int)mTombRaider.NumSpriteSequences())
327
-                continue;
328
-        }
329
-
330
-        for (j = 0; j < (int)mTombRaider.NumMoveables(); ++j) {
331
-            if ((int)moveable[j].object_id == object_id)
332
-                break;
333
-        }
334
-
335
-        // It's not a moveable or even a sprite? Skip unknown
336
-        if (j == (int)mTombRaider.NumMoveables())
337
-            continue;
338
-
339
-        processMoveable(j, i, object_id);
340
-        statCount++;
341
-    }
342
-
343
-    /*
344
-    // Get models that aren't items
345
-    for (int i = 0; i < mTombRaider.NumMoveables(); ++i)
346
-    {
347
-        switch ((int)moveable[i].object_id)
348
-        {
349
-            case 30:
350
-            case 2: // Which tr needs this as model again?
351
-                processMoveable(i, i, (int)moveable[i].object_id);
352
-                break;
353
-            default:
354
-                switch (mTombRaider.Engine())
355
-                {
356
-                    case TR_VERSION_1:
357
-                        switch ((int)moveable[i].object_id)
358
-                        {
359
-                            case TombRaider1::LaraMutant:
360
-                                processMoveable(i, i, (int)moveable[i].object_id);
361
-                                break;
362
-                        }
363
-                        break;
364
-                    case TR_VERSION_4:
365
-                        switch ((int)moveable[i].object_id)
366
-                        {
367
-                            case TR4_PISTOLS_ANIM:
368
-                            case TR4_UZI_ANIM:
369
-                            case TR4_SHOTGUN_ANIM:
370
-                            case TR4_CROSSBOW_ANIM:
371
-                            case TR4_GRENADE_GUN_ANIM:
372
-                            case TR4_SIXSHOOTER_ANIM:
373
-                                processMoveable(i, i, (int)moveable[i].object_id);
374
-                                break;
375
-                        }
376
-                        break;
377
-                    case TR_VERSION_2:
378
-                    case TR_VERSION_3:
379
-                    case TR_VERSION_5:
380
-                    case TR_VERSION_UNKNOWN:
381
-                        break;
382
-                }
383
-        }
384
-    }
385
-    */
386
-
387
-    getLog() << "Found " << mTombRaider.NumMoveables() + statCount << " moveables." << Log::endl;
388
-}
389
-
390
-// index moveable, i item, sometimes both moveable
391
-// object_id of item or moveable
392
-void Game::processMoveable(int index, int i, int object_id) {
393
-    // Check if the SkeletalModel is already cached
394
-    bool cached = false;
395
-    unsigned int model;
396
-    for (model = 0; model < getWorld().sizeSkeletalModel(); model++) {
397
-        if (getWorld().getSkeletalModel(model).getId() == object_id) {
398
-            cached = true;
399
-            break;
400
-        }
401
-    }
402
-
403
-    // Create a new SkeletalModel, if needed
404
-    if (!cached)
405
-        getWorld().addSkeletalModel(new SkeletalModel(mTombRaider, index, object_id));
406
-
407
-    // Create a new Entity, using the cached or the new SkeletalModel
408
-    Entity* entity = new Entity(mTombRaider, index, i, model);
409
-    getWorld().addEntity(entity);
410
-
411
-    // Store reference to Lara
412
-    if (entity->getObjectId() == 0)
413
-        mLara = getWorld().sizeEntity() - 1;
414
-
415
-    // Store reference to the SkyMesh
416
-    if (i == mTombRaider.getSkyModelId())
417
-        getRender().setSkyMesh(i, //moveable[i].starting_mesh,
418
-                               (mTombRaider.Engine() == TR_VERSION_2));
419
-}
420
-

+ 2
- 0
src/Menu.cpp Parādīt failu

@@ -142,10 +142,12 @@ void Menu::displayDialog() {
142 142
         unsigned int xOverlay = (::getWindow().getWidth() - wOverlay) / 2;
143 143
         unsigned int yOverlay = (::getWindow().getHeight() - hOverlay) / 2;
144 144
 
145
+        /*
145 146
         glColor4f(0.0f, 0.0f, 0.0f, 0.75f);
146 147
         glDisable(GL_TEXTURE_2D);
147 148
         glRecti(xOverlay, yOverlay, xOverlay + wOverlay, yOverlay + hOverlay);
148 149
         glEnable(GL_TEXTURE_2D);
150
+        */
149 151
 
150 152
         Font::drawTextWrapped(xOverlay + 10, yOverlay + 5, 1.0f, BLUE, w0, dialogText);
151 153
         if (dialogButton2.length() > 0) {

+ 7
- 9
src/MenuFolder.cpp Parādīt failu

@@ -9,6 +9,7 @@
9 9
 #include "Game.h"
10 10
 #include "loader/Loader.h"
11 11
 #include "Log.h"
12
+#include "Render.h"
12 13
 #include "RunTime.h"
13 14
 #include "MenuFolder.h"
14 15
 #include "system/Font.h"
@@ -76,19 +77,18 @@ void MenuFolder::display() {
76 77
     if (!visible)
77 78
         return;
78 79
 
79
-    ::getWindow().glEnter2D();
80
+    Font::drawTextCentered(0, 10, 1.2f, BLUE, ::getWindow().getWidth(), VERSION);
80 81
 
81 82
     // Draw half-transparent overlay
82
-    glColor4f(0.0f, 0.0f, 0.0f, 0.75f);
83
-    glDisable(GL_TEXTURE_2D);
84
-    glRecti(0, 0, (GLint)::getWindow().getWidth(), (GLint)::getWindow().getHeight());
85
-    glEnable(GL_TEXTURE_2D);
83
+    glm::vec4 color(0.0f, 0.0f, 0.0f, 0.75f);
84
+    Render::drawTexture(0.0f, 0.0f, getWindow().getWidth(), getWindow().getHeight(),
85
+                    color, TEXTURE_WHITE, TextureManager::TextureStorage::SYSTEM);
86 86
 
87 87
     // Draw heading
88
-    Font::drawTextCentered(0, 10, 1.2f, BLUE, ::getWindow().getWidth(), VERSION);
88
+    Font::drawTextCentered(0, 10, 1.2f, BLUE, getWindow().getWidth(), VERSION);
89 89
 
90 90
     // Estimate displayable number of items
91
-    int items = (::getWindow().getHeight() - 60) / 25;
91
+    int items = (getWindow().getHeight() - 60) / 25;
92 92
 
93 93
     // Print list of "..", folders, files
94 94
     for (long i = mMin; (i < (mMin + items))
@@ -105,8 +105,6 @@ void MenuFolder::display() {
105 105
     }
106 106
 
107 107
     displayDialog();
108
-
109
-    ::getWindow().glExit2D();
110 108
 }
111 109
 
112 110
 void MenuFolder::loadOrOpen() {

+ 94
- 54
src/Mesh.cpp Parādīt failu

@@ -11,23 +11,25 @@
11 11
 #include "TextureManager.h"
12 12
 #include "Mesh.h"
13 13
 
14
-void Mesh::addTexturedRectangle(Vec3 a, Vec3 b, Vec3 c, Vec3 d, uint16_t textile) {
14
+void Mesh::addTexturedRectangle(glm::vec3 a, glm::vec3 b, glm::vec3 c, glm::vec3 d,
15
+                                uint16_t textile) {
15 16
     texturedRectangles.emplace_back(a, b, c, d, textile);
16 17
 }
17 18
 
18
-void Mesh::addTexturedTriangle(Vec3 a, Vec3 b, Vec3 c, uint16_t textile) {
19
-    texturedTriangles.emplace_back(a, b, c, Vec3(), textile);
19
+void Mesh::addTexturedTriangle(glm::vec3 a, glm::vec3 b, glm::vec3 c, uint16_t textile) {
20
+    texturedTriangles.emplace_back(a, b, c, glm::vec3(), textile);
20 21
 }
21 22
 
22
-void Mesh::addColoredRectangle(Vec3 a, Vec3 b, Vec3 c, Vec3 d, float re, float gr, float bl) {
23
+void Mesh::addColoredRectangle(glm::vec3 a, glm::vec3 b, glm::vec3 c, glm::vec3 d, float re,
24
+                               float gr, float bl) {
23 25
     coloredRectangles.emplace_back(a, b, c, d, -1, re, gr, bl);
24 26
 }
25 27
 
26
-void Mesh::addColoredTriangle(Vec3 a, Vec3 b, Vec3 c, float re, float gr, float bl) {
27
-    coloredTriangles.emplace_back(a, b, c, Vec3(), -1, re, gr, bl);
28
+void Mesh::addColoredTriangle(glm::vec3 a, glm::vec3 b, glm::vec3 c, float re, float gr, float bl) {
29
+    coloredTriangles.emplace_back(a, b, c, glm::vec3(), -1, re, gr, bl);
28 30
 }
29 31
 
30
-void Mesh::addNormal(Vec3 n) {
32
+void Mesh::addNormal(glm::vec3 n) {
31 33
     normals.emplace_back(n);
32 34
 }
33 35
 
@@ -54,10 +56,10 @@ void Mesh::drawSolid() {
54 56
         return;
55 57
     }
56 58
 
57
-    // Render textured quads
58 59
     for (auto& q : texturedRectangles) {
59 60
         if (mMode == MeshModeWireframe) {
60 61
             getTextureManager().bindTextureId(TEXTURE_WHITE, TextureManager::TextureStorage::SYSTEM);
62
+            /*
61 63
             glBegin(GL_QUADS);
62 64
             glTexCoord2f(0.0f, 0.0f);
63 65
             glVertex3f(q.a.x, q.a.y, q.a.z);
@@ -68,8 +70,73 @@ void Mesh::drawSolid() {
68 70
             glTexCoord2f(0.0f, 1.0f);
69 71
             glVertex3f(q.d.x, q.d.y, q.d.z);
70 72
             glEnd();
73
+            */
74
+        } else if (mMode == MeshModeSolid) {
75
+            // TODO
71 76
         } else if (mMode == MeshModeTexture) {
72
-            getTextureManager().getTile(q.texture).displayRectangle(q.a, q.b, q.c, q.d);
77
+            //getTextureManager().getTile(q.texture).displayRectangle(q.a, q.b, q.c, q.d);
78
+        }
79
+    }
80
+
81
+    for (auto& t : texturedTriangles) {
82
+        if (mMode == MeshModeWireframe) {
83
+            getTextureManager().bindTextureId(TEXTURE_WHITE, TextureManager::TextureStorage::SYSTEM);
84
+            /*
85
+            glBegin(GL_TRIANGLES);
86
+            glTexCoord2f(0.0f, 0.0f);
87
+            glVertex3f(t.a.x, t.a.y, t.a.z);
88
+            glTexCoord2f(1.0f, 0.0f);
89
+            glVertex3f(t.b.x, t.b.y, t.b.z);
90
+            glTexCoord2f(1.0f, 1.0f);
91
+            glVertex3f(t.c.x, t.c.y, t.c.z);
92
+            glEnd();
93
+            */
94
+        } else if (mMode == MeshModeSolid) {
95
+            // TODO
96
+        } else if (mMode == MeshModeTexture) {
97
+            //getTextureManager().getTile(t.texture).displayTriangle(t.a, t.b, t.c);
98
+        }
99
+    }
100
+
101
+    for (auto& q : coloredRectangles) {
102
+        if (mMode == MeshModeWireframe) {
103
+            getTextureManager().bindTextureId(TEXTURE_WHITE, TextureManager::TextureStorage::SYSTEM);
104
+            /*
105
+            glBegin(GL_QUADS);
106
+            glTexCoord2f(0.0f, 0.0f);
107
+            glVertex3f(q.a.x, q.a.y, q.a.z);
108
+            glTexCoord2f(1.0f, 0.0f);
109
+            glVertex3f(q.b.x, q.b.y, q.b.z);
110
+            glTexCoord2f(1.0f, 1.0f);
111
+            glVertex3f(q.c.x, q.c.y, q.c.z);
112
+            glTexCoord2f(0.0f, 1.0f);
113
+            glVertex3f(q.d.x, q.d.y, q.d.z);
114
+            glEnd();
115
+            */
116
+        } else if (mMode == MeshModeSolid) {
117
+            // TODO
118
+        } else if (mMode == MeshModeTexture) {
119
+            // TODO
120
+        }
121
+    }
122
+
123
+    for (auto& t : coloredTriangles) {
124
+        if (mMode == MeshModeWireframe) {
125
+            getTextureManager().bindTextureId(TEXTURE_WHITE, TextureManager::TextureStorage::SYSTEM);
126
+            /*
127
+            glBegin(GL_TRIANGLES);
128
+            glTexCoord2f(0.0f, 0.0f);
129
+            glVertex3f(t.a.x, t.a.y, t.a.z);
130
+            glTexCoord2f(1.0f, 0.0f);
131
+            glVertex3f(t.b.x, t.b.y, t.b.z);
132
+            glTexCoord2f(1.0f, 1.0f);
133
+            glVertex3f(t.c.x, t.c.y, t.c.z);
134
+            glEnd();
135
+            */
136
+        } else if (mMode == MeshModeSolid) {
137
+            // TODO
138
+        } else if (mMode == MeshModeTexture) {
139
+            // TODO
73 140
         }
74 141
     }
75 142
 }
@@ -114,17 +181,17 @@ Mesh::~Mesh() {
114 181
     for (unsigned int i = 0; i < mNumVertices; i++)
115 182
         delete [] mVertices[i];
116 183
     delete [] mVertices;
117
-    mVertices = NULL;
184
+    mVertices = nullptr;
118 185
 
119 186
     for (unsigned int i = 0; i < mNumNormals; i++)
120 187
         delete [] mNormals[i];
121 188
     delete [] mNormals;
122
-    mNormals = NULL;
189
+    mNormals = nullptr;
123 190
 
124 191
     for (unsigned int i = 0; i < mNumColors; i++)
125 192
         delete [] mColors[i];
126 193
     delete [] mColors;
127
-    mColors = NULL;
194
+    mColors = nullptr;
128 195
 
129 196
     if (mTris) {
130 197
         for (unsigned int i = 0; i < mNumTris; ++i) {
@@ -135,7 +202,7 @@ Mesh::~Mesh() {
135 202
         }
136 203
 
137 204
         delete [] mTris;
138
-        mTris = NULL;
205
+        mTris = nullptr;
139 206
     }
140 207
 
141 208
     if (mQuads) {
@@ -147,29 +214,29 @@ Mesh::~Mesh() {
147 214
         }
148 215
 
149 216
         delete [] mQuads;
150
-        mQuads = NULL;
217
+        mQuads = nullptr;
151 218
     }
152 219
 
153 220
     delete [] mVertexArray;
154
-    mVertexArray = NULL;
221
+    mVertexArray = nullptr;
155 222
 
156 223
     delete [] mNormalArray;
157
-    mNormalArray = NULL;
224
+    mNormalArray = nullptr;
158 225
 
159 226
     delete [] mColorArray;
160
-    mColorArray = NULL;
227
+    mColorArray = nullptr;
161 228
 
162 229
     delete [] mTriangleTextures;
163
-    mTriangleTextures = NULL;
230
+    mTriangleTextures = nullptr;
164 231
 
165 232
     delete [] mTriangleIndices;
166
-    mTriangleIndices = NULL;
233
+    mTriangleIndices = nullptr;
167 234
 
168 235
     delete [] mTriangleFlags;
169
-    mTriangleFlags = NULL;
236
+    mTriangleFlags = nullptr;
170 237
 
171 238
     delete [] mTriangleTexCoordArray;
172
-    mTriangleTexCoordArray = NULL;
239
+    mTriangleTexCoordArray = nullptr;
173 240
 }
174 241
 
175 242
 
@@ -180,6 +247,7 @@ Mesh::~Mesh() {
180 247
 void Mesh::drawAlphaOld() {
181 248
     unsigned int i, j, k, index;
182 249
 
250
+    /*
183 251
 
184 252
     // Render quadralaterals
185 253
     for (mQuads ? i = 0 : i = mNumQuads; i < mNumQuads; ++i) {
@@ -246,46 +314,16 @@ void Mesh::drawAlphaOld() {
246 314
 
247 315
         glEnd();
248 316
     }
317
+
318
+    */
249 319
 }
250 320
 
251 321
 
252 322
 void Mesh::drawSolidOld() {
253 323
     unsigned int i, j, k, index;
254 324
 
325
+    /*
255 326
 
256
-    if (mFlags & fMesh_UseVertexArray) {
257
-        //glEnableClientState(GL_VERTEX_ARRAY);
258
-        //glVertexPointer(3, GL_FLOAT, 0, mVertexArray);
259
-
260
-        glPointSize(2.0f);
261
-        glColor3f(1.0f, 1.0f, 1.0f);
262
-        glBegin(GL_TRIANGLES);
263
-
264
-        for (i = 0; i < mTriangleCount * 3; ++i) {
265
-            //glArrayElement(mTriangleIndices[i]);
266
-            glVertex3fv(mVertexArray + mTriangleIndices[i]);
267
-        }
268
-
269
-        glEnd();
270
-
271
-        glPointSize(1.0f);
272
-
273
-        //! \fixme
274
-        /*
275
-        for (j = 0; j < mQuads[i].num_quads; ++j)
276
-        {
277
-            for (k = 0; k < 4; ++k)
278
-            {
279
-                index = mQuads[i].quads[j*4+k];
280
-
281
-                glTexCoord2fv(mQuads[i].texcoors[j*4+k]);
282
-                glArrayElement(mQuads[i].quads[j*4+k]);
283
-            }
284
-        }
285
-        */
286
-
287
-        return;
288
-    }
289 327
 
290 328
     // Render quadralaterals
291 329
     for (mQuads ? i = 0 : i = mNumQuads; i < mNumQuads; ++i) {
@@ -402,6 +440,8 @@ void Mesh::drawSolidOld() {
402 440
         glActiveTextureARB(GL_TEXTURE0_ARB);
403 441
     }
404 442
 #endif
443
+
444
+    */
405 445
 }
406 446
 
407 447
 

+ 63
- 511
src/Render.cpp Parādīt failu

@@ -22,556 +22,108 @@
22 22
 #include "World.h"
23 23
 #include "system/Window.h"
24 24
 
25
-Render::Render() {
26
-    mSkyMesh = -1;
27
-    mSkyMeshRotation = false;
28
-    mMode = Render::modeDisabled;
29
-    mLock = 0;
30
-    mFlags = (fRoomAlpha | fEntityModels | fRenderPonytail);
25
+RenderMode Render::mode = RenderMode::Disabled;
31 26
 
32
-    debugTexture = -1;
33
-    debugTextile = -1;
34
-    debugSprite = -1;
35
-    debugTextureStorage = TextureManager::TextureStorage::GAME;
36
-    debugSpriteOffset = 0;
37
-    debugX = 0.0f;
38
-    debugY = 0.0f;
39
-    debugW = 256.0f;
40
-    debugH = 256.0f;
27
+RenderMode Render::getMode() {
28
+    return mode;
41 29
 }
42 30
 
43
-Render::~Render() {
44
-    ClearWorld();
45
-}
46
-
47
-void Render::ClearWorld() {
48
-    mRoomRenderList.clear();
49
-}
50
-
51
-void Render::screenShot(const char* filenameBase) {
52
-    int sz = getWindow().getWidth() * getWindow().getHeight();
53
-    unsigned char* image = new unsigned char[sz * 3];
54
-    static int count = 0;
55
-    bool done = false;
56
-
57
-    assert(filenameBase != nullptr);
58
-
59
-    // Don't overwrite files
60
-    std::ostringstream filename;
61
-    while (!done) {
62
-        filename << filenameBase << "-" << count++ << ".tga";
63
-
64
-        FILE* f = fopen(filename.str().c_str(), "rb");
65
-        if (f) {
66
-            fclose(f);
67
-        } else {
68
-            done = true;
69
-        }
70
-    }
71
-
72
-    glReadPixels(0, 0, getWindow().getWidth(), getWindow().getHeight(), GL_BGR_EXT, GL_UNSIGNED_BYTE,
73
-                 image);
74
-    tgaSave(filename.str().c_str(), image, getWindow().getWidth(), getWindow().getHeight(), 0);
75
-    delete [] image;
76
-}
77
-
78
-unsigned int Render::getFlags() {
79
-    return mFlags;
80
-}
81
-
82
-void Render::lightRoom(Room& room) {
83
-    for (unsigned int i = 0; i < room.sizeLights(); ++i) {
84
-        Light& light = room.getLight(i);
85
-        float pos[4], color[4];
86
-        float dir[3];
87
-        light.getPos(pos);
88
-        light.getColor(color);
89
-        light.getDir(dir);
90
-
91
-        glEnable(GL_LIGHT0 + i);
92
-
93
-        switch (light.getType()) {
94
-            case Light::typeSpot:
95
-                glLightf(GL_LIGHT0 + i,  GL_SPOT_CUTOFF,    light.getCutoff());
96
-                glLightfv(GL_LIGHT0 + i, GL_POSITION,       pos);
97
-                glLightfv(GL_LIGHT0 + i, GL_SPOT_DIRECTION, dir);
98
-                glLightfv(GL_LIGHT0 + i, GL_DIFFUSE,        color);
99
-                break;
100
-            case Light::typePoint:
101
-            case Light::typeDirectional:
102
-                glLightf(GL_LIGHT0 + i, GL_CONSTANT_ATTENUATION, 1.0); // 1.0
103
-
104
-                // GL_QUADRATIC_ATTENUATION
105
-                // GL_LINEAR_ATTENUATION
106
-                glLightf(GL_LIGHT0 + i, GL_LINEAR_ATTENUATION, light.getAtt());
107
-
108
-                glLightfv(GL_LIGHT0 + i, GL_DIFFUSE, color); // GL_DIFFUSE
109
-                glLightfv(GL_LIGHT0 + i, GL_POSITION, pos);
110
-                break;
111
-        }
112
-    }
113
-}
114
-
115
-void Render::clearFlags(unsigned int flags) {
116
-    mFlags &= ~flags;
117
-
118
-    if (flags & Render::fFog) {
119
-        if (glIsEnabled(GL_FOG)) {
120
-            glDisable(GL_FOG);
121
-        }
122
-    }
123
-
124
-    if (flags & Render::fGL_Lights) {
125
-        glDisable(GL_LIGHTING);
126
-    }
127
-}
128
-
129
-void Render::setFlags(unsigned int flags) {
130
-    mFlags |= flags;
131
-
132
-    if (flags & Render::fFog) {
133
-        glEnable(GL_FOG);
134
-        glFogf(GL_FOG_MODE, GL_EXP2);
135
-        glFogf(GL_FOG_DENSITY, 0.00008f);
136
-        glFogf(GL_FOG_START, 30000.0f);
137
-        glFogf(GL_FOG_END, 50000.0f);
138
-
139
-        float color[4];
140
-        color[0] = BLACK[0] * 256.0f;
141
-        color[1] = BLACK[1] * 256.0f;
142
-        color[2] = BLACK[2] * 256.0f;
143
-        color[3] = BLACK[3] * 256.0f;
144
-        glFogfv(GL_FOG_COLOR, color);
145
-    }
146
-
147
-    if (flags & Render::fGL_Lights) {
148
-        float color[4];
149
-        color[0] = WHITE[0] * 256.0f;
150
-        color[1] = WHITE[1] * 256.0f;
151
-        color[2] = WHITE[2] * 256.0f;
152
-        color[3] = WHITE[3] * 256.0f;
153
-
154
-        glEnable(GL_LIGHTING);
155
-        glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0);
156
-        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color);
157
-        glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color);
158
-
159
-        color[0] = GREY[0] * 256.0f;
160
-        color[1] = GREY[1] * 256.0f;
161
-        color[2] = GREY[2] * 256.0f;
162
-        color[3] = GREY[3] * 256.0f;
163
-        glLightModelfv(GL_LIGHT_MODEL_AMBIENT, color);
164
-    }
165
-}
166
-
167
-int Render::getMode() {
168
-    return mMode;
169
-}
170
-
171
-void Render::setMode(int n) {
172
-    mMode = n;
173
-
174
-    switch (mMode) {
175
-        case Render::modeDisabled:
31
+void Render::setMode(RenderMode m) {
32
+    mode = m;
33
+    switch (mode) {
34
+        case RenderMode::Disabled:
176 35
             break;
177
-        case Render::modeSolid:
178
-        case Render::modeWireframe:
36
+        case RenderMode::Solid:
37
+        case RenderMode::Wireframe:
179 38
             glClearColor(PURPLE[0] / 256.0f, PURPLE[1] / 256.0f,
180 39
                          PURPLE[2] / 256.0f, PURPLE[3] / 256.0f);
181
-            glDisable(GL_TEXTURE_2D);
40
+            //glDisable(GL_TEXTURE_2D);
182 41
             break;
183 42
         default:
184
-            if (mMode == Render::modeLoadScreen) {
185
-                glBlendFunc(GL_SRC_ALPHA, GL_ONE);
186
-            } else {
187
-                glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
188
-            }
189
-
190 43
             glClearColor(BLACK[0] / 256.0f, BLACK[1] / 256.0f,
191 44
                          BLACK[2] / 256.0f, BLACK[3] / 256.0f);
192
-
193
-            glEnable(GL_TEXTURE_2D);
45
+            //glEnable(GL_TEXTURE_2D);
194 46
     }
195 47
 }
196 48
 
197 49
 void Render::display() {
198
-    switch (mMode) {
199
-        case Render::modeDisabled:
200
-            return;
201
-        case Render::modeLoadScreen:
202
-            drawLoadScreen();
203
-            return;
204
-        default:
205
-            break;
206
-    }
207
-
208
-    if (mMode == Render::modeWireframe)
209
-        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
210
-    else
211
-        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
212
-
213
-    float camOffsetH = 0.0f;
214
-
215
-    switch (getGame().getLara().getMoveType()) {
216
-        case Entity::MoveTypeFly:
217
-        case Entity::MoveTypeNoClipping:
218
-        case Entity::MoveTypeSwim:
219
-            //camOffsetH = 64.0f;
220
-            camOffsetH = 512.0f;
221
-            break;
222
-        case Entity::MoveTypeWalk:
223
-        case Entity::MoveTypeWalkNoSwim:
224
-            camOffsetH = 512.0f;
225
-            break;
226
-    }
227
-
228
-    float curPos[3], camPos[3], atPos[3];
229
-
230
-    curPos[0] = getGame().getLara().getPos(0);
231
-    curPos[1] = getGame().getLara().getPos(1);
232
-    curPos[2] = getGame().getLara().getPos(2);
233
-    float yaw = getGame().getLara().getAngle(1);
234
-
235
-    // Mongoose 2002.08.24, New 3rd person camera hack
236
-    camPos[0] = curPos[0] - (1024.0f * sinf(yaw));
237
-    camPos[1] = curPos[1] - camOffsetH; // UP is lower val
238
-    camPos[2] = curPos[2] - (1024.0f * cosf(yaw));
239
-
240
-    long index = getGame().getLara().getRoom();
241
-    long sector = getWorld().getRoom(index).getSector(camPos[0], camPos[2]);
242
-
243
-    // Handle camera out of world
244
-    if ((sector < 0) ||
245
-        ((unsigned int)sector >= getWorld().getRoom(index).sizeSectors()) ||
246
-        getWorld().getRoom(index).isWall(sector)) {
247
-        camPos[0] = curPos[0] + (64.0f * sinf(yaw));
248
-        camPos[1] -= 64.0f;
249
-        camPos[2] = curPos[2] + (64.0f * cosf(yaw));
250
-    }
251
-
252 50
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
253
-    glLoadIdentity();
254
-
255
-    // Setup view in OpenGL with camera
256
-    getCamera().setPosition(camPos);
257
-    getCamera().update();
258
-    getCamera().getTarget(atPos);
259
-    // Mongoose 2002.08.13, Quick fix to render OpenRaider upside down
260
-    Window::lookAt(camPos[0], camPos[1], camPos[2], atPos[0], atPos[1], atPos[2], 0.0f, -1.0f, 0.0f);
261
-
262
-    // Update view volume for vising
263
-    updateViewVolume();
264
-
265
-    // Render world
266
-    glColor3ubv(GREY); // was WHITE
267
-    drawSkyMesh(96.0);
268
-
269
-    // Figure out how much of the map to render
270
-    newRoomRenderList(index);
271
-
272
-    // Room solid pass, need to do depth sorting to avoid 2 pass render
273
-    for (unsigned int i = 0; i < mRoomRenderList.size(); i++) {
274
-        Room& room = *mRoomRenderList[i];
275
-
276
-        if (mFlags & Render::fGL_Lights)
277
-            lightRoom(room);
278
-
279
-        room.display(false);
280
-    }
281
-
282
-    // Draw all visible enities
283
-    if (mFlags & Render::fEntityModels) {
284
-        std::vector<Entity*> entityRenderList;
285
-
286
-        for (unsigned int i = 0; i < getWorld().sizeEntity(); i++) {
287
-            Entity& e = getWorld().getEntity(i);
288
-
289
-            // Don't show Lara to the player
290
-            if (&e == &getGame().getLara())
291
-                continue;
292
-
293
-            // Mongoose 2002.08.15, Nothing to draw, skip
294
-            // Mongoose 2002.12.24, Some entities have no animation =p
295
-            if (e.getModel().size() == 0)
296
-                continue;
297 51
 
298
-            // Is it in view volume? ( Hack to use sphere )
299
-            if (!isVisible(e.getPos(0), e.getPos(1), e.getPos(2), 512.0f))
300
-                continue;
301
-
302
-            //! \fixme Is it in a room we're rendering?
303
-            //if (mRoomRenderList[e->room] == 0x0)
304
-            //{
305
-            //  continue;
306
-            //}
307
-
308
-            entityRenderList.push_back(&e);
309
-        }
310
-
311
-        // Draw objects not tied to rooms
312
-        glPushMatrix();
313
-
314
-        // Draw lara or other player model ( move to entity rendering method )
315
-        getGame().getLara().display();
316
-
317
-        // Draw sprites after player to handle alpha
318
-        for (unsigned int i = 0; i < getWorld().sizeSprite(); i++) {
319
-            SpriteSequence& sprite = getWorld().getSprite(i);
320
-            for (unsigned int j = 0; j < sprite.size(); j++)
321
-                sprite.get(j).display();
322
-        }
323
-
324
-        glPopMatrix();
325
-
326
-        // Depth sort entityRenderList and display each entity
327
-        std::sort(entityRenderList.begin(), entityRenderList.end(), Entity::compare);
328
-        for (unsigned int i = 0; i < entityRenderList.size(); i++) {
329
-            entityRenderList[i]->display();
330
-        }
331
-    }
332
-
333
-    // Room alpha pass
334
-    // Skip room alpha pass for modes w/o texture
335
-    if (!(mMode == Render::modeSolid || mMode == Render::modeWireframe)) {
336
-        for (unsigned int i = 0; i < mRoomRenderList.size(); i++)
337
-            mRoomRenderList[i]->display(true);
338
-
339
-        if (debugTexture >= 0) {
340
-            getWindow().glEnter2D();
341
-            drawTexture(debugX, debugY, debugW, debugH, debugTexture, debugTextureStorage);
342
-            getWindow().glExit2D();
343
-        } else if (debugTextile >= 0) {
344
-            getWindow().glEnter2D();
345
-            drawTextile(debugX, debugY, debugW, debugH, debugTextile);
346
-            getWindow().glExit2D();
347
-        } else if (debugSprite >= 0) {
348
-            getWindow().glEnter2D();
349
-            drawSprite(debugX, debugY, debugW, debugH, debugSprite, debugSpriteOffset);
350
-            getWindow().glExit2D();
351
-        }
52
+    if (mode == RenderMode::LoadScreen) {
53
+        glm::vec4 color(1.0f, 1.0f, 1.0f, 1.0f);
54
+        drawTexture(0.0f, 0.0f, getWindow().getWidth(), getWindow().getHeight(),
55
+                    color, TEXTURE_SPLASH, TextureManager::TextureStorage::SYSTEM);
56
+        return;
57
+    } else if (mode == RenderMode::Disabled) {
58
+        return;
352 59
     }
353 60
 
354
-    if (mMode == Render::modeWireframe)
61
+    if (mode == RenderMode::Wireframe) {
62
+        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
63
+    } else {
355 64
         glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
356
-
357
-    glFlush();
358
-}
359
-
360
-void Render::drawLoadScreen() {
361
-    getWindow().glEnter2D();
362
-
363
-    drawTexture(0.0f, 0.0f, getWindow().getWidth(), getWindow().getHeight(),
364
-                TEXTURE_SPLASH, TextureManager::TextureStorage::SYSTEM);
365
-
366
-    if (debugTexture >= 0)
367
-        drawTexture(debugX, debugY, debugW, debugH, debugTexture, debugTextureStorage);
368
-    else if (debugTextile >= 0)
369
-        drawTextile(debugX, debugY, debugW, debugH, debugTextile);
370
-    else if (debugSprite >= 0)
371
-        drawSprite(debugX, debugY, debugW, debugH, debugSprite, debugSpriteOffset);
372
-
373
-    getWindow().glExit2D();
374
-
375
-    glFlush();
376
-}
377
-
378
-void Render::newRoomRenderList(int index) {
379
-    assert(index >= 0);
380
-
381
-    static int currentRoomId = -1;
382
-
383
-    // Update room render list if needed
384
-    if (currentRoomId != index) {
385
-        buildRoomRenderList(getWorld().getRoom(index));
386
-    }
387
-
388
-    currentRoomId = index;
389
-}
390
-
391
-void Render::buildRoomRenderList(Room& room) {
392
-
393
-    // Must be visible
394
-    //! \fixme Add depth sorting here - remove multipass
395
-    if (!isVisible(room.getBoundingBox()))
396
-        return;
397
-
398
-    // Must not already be cached
399
-    for (unsigned int i = 0; i < mRoomRenderList.size(); i++) {
400
-        Room* room2 = mRoomRenderList[i];
401
-
402
-        if (room2 == &room)
403
-            return;
404 65
     }
405 66
 
406
-    /* Add current room to list */
407
-    mRoomRenderList.push_back(&room);
67
+    // TODO Setup matrices
408 68
 
409
-    // Try to add adj rooms and their adj rooms, skip this room
410
-    for (unsigned int i = 1; i < room.sizeAdjacentRooms(); i++) {
411
-        if (room.getAdjacentRoom(i) < 0)
412
-            continue;
69
+    // TODO Render world
413 70
 
414
-        Room& room2 = getWorld().getRoom(room.getAdjacentRoom(i));
415
-
416
-        //! \fixme Add portal visibility check here
417
-
418
-        if (&room2 != &room)
419
-            buildRoomRenderList(room2);
71
+    if (mode == RenderMode::Wireframe) {
72
+        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
420 73
     }
421 74
 }
422 75
 
423
-void Render::drawSkyMesh(float scale) {
424
-    //skeletal_model_t *model = getWorld().getModel(mSkyMesh);
425
-    //if (!model)
426
-    //    return;
427
-
428
-    glDisable(GL_DEPTH_TEST);
429
-    glPushMatrix();
430
-
431
-    if (mSkyMeshRotation)
432
-        glRotated(90.0, 1, 0, 0);
433
-
434
-    glTranslated(0.0, 1000.0, 0.0);
435
-    glScaled(scale, scale, scale);
436
-    //drawModel(model);
437
-    //drawModelMesh(getWorld().getMesh(mSkyMesh), );
438
-    glPopMatrix();
439
-    glEnable(GL_DEPTH_TEST);
440
-}
441
-
442
-void Render::setSkyMesh(int index, bool rot) {
443
-    mSkyMesh = index;
444
-    mSkyMeshRotation = rot;
445
-}
446
-
447
-void Render::updateViewVolume() {
448
-    float proj[16], mdl[16];
449
-
450
-    glGetFloatv(GL_PROJECTION_MATRIX, proj);
451
-    glGetFloatv(GL_MODELVIEW_MATRIX, mdl);
452
-    mViewVolume.updateFrame(proj, mdl);
453
-}
454
-
455
-bool Render::isVisible(BoundingBox& box) {
456
-    float bbox[2][3];
457
-    box.getBoundingBox(bbox);
458
-
459
-    // For debugging purposes
460
-    if (mMode == Render::modeWireframe)
461
-        box.display(true, PINK, RED);
462
-
463
-    return mViewVolume.isBboxInFrustum(bbox[0], bbox[1]);
464
-}
76
+void Render::screenShot(const char* filenameBase) {
77
+    int sz = getWindow().getWidth() * getWindow().getHeight();
78
+    unsigned char* image = new unsigned char[sz * 3];
79
+    static int count = 0;
80
+    bool done = false;
465 81
 
466
-bool Render::isVisible(float x, float y, float z) {
467
-    // For debugging purposes
468
-    if (mMode == Render::modeWireframe) {
469
-        glPointSize(5.0);
470
-        glColor3ubv(PINK);
471
-        glBegin(GL_POINTS);
472
-        glVertex3f(x, y, z);
473
-        glEnd();
474
-    }
82
+    assert(filenameBase != nullptr);
475 83
 
476
-    return (mViewVolume.isPointInFrustum(x, y, z));
477
-}
84
+    // Don't overwrite files
85
+    std::ostringstream filename;
86
+    while (!done) {
87
+        filename << filenameBase << "-" << count++ << ".tga";
478 88
 
479
-bool Render::isVisible(float x, float y, float z, float radius) {
480
-    // For debugging purposes
481
-    if (mMode == Render::modeWireframe) {
482
-        glPointSize(5.0);
483
-        glColor3ubv(PINK);
484
-        glBegin(GL_POINTS);
485
-        glVertex3f(x, y, z);
486
-        glEnd();
89
+        FILE* f = fopen(filename.str().c_str(), "rb");
90
+        if (f) {
91
+            fclose(f);
92
+        } else {
93
+            done = true;
94
+        }
487 95
     }
488 96
 
489
-    return (mViewVolume.isSphereInFrustum(x, y, z, radius));
490
-}
491
-
492
-float Render::getDistToSphereFromNear(float x, float y, float z, float radius) {
493
-    return mViewVolume.getDistToSphereFromNear(x, y, z, radius);
494
-}
495
-
496
-void Render::debugDisplayTexture(int texture, TextureManager::TextureStorage s,
497
-                                 float x, float y, float w, float h) {
498
-    debugTexture = texture;
499
-    debugTextureStorage = s;
500
-    debugX = x;
501
-    debugY = y;
502
-    debugW = w;
503
-    debugH = h;
504
-    debugTextile = -1;
97
+    //glReadPixels(0, 0, getWindow().getWidth(), getWindow().getHeight(), GL_BGR_EXT, GL_UNSIGNED_BYTE,
98
+    //             image);
99
+    //tgaSave(filename.str().c_str(), image, getWindow().getWidth(), getWindow().getHeight(), 0);
100
+    delete [] image;
505 101
 }
506 102
 
507
-void Render::drawTexture(float x, float y, float w, float h,
103
+void Render::drawTexture(float x, float y, float w, float h, glm::vec4 color,
508 104
                          unsigned int texture, TextureManager::TextureStorage s) {
509
-    float z = 0.0f;
510
-
511
-    glColor3ubv(WHITE);
512
-
513
-    if (mFlags & Render::fGL_Lights)
514
-        glDisable(GL_LIGHTING);
105
+    std::vector<glm::vec2> vertices;
106
+    std::vector<glm::vec2> uvs;
515 107
 
516
-    getTextureManager().bindTextureId(texture, s);
108
+    vertices.push_back(glm::vec2(x, y + h));
109
+    vertices.push_back(glm::vec2(x, y));
110
+    vertices.push_back(glm::vec2(x + w, y + h));
517 111
 
518
-    glBegin(GL_TRIANGLE_STRIP);
519
-    glTexCoord2f(1.0, 1.0);
520
-    glVertex3f(x + w, y + h, z);
521
-    glTexCoord2f(0.0, 1.0);
522
-    glVertex3f(x, y + h, z);
523
-    glTexCoord2f(1.0, 0.0);
524
-    glVertex3f(x + w, y, z);
525
-    glTexCoord2f(0.0, 0.0);
526
-    glVertex3f(x, y, z);
527
-    glEnd();
528
-
529
-    if (mFlags & Render::fGL_Lights)
530
-        glEnable(GL_LIGHTING);
531
-}
532
-
533
-void Render::debugDisplayTextile(int texture, float x, float y, float w, float h) {
534
-    debugTextile = texture;
535
-    debugX = x;
536
-    debugY = y;
537
-    debugW = w;
538
-    debugH = h;
539
-    debugTexture = -1;
540
-}
541
-
542
-void Render::drawTextile(float x, float y, float w, float h, unsigned int textile) {
543
-    glColor3ubv(WHITE);
544
-
545
-    if (mFlags & Render::fGL_Lights)
546
-        glDisable(GL_LIGHTING);
547
-
548
-    getTextureManager().getTile(textile).display(x, y, w, h, 0.0f);
549
-
550
-    if (mFlags & Render::fGL_Lights)
551
-        glEnable(GL_LIGHTING);
552
-}
553
-
554
-void Render::debugDisplaySprite(int sprite, int offset, float x, float y, float w, float h) {
555
-    debugSprite = sprite;
556
-    debugSpriteOffset = offset;
557
-    debugX = x;
558
-    debugY = y;
559
-    debugW = w;
560
-    debugH = h;
561
-    debugTexture = -1;
562
-    debugTextile = -1;
563
-}
112
+    vertices.push_back(glm::vec2(x + w, y));
113
+    vertices.push_back(glm::vec2(x + w, y + h));
114
+    vertices.push_back(glm::vec2(x, y));
564 115
 
565
-void Render::drawSprite(float x, float y, float w, float h, unsigned int sprite,
566
-                        unsigned int offset) {
567
-    glColor3ubv(WHITE);
116
+    uvs.push_back(glm::vec2(0.0f, 1.0f));
117
+    uvs.push_back(glm::vec2(0.0f, 0.0f));
118
+    uvs.push_back(glm::vec2(1.0f, 1.0f));
568 119
 
569
-    if (mFlags & Render::fGL_Lights)
570
-        glDisable(GL_LIGHTING);
120
+    uvs.push_back(glm::vec2(1.0f, 0.0f));
121
+    uvs.push_back(glm::vec2(1.0f, 1.0f));
122
+    uvs.push_back(glm::vec2(0.0f, 0.0f));
571 123
 
572
-    getWorld().getSprite(sprite).get(offset).display(x, y, w, h);
124
+    //! \fixme drawTextGL only uses SYSTEM textures!
125
+    assert(s == TextureManager::TextureStorage::SYSTEM);
573 126
 
574
-    if (mFlags & Render::fGL_Lights)
575
-        glEnable(GL_LIGHTING);
127
+    Window::drawTextGL(vertices, uvs, color, texture);
576 128
 }
577 129
 

+ 25
- 388
src/Room.cpp Parādīt failu

@@ -5,6 +5,8 @@
5 5
  * \author xythobuz
6 6
  */
7 7
 
8
+#include "glm/gtx/intersect.hpp"
9
+
8 10
 #include <algorithm>
9 11
 
10 12
 #include "global.h"
@@ -14,11 +16,6 @@
14 16
 #include "Room.h"
15 17
 #include "TextureManager.h"
16 18
 
17
-#ifdef MULTITEXTURE
18
-#include <map>
19
-extern std::map<int, int> gMapTex2Bump;
20
-#endif
21
-
22 19
 Room::Room(float p[3], unsigned int f, unsigned int x, unsigned int z)
23 20
     : flags(f), numXSectors(x), numZSectors(z) {
24 21
     if (p == nullptr) {
@@ -45,369 +42,6 @@ void Room::setPos(float p[3]) {
45 42
         pos[i] = p[i];
46 43
 }
47 44
 
48
-Room::Room(TombRaider& tr, unsigned int index) {
49
-    if (!tr.isRoomValid(index)) {
50
-        getLog() << "WARNING: Handling invalid vertex array in room" << Log::endl;
51
-        return;
52
-    }
53
-
54
-    flags = 0;
55
-    unsigned int trFlags = 0;
56
-    float box[2][3];
57
-    tr.getRoomInfo(index, &trFlags, pos, box[0], box[1]);
58
-
59
-    if (trFlags & tombraiderRoom_underWater)
60
-        flags |= RoomFlagUnderWater;
61
-
62
-    // Adjust positioning for OR world coordinate translation
63
-    box[0][0] += pos[0];
64
-    box[1][0] += pos[0];
65
-    box[0][2] += pos[2];
66
-    box[1][2] += pos[2];
67
-
68
-    bbox.setBoundingBox(box[0], box[1]);
69
-
70
-    // Mongoose 2002.04.03, Setup 3D transform
71
-    Matrix transform;
72
-    transform.setIdentity();
73
-    transform.translate(pos);
74
-
75
-    // Current room is always first
76
-    adjacentRooms.push_back(index);
77
-
78
-    // Setup portals
79
-    unsigned int count = tr.getRoomPortalCount(index);
80
-    for (unsigned int i = 0; i < count; i++) {
81
-        portals.push_back(new Portal(tr, index, i, transform));
82
-        adjacentRooms.push_back(portals.back()->getAdjoiningRoom());
83
-    }
84
-
85
-    // List of sectors in this room
86
-    count = tr.getRoomSectorCount(index, &numZSectors, &numXSectors);
87
-    for (unsigned int i = 0; i < count; i++)
88
-        sectors.push_back(new Sector(tr, index, i));
89
-
90
-    // Setup room lights
91
-    count = tr.getRoomLightCount(index);
92
-    for (unsigned int i = 0; i < count; i++)
93
-        lights.push_back(new Light(tr, index, i));
94
-
95
-    // Room models
96
-    count = tr.getRoomModelCount(index);
97
-    for (unsigned int i = 0; i < count; i++)
98
-        models.push_back(new StaticModel(tr, index, i));
99
-
100
-    // Room sprites
101
-    count = tr.getRoomSpriteCount(index);
102
-    for (unsigned int i = 0; i < count; i++)
103
-        sprites.push_back(new Sprite(tr, index, i));
104
-
105
-//#define EXPERIMENTAL_UNIFIED_ROOM_GEOMETERY
106
-#ifdef EXPERIMENTAL_UNIFIED_ROOM_GEOMETERY
107
-    unsigned int vertexCount, normalCount, colorCount, triCount;
108
-    float* vertexArray;
109
-    float* normalArray;
110
-    float* colorArray;
111
-    unsigned int* indices, *fflags;
112
-    float* texCoords;
113
-    int* textures;
114
-
115
-    tr.getRoomVertexArrays(index,
116
-                           &vertexCount, &vertexArray,
117
-                           &normalCount, &normalArray,
118
-                           &colorCount, &colorArray);
119
-
120
-    mesh.bufferVertexArray(vertexCount, vertexArray);
121
-    mesh.bufferNormalArray(normalCount, normalArray);
122
-    mesh.bufferColorArray(vertexCount, colorArray);
123
-
124
-    tr.getRoomTriangles(index, 0, &triCount, &indices, &texCoords, &textures, &fflags);
125
-
126
-    mesh.bufferTriangles(triCount, indices, texCoords, textures, fflags);
127
-#else
128
-    const unsigned int TextureLimit = 24;
129
-    float rgba[4];
130
-    float xyz[3];
131
-
132
-    count = tr.getRoomVertexCount(index);
133
-    mesh.allocateVertices(count);
134
-    mesh.allocateNormals(0); // count
135
-    mesh.allocateColors(count);
136
-
137
-    for (unsigned int i = 0; i < count; ++i) {
138
-        tr.getRoomVertex(index, i, xyz, rgba);
139
-
140
-        mesh.setVertex(i, xyz[0], xyz[1], xyz[2]);
141
-        mesh.setColor(i, rgba);
142
-    }
143
-
144
-    // Mongoose 2002.06.09, Setup allocation of meshes and polygons
145
-    // Counters ( Textured polygon lists are allocated per texture)
146
-    //          ( Textures are mapped to these meshes )
147
-    int triangle_counter[TextureLimit];
148
-    int triangle_counter_alpha[TextureLimit];
149
-    int rectangle_counter[TextureLimit];
150
-    int rectangle_counter_alpha[TextureLimit];
151
-    int tris_mesh_map[TextureLimit];
152
-    int rect_mesh_map[TextureLimit];
153
-
154
-    for (unsigned int i = 0; i < TextureLimit; ++i) {
155
-        triangle_counter[i]        = 0;
156
-        triangle_counter_alpha[i]  = 0;
157
-        rectangle_counter[i]       = 0;
158
-        rectangle_counter_alpha[i] = 0;
159
-
160
-        tris_mesh_map[i] = -1;
161
-        rect_mesh_map[i] = -1;
162
-    }
163
-
164
-    unsigned int numTris = 0;
165
-    unsigned int numQuads = 0;
166
-
167
-    int texture;
168
-    unsigned int r, t, q, v;
169
-    unsigned int indices[4];
170
-    float texCoords[8];
171
-
172
-    count = tr.getRoomTriangleCount(index);
173
-
174
-    // Mongoose 2002.08.15, Presort by alpha and texture and setup mapping
175
-    for (t = 0; t < count; ++t) {
176
-        tr.getRoomTriangle(index, t,
177
-                           indices, texCoords, &texture, &flags);
178
-
179
-        if (texture > (int)TextureLimit) {
180
-            getLog() << "Handling bad room[" << index << "].tris["
181
-                     << t << "].texture = " << texture << Log::endl;
182
-            texture = TextureLimit - 1;
183
-        }
184
-
185
-        // Counters set up polygon allocation
186
-        if (flags & tombraiderFace_Alpha ||
187
-            flags & tombraiderFace_PartialAlpha) {
188
-            triangle_counter_alpha[texture] += 1;
189
-        } else {
190
-            triangle_counter[texture] += 1;
191
-        }
192
-
193
-        // Counter sets up texture id to mesh id mapping
194
-        if (tris_mesh_map[texture] == -1) {
195
-            tris_mesh_map[texture] = ++numTris;
196
-        }
197
-    }
198
-
199
-    count = tr.getRoomRectangleCount(index);
200
-
201
-    for (r = 0; r < count; ++r) {
202
-        tr.getRoomRectangle(index, r,
203
-                            indices, texCoords, &texture, &flags);
204
-
205
-        if (texture > (int)TextureLimit) {
206
-            getLog() << "Handling bad room[" << index << "].quad["
207
-                     << r << "].texture = " << texture << Log::endl;
208
-            texture = TextureLimit - 1;
209
-        }
210
-
211
-        if (flags & tombraiderFace_Alpha ||
212
-            flags & tombraiderFace_PartialAlpha) {
213
-            rectangle_counter_alpha[texture] += 1;
214
-        } else {
215
-            rectangle_counter[texture] += 1;
216
-        }
217
-
218
-        if (rect_mesh_map[texture] == -1) {
219
-            rect_mesh_map[texture] = ++numQuads;
220
-        }
221
-    }
222
-
223
-    // Allocate indexed polygon meshes
224
-    mesh.allocateTriangles(numTris);
225
-    mesh.allocateRectangles(numQuads);
226
-
227
-    for (unsigned int i = 0, j = 0; i < TextureLimit; ++i) {
228
-        if (tris_mesh_map[i] > 0) {
229
-            j = tris_mesh_map[i] - 1;
230
-
231
-            t = triangle_counter[i];
232
-
233
-            mesh.mTris[j].texture = i;
234
-#ifdef MULTITEXTURE
235
-            mesh.mTris[j].bumpmap = gMapTex2Bump[i];
236
-#endif
237
-            mesh.mTris[j].cnum_triangles = 0;
238
-            mesh.mTris[j].num_triangles = 0;
239
-            mesh.mTris[j].cnum_alpha_triangles = 0;
240
-            mesh.mTris[j].num_alpha_triangles = 0;
241
-            mesh.mTris[j].triangles = 0x0;
242
-            mesh.mTris[j].alpha_triangles = 0x0;
243
-            mesh.mTris[j].texcoors = 0x0;
244
-            mesh.mTris[j].texcoors2 = 0x0;
245
-
246
-            if (t > 0) {
247
-                mesh.mTris[j].num_triangles = t;
248
-                mesh.mTris[j].triangles = new unsigned int[t * 3];
249
-                mesh.mTris[j].num_texcoors = t * 3;
250
-                mesh.mTris[j].texcoors = new float *[t * 3];
251
-                for (unsigned int tmp = 0; tmp < (t * 3); tmp++)
252
-                    mesh.mTris[j].texcoors[tmp] = new float[2];
253
-            }
254
-
255
-            t = triangle_counter_alpha[i];
256
-
257
-            if (t > 0) {
258
-                mesh.mTris[j].num_alpha_triangles = t;
259
-                mesh.mTris[j].alpha_triangles = new unsigned int[t * 3];
260
-                mesh.mTris[j].num_texcoors2 = t * 3;
261
-                mesh.mTris[j].texcoors2 = new float *[t * 3];
262
-                for (unsigned int tmp = 0; tmp < (t * 3); tmp++)
263
-                    mesh.mTris[j].texcoors2[tmp] = new float[2];
264
-            }
265
-        }
266
-
267
-        ///////////////////////////////////////////
268
-
269
-        if (rect_mesh_map[i] > 0) {
270
-            j = rect_mesh_map[i] - 1;
271
-
272
-            r = rectangle_counter[i];
273
-
274
-            mesh.mQuads[j].texture = i;
275
-#ifdef MULTITEXTURE
276
-            mesh.mQuads[j].bumpmap = gMapTex2Bump[i];
277
-#endif
278
-            mesh.mQuads[j].cnum_quads = 0;
279
-            mesh.mQuads[j].num_quads = 0;
280
-            mesh.mQuads[j].cnum_alpha_quads = 0;
281
-            mesh.mQuads[j].num_alpha_quads = 0;
282
-            mesh.mQuads[j].quads = 0x0;
283
-            mesh.mQuads[j].alpha_quads = 0x0;
284
-            mesh.mQuads[j].texcoors = 0x0;
285
-            mesh.mQuads[j].texcoors2 = 0x0;
286
-
287
-            if (r > 0) {
288
-                mesh.mQuads[j].num_quads = r;
289
-                mesh.mQuads[j].quads = new unsigned int[r * 4];
290
-                mesh.mQuads[j].num_texcoors = r * 4;
291
-                mesh.mQuads[j].texcoors = new float *[r * 4];
292
-                for (unsigned int tmp = 0; tmp < (r * 4); tmp++)
293
-                    mesh.mQuads[j].texcoors[tmp] = new float[2];
294
-            }
295
-
296
-            r = rectangle_counter_alpha[i];
297
-
298
-            if (r > 0) {
299
-                mesh.mQuads[j].num_alpha_quads = r;
300
-                mesh.mQuads[j].alpha_quads = new unsigned int[r * 4];
301
-                mesh.mQuads[j].num_texcoors2 = r * 4;
302
-                mesh.mQuads[j].texcoors2 = new float *[r * 4];
303
-                for (unsigned int tmp = 0; tmp < (r * 4); tmp++)
304
-                    mesh.mQuads[j].texcoors2[tmp] = new float[2];
305
-            }
306
-        }
307
-    }
308
-
309
-    // Generate textured triangles
310
-    count = tr.getRoomTriangleCount(index);
311
-
312
-    for (t = 0; t < count; ++t) {
313
-        tr.getRoomTriangle(index, t,
314
-                           indices, texCoords, &texture, &flags);
315
-
316
-        unsigned int j = tris_mesh_map[texture] - 1;
317
-
318
-        // Setup per vertex
319
-        for (unsigned int i = 0; i < 3; ++i) {
320
-            // Get vertex index {(0, a), (1, b), (2, c)}
321
-            v = indices[i];
322
-
323
-            if ((flags & tombraiderFace_Alpha ||
324
-                 flags & tombraiderFace_PartialAlpha) &&
325
-                mesh.mTris[j].num_alpha_triangles > 0) {
326
-                q = mesh.mTris[j].cnum_alpha_triangles * 3 + i;
327
-
328
-                mesh.mTris[j].alpha_triangles[q] = v;
329
-
330
-                mesh.mTris[j].texcoors2[q][0] = texCoords[i * 2];
331
-                mesh.mTris[j].texcoors2[q][1] = texCoords[i * 2 + 1];
332
-            } else if (mesh.mTris[j].num_triangles > 0) {
333
-                q = mesh.mTris[j].cnum_triangles * 3 + i;
334
-
335
-                mesh.mTris[j].triangles[q] = v;
336
-
337
-                mesh.mTris[j].texcoors[q][0] = texCoords[i * 2];
338
-                mesh.mTris[j].texcoors[q][1] = texCoords[i * 2 + 1];
339
-            }
340
-
341
-            // Partial alpha hack
342
-            if (flags & tombraiderFace_PartialAlpha) {
343
-                //mesh.colors[v].rgba[3] = 0.45;
344
-            }
345
-        }
346
-
347
-        if (flags & tombraiderFace_Alpha ||
348
-            flags & tombraiderFace_PartialAlpha) {
349
-            mesh.mTris[j].cnum_alpha_triangles++;
350
-        } else {
351
-            mesh.mTris[j].cnum_triangles++;
352
-        }
353
-    }
354
-
355
-    // Generate textured quads
356
-    count = tr.getRoomRectangleCount(index);
357
-
358
-    for (r = 0; r < count; ++r) {
359
-        tr.getRoomRectangle(index, r,
360
-                            indices, texCoords, &texture, &flags);
361
-
362
-        if (texture > (int)TextureLimit) {
363
-            texture = TextureLimit - 1;
364
-        }
365
-
366
-        unsigned int j = rect_mesh_map[texture] - 1;
367
-
368
-        if (mesh.mQuads[j].num_quads <= 0 &&
369
-            mesh.mQuads[j].num_alpha_quads <= 0)
370
-            continue;
371
-
372
-        // Setup per vertex
373
-        for (unsigned int i = 0; i < 4; ++i) {
374
-            // Get vertex index {(0, a), (1, b), (2, c), (3, d)}
375
-            v = indices[i];
376
-
377
-            if ((flags & tombraiderFace_Alpha ||
378
-                 flags & tombraiderFace_PartialAlpha) &&
379
-                mesh.mQuads[j].num_alpha_quads > 0) {
380
-                q = mesh.mQuads[j].cnum_alpha_quads * 4 + i;
381
-
382
-                mesh.mQuads[j].alpha_quads[q] = v;
383
-
384
-                mesh.mQuads[j].texcoors2[q][0] = texCoords[i * 2];
385
-                mesh.mQuads[j].texcoors2[q][1] = texCoords[i * 2 + 1];
386
-            } else if (mesh.mQuads[j].num_quads > 0) {
387
-                q = mesh.mQuads[j].cnum_quads * 4 + i;
388
-
389
-                mesh.mQuads[j].quads[q] = v;
390
-
391
-                mesh.mQuads[j].texcoors[q][0] = texCoords[i * 2];
392
-                mesh.mQuads[j].texcoors[q][1] = texCoords[i * 2 + 1];
393
-            }
394
-
395
-            // Partial alpha hack
396
-            if (flags & tombraiderFace_PartialAlpha) {
397
-                //rRoom->mesh.colors[v].rgba[3] = 0.45;
398
-            }
399
-        }
400
-
401
-        if (flags & tombraiderFace_Alpha ||
402
-            flags & tombraiderFace_PartialAlpha) {
403
-            mesh.mQuads[j].cnum_alpha_quads++;
404
-        } else {
405
-            mesh.mQuads[j].cnum_quads++;
406
-        }
407
-    }
408
-#endif
409
-}
410
-
411 45
 #define EMPTY_VECTOR(x)     \
412 46
 while (!x.empty()) {        \
413 47
     delete x[x.size() - 1]; \
@@ -423,12 +57,13 @@ Room::~Room() {
423 57
 }
424 58
 
425 59
 void Room::display(bool alpha) {
60
+    /*
426 61
     glPushMatrix();
427 62
     //LightingSetup();
428 63
 
429 64
     getTextureManager().bindTextureId(TEXTURE_WHITE, TextureManager::TextureStorage::SYSTEM);
430 65
 
431
-    if ((!alpha) && getRender().getMode() == Render::modeWireframe) {
66
+    if ((!alpha) && Render::getMode() == RenderMode::Wireframe) {
432 67
         glLineWidth(2.0);
433 68
         glColor3ubv(RED);
434 69
 
@@ -448,7 +83,7 @@ void Room::display(bool alpha) {
448 83
         glLineWidth(1.0);
449 84
     }
450 85
 
451
-    if (getRender().getMode() == Render::modeWireframe && (!alpha)) {
86
+    if (Render::getMode() == RenderMode::Wireframe && (!alpha)) {
452 87
         bbox.display(true, RED, GREEN);
453 88
     }
454 89
 
@@ -457,11 +92,11 @@ void Room::display(bool alpha) {
457 92
     // Reset since GL_MODULATE used, reset to WHITE
458 93
     glColor3ubv(WHITE);
459 94
 
460
-    switch (getRender().getMode()) {
461
-        case Render::modeWireframe:
95
+    switch (Render::getMode()) {
96
+        case RenderMode::Wireframe:
462 97
             mesh.mMode = Mesh::MeshModeWireframe;
463 98
             break;
464
-        case Render::modeSolid:
99
+        case RenderMode::Solid:
465 100
             mesh.mMode = Mesh::MeshModeSolid;
466 101
             break;
467 102
         default:
@@ -477,15 +112,16 @@ void Room::display(bool alpha) {
477 112
     glPopMatrix();
478 113
 
479 114
     // Draw other room meshes and sprites
480
-    if (alpha || (getRender().getMode() == Render::modeWireframe)
481
-        || (getRender().getMode() == Render::modeSolid)) {
482
-        sortModels();
115
+    if (alpha || (Render::getMode() == RenderMode::Wireframe)
116
+        || (Render::getMode() == RenderMode::Solid)) {
117
+        //sortModels(); // TODO
483 118
         for (unsigned int i = 0; i < sizeModels(); i++)
484 119
             getModel(i).display();
485 120
 
486 121
         for (unsigned int i = 0; i < sizeSprites(); i++)
487 122
             getSprite(i).display();
488 123
     }
124
+    */
489 125
 }
490 126
 
491 127
 bool Room::isWall(unsigned long sector) {
@@ -496,8 +132,8 @@ bool Room::isWall(unsigned long sector) {
496 132
 }
497 133
 
498 134
 long Room::getSector(float x, float z, float* floor, float* ceiling) {
499
-    assert(floor != NULL);
500
-    assert(ceiling != NULL);
135
+    assert(floor != nullptr);
136
+    assert(ceiling != nullptr);
501 137
 
502 138
     long sector = getSector(x, z);
503 139
 
@@ -527,16 +163,21 @@ void Room::getHeightAtPosition(float x, float* y, float z) {
527 163
 
528 164
 int Room::getAdjoiningRoom(float x, float y, float z,
529 165
                            float x2, float y2, float z2) {
530
-    float intersect[3], p1[3], p2[3];
531 166
     float vertices[4][3];
532
-
533
-    p1[0] = x;  p1[1] = y;  p1[2] = z;
534
-    p2[0] = x2; p2[1] = y2; p2[2] = z2;
167
+    glm::vec3 orig(x, y, z);
168
+    glm::vec3 dir(x2 - x, y2 - y, z2 - z);
169
+    glm::vec3 intersect;
170
+    glm::vec3 verts[4];
535 171
 
536 172
     for (unsigned long i = 0; i < portals.size(); i++) {
537 173
         portals.at(i)->getVertices(vertices);
538
-        if (intersectionLinePolygon(intersect, p1, p2, //4,
539
-                                    vertices))
174
+        verts[0] = glm::vec3(vertices[0][0], vertices[0][1], vertices[0][2]);
175
+        verts[1] = glm::vec3(vertices[1][0], vertices[1][1], vertices[1][2]);
176
+        verts[2] = glm::vec3(vertices[2][0], vertices[2][1], vertices[2][2]);
177
+        verts[3] = glm::vec3(vertices[3][0], vertices[3][1], vertices[3][2]);
178
+
179
+        if ((glm::intersectLineTriangle(orig, dir, verts[0], verts[1], verts[2], intersect))
180
+            || (glm::intersectLineTriangle(orig, dir, verts[0], verts[3], verts[1], intersect)))
540 181
             return portals.at(i)->getAdjoiningRoom();
541 182
     }
542 183
 
@@ -616,10 +257,6 @@ void Room::addModel(StaticModel* s) {
616 257
     models.push_back(s);
617 258
 }
618 259
 
619
-void Room::sortModels() {
620
-    std::sort(models.begin(), models.end(), StaticModel::compare);
621
-}
622
-
623 260
 unsigned long Room::sizeLights() {
624 261
     return lights.size();
625 262
 }

+ 7
- 66
src/RoomData.cpp Parādīt failu

@@ -6,7 +6,6 @@
6 6
  */
7 7
 
8 8
 #include "global.h"
9
-#include "Render.h"
10 9
 #include "SkeletalModel.h"
11 10
 #include "World.h"
12 11
 #include "RoomData.h"
@@ -44,6 +43,7 @@ bool BoundingBox::inBoxPlane(float x, float z) {
44 43
 }
45 44
 
46 45
 void BoundingBox::display(bool points, const unsigned char c1[4], const unsigned char c2[4]) {
46
+    /*
47 47
     // Bind before entering now
48 48
     //glBindTexture(GL_TEXTURE_2D, 1);
49 49
     glPointSize(4.0);
@@ -114,31 +114,11 @@ void BoundingBox::display(bool points, const unsigned char c1[4], const unsigned
114 114
 
115 115
     glPointSize(1.0);
116 116
     //glLineWidth(1.0);
117
+    */
117 118
 }
118 119
 
119 120
 // ----------------------------------------------------------------------------
120 121
 
121
-Light::Light(TombRaider& tr, unsigned int room, unsigned int index) {
122
-    unsigned int lightFlags, lightType;
123
-
124
-    tr.getRoomLight(room, index, pos, color,
125
-                    dir, &att, &cutoff, &lightType, &lightFlags);
126
-
127
-    switch (lightType) {
128
-        case tombraiderLight_typeDirectional:
129
-            type = Light::typeDirectional;
130
-            break;
131
-        case tombraiderLight_typeSpot:
132
-            type = Light::typeSpot;
133
-            break;
134
-        case tombraiderLight_typePoint:
135
-        default:
136
-            type = Light::typePoint;
137
-    }
138
-
139
-    //! \todo Light flags?
140
-}
141
-
142 122
 void Light::getPos(float p[4]) {
143 123
     p[0] = pos[0];
144 124
     p[1] = pos[1];
@@ -173,52 +153,24 @@ Light::LightType Light::getType() {
173 153
 
174 154
 // ----------------------------------------------------------------------------
175 155
 
176
-StaticModel::StaticModel(TombRaider& tr, unsigned int room, unsigned int i) {
177
-    tr.getRoomModel(room, i, &index, pos, &yaw);
178
-}
179
-
180 156
 void StaticModel::display() {
181 157
     StaticMesh& mesh = getWorld().getStaticMesh(index);
182 158
 
183
-    if (!getRender().isVisible(pos[0], pos[1], pos[2], mesh.getRadius()))
184
-        return;
159
+    //if (!getRender().isVisible(pos[0], pos[1], pos[2], mesh.getRadius()))
160
+    //    return;
185 161
 
162
+    /*
186 163
     glPushMatrix();
187 164
     glTranslated(pos[0], pos[1], pos[2]);
188 165
     glRotated(yaw, 0, 1, 0);
189 166
     mesh.display();
190 167
     glPopMatrix();
191
-}
192
-
193
-bool StaticModel::operator<(const StaticModel& other) {
194
-    float distA, distB;
195
-    distA = getRender().getDistToSphereFromNear(pos[0],
196
-            pos[1], pos[2], 128.0f);
197
-    distB = getRender().getDistToSphereFromNear(other.pos[0],
198
-            other.pos[1], other.pos[2], 128.0f);
199
-    return (distA < distB);
200
-}
201
-
202
-bool StaticModel::compare(StaticModel* a, StaticModel* b) {
203
-    return (*b) < (*a);
168
+    */
204 169
 }
205 170
 
206 171
 // ----------------------------------------------------------------------------
207 172
 
208
-Portal::Portal(TombRaider& tr, unsigned int room, unsigned int index, Matrix& transform) {
209
-    float portalVertices[12];
210
-    tr.getRoomPortal(room, index, &adjoiningRoom, normal, portalVertices);
211
-    for (unsigned int j = 0; j < 4; ++j) {
212
-        vertices[j][0] = portalVertices[j * 3];
213
-        vertices[j][1] = portalVertices[j * 3 + 1];
214
-        vertices[j][2] = portalVertices[j * 3 + 2];
215
-
216
-        // Relative coors in vis portals
217
-        transform.multiply3v(vertices[j], vertices[j]);
218
-    }
219
-}
220
-
221
-Portal::Portal(float vert[4][3], float norm[3], int adj) {
173
+Portal::Portal(glm::vec3 vert[4], float norm[3], int adj) {
222 174
     for (unsigned int i = 0; i < 4; i++) {
223 175
         for (unsigned int j = 0; j < 3; j++) {
224 176
             vertices[i][j] = vert[i][j];
@@ -246,17 +198,6 @@ int Portal::getAdjoiningRoom() {
246 198
 
247 199
 // ----------------------------------------------------------------------------
248 200
 
249
-Sector::Sector(TombRaider& tr, unsigned int room, unsigned int index) {
250
-    unsigned int sectorFlags;
251
-    int floorDataIndex, boxIndex, roomBelow, roomAbove;
252
-
253
-    tr.getRoomSector(room, index, &sectorFlags,
254
-                     &ceiling, &floor, &floorDataIndex, &boxIndex,
255
-                     &roomBelow, &roomAbove);
256
-
257
-    wall = (sectorFlags & tombraiderSector_wall);
258
-}
259
-
260 201
 float Sector::getFloor() {
261 202
     return floor;
262 203
 }

+ 2
- 254
src/SkeletalModel.cpp Parādīt failu

@@ -8,7 +8,6 @@
8 8
 
9 9
 #include "global.h"
10 10
 #include "Log.h"
11
-#include "Render.h"
12 11
 #include "SkeletalModel.h"
13 12
 #include "World.h"
14 13
 
@@ -21,43 +20,6 @@ BoneTag::BoneTag(int m, float o[3], float r[3], char f) {
21 20
     }
22 21
 }
23 22
 
24
-BoneTag::BoneTag(TombRaider& tr, unsigned int index, unsigned int i, unsigned int* l,
25
-                 unsigned int frame_offset) {
26
-    tr2_moveable_t* moveable = tr.Moveable();
27
-    tr2_meshtree_t* meshtree = tr.MeshTree();
28
-    unsigned short* frame = tr.Frame();
29
-
30
-    off[0] = 0.0f;
31
-    off[1] = 0.0f;
32
-    off[2] = 0.0f;
33
-    flag = 0x00;
34
-    rot[0] = 0.0f;
35
-    rot[1] = 0.0f;
36
-    rot[2] = 0.0f;
37
-    mesh = moveable[index].starting_mesh + i;
38
-
39
-    // Setup offsets to produce skeleton
40
-    if (i == 0) {
41
-        // Always push tag[0], this isn't really used either
42
-        flag = 0x02;
43
-    } else { // Nonprimary tag - position relative to first tag
44
-
45
-        // Hack: moveable[index].mesh_tree is a byte offset
46
-        //       into mesh_tree[], so we have to convert to index
47
-        int* tree = (int*)(void*)meshtree;
48
-        tr2_meshtree_t* mesh_tree = (tr2_meshtree_t*)(tree
49
-                                    + moveable[index].mesh_tree + ((i - 1) * 4));
50
-
51
-        off[0] = mesh_tree->x;
52
-        off[1] = mesh_tree->y;
53
-        off[2] = mesh_tree->z;
54
-        flag = (char)mesh_tree->flags;
55
-    }
56
-
57
-    // Setup tag rotations
58
-    tr.computeRotationAngles(&frame, &frame_offset, l, rot, rot + 1, rot + 2);
59
-}
60
-
61 23
 void BoneTag::display() {
62 24
     if (getWorld().sizeMesh() > 0)
63 25
         getWorld().getMesh(mesh).drawSolid(); // TODO ?
@@ -88,20 +50,6 @@ BoneFrame::BoneFrame(float p[3]) {
88 50
         pos[i] = p[i];
89 51
 }
90 52
 
91
-BoneFrame::BoneFrame(TombRaider& tr, unsigned int index, unsigned int frame_offset) {
92
-    tr2_moveable_t* moveable = tr.Moveable();
93
-    unsigned short* frame = tr.Frame();
94
-
95
-    pos[0] = (short)frame[frame_offset + 6];
96
-    pos[1] = (short)frame[frame_offset + 7];
97
-    pos[2] = (short)frame[frame_offset + 8];
98
-
99
-    unsigned int l = 9; // First angle offset in this Frame
100
-
101
-    for (unsigned int i = 0; i < moveable[index].num_meshes; i++)
102
-        tag.push_back(new BoneTag(tr, index, i, &l, frame_offset));
103
-}
104
-
105 53
 BoneFrame::~BoneFrame() {
106 54
     for (unsigned long i = 0; i < tag.size(); i++)
107 55
         delete tag[i];
@@ -132,52 +80,6 @@ AnimationFrame::AnimationFrame(char r) {
132 80
     rate = r;
133 81
 }
134 82
 
135
-AnimationFrame::AnimationFrame(TombRaider& tr, unsigned int index, int a,
136
-                               unsigned int* frame_offset, int frame_step) {
137
-    tr2_moveable_t* moveable = tr.Moveable();
138
-    tr2_animation_t* animation = tr.Animation();
139
-
140
-    unsigned int frame_count = (animation[a].frame_end - animation[a].frame_start) + 1;
141
-    rate = animation[a].frame_rate;
142
-
143
-    for (unsigned int f = 0; f < frame_count; f++, *frame_offset += frame_step) {
144
-        // HACK: Lara's ObjectID is 315, but her meshes start at 0, so make a
145
-        // quick substitution (so she doesn't appear as a bunch of thighs)
146
-        if ((index == 0) && (tr.Engine() == TR_VERSION_3)) {
147
-            for (int j = 0; (j < (int)tr.NumMoveables()) && (index == 0); j++) {
148
-                if (moveable[j].object_id == 315)
149
-                    index = j;
150
-            }
151
-        }
152
-
153
-        // Fix Lara in TR4
154
-        // Body is ItemID 8, joints are ItemID 9
155
-        // (TR4 demo: body is ItemID 10, joints are ItemID 11)
156
-        if ((index == 0) && (tr.Engine() == TR_VERSION_4)) {
157
-            for (int j = 0; (j < (int)tr.NumMoveables()) && (index == 0); j++) {
158
-                if (moveable[j].object_id == 8)
159
-                    index = j;
160
-            }
161
-        } else if ((moveable[index].object_id == 8) && (tr.Engine() == TR_VERSION_4)) {
162
-            // KLUDGE to do "skinning"
163
-            index = 0;
164
-            for (int j = 0; (j < (int)tr.NumMoveables()) && (index == 0); j++) {
165
-                if (moveable[j].object_id == 9)
166
-                    index = j;
167
-            }
168
-        }
169
-
170
-        if (*frame_offset > tr.NumFrames()) {
171
-            getLog() << "WARNING: Bad animation frame " << *frame_offset
172
-                     << " > " << tr.NumFrames() << " (" << index << "." << a << ")"
173
-                     << Log::endl;
174
-            return;
175
-        }
176
-
177
-        frame.push_back(new BoneFrame(tr, index, *frame_offset));
178
-    }
179
-}
180
-
181 83
 AnimationFrame::~AnimationFrame() {
182 84
     for (unsigned long i = 0; i < frame.size(); i++)
183 85
         delete frame[i];
@@ -202,113 +104,13 @@ SkeletalModel::SkeletalModel(int i) {
202 104
     id = i;
203 105
 }
204 106
 
205
-SkeletalModel::SkeletalModel(TombRaider& tr, unsigned int index, int objectId) {
206
-    tr2_moveable_t* moveable = tr.Moveable();
207
-    tr2_animation_t* anim = tr.Animation();
208
-    tr2_mesh_t* mesh = tr.Mesh();
209
-
210
-    id = objectId;
211
-
212
-    // Gather more info if this is lara
213
-    if (id == 0) {
214
-        // Only TR4 lara has 2 layer bone tags/meshes per bone frame
215
-        tr4Overlay = (tr.Engine() == TR_VERSION_4);
216
-        ponytailId = 0;
217
-    } else {
218
-        tr4Overlay = false;
219
-        ponytailId = -1;
220
-    }
221
-
222
-    switch (tr.Engine()) {
223
-        case TR_VERSION_4:
224
-            if (moveable[index].object_id == 30) {
225
-                ponytailId = getWorld().sizeSkeletalModel(); //! \fixme Why is this even needed?
226
-                ponytailMeshId = moveable[index].starting_mesh;
227
-                ponytailNumMeshes = ((moveable[index].num_meshes > 0) ?
228
-                                     moveable[index].num_meshes : 0);
229
-                ponytailAngle = -90.0f;
230
-                ponytail[0] = -3;
231
-                ponytail[1] = -22;
232
-                ponytail[2] = -20;
233
-                ponyOff = 40;
234
-                ponyOff2 = 32;
235
-                pigtails = false;
236
-
237
-                // Try to guess pigtails by looking for certian num verts in head
238
-                if (mesh[moveable[0].starting_mesh].num_vertices > 80) {
239
-                    pigtails = true;
240
-                    ponyOff -= 20;
241
-                    ponytail[1] -= 32;
242
-                }
243
-
244
-                getRender().setFlags(Render::fRenderPonytail);
245
-                getLog() << "Found known ponytail" << Log::endl;
246
-            }
247
-            break;
248
-
249
-        case TR_VERSION_1:
250
-        case TR_VERSION_2:
251
-        case TR_VERSION_3:
252
-        case TR_VERSION_5:
253
-        case TR_VERSION_UNKNOWN:
254
-            if (moveable[index].object_id == 2) {
255
-                ponytailId = getWorld().sizeSkeletalModel(); //! \fixme Why is this even needed?
256
-                ponytailMeshId = moveable[index].starting_mesh;
257
-                ponytailNumMeshes = ((moveable[index].num_meshes > 0) ?
258
-                                     moveable[index].num_meshes : 0);
259
-                ponytailAngle = -90.0f;
260
-                ponytail[0] = 0;
261
-                ponytail[1] = -20;
262
-                ponytail[2] = -20;
263
-                ponyOff = 40;
264
-                ponyOff2 = 0;
265
-
266
-                getRender().setFlags(Render::fRenderPonytail);
267
-                getLog() << "Found ponytail?" << Log::endl;
268
-            }
269
-            break;
270
-    }
271
-
272
-    // Animations
273
-    int a = moveable[index].animation;
274
-    unsigned int frame_offset = anim[a].frame_offset / 2;
275
-    int frame_step = anim[a].frame_size;
276
-
277
-    int frame_cycle = 0;
278
-
279
-    if (a >= (int)tr.NumAnimations())
280
-        a = tr.NumFrames() - frame_offset; //! \fixme Couldn't a be already used out of range?!
281
-    else
282
-        a = (anim[a].frame_offset / 2) - frame_offset; //! \fixme Same as a = 0; ??
283
-
284
-    if (frame_step != 0) // prevent divide-by-zero errors
285
-        a /= frame_step;
286
-
287
-    if (a != 0)
288
-        frame_offset += frame_step * (frame_cycle % a);
289
-
290
-    if (a < 0) {
291
-        getLog() << "Invalid animation data for model " << index << ". Skip!" << Log::endl;
292
-        return;
293
-    } else {
294
-        for (; a < tr.getNumAnimsForMoveable(index); a++) {
295
-            animation.push_back(new AnimationFrame(tr, index, a, &frame_offset, frame_step));
296
-
297
-            if (frame_offset > tr.NumFrames())
298
-                return;
299
-
300
-            frame_offset = anim[a].frame_offset / 2;
301
-            frame_step = anim[a].frame_size;
302
-        }
303
-    }
304
-}
305
-
306 107
 SkeletalModel::~SkeletalModel() {
307 108
     for (unsigned long i = 0; i < animation.size(); i++)
308 109
         delete animation[i];
309 110
 }
310 111
 
311 112
 void SkeletalModel::display(unsigned long aframe, unsigned long bframe) {
113
+    /*
312 114
     assert(aframe < size());
313 115
     assert(bframe < get(aframe).size());
314 116
 
@@ -343,63 +145,9 @@ void SkeletalModel::display(unsigned long aframe, unsigned long bframe) {
343 145
             glRotatef(rot[2], 0, 0, 1);
344 146
         }
345 147
 
346
-        // Draw layered lara in TR4 (2 meshes per tag)
347
-        if (tr4Overlay) {
348
-            BoneFrame& boneframe2 = get(0).get(0); //! \fixme Woot?
349
-            if (a < boneframe2.size())
350
-                boneframe2.get(a).display();
351
-        }
352
-
353
-        if (getRender().getFlags() & Render::fRenderPonytail) {
354
-            if ((ponytailId > 0) && (a == 14)) {
355
-                glPushMatrix();
356
-
357
-                // Mongoose 2002.08.30, TEST to align offset
358
-                glTranslatef(ponytail[0], ponytail[1], ponytail[2]);
359
-                glRotatef(ponytailAngle, 1, 0, 0);
360
-
361
-                // HACK: To fill TR4 void between ponytail/head
362
-                //   since no vertex welds are implemented yet
363
-                if (tr4Overlay)
364
-                    glScalef(1.20f, 1.20f, 1.20f);
365
-
366
-#ifdef EXPERIMENTAL_NON_ITEM_RENDER
367
-                getWorld().getSkeletalModel(ponytail).display(0, 0);
368
-#else
369
-                for (unsigned int i = 0; i < ponytailNumMeshes; i++) {
370
-                    glPushMatrix();
371
-
372
-                    if (i > 0) {
373
-                        glRotatef(randomNum(-8.0f, -10.0f), 1, 0, 0);
374
-                        glRotatef(randomNum(-5.0f, 5.0f), 0, 1, 0);
375
-                        glRotatef(randomNum(-5.0f, 5.0f), 0, 0, 1);
376
-                        glTranslatef(0.0, 0.0, ponyOff);
377
-                    }
378
-
379
-                    if (pigtails) {
380
-                        glPushMatrix();
381
-                        glTranslatef(ponyOff2, 0.0, 0.0);
382
-                        getWorld().getStaticMesh(ponytailMeshId + i).display();
383
-                        glPopMatrix();
384
-
385
-                        glPushMatrix();
386
-                        glTranslatef(-ponyOff2, 0.0, 0.0);
387
-                        getWorld().getStaticMesh(ponytailMeshId + i).display();
388
-                        glPopMatrix();
389
-                    } else {
390
-                        getWorld().getStaticMesh(ponytailMeshId + i).display();
391
-                    }
392
-                }
393
-
394
-                for (unsigned int i = 0; i < ponytailNumMeshes; i++)
395
-                    glPopMatrix();
396
-#endif
397
-                glPopMatrix();
398
-            }
399
-        }
400
-
401 148
         tag.display();
402 149
     }
150
+    */
403 151
 }
404 152
 
405 153
 int SkeletalModel::getId() {

+ 14
- 47
src/Sprite.cpp Parādīt failu

@@ -5,6 +5,8 @@
5 5
  * \author xythobuz
6 6
  */
7 7
 
8
+#include "glm/glm.hpp"
9
+
8 10
 #include "global.h"
9 11
 #include "Camera.h"
10 12
 #include "Game.h"
@@ -20,33 +22,13 @@ void SpriteSequence::add(Sprite s) {
20 22
     sprites.push_back(s);
21 23
 }
22 24
 
23
-// -----------------------
24
-
25
-SpriteSequence::SpriteSequence(TombRaider& tr, unsigned int item, unsigned int sequence) {
26
-    for (int i = 0; i < (-tr.SpriteSequence()[sequence].negative_length); i++)
27
-        oldsprites.push_back(new Sprite(tr, item, sequence, i));
28
-}
29
-
30
-SpriteSequence::~SpriteSequence() {
31
-    for (unsigned int i = 0; i < oldsprites.size(); i++)
32
-        delete oldsprites.at(i);
33
-}
34
-
35 25
 unsigned long SpriteSequence::size() {
36
-    if (oldsprites.size() > 0)
37
-        return oldsprites.size();
38
-    else
39
-        return sprites.size();
26
+    return sprites.size();
40 27
 }
41 28
 
42 29
 Sprite& SpriteSequence::get(unsigned long index) {
43
-    if (oldsprites.size() > 0) {
44
-        assert(index < oldsprites.size());
45
-        return *oldsprites.at(index);
46
-    } else {
47
-        assert(index < sprites.size());
48
-        return sprites.at(index);
49
-    }
30
+    assert(index < sprites.size());
31
+    return sprites.at(index);
50 32
 }
51 33
 
52 34
 // ----------------------------------------------------------------------------
@@ -98,39 +80,21 @@ Sprite::Sprite(uint16_t tile, uint8_t x, uint8_t y, uint16_t width, uint16_t hei
98 80
     //radius = width2 / 2.0f;
99 81
 }
100 82
 
101
-// -----------------------
102
-
103
-Sprite::Sprite(TombRaider& tr, unsigned int room, unsigned int index) {
104
-    float spriteVertices[12];
105
-    float spriteTexCoords[8];
106
-    float posUnused[3];
107
-
108
-    tr.getRoomSprite(room, index,
109
-                     10.0f, &texture, posUnused, spriteVertices, spriteTexCoords);
110
-
111
-    for (unsigned int j = 0; j < 12; j++)
112
-        vertex[j / 3][j % 3] = spriteVertices[j];
113
-
114
-    for (unsigned int j = 0; j < 8; j++)
115
-        texel[j / 2][j % 2] = spriteTexCoords[j];
116
-
117
-    //radius = 0.0f;
118
-}
119
-
120 83
 void Sprite::display() {
121
-    //if (!getRender().isVisible(pos[0], pos[1], pos[2], radius))
84
+    /*
85
+    //if (!Render::isVisible(pos[0], pos[1], pos[2], radius))
122 86
     //    return;
123 87
 
124 88
     glPushMatrix();
125 89
     //glTranslated(pos[0], pos[1], pos[2]);
126 90
 
127 91
     // Sprites must always face camera, because they have no depth =)
128
-    glRotated(OR_RAD_TO_DEG(getCamera().getRadianYaw()), 0, 1, 0);
92
+    glRotated(glm::degrees(Camera::getRadianYaw()), 0, 1, 0);
129 93
 
130
-    switch (getRender().getMode()) {
94
+    switch (Render::getMode()) {
131 95
         // No vertex lighting on sprites, as far as I see in specs
132 96
         // So just draw normal texture, no case 2
133
-        case Render::modeSolid:
97
+        case RenderMode::Solid:
134 98
             glBegin(GL_TRIANGLE_STRIP);
135 99
             glColor3f(texel[0][0], texel[0][1], 0.5);
136 100
             glVertex3fv(vertex[0]);
@@ -145,7 +109,7 @@ void Sprite::display() {
145 109
             glVertex3fv(vertex[2]);
146 110
             glEnd();
147 111
             break;
148
-        case Render::modeWireframe:
112
+        case RenderMode::Wireframe:
149 113
             glColor3ubv(CYAN);
150 114
             glBegin(GL_LINE_LOOP);
151 115
             glVertex3fv(vertex[0]);
@@ -171,9 +135,11 @@ void Sprite::display() {
171 135
     }
172 136
 
173 137
     glPopMatrix();
138
+    */
174 139
 }
175 140
 
176 141
 void Sprite::display(float x, float y, float w, float h) {
142
+    /*
177 143
     float z = 0.0f;
178 144
 
179 145
     getTextureManager().bindTextureId(texture);
@@ -193,5 +159,6 @@ void Sprite::display(float x, float y, float w, float h) {
193 159
     glVertex3f(x, y + h, z);
194 160
 
195 161
     glEnd();
162
+    */
196 163
 }
197 164
 

+ 14
- 141
src/StaticMesh.cpp Parādīt failu

@@ -28,19 +28,20 @@ TexturedTriangle::TexturedTriangle(int i[3], float s[6], int tex, unsigned short
28 28
 }
29 29
 
30 30
 void TexturedTriangle::display(float* vertices, float* colors, float* normals) {
31
-    assert(vertices != NULL);
31
+    /*
32
+    assert(vertices != nullptr);
32 33
 
33
-    if ((getRender().getMode() != Render::modeWireframe)
34
-        && (getRender().getMode() != Render::modeSolid)) {
34
+    if ((Render::getMode() != RenderMode::Wireframe)
35
+        && (Render::getMode() != RenderMode::Solid)) {
35 36
         getTextureManager().bindTextureId(texture);
36 37
     }
37 38
 
38 39
     glBegin(GL_TRIANGLES);
39 40
 
40
-    switch (getRender().getMode()) {
41
-        case Render::modeSolid:
42
-        case Render::modeVertexLight:
43
-            if (colors != NULL) {
41
+    switch (Render::getMode()) {
42
+        case RenderMode::Solid:
43
+            //case RenderMode::VertexLight:
44
+            if (colors != nullptr) {
44 45
                 glColor3fv(colors + index[0]);
45 46
                 glTexCoord2fv(st);
46 47
                 glVertex3fv(vertices + (index[0] * 3));
@@ -52,7 +53,7 @@ void TexturedTriangle::display(float* vertices, float* colors, float* normals) {
52 53
                 glColor3fv(colors + index[2]);
53 54
                 glTexCoord2fv(st + 4);
54 55
                 glVertex3fv(vertices + (index[2] * 3));
55
-            } else if (normals != NULL) {
56
+            } else if (normals != nullptr) {
56 57
                 glNormal3fv(normals + (index[0] * 3));
57 58
                 glTexCoord2fv(st);
58 59
                 glVertex3fv(vertices + (index[0] * 3));
@@ -74,7 +75,7 @@ void TexturedTriangle::display(float* vertices, float* colors, float* normals) {
74 75
             }
75 76
             break;
76 77
 
77
-        case Render::modeWireframe:
78
+        case RenderMode::Wireframe:
78 79
             glVertex3fv(vertices + (index[0] * 3));
79 80
             glVertex3fv(vertices + (index[1] * 3));
80 81
             glVertex3fv(vertices + (index[2] * 3));
@@ -90,6 +91,7 @@ void TexturedTriangle::display(float* vertices, float* colors, float* normals) {
90 91
     }
91 92
 
92 93
     glEnd();
94
+    */
93 95
 }
94 96
 
95 97
 // ----------------------------------------------------------------------------
@@ -98,137 +100,6 @@ StaticMesh::StaticMesh(int i, int m) : id(i), mesh(m) {
98 100
     vertices = colors = normals = nullptr;
99 101
 }
100 102
 
101
-#ifdef EXPERIMENTAL
102
-
103
-#include <map>
104
-std::map<unsigned int, unsigned int> gColorTextureHACK;
105
-
106
-int setupTextureColor(float* colorf) {
107
-    unsigned char color[4];
108
-    unsigned int colorI;
109
-    unsigned int texture;
110
-
111
-    color[0] = (unsigned char)(colorf[0] * 255.0f);
112
-    color[1] = (unsigned char)(colorf[1] * 255.0f);
113
-    color[2] = (unsigned char)(colorf[2] * 255.0f);
114
-    color[3] = (unsigned char)(colorf[3] * 255.0f);
115
-
116
-    ((unsigned char*)(&colorI))[3] = color[0];
117
-    ((unsigned char*)(&colorI))[2] = color[1];
118
-    ((unsigned char*)(&colorI))[1] = color[2];
119
-    ((unsigned char*)(&colorI))[0] = color[3];
120
-
121
-    try {
122
-        texture = gColorTextureHACK.at(colorI);
123
-    } catch (...) {
124
-        unsigned char* image = generateColorTexture(color, 32, 32, 32);
125
-        texture = getTextureManager().loadBufferSlot(image, 32, 32, RGBA, 32);
126
-        delete [] image;
127
-    }
128
-
129
-    return texture;
130
-}
131
-
132
-#endif
133
-
134
-StaticMesh::StaticMesh(TombRaider& tr, unsigned int index) {
135
-    int count, texture;
136
-    int vertexIndices[6];
137
-    float st[12];
138
-    float color[4];
139
-    unsigned short transparency;
140
-
141
-    if (!tr.isMeshValid(index)) {
142
-        dontshow = true;
143
-        return;
144
-    } else {
145
-        dontshow = false;
146
-    }
147
-
148
-    // Mongoose 2002.08.30, Testing support for 'shootable' models ( traceable )
149
-    tr.getMeshCollisionInfo(index, center, &radius);
150
-
151
-    //! \fixme Arrays don't work either  =)
152
-    // Mesh geometery, colors, etc
153
-    tr.getMeshVertexArrays(index,
154
-                           &vertexCount, &vertices,
155
-                           &normalCount, &normals,
156
-                           &colorCount,  &colors);
157
-
158
-    // Textured Triangles
159
-    count = tr.getMeshTexturedTriangleCount(index);
160
-    for (int i = 0; i < count; i++) {
161
-        tr.getMeshTexturedTriangle(index, i,
162
-                                   vertexIndices, st,
163
-                                   &texture, &transparency);
164
-        triangles.push_back(
165
-            new TexturedTriangle(vertexIndices, st, texture, transparency));
166
-    }
167
-
168
-    // Coloured Triangles
169
-    count = tr.getMeshColoredTriangleCount(index);
170
-    for (int i = 0; i < count; i++) {
171
-        tr.getMeshColoredTriangle(index, i,
172
-                                  vertexIndices, color);
173
-        st[0] = color[0];
174
-        st[1] = color[1];
175
-        st[2] = color[2];
176
-        st[3] = color[3];
177
-        st[4] = 1.0;
178
-        st[5] = 1.0;
179
-
180
-#ifdef EXPERIMENTAL
181
-        texture = setupTextureColor(color);
182
-#else
183
-        texture = 0; // White texture
184
-#endif
185
-        transparency = 0;
186
-
187
-        triangles.push_back(
188
-            new TexturedTriangle(vertexIndices, st, texture, transparency));
189
-    }
190
-
191
-    // Textured Rectangles
192
-    count = tr.getMeshTexturedRectangleCount(index);
193
-    for (int i = 0; i < count; i++) {
194
-        tr.getMeshTexturedRectangle(index, i,
195
-                                    vertexIndices, st,
196
-                                    &texture, &transparency);
197
-        triangles.push_back(
198
-            new TexturedTriangle(vertexIndices, st, texture, transparency));
199
-        triangles.push_back(
200
-            new TexturedTriangle(vertexIndices + 3, st + 6, texture, transparency));
201
-    }
202
-
203
-    // Coloured Rectangles
204
-    count = tr.getMeshColoredRectangleCount(index);
205
-    for (int i = 0; i < count; i++) {
206
-        tr.getMeshColoredRectangle(index, i,
207
-                                   vertexIndices, color);
208
-
209
-        st[0] = color[0];
210
-        st[1] = color[1];
211
-        st[2] = color[2];
212
-        st[3] = color[3];
213
-        st[4] = 1.0;
214
-        st[5] = 1.0;
215
-
216
-#ifdef EXPERIMENTAL
217
-        texture = setupTextureColor(color);
218
-#else
219
-        texture = 0; // White texture
220
-#endif
221
-        transparency = 0;
222
-
223
-        triangles.push_back(
224
-            new TexturedTriangle(vertexIndices, st, texture, transparency));
225
-        triangles.push_back(
226
-            new TexturedTriangle(vertexIndices + 3, st, texture, transparency));
227
-    }
228
-
229
-    id = mesh = -1;
230
-}
231
-
232 103
 StaticMesh::~StaticMesh() {
233 104
     while (!triangles.empty()) {
234 105
         delete triangles.back();
@@ -241,6 +112,7 @@ StaticMesh::~StaticMesh() {
241 112
 }
242 113
 
243 114
 void StaticMesh::display() {
115
+    /*
244 116
     if ((id != -1) && (mesh != -1)) {
245 117
         getWorld().getMesh(mesh).drawSolid();
246 118
         return;
@@ -254,7 +126,7 @@ void StaticMesh::display() {
254 126
         //! \fixme 'AMBIENT' -- Mongoose 2002.01.08
255 127
         glColor3ubv(WHITE);
256 128
 
257
-        if (getRender().getMode() == Render::modeWireframe)
129
+        if (Render::getMode() == RenderMode::Wireframe)
258 130
             glColor3ubv(WHITE);
259 131
 
260 132
         getTextureManager().bindTextureId(TEXTURE_WHITE, TextureManager::TextureStorage::SYSTEM);
@@ -262,6 +134,7 @@ void StaticMesh::display() {
262 134
         for (unsigned int i = 0; i < triangles.size(); i++)
263 135
             triangles.at(i)->display(vertices, colors, normals);
264 136
     }
137
+    */
265 138
 }
266 139
 
267 140
 float StaticMesh::getRadius() {

+ 45
- 81
src/TextureManager.cpp Parādīt failu

@@ -40,21 +40,7 @@ void TextureTile::add(TextureTileVertex* t) {
40 40
     vertices.push_back(t);
41 41
 }
42 42
 
43
-bool TextureTile::isTriangle() {
44
-    assert(vertices.size() >= 3);
45
-
46
-    if (vertices.size() == 3)
47
-        return true;
48
-
49
-    return ((vertices.at(3)->xPixel == 0)
50
-            && (vertices.at(3)->xCoordinate == 0)
51
-            && (vertices.at(3)->yPixel == 0)
52
-            && (vertices.at(3)->yCoordinate == 0));
53
-}
54
-
55
-void TextureTile::display(float x, float y, float w, float h, float z) {
56
-    getTextureManager().bindTextureId(texture);
57
-
43
+void TextureTile::displayRectangle(float a[3], float b[3], float c[3], float d[3]) {
58 44
     //! \fixme TR Rosetta Stone says this, but looks strange?
59 45
     /*
60 46
     if (attribute == 0) {
@@ -63,23 +49,6 @@ void TextureTile::display(float x, float y, float w, float h, float z) {
63 49
     }
64 50
     */
65 51
 
66
-    if (isTriangle())
67
-        displayTriangle(x, y, w, h, z);
68
-    else
69
-        displayRectangle(x, y, w, h, z);
70
-
71
-    /*
72
-    if (attribute == 0) {
73
-        glEnable(GL_BLEND);
74
-    }
75
-    */
76
-}
77
-
78
-void TextureTile::displayRectangle(float x, float y, float w, float h, float z) {
79
-    displayRectangle(Vec3(x, y, z), Vec3(x + w, y, z), Vec3(x + w, y + h, z), Vec3(x, y + h, z));
80
-}
81
-
82
-void TextureTile::displayRectangle(Vec3 a, Vec3 b, Vec3 c, Vec3 d) {
83 52
     float xmin = 256.0f, xmax = 0.0f;
84 53
     float ymin = 256.0f, ymax = 0.0f;
85 54
     for (int i = 0; i < 4; i++) {
@@ -98,6 +67,7 @@ void TextureTile::displayRectangle(Vec3 a, Vec3 b, Vec3 c, Vec3 d) {
98 67
         }
99 68
     }
100 69
 
70
+    /*
101 71
     glBegin(GL_QUADS);
102 72
     glTexCoord2f(xmin / 256.0f, ymin / 256.0f);
103 73
     glVertex3f(a.x, a.y, a.z);
@@ -108,24 +78,11 @@ void TextureTile::displayRectangle(Vec3 a, Vec3 b, Vec3 c, Vec3 d) {
108 78
     glTexCoord2f(xmin / 256.0f, ymax / 256.0f);
109 79
     glVertex3f(d.x, d.y, d.z);
110 80
     glEnd();
81
+    */
111 82
 }
112 83
 
113
-void TextureTile::displayTriangle(float x, float y, float w, float h, float z) {
114
-    displayTriangle(Vec3(x, y, z), Vec3(x + w, y, z), Vec3(x + w, y + h, z));
115
-}
84
+void TextureTile::displayTriangle(float a[3], float b[3], float c[3]) {
116 85
 
117
-void TextureTile::displayTriangle(Vec3 a, Vec3 b, Vec3 c) {
118
-    glBegin(GL_TRIANGLE_STRIP);
119
-    glTexCoord2f(vertices.at(0)->xPixel / 256.0f,
120
-                 vertices.at(0)->yPixel / 256.0f);
121
-    glVertex3f(a.x, a.y, a.z);
122
-    glTexCoord2f(vertices.at(1)->xPixel / 256.0f,
123
-                 vertices.at(1)->yPixel / 256.0f);
124
-    glVertex3f(b.x, b.y, b.z);
125
-    glTexCoord2f(vertices.at(2)->xPixel / 256.0f,
126
-                 vertices.at(2)->yPixel / 256.0f);
127
-    glVertex3f(c.x, c.y, c.z);
128
-    glEnd();
129 86
 }
130 87
 
131 88
 // ----------------------------------------------------------------------------
@@ -209,8 +166,21 @@ std::vector<unsigned int>& TextureManager::getIds(TextureStorage s) {
209 166
 }
210 167
 
211 168
 int TextureManager::initialize() {
169
+    assert(mTextureIdsGame.size() == 0);
170
+    assert(mTextureIdsSystem.size() == 0);
171
+
172
+    while (mTextureIdsSystem.size() < 2) {
173
+        unsigned int id;
174
+        glGenTextures(1, &id);
175
+        mTextureIdsSystem.push_back(id);
176
+    }
177
+
178
+    return 0;
179
+}
180
+
181
+int TextureManager::initializeSplash() {
212 182
     unsigned char* image = generateColorTexture(WHITE, 32, 32, 32);
213
-    int res = loadBufferSlot(image, 32, 32, RGBA, 32, TextureStorage::SYSTEM, TEXTURE_WHITE);
183
+    int res = loadBufferSlot(image, 32, 32, ColorMode::RGBA, 32, TextureStorage::SYSTEM, TEXTURE_WHITE, false);
214 184
     delete [] image;
215 185
     if (res < 0) {
216 186
         return -1;
@@ -232,12 +202,13 @@ int TextureManager::loadBufferSlot(unsigned char* image,
232 202
                                    unsigned int width, unsigned int height,
233 203
                                    ColorMode mode, unsigned int bpp,
234 204
                                    TextureStorage s, int slot, bool filter) {
235
-    assert(image != NULL);
236 205
     assert(width > 0);
237 206
     assert(height > 0);
238
-    assert((mode == GREYSCALE) || (mode == RGB)
239
-           || (mode == BGR) || (mode == ARGB)
240
-           || (mode == RGBA) || (mode ==  BGRA));
207
+    assert((mode == ColorMode::RGB)
208
+           || (mode == ColorMode::BGR)
209
+           || (mode == ColorMode::ARGB)
210
+           || (mode == ColorMode::RGBA)
211
+           || (mode ==  ColorMode::BGRA));
241 212
     assert((bpp == 8) || (bpp == 24) || (bpp == 32));
242 213
 
243 214
     if (slot == -1)
@@ -249,55 +220,49 @@ int TextureManager::loadBufferSlot(unsigned char* image,
249 220
         getIds(s).push_back(id);
250 221
     }
251 222
 
223
+    if (image == nullptr)
224
+        return slot;
225
+
252 226
     unsigned int glcMode;
253 227
     switch (mode) {
254
-        case GREYSCALE:
255
-            glcMode = GL_LUMINANCE;
228
+        case ColorMode::BGR:
229
+            glcMode = GL_BGR;
256 230
             break;
257 231
 
258
-        case BGR:
259
-            bgr2rgb24(image, width, height);
232
+        case ColorMode::RGB:
260 233
             glcMode = GL_RGB;
261 234
             break;
262 235
 
263
-        case RGB:
264
-            glcMode = GL_RGB;
265
-            break;
266
-
267
-        case ARGB:
236
+        case ColorMode::ARGB:
268 237
             argb2rgba32(image, width, height);
269 238
             glcMode = GL_RGBA;
270 239
             break;
271 240
 
272
-        case BGRA:
273
-            bgra2rgba32(image, width, height);
274
-            glcMode = GL_RGBA;
241
+        case ColorMode::BGRA:
242
+            glcMode = GL_BGRA;
275 243
             break;
276 244
 
277
-        case RGBA:
245
+        case ColorMode::RGBA:
278 246
             glcMode = GL_RGBA;
279 247
             break;
280 248
     }
281 249
 
282
-    glColor3ubv(WHITE);
283
-    glEnable(GL_DEPTH_TEST);
284
-    glShadeModel(GL_SMOOTH);
285 250
     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
286 251
     glBindTexture(GL_TEXTURE_2D, getIds(s).at(slot));
252
+    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, glcMode, GL_UNSIGNED_BYTE, image);
287 253
 
288 254
     if (filter) {
289
-        glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
290
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
291
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
255
+        // Trilinear filtering
292 256
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
293 257
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
258
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
259
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
260
+        glGenerateMipmap(GL_TEXTURE_2D);
294 261
     } else {
295 262
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
296 263
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
297 264
     }
298 265
 
299
-    glTexImage2D(GL_TEXTURE_2D, 0, bpp / 8, width, height, 0, glcMode, GL_UNSIGNED_BYTE, image);
300
-
301 266
     return slot;
302 267
 }
303 268
 
@@ -305,12 +270,11 @@ int TextureManager::numTextures(TextureStorage s) {
305 270
     return getIds(s).size();
306 271
 }
307 272
 
308
-void TextureManager::bindTextureId(unsigned int n, TextureStorage s) {
273
+void TextureManager::bindTextureId(unsigned int n, TextureStorage s, unsigned int unit) {
309 274
     assert(n < getIds(s).size());
275
+    assert(unit < 80); //! \todo Query GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS
310 276
 
311
-    glEnable(GL_TEXTURE_2D);
312
-    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
313
-
277
+    glActiveTexture(GL_TEXTURE0 + unit);
314 278
     glBindTexture(GL_TEXTURE_2D, getIds(s).at(n));
315 279
 }
316 280
 
@@ -329,7 +293,7 @@ int TextureManager::loadImage(const char* filename, TextureStorage s, int slot)
329 293
 }
330 294
 
331 295
 int TextureManager::loadPCX(const char* filename, TextureStorage s, int slot) {
332
-    assert(filename != NULL);
296
+    assert(filename != nullptr);
333 297
     assert(filename[0] != '\0');
334 298
 
335 299
     unsigned char* image;
@@ -353,7 +317,7 @@ int TextureManager::loadPCX(const char* filename, TextureStorage s, int slot) {
353 317
 
354 318
 int TextureManager::loadPNG(const char* filename, TextureStorage s, int slot) {
355 319
 #ifdef USING_PNG
356
-    assert(filename != NULL);
320
+    assert(filename != nullptr);
357 321
     assert(filename[0] != '\0');
358 322
 
359 323
     if (pngCheck(filename) != 0) {
@@ -384,7 +348,7 @@ int TextureManager::loadPNG(const char* filename, TextureStorage s, int slot) {
384 348
 }
385 349
 
386 350
 int TextureManager::loadTGA(const char* filename, TextureStorage s, int slot) {
387
-    assert(filename != NULL);
351
+    assert(filename != nullptr);
388 352
     assert(filename[0] != '\0');
389 353
 
390 354
     unsigned char* image;
@@ -402,7 +366,7 @@ int TextureManager::loadTGA(const char* filename, TextureStorage s, int slot) {
402 366
         }
403 367
         if (image) {
404 368
             id = loadBufferSlot(image, w, h,
405
-                                (type == 2) ? RGBA : RGB,
369
+                                (type == 2) ? ColorMode::RGBA : ColorMode::RGB,
406 370
                                 (type == 2) ? 32 : 24,
407 371
                                 s, slot);
408 372
             delete [] image;

+ 0
- 5631
src/TombRaider.cpp
Failā izmaiņas netiks attēlotas, jo tās ir par lielu
Parādīt failu


+ 116
- 74
src/UI.cpp Parādīt failu

@@ -73,14 +73,14 @@ int UI::initialize() {
73 73
     //! \todo Use our own font subsystem instead of this?
74 74
     const void* png_data;
75 75
     unsigned int png_size;
76
-    ImGui::GetDefaultFontData(NULL, NULL, &png_data, &png_size);
76
+    ImGui::GetDefaultFontData(nullptr, nullptr, &png_data, &png_size);
77 77
     int tex_x, tex_y, tex_comp;
78 78
     void* tex_data = stbi_load_from_memory((const unsigned char*)png_data,
79 79
                                            (int)png_size, &tex_x, &tex_y, &tex_comp, 0);
80 80
 
81
-    //! \fixme TODO use proper texture slot
82 81
     fontTex = getTextureManager().loadBufferSlot((unsigned char*)tex_data,
83
-              tex_x, tex_y, RGBA, 32, TextureManager::TextureStorage::SYSTEM, -1, false);
82
+              tex_x, tex_y, TextureManager::ColorMode::RGBA, 32,
83
+              TextureManager::TextureStorage::SYSTEM, -1, false);
84 84
 
85 85
     stbi_image_free(tex_data);
86 86
 
@@ -311,6 +311,43 @@ void UI::display() {
311 311
 
312 312
         ImGui::Separator();
313 313
 
314
+        if (ImGui::CollapsingHeader("Sound Map Player")) {
315
+            if (!Sound::getEnabled()) {
316
+                ImGui::Text("Please enable Sound first!");
317
+                if (ImGui::Button("Enable Sound!")) {
318
+                    Sound::setEnabled(true);
319
+                }
320
+            } else if (Sound::numBuffers() == 0) {
321
+                ImGui::Text("Please load a level!");
322
+            } else {
323
+                static int index = 0;
324
+                ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
325
+                ImGui::SliderInt("##soundslide", &index, 0, SoundManager::sizeSoundMap() - 1);
326
+                ImGui::PopItemWidth();
327
+                ImGui::SameLine();
328
+                if (ImGui::Button("+##soundplus", ImVec2(0, 0), true)) {
329
+                    if (index < (SoundManager::sizeSoundMap() - 1))
330
+                        index++;
331
+                    else
332
+                        index = 0;
333
+                }
334
+                ImGui::SameLine();
335
+                if (ImGui::Button("-##soundminus", ImVec2(0, 0), true)) {
336
+                    if (index > 0)
337
+                        index--;
338
+                    else
339
+                        index = SoundManager::sizeSoundMap() - 1;
340
+                }
341
+                ImGui::SameLine();
342
+                if (ImGui::Button("Play##soundplay")) {
343
+                    SoundManager::playSound(index);
344
+                }
345
+
346
+                ImGui::Text("Index: %d", SoundManager::getIndex(index));
347
+            }
348
+        }
349
+
350
+        /*
314 351
         static bool visibleTex = false;
315 352
         static bool visibleTile = false;
316 353
         static bool visibleAnim = false;
@@ -471,42 +508,6 @@ void UI::display() {
471 508
             }
472 509
         }
473 510
 
474
-        if (ImGui::CollapsingHeader("Sound Map Player")) {
475
-            if (!Sound::getEnabled()) {
476
-                ImGui::Text("Please enable Sound first!");
477
-                if (ImGui::Button("Enable Sound!")) {
478
-                    Sound::setEnabled(true);
479
-                }
480
-            } else if (Sound::numBuffers() == 0) {
481
-                ImGui::Text("Please load a level!");
482
-            } else {
483
-                static int index = 0;
484
-                ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
485
-                ImGui::SliderInt("##soundslide", &index, 0, SoundManager::sizeSoundMap() - 1);
486
-                ImGui::PopItemWidth();
487
-                ImGui::SameLine();
488
-                if (ImGui::Button("+##soundplus", ImVec2(0, 0), true)) {
489
-                    if (index < (SoundManager::sizeSoundMap() - 1))
490
-                        index++;
491
-                    else
492
-                        index = 0;
493
-                }
494
-                ImGui::SameLine();
495
-                if (ImGui::Button("-##soundminus", ImVec2(0, 0), true)) {
496
-                    if (index > 0)
497
-                        index--;
498
-                    else
499
-                        index = SoundManager::sizeSoundMap() - 1;
500
-                }
501
-                ImGui::SameLine();
502
-                if (ImGui::Button("Play##soundplay")) {
503
-                    SoundManager::playSound(index);
504
-                }
505
-
506
-                ImGui::Text("Index: %d", SoundManager::getIndex(index));
507
-            }
508
-        }
509
-
510 511
         if (ImGui::CollapsingHeader("Sprite Sequence Viewer")) {
511 512
             if (getWorld().sizeSprite() <= 0) {
512 513
                 ImGui::Text("Please load a level containing sprites!");
@@ -566,13 +567,14 @@ void UI::display() {
566 567
                 }
567 568
             }
568 569
         }
570
+        */
569 571
 
570 572
         ImGui::Separator();
571 573
 
572 574
         if (ImGui::CollapsingHeader("ImGui/Debug UI Help")) {
573
-            ImGui::TextWrapped("DebugViewer Textures/Textiles/Sprites will be drawn on"
574
-                               " the left side and scale with the size of this window!");
575
-            ImGui::Separator();
575
+            //ImGui::TextWrapped("DebugViewer Textures/Textiles/Sprites will be drawn on"
576
+            //                   " the left side and scale with the size of this window!");
577
+            //ImGui::Separator();
576 578
             ImGui::ShowUserGuide();
577 579
         }
578 580
     }
@@ -652,44 +654,84 @@ void UI::renderImGui(ImDrawList** const cmd_lists, int cmd_lists_count) {
652 654
     if (cmd_lists_count == 0)
653 655
         return;
654 656
 
655
-    getWindow().glEnter2D();
656
-
657
-    glDisable(GL_DEPTH_TEST);
658 657
     glEnable(GL_SCISSOR_TEST);
658
+    glDisable(GL_DEPTH_TEST);
659
+
660
+    Window::imguiShader.use();
661
+
662
+    glUniform2f(Window::imguiShader.getUniform(0), getWindow().getWidth(), getWindow().getHeight());
663
+
664
+    getTextureManager().bindTextureId(fontTex, TextureManager::TextureStorage::SYSTEM, 0);
665
+    glUniform1i(Window::imguiShader.getUniform(1), 0);
666
+
667
+    glEnableVertexAttribArray(0); // Vertices
668
+    glBindBuffer(GL_ARRAY_BUFFER, Window::imguiShader.getBuffer(0));
669
+    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, nullptr);
670
+
671
+    glEnableVertexAttribArray(1); // UVs
672
+    glBindBuffer(GL_ARRAY_BUFFER, Window::imguiShader.getBuffer(1));
673
+    glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, nullptr);
674
+
675
+    glEnableVertexAttribArray(2); // Colors
676
+    glBindBuffer(GL_ARRAY_BUFFER, Window::imguiShader.getBuffer(2));
677
+    glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
678
+
679
+    std::vector<glm::vec2> vertices;
680
+    std::vector<glm::vec2> uvs;
681
+    std::vector<glm::vec4> colors;
682
+
683
+    /*! \fixme Don't copy data
684
+     * The GL calls and the shaders can probably be slightly altered
685
+     * to avoid copying all the vertices, uvs and colors again here.
686
+     */
687
+
688
+    for (int i = 0; i < cmd_lists_count; i++) {
689
+        auto& commands = cmd_lists[i]->commands;
690
+        auto& buffer = cmd_lists[i]->vtx_buffer;
659 691
 
660
-    glEnableClientState(GL_VERTEX_ARRAY);
661
-    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
662
-    glEnableClientState(GL_COLOR_ARRAY);
663
-
664
-    // Setup texture
665
-    getTextureManager().bindTextureId(fontTex, TextureManager::TextureStorage::SYSTEM);
666
-
667
-    // Render command lists
668
-    for (int n = 0; n < cmd_lists_count; n++) {
669
-        const ImDrawList* cmd_list = cmd_lists[n];
670
-        const unsigned char* vtx_buffer = (const unsigned char*)cmd_list->vtx_buffer.begin();
671
-        glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer));
672
-        glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer + 8));
673
-        glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (void*)(vtx_buffer + 16));
674
-
675
-        int vtx_offset = 0;
676
-        const ImDrawCmd* pcmd_end = cmd_list->commands.end();
677
-        for (const ImDrawCmd* pcmd = cmd_list->commands.begin(); pcmd != pcmd_end; pcmd++) {
678
-            glScissor((int)pcmd->clip_rect.x, (int)(ImGui::GetIO().DisplaySize.y - pcmd->clip_rect.w),
679
-                      (int)(pcmd->clip_rect.z - pcmd->clip_rect.x),
680
-                      (int)(pcmd->clip_rect.w - pcmd->clip_rect.y));
681
-            glDrawArrays(GL_TRIANGLES, vtx_offset, pcmd->vtx_count);
682
-            vtx_offset += pcmd->vtx_count;
692
+        int offset = 0;
693
+        for (int n = 0; n < commands.size(); n++) {
694
+            for (int v = 0; v < commands[n].vtx_count; v++) {
695
+                vertices.push_back(glm::vec2(buffer[offset + v].pos.x, buffer[offset + v].pos.y));
696
+                uvs.push_back(glm::vec2(buffer[offset + v].uv.x, buffer[offset + v].uv.y));
697
+
698
+                float r, g, b, a;
699
+                a = ((buffer[offset + v].col & 0xFF000000) >> 24) / 255.0f;
700
+                b = ((buffer[offset + v].col & 0x00FF0000) >> 16) / 255.0f;
701
+                g = ((buffer[offset + v].col & 0x0000FF00) >> 8) / 255.0f;
702
+                r = (buffer[offset + v].col & 0x000000FF) / 255.0f;
703
+                colors.push_back(glm::vec4(r, g, b, a));
704
+            }
705
+
706
+            offset += commands[n].vtx_count;
707
+
708
+            glBindBuffer(GL_ARRAY_BUFFER, Window::imguiShader.getBuffer(0));
709
+            glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(glm::vec2), &vertices[0], GL_STATIC_DRAW);
710
+
711
+            glBindBuffer(GL_ARRAY_BUFFER, Window::imguiShader.getBuffer(1));
712
+            glBufferData(GL_ARRAY_BUFFER, uvs.size() * sizeof(glm::vec2), &uvs[0], GL_STATIC_DRAW);
713
+
714
+            glBindBuffer(GL_ARRAY_BUFFER, Window::imguiShader.getBuffer(2));
715
+            glBufferData(GL_ARRAY_BUFFER, colors.size() * sizeof(glm::vec4), &colors[0], GL_STATIC_DRAW);
716
+
717
+            glScissor(commands[n].clip_rect.x,
718
+                      getWindow().getHeight() - commands[n].clip_rect.w,
719
+                      commands[n].clip_rect.z - commands[n].clip_rect.x,
720
+                      commands[n].clip_rect.w - commands[n].clip_rect.y);
721
+
722
+            glDrawArrays(GL_TRIANGLES, 0, vertices.size());
723
+
724
+            vertices.clear();
725
+            uvs.clear();
726
+            colors.clear();
683 727
         }
684 728
     }
685 729
 
730
+    glDisableVertexAttribArray(0);
731
+    glDisableVertexAttribArray(1);
732
+    glDisableVertexAttribArray(2);
733
+
686 734
     glEnable(GL_DEPTH_TEST);
687 735
     glDisable(GL_SCISSOR_TEST);
688
-
689
-    glDisableClientState(GL_VERTEX_ARRAY);
690
-    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
691
-    glDisableClientState(GL_COLOR_ARRAY);
692
-
693
-    getWindow().glExit2D();
694 736
 }
695 737
 

+ 0
- 254
src/ViewVolume.cpp Parādīt failu

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

+ 0
- 1
src/commands/CMakeLists.txt Parādīt failu

@@ -1,6 +1,5 @@
1 1
 # Source files
2 2
 set (CMD_SRCS ${CMD_SRCS} "Command.cpp")
3
-set (CMD_SRCS ${CMD_SRCS} "CommandAnimate.cpp")
4 3
 set (CMD_SRCS ${CMD_SRCS} "CommandBind.cpp")
5 4
 set (CMD_SRCS ${CMD_SRCS} "CommandEngine.cpp")
6 5
 set (CMD_SRCS ${CMD_SRCS} "CommandGame.cpp")

+ 0
- 3
src/commands/Command.cpp Parādīt failu

@@ -12,7 +12,6 @@
12 12
 #include "Log.h"
13 13
 #include "utils/strings.h"
14 14
 #include "commands/Command.h"
15
-#include "commands/CommandAnimate.h"
16 15
 #include "commands/CommandBind.h"
17 16
 #include "commands/CommandEngine.h"
18 17
 #include "commands/CommandGame.h"
@@ -36,10 +35,8 @@ void Command::fillCommandList() {
36 35
     commands.push_back(std::shared_ptr<Command>(new CommandSet()));
37 36
     commands.push_back(std::shared_ptr<Command>(new CommandGet()));
38 37
     commands.push_back(std::shared_ptr<Command>(new CommandScreenshot()));
39
-    commands.push_back(std::shared_ptr<Command>(new CommandAnimate()));
40 38
     commands.push_back(std::shared_ptr<Command>(new CommandMove()));
41 39
     commands.push_back(std::shared_ptr<Command>(new CommandMode()));
42
-    commands.push_back(std::shared_ptr<Command>(new CommandRenderflag()));
43 40
     commands.push_back(std::shared_ptr<Command>(new CommandPos()));
44 41
     commands.push_back(std::shared_ptr<Command>(new CommandViewmodel()));
45 42
     commands.push_back(std::shared_ptr<Command>(new CommandPigtail()));

+ 0
- 82
src/commands/CommandAnimate.cpp Parādīt failu

@@ -1,82 +0,0 @@
1
-/*!
2
- * \file src/commands/CommandAnimate.cpp
3
- * \brief Animate command
4
- *
5
- * \author xythobuz
6
- */
7
-
8
-#include "global.h"
9
-#include "Log.h"
10
-#include "Game.h"
11
-#include "Render.h"
12
-#include "World.h"
13
-#include "commands/CommandAnimate.h"
14
-
15
-std::string CommandAnimate::name() {
16
-    return "animate";
17
-}
18
-
19
-std::string CommandAnimate::brief() {
20
-    return "[BOOL|n|p] - Animate models";
21
-}
22
-
23
-void CommandAnimate::printHelp() {
24
-    getLog() << "animate-Command Usage:" << Log::endl;
25
-    getLog() << "  animate [n|p|BOOL]" << Log::endl;
26
-    getLog() << "Where the commands have the following meaning:" << Log::endl;
27
-    getLog() << "  BOOL to (de)activate animating all models" << Log::endl;
28
-    getLog() << "  n to step all models to their next animation" << Log::endl;
29
-    getLog() << "  p to step all models to their previous animation" << Log::endl;
30
-}
31
-
32
-int CommandAnimate::execute(std::istream& args) {
33
-    if (!getGame().isLoaded()) {
34
-        getLog() << "Use animate command interactively!" << Log::endl;
35
-        return -1;
36
-    }
37
-
38
-    if (args.peek() == 'n') {
39
-        // Step all skeletal models to their next animation
40
-        if (getRender().getFlags() & Render::fAnimateAllModels) {
41
-            for (unsigned int i = 0; i < getWorld().sizeEntity(); i++) {
42
-                Entity& e = getWorld().getEntity(i);
43
-                SkeletalModel& m = e.getModel();
44
-                if (e.getAnimation() < (m.size() - 1))
45
-                    e.setAnimation(e.getAnimation() + 1);
46
-                else
47
-                    e.setAnimation(0);
48
-            }
49
-        } else {
50
-            getLog() << "Animations need to be enabled!" << Log::endl;
51
-        }
52
-    } else if (args.peek() == 'p') {
53
-        // Step all skeletal models to their previous animation
54
-        if (getRender().getFlags() & Render::fAnimateAllModels) {
55
-            for (unsigned int i = 0; i < getWorld().sizeEntity(); i++) {
56
-                Entity& e = getWorld().getEntity(i);
57
-                SkeletalModel& m = e.getModel();
58
-                if (e.getAnimation() > 0)
59
-                    e.setAnimation(e.getAnimation() - 1);
60
-                else if (m.size() > 0)
61
-                    e.setAnimation(m.size() - 1);
62
-            }
63
-        } else {
64
-            getLog() << "Animations need to be enabled!" << Log::endl;
65
-        }
66
-    } else {
67
-        // Enable or disable animating all skeletal models
68
-        bool b = false;
69
-        if (!(args >> b)) {
70
-            getLog() << "Pass BOOL to animate command!" << Log::endl;
71
-            return -2;
72
-        }
73
-        if (b)
74
-            getRender().setFlags(Render::fAnimateAllModels);
75
-        else
76
-            getRender().clearFlags(Render::fAnimateAllModels);
77
-        getLog() << (b ? "Animating all models" : "No longer animating all models") << Log::endl;
78
-    }
79
-
80
-    return 0;
81
-}
82
-

+ 1
- 1
src/commands/CommandEngine.cpp Parādīt failu

@@ -83,7 +83,7 @@ int CommandScreenshot::execute(std::istream& args) {
83 83
 
84 84
     renderFrame();
85 85
     renderFrame(); // Double buffered
86
-    getRender().screenShot(filename.c_str());
86
+    Render::screenShot(filename.c_str());
87 87
 
88 88
     getMenu().setVisible(false);
89 89
     UI::setVisible(true);

+ 13
- 80
src/commands/CommandRender.cpp Parādīt failu

@@ -8,7 +8,6 @@
8 8
 #include "global.h"
9 9
 #include "Game.h"
10 10
 #include "Log.h"
11
-#include "RunTime.h"
12 11
 #include "Render.h"
13 12
 #include "commands/CommandRender.h"
14 13
 
@@ -27,8 +26,8 @@ void CommandMode::printHelp() {
27 26
     getLog() << "  wireframe" << Log::endl;
28 27
     getLog() << "  solid" << Log::endl;
29 28
     getLog() << "  texture" << Log::endl;
30
-    getLog() << "  vertexlight" << Log::endl;
31 29
     getLog() << "  titlescreen" << Log::endl;
30
+    getLog() << "  disabled" << Log::endl;
32 31
 
33 32
 }
34 33
 
@@ -41,21 +40,21 @@ int CommandMode::execute(std::istream& args) {
41 40
     std::string s;
42 41
     args >> s;
43 42
 
44
-    if (s.compare("wireframe") == 0) {
45
-        getRender().setMode(Render::modeWireframe);
43
+    if (s == "wireframe") {
44
+        Render::setMode(RenderMode::Wireframe);
46 45
         getLog() << "Wireframe mode" << Log::endl;
47
-    } else if (s.compare("solid") == 0) {
48
-        getRender().setMode(Render::modeSolid);
46
+    } else if (s == "solid") {
47
+        Render::setMode(RenderMode::Solid);
49 48
         getLog() << "Solid mode" << Log::endl;
50
-    } else if (s.compare("texture") == 0) {
51
-        getRender().setMode(Render::modeTexture);
52
-        getLog() << "Texture mode" << Log::endl;
53
-    } else if (s.compare("vertexlight") == 0) {
54
-        getRender().setMode(Render::modeVertexLight);
55
-        getLog() << "Vertexlight mode" << Log::endl;
56
-    } else if (s.compare("titlescreen") == 0) {
57
-        getRender().setMode(Render::modeLoadScreen);
49
+    } else if (s == "texture") {
50
+        Render::setMode(RenderMode::Texture);
51
+        getLog() << "Texture Mode" << Log::endl;
52
+    } else if (s == "titlescreen") {
53
+        Render::setMode(RenderMode::LoadScreen);
58 54
         getLog() << "Titlescreen mode" << Log::endl;
55
+    } else if (s == "disabled") {
56
+        Render::setMode(RenderMode::Disabled);
57
+        getLog() << "Disabled mode" << Log::endl;
59 58
     } else {
60 59
         getLog() << "Invalid use of mode command (" << s << ")!" << Log::endl;
61 60
         return -2;
@@ -64,69 +63,3 @@ int CommandMode::execute(std::istream& args) {
64 63
     return 0;
65 64
 }
66 65
 
67
-// --------------------------------------
68
-
69
-std::string CommandRenderflag::name() {
70
-    return "renderflag";
71
-}
72
-
73
-std::string CommandRenderflag::brief() {
74
-    return "STRING BOOL - Toggle Render flag";
75
-}
76
-
77
-void CommandRenderflag::printHelp() {
78
-    getLog() << "renderflag-Command Usage:" << Log::endl;
79
-    getLog() << "  renderflag STRING BOOL" << Log::endl;
80
-    getLog() << "Where STRING is one of the following:" << Log::endl;
81
-    getLog() << "  ralpha" << Log::endl;
82
-    getLog() << "  entmodel" << Log::endl;
83
-    getLog() << "  fog" << Log::endl;
84
-    getLog() << "  light" << Log::endl;
85
-    getLog() << "  ponytail" << Log::endl;
86
-}
87
-
88
-int CommandRenderflag::execute(std::istream& args) {
89
-    if (!getRunTime().isRunning()) {
90
-        getLog() << "Use renderflag-Command interactively!" << Log::endl;
91
-        return -1;
92
-    }
93
-
94
-    std::string flag;
95
-    bool b;
96
-    args >> flag >> b;
97
-    if (!args) {
98
-        getLog() << "Pass STRING and BOOL to renderflag command!" << Log::endl;
99
-        return -2;
100
-    }
101
-
102
-    int f = stringToFlag(flag);
103
-    if (f == -1) {
104
-        getLog() << "Unknown flag \"" << flag << "\"!" << Log::endl;
105
-        return -3;
106
-    }
107
-
108
-    if (b) {
109
-        getRender().setFlags((unsigned int)f);
110
-    } else {
111
-        getRender().clearFlags((unsigned int)f);
112
-    }
113
-
114
-    return 0;
115
-}
116
-
117
-int CommandRenderflag::stringToFlag(std::string flag) {
118
-    if (flag == "ralpha") {
119
-        return Render::fRoomAlpha;
120
-    } else if (flag == "entmodel") {
121
-        return Render::fEntityModels;
122
-    } else if (flag == "fog") {
123
-        return Render::fFog;
124
-    } else if (flag == "light") {
125
-        return Render::fGL_Lights;
126
-    } else if (flag == "ponytail") {
127
-        return Render::fRenderPonytail;
128
-    } else {
129
-        return -1;
130
-    }
131
-}
132
-

+ 6
- 4
src/commands/CommandSet.cpp Parādīt failu

@@ -5,6 +5,8 @@
5 5
  * \author xythobuz
6 6
  */
7 7
 
8
+#include "glm/glm.hpp"
9
+
8 10
 #include "global.h"
9 11
 #include "Camera.h"
10 12
 #include "Log.h"
@@ -103,14 +105,14 @@ int CommandSet::execute(std::istream& args) {
103 105
             getLog() << "set-mouse_x-Error: Invalid value" << Log::endl;
104 106
             return -6;
105 107
         }
106
-        getCamera().setSensitivityX(OR_DEG_TO_RAD(sense));
108
+        Camera::setSensitivityX(glm::radians(sense));
107 109
     } else if (var.compare("mouse_y") == 0) {
108 110
         float sense = 1.0f;
109 111
         if (!(args >> sense)) {
110 112
             getLog() << "set-mouse_y-Error: Invalid value" << Log::endl;
111 113
             return -7;
112 114
         }
113
-        getCamera().setSensitivityY(OR_DEG_TO_RAD(sense));
115
+        Camera::setSensitivityY(glm::radians(sense));
114 116
     } else if (var.compare("fps") == 0) {
115 117
         bool fps = false;
116 118
         if (!(args >> fps)) {
@@ -187,9 +189,9 @@ int CommandGet::execute(std::istream& args) {
187 189
     } else if (var.compare("volume") == 0) {
188 190
         getLog() << Sound::getVolume() << Log::endl;
189 191
     } else if (var.compare("mouse_x") == 0) {
190
-        getLog() << OR_RAD_TO_DEG(getCamera().getSensitivityX()) << Log::endl;
192
+        getLog() << glm::degrees(Camera::getSensitivityX()) << Log::endl;
191 193
     } else if (var.compare("mouse_y") == 0) {
192
-        getLog() << OR_RAD_TO_DEG(getCamera().getSensitivityY()) << Log::endl;
194
+        getLog() << glm::degrees(Camera::getSensitivityY()) << Log::endl;
193 195
     } else if (var.compare("fps") == 0) {
194 196
         getLog() << getRunTime().getShowFPS() << Log::endl;
195 197
     } else if (var.compare("basedir") == 0) {

+ 1
- 1
src/loader/Loader.cpp Parādīt failu

@@ -42,7 +42,7 @@ std::unique_ptr<Loader> Loader::createLoader(std::string f) {
42 42
         case TR_4:
43 43
         case TR_5:
44 44
         case TR_UNKNOWN:
45
-            return NULL;
45
+            return nullptr;
46 46
 
47 47
         case TR_2:
48 48
             return std::unique_ptr<Loader>(new LoaderTR2());

+ 38
- 27
src/loader/LoaderTR2.cpp Parādīt failu

@@ -7,6 +7,9 @@
7 7
 
8 8
 #include <vector>
9 9
 
10
+#include "glm/glm.hpp"
11
+#include "glm/gtc/matrix_transform.hpp"
12
+
10 13
 #include "global.h"
11 14
 #include "Game.h"
12 15
 #include "Log.h"
@@ -15,8 +18,6 @@
15 18
 #include "SoundManager.h"
16 19
 #include "TextureManager.h"
17 20
 #include "World.h"
18
-#include "math/Matrix.h"
19
-#include "math/Vec3.h"
20 21
 #include "system/Sound.h"
21 22
 #include "utils/pixel.h"
22 23
 #include "loader/LoaderTR2.h"
@@ -88,7 +89,8 @@ void LoaderTR2::loadPaletteTextiles() {
88 89
 
89 90
         // Convert 16bit textile to 32bit textile
90 91
         unsigned char* img = argb16to32(&arr[0], 256, 256);
91
-        int r = getTextureManager().loadBufferSlot(img, 256, 256, ARGB, 32,
92
+        int r = getTextureManager().loadBufferSlot(img, 256, 256,
93
+                TextureManager::ColorMode::ARGB, 32,
92 94
                 TextureManager::TextureStorage::GAME, i);
93 95
         assert(r >= 0); //! \fixme properly handle error when texture could not be loaded!
94 96
         delete [] img;
@@ -190,16 +192,16 @@ void LoaderTR2::loadRooms() {
190 192
         uint32_t dataToFollow = file.readU32();
191 193
 
192 194
         uint16_t numVertices = file.readU16();
193
-        std::vector<Vec3> vertices;
195
+        std::vector<glm::vec3> vertices;
194 196
         float bbox[2][3] = {
195 197
             { 0.0f, 0.0f, 0.0f },
196 198
             { 0.0f, 0.0f, 0.0f }
197 199
         };
198 200
         for (unsigned int v = 0; v < numVertices; v++) {
199 201
             // Vertex coordinates, relative to x/zOffset
200
-            int16_t x = file.read16();
202
+            int32_t x = file.read16() + xOffset;
201 203
             int16_t y = file.read16();
202
-            int16_t z = file.read16();
204
+            int32_t z = file.read16() + zOffset;
203 205
 
204 206
             int16_t light1 = file.read16();
205 207
 
@@ -289,9 +291,7 @@ void LoaderTR2::loadRooms() {
289 291
             // TODO store sprites somewhere
290 292
         }
291 293
 
292
-        Matrix transform;
293
-        transform.setIdentity();
294
-        transform.translate(pos);
294
+        glm::mat4 transform = glm::translate(glm::mat4(1.0f), glm::vec3(pos[0], pos[1], pos[2]));
295 295
         room->addAdjacentRoom(i); // Always set room itself as first
296 296
 
297 297
         uint16_t numPortals = file.readU16();
@@ -321,31 +321,35 @@ void LoaderTR2::loadRooms() {
321 321
             int16_t yCorner4 = file.read16();
322 322
             int16_t zCorner4 = file.read16();
323 323
 
324
-            float vertices[4][3] = {
325
-                {
324
+            glm::vec4 vertices[4] = {
325
+                glm::vec4(
326 326
                     static_cast<float>(xCorner1),
327 327
                     static_cast<float>(yCorner1),
328
-                    static_cast<float>(zCorner1)
329
-                }, {
328
+                    static_cast<float>(zCorner1),
329
+                    1.0f
330
+                ), glm::vec4(
330 331
                     static_cast<float>(xCorner2),
331 332
                     static_cast<float>(yCorner2),
332
-                    static_cast<float>(zCorner2)
333
-                }, {
333
+                    static_cast<float>(zCorner2),
334
+                    1.0f
335
+                ), glm::vec4(
334 336
                     static_cast<float>(xCorner3),
335 337
                     static_cast<float>(yCorner3),
336
-                    static_cast<float>(zCorner3)
337
-                }, {
338
+                    static_cast<float>(zCorner3),
339
+                    1.0f
340
+                ), glm::vec4(
338 341
                     static_cast<float>(xCorner4),
339 342
                     static_cast<float>(yCorner4),
340
-                    static_cast<float>(zCorner4)
341
-                }
343
+                    static_cast<float>(zCorner4),
344
+                    0.0f
345
+                )
342 346
             };
343 347
 
344 348
             // Portals have relative coordinates
345
-            transform.multiply3v(vertices[0], vertices[0]);
346
-            transform.multiply3v(vertices[1], vertices[1]);
347
-            transform.multiply3v(vertices[2], vertices[2]);
348
-            transform.multiply3v(vertices[3], vertices[3]);
349
+            vertices[0] = transform * vertices[0];
350
+            vertices[1] = transform * vertices[1];
351
+            vertices[2] = transform * vertices[2];
352
+            vertices[3] = transform * vertices[3];
349 353
 
350 354
             float normals[3] = {
351 355
                 static_cast<float>(xNormal),
@@ -353,7 +357,14 @@ void LoaderTR2::loadRooms() {
353 357
                 static_cast<float>(zNormal)
354 358
             };
355 359
 
356
-            room->addPortal(new Portal(vertices, normals, adjoiningRoom));
360
+            glm::vec3 verts[4] = {
361
+                glm::vec3(vertices[0]),
362
+                glm::vec3(vertices[1]),
363
+                glm::vec3(vertices[2]),
364
+                glm::vec3(vertices[3])
365
+            };
366
+
367
+            room->addPortal(new Portal(verts, normals, adjoiningRoom));
357 368
             room->addAdjacentRoom(adjoiningRoom);
358 369
         }
359 370
 
@@ -542,7 +553,7 @@ void LoaderTR2::loadMeshes() {
542 553
         // TODO store mesh collision info somewhere
543 554
 
544 555
         uint16_t numVertices = mem.readU16();
545
-        std::vector<Vec3> vertices;
556
+        std::vector<glm::vec3> vertices;
546 557
         for (int v = 0; v < numVertices; v++) {
547 558
             int16_t x = mem.read16();
548 559
             int16_t y = mem.read16();
@@ -564,7 +575,7 @@ void LoaderTR2::loadMeshes() {
564 575
                 int16_t y = mem.read16();
565 576
                 int16_t z = mem.read16();
566 577
 
567
-                mesh->addNormal(Vec3(x, y, z));
578
+                mesh->addNormal(glm::vec3(x, y, z));
568 579
             }
569 580
         } else if (numNormals < 0) {
570 581
             // Internal vertex lighting is used,
@@ -957,7 +968,7 @@ void LoaderTR2::loadItems() {
957 968
 
958 969
                 float rot[3] = {
959 970
                     0.0f,
960
-                    OR_DEG_TO_RAD(((angle >> 14) & 0x03) * 90.0f),
971
+                    glm::radians(((angle >> 14) & 0x03) * 90.0f),
961 972
                     0.0f
962 973
                 };
963 974
 

+ 11
- 23
src/main.cpp Parādīt failu

@@ -17,11 +17,9 @@
17 17
 
18 18
 #ifndef UNIT_TEST
19 19
 
20
-#include "Camera.h"
21 20
 #include "Game.h"
22 21
 #include "Log.h"
23 22
 #include "MenuFolder.h"
24
-#include "Render.h"
25 23
 #include "RunTime.h"
26 24
 #include "SoundManager.h"
27 25
 #include "TextureManager.h"
@@ -41,20 +39,14 @@
41 39
 
42 40
 static std::string configFileToUse;
43 41
 
44
-static std::shared_ptr<Camera> gCamera;
45 42
 static std::shared_ptr<Game> gGame;
46 43
 static std::shared_ptr<Log> gLog;
47 44
 static std::shared_ptr<MenuFolder> gMenu;
48
-static std::shared_ptr<Render> gRender;
49 45
 static std::shared_ptr<RunTime> gRunTime;
50 46
 static std::shared_ptr<TextureManager> gTextureManager;
51 47
 static std::shared_ptr<Window> gWindow;
52 48
 static std::shared_ptr<World> gWorld;
53 49
 
54
-Camera& getCamera() {
55
-    return *gCamera;
56
-}
57
-
58 50
 Game& getGame() {
59 51
     return *gGame;
60 52
 }
@@ -67,10 +59,6 @@ Menu& getMenu() {
67 59
     return *gMenu;
68 60
 }
69 61
 
70
-Render& getRender() {
71
-    return *gRender;
72
-}
73
-
74 62
 RunTime& getRunTime() {
75 63
     return *gRunTime;
76 64
 }
@@ -100,11 +88,9 @@ int main(int argc, char* argv[]) {
100 88
     // RunTime is required by other constructors
101 89
     gRunTime.reset(new RunTime());
102 90
 
103
-    gCamera.reset(new Camera());
104 91
     gGame.reset(new Game());
105 92
     gLog.reset(new Log());
106 93
     gMenu.reset(new MenuFolder());
107
-    gRender.reset(new Render());
108 94
     gTextureManager.reset(new TextureManager());
109 95
     gWorld.reset(new World());
110 96
 
@@ -132,10 +118,10 @@ int main(int argc, char* argv[]) {
132 118
         return -2;
133 119
     }
134 120
 
135
-    // Initialize Font
136
-    error = Font::initialize();
121
+    // Initialize Texture Manager
122
+    error = getTextureManager().initialize();
137 123
     if (error != 0) {
138
-        std::cout << "Could not initialize Font (" << error << ")!" << std::endl;
124
+        std::cout << "Could not initialize TextureManager (" << error << ")!" << std::endl;
139 125
         return -3;
140 126
     }
141 127
 
@@ -153,17 +139,16 @@ int main(int argc, char* argv[]) {
153 139
         Command::executeFile(configFileToUse);
154 140
     }
155 141
 
156
-    // Initialize Sound
157
-    error = Sound::initialize();
142
+    error = getTextureManager().initializeSplash();
158 143
     if (error != 0) {
159
-        std::cout << "Could not initialize Sound (" << error << ")!" << std::endl;
144
+        std::cout << "Coult not load Splash Texture (" << error << ")!" << std::endl;
160 145
         return -4;
161 146
     }
162 147
 
163
-    // Initialize Texture Manager
164
-    error = getTextureManager().initialize();
148
+    // Initialize Sound
149
+    error = Sound::initialize();
165 150
     if (error != 0) {
166
-        std::cout << "Could not initialize TextureManager (" << error << ")!" << std::endl;
151
+        std::cout << "Could not initialize Sound (" << error << ")!" << std::endl;
167 152
         return -5;
168 153
     }
169 154
 
@@ -201,6 +186,7 @@ int main(int argc, char* argv[]) {
201 186
     UI::shutdown();
202 187
     Font::shutdown();
203 188
     Sound::shutdown();
189
+    Window::shutdownGL();
204 190
 
205 191
 #ifdef DEBUG
206 192
     std::cout << std::endl;
@@ -219,6 +205,7 @@ void renderFrame() {
219 205
     getMenu().display();
220 206
     UI::display();
221 207
 
208
+    /*
222 209
     if (getRunTime().getShowFPS()) {
223 210
         std::ostringstream s;
224 211
         s << getRunTime().getFPS() << "FPS";
@@ -226,6 +213,7 @@ void renderFrame() {
226 213
         Font::drawText(10, getWindow().getHeight() - 25, 0.6f, BLUE, s.str());
227 214
         getWindow().glExit2D();
228 215
     }
216
+    */
229 217
 
230 218
     getWindow().swapBuffersGL();
231 219
 

+ 0
- 9
src/math/CMakeLists.txt Parādīt failu

@@ -1,9 +0,0 @@
1
-# Source files
2
-set (MATH_SRCS ${MATH_SRCS} "math.cpp")
3
-set (MATH_SRCS ${MATH_SRCS} "Matrix.cpp")
4
-set (MATH_SRCS ${MATH_SRCS} "Quaternion.cpp")
5
-set (MATH_SRCS ${MATH_SRCS} "Vec3.cpp")
6
-
7
-# Add library
8
-add_library (OpenRaider_math OBJECT ${MATH_SRCS})
9
-

+ 0
- 515
src/math/Matrix.cpp Parādīt failu

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

+ 0
- 290
src/math/Quaternion.cpp Parādīt failu

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

+ 0
- 118
src/math/Vec3.cpp Parādīt failu

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

+ 0
- 94
src/math/math.cpp Parādīt failu

@@ -1,94 +0,0 @@
1
-/*!
2
- *
3
- * \file src/math/math.cpp
4
- * \brief Vector and Matrix math
5
- *
6
- * \author Mongoose
7
- * \author xythobuz
8
- */
9
-
10
-#include <cstdlib>
11
-#include <cmath>
12
-#include <float.h>
13
-#include <algorithm>
14
-
15
-#include "global.h"
16
-#include "math/Vec3.h"
17
-#include "math/Matrix.h"
18
-#include "math/math.h"
19
-
20
-bool equalEpsilon(float a, float b) {
21
-    float epsilon = FLT_EPSILON;
22
-    if (fabs(a - b) <= (std::max(fabs(a), fabs(b)) * epsilon))
23
-        return true;
24
-    return false;
25
-}
26
-
27
-int intersectionLinePolygon(float intersect[3],
28
-                            float p1[3], float p2[3], float polygon[3][3]) {
29
-    assert(polygon != NULL);
30
-
31
-    // float normal[3], a[3], b[3];
32
-    Vec3 a, b, normal, pA, pB;
33
-    float d, denominator, mu;
34
-
35
-
36
-    pA = Vec3(p1);
37
-    pB = Vec3(p2);
38
-
39
-    // Find normal
40
-    a = Vec3(polygon[1]) - Vec3(polygon[0]);
41
-    b = Vec3(polygon[2]) - Vec3(polygon[0]);
42
-    normal = Vec3::cross(a, b);
43
-    normal.normalize();
44
-
45
-    // find D
46
-    d = (normal.x * polygon[0][0] -
47
-         normal.y * polygon[0][1] -
48
-         normal.z * polygon[0][2]);
49
-
50
-    // line segment parallel to plane?
51
-    a = pB - pA;
52
-
53
-    denominator = Vec3::dot(normal, a);
54
-
55
-    if (denominator > 0.0)
56
-        return 0;
57
-
58
-    // Line segment contains intercept point?
59
-    mu = -((d + Vec3::dot(normal, pA)) / denominator);
60
-
61
-    if (mu < 0.0 || mu > 1.0)
62
-        return 0;
63
-
64
-    b = pA + (a * mu);
65
-    intersect[0] = b.x;
66
-    intersect[1] = b.y;
67
-    intersect[2] = b.z;
68
-
69
-    // See if the intercept is bound by polygon by winding number
70
-    // assume convex polygons here for sure
71
-    double theta = Vec3::dot(b - Vec3(polygon[0]), normal); // b = intersect
72
-
73
-    if (theta >= 90.0) // Yeah I know
74
-        return 0;
75
-
76
-    return 1;
77
-}
78
-
79
-float distance(const float a[3], const float b[3]) {
80
-    return sqrtf(((b[0] - a[0]) * (b[0] - a[0])) +
81
-                 ((b[1] - a[1]) * (b[1] - a[1])) +
82
-                 ((b[2] - a[2]) * (b[2] - a[2])));
83
-}
84
-
85
-void midpoint(const float a[3], const float b[3], float mid[3]) {
86
-    mid[0] = (a[0] + b[0]) / 2.0f;
87
-    mid[1] = (a[1] + b[1]) / 2.0f;
88
-    mid[2] = (a[2] + b[2]) / 2.0f;
89
-}
90
-
91
-float randomNum(float from, float to) {
92
-    return from + ((to - from) * rand() / (RAND_MAX + 1.0f));
93
-}
94
-

+ 18
- 11
src/system/FontImGui.cpp Parādīt failu

@@ -13,11 +13,10 @@
13 13
 #define SCALE_DRAW 20.0f
14 14
 
15 15
 unsigned int FontImGui::widthText(float scale, std::string s) {
16
-    //ImGuiIO& io = ImGui::GetIO();
17
-    //ImVec2 size = io.Font->CalcTextSizeA(scale * SCALE_CALC, io.DisplaySize.y, s.c_str(),
18
-    //                                     s.c_str() + s.length());
19
-    //return size.y;
20
-    return s.length() * 15;
16
+    ImGuiIO& io = ImGui::GetIO();
17
+    ImVec2 size = io.Font->CalcTextSizeA(scale * SCALE_CALC, FLT_MAX, io.DisplaySize.y, s.c_str(),
18
+                                         s.c_str() + s.length());
19
+    return size.y;
21 20
 }
22 21
 
23 22
 void FontImGui::drawText(unsigned int x, unsigned int y, float scale,
@@ -35,15 +34,23 @@ void FontImGui::drawText(unsigned int x, unsigned int y, float scale,
35 34
 }
36 35
 
37 36
 unsigned int FontImGui::heightText(float scale, unsigned int maxWidth, std::string s) {
38
-    //ImGuiIO& io = ImGui::GetIO();
39
-    //ImVec2 size = io.Font->CalcTextSizeA(scale * SCALE_CALC, maxWidth, s.c_str(),
40
-    //                                     s.c_str() + s.length());
41
-    //return size.x;
42
-    return 15;
37
+    ImGuiIO& io = ImGui::GetIO();
38
+    ImVec2 size = io.Font->CalcTextSizeA(scale * SCALE_CALC, FLT_MAX, maxWidth, s.c_str(),
39
+                                         s.c_str() + s.length());
40
+    return size.x;
43 41
 }
44 42
 
45 43
 void FontImGui::drawTextWrapped(unsigned int x, unsigned int y, float scale,
46 44
                                 const unsigned char color[4], unsigned int maxWidth, std::string s) {
47
-    drawText(x, y, scale, color, s);
45
+    ImGuiIO& io = ImGui::GetIO();
46
+    ImVec2 pos = ImVec2(x, y);
47
+    ImU32 col = color[0] | (color[1] << 8) | (color[2] << 16) | (color[3] << 24);
48
+
49
+    ImDrawList dl;
50
+    dl.PushClipRect(ImVec4(0.0f, 0.0f, io.DisplaySize.x, io.DisplaySize.y));
51
+    dl.AddText(io.Font, scale * SCALE_DRAW, pos, col, s.c_str(), s.c_str() + s.length(), maxWidth);
52
+
53
+    ImDrawList* dlp = &dl;
54
+    UI::renderImGui(&dlp, 1);
48 55
 }
49 56
 

+ 59
- 53
src/system/FontSDL.cpp Parādīt failu

@@ -8,11 +8,13 @@
8 8
 #include <iostream>
9 9
 
10 10
 #include "global.h"
11
+#include "TextureManager.h"
12
+#include "system/Window.h"
11 13
 #include "system/FontSDL.h"
12 14
 
13 15
 bool FontSDL::mFontInit = false;
14 16
 TTF_Font* FontSDL::mFont = nullptr;
15
-unsigned int FontSDL::mFontTexture = 0;
17
+unsigned int FontSDL::mFontTexture = -1;
16 18
 
17 19
 void FontSDL::shutdown() {
18 20
     if (mFont != nullptr)
@@ -21,7 +23,6 @@ void FontSDL::shutdown() {
21 23
 
22 24
     if (mFontInit) {
23 25
         TTF_Quit();
24
-        glDeleteTextures(1, &mFontTexture);
25 26
         mFontInit = false;
26 27
     }
27 28
 }
@@ -33,7 +34,10 @@ int FontSDL::initialize(std::string font) {
33 34
             return -1;
34 35
         }
35 36
 
36
-        glGenTextures(1, &mFontTexture);
37
+        // Reserve slot
38
+        mFontTexture = getTextureManager().loadBufferSlot(nullptr, 256, 256,
39
+                TextureManager::ColorMode::RGBA, 32, TextureManager::TextureStorage::SYSTEM);
40
+
37 41
         mFontInit = true;
38 42
     }
39 43
 
@@ -82,46 +86,47 @@ void FontSDL::drawText(unsigned int x, unsigned int y, float scale,
82 86
     int w = (int)((float)surface->w * scale);
83 87
     int h = (int)((float)surface->h * scale);
84 88
 
85
-    GLenum textureFormat;
89
+    TextureManager::ColorMode textureFormat;
90
+    unsigned int bpp = 0;
86 91
     if (surface->format->BytesPerPixel == 4) {
87 92
         if (surface->format->Rmask == 0x000000FF)
88
-            textureFormat = GL_RGBA;
93
+            textureFormat = TextureManager::ColorMode::RGBA;
89 94
         else
90
-            textureFormat = GL_BGRA_EXT;
95
+            textureFormat = TextureManager::ColorMode::BGRA;
96
+        bpp = 32;
91 97
     } else {
92 98
         if (surface->format->Rmask == 0x000000FF)
93
-            textureFormat = GL_RGB;
99
+            textureFormat = TextureManager::ColorMode::RGB;
94 100
         else
95
-            textureFormat = GL_BGR_EXT;
101
+            textureFormat = TextureManager::ColorMode::BGR;
102
+        bpp = 24;
96 103
     }
97 104
 
98
-    glBindTexture(GL_TEXTURE_2D, mFontTexture);
99
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
100
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
101
-    glTexImage2D(GL_TEXTURE_2D, 0, surface->format->BytesPerPixel, surface->w, surface->h, 0,
102
-                 textureFormat, GL_UNSIGNED_BYTE, surface->pixels);
105
+    getTextureManager().loadBufferSlot(static_cast<unsigned char*>(surface->pixels),
106
+                                       surface->w, surface->h, textureFormat, bpp,
107
+                                       TextureManager::TextureStorage::SYSTEM, mFontTexture);
103 108
     SDL_FreeSurface(surface);
104 109
 
105
-    GLuint xMin = x;
106
-    GLuint yMin = y;
107
-    GLuint xMax = xMin + w;
108
-    GLuint yMax = yMin + h;
110
+    std::vector<glm::vec2> vertices;
111
+    std::vector<glm::vec2> uvs;
109 112
 
110
-    glColor4ubv(color);
113
+    vertices.push_back(glm::vec2(x, y + h));
114
+    vertices.push_back(glm::vec2(x, y));
115
+    vertices.push_back(glm::vec2(x + w, y + h));
111 116
 
112
-    glBegin(GL_QUADS);
113
-    glTexCoord2f(0.0f, 0.0f);
114
-    glVertex2i(xMin, yMin);
117
+    vertices.push_back(glm::vec2(x + w, y));
118
+    vertices.push_back(glm::vec2(x + w, y + h));
119
+    vertices.push_back(glm::vec2(x, y));
115 120
 
116
-    glTexCoord2f(0.0f, 1.0f);
117
-    glVertex2i(xMin, yMax);
121
+    uvs.push_back(glm::vec2(0.0f, 1.0f));
122
+    uvs.push_back(glm::vec2(0.0f, 0.0f));
123
+    uvs.push_back(glm::vec2(1.0f, 1.0f));
118 124
 
119
-    glTexCoord2f(1.0f, 1.0f);
120
-    glVertex2i(xMax, yMax);
125
+    uvs.push_back(glm::vec2(1.0f, 0.0f));
126
+    uvs.push_back(glm::vec2(1.0f, 1.0f));
127
+    uvs.push_back(glm::vec2(0.0f, 0.0f));
121 128
 
122
-    glTexCoord2f(1.0f, 0.0f);
123
-    glVertex2i(xMax, yMin);
124
-    glEnd();
129
+    Window::drawTextGL(vertices, uvs, glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), mFontTexture);
125 130
 }
126 131
 
127 132
 unsigned int FontSDL::heightText(float scale, unsigned int maxWidth, std::string s) {
@@ -163,45 +168,46 @@ void FontSDL::drawTextWrapped(unsigned int x, unsigned int y, float scale,
163 168
     int w = (int)((float)surface->w * scale);
164 169
     int h = (int)((float)surface->h * scale);
165 170
 
166
-    GLenum textureFormat;
171
+    TextureManager::ColorMode textureFormat;
172
+    unsigned int bpp = 0;
167 173
     if (surface->format->BytesPerPixel == 4) {
168 174
         if (surface->format->Rmask == 0x000000FF)
169
-            textureFormat = GL_RGBA;
175
+            textureFormat = TextureManager::ColorMode::RGBA;
170 176
         else
171
-            textureFormat = GL_BGRA_EXT;
177
+            textureFormat = TextureManager::ColorMode::BGRA;
178
+        bpp = 32;
172 179
     } else {
173 180
         if (surface->format->Rmask == 0x000000FF)
174
-            textureFormat = GL_RGB;
181
+            textureFormat = TextureManager::ColorMode::RGB;
175 182
         else
176
-            textureFormat = GL_BGR_EXT;
183
+            textureFormat = TextureManager::ColorMode::BGR;
184
+        bpp = 24;
177 185
     }
178 186
 
179
-    glBindTexture(GL_TEXTURE_2D, mFontTexture);
180
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
181
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
182
-    glTexImage2D(GL_TEXTURE_2D, 0, surface->format->BytesPerPixel, surface->w, surface->h, 0,
183
-                 textureFormat, GL_UNSIGNED_BYTE, surface->pixels);
187
+    getTextureManager().loadBufferSlot(static_cast<unsigned char*>(surface->pixels),
188
+                                       surface->w, surface->h, textureFormat, bpp,
189
+                                       TextureManager::TextureStorage::SYSTEM, mFontTexture);
184 190
     SDL_FreeSurface(surface);
185 191
 
186
-    GLuint xMin = x;
187
-    GLuint yMin = y;
188
-    GLuint xMax = xMin + w;
189
-    GLuint yMax = yMin + h;
192
+    std::vector<glm::vec2> vertices;
193
+    std::vector<glm::vec2> uvs;
190 194
 
191
-    glColor4ubv(color);
195
+    vertices.push_back(glm::vec2(x, y + h));
196
+    vertices.push_back(glm::vec2(x, y));
197
+    vertices.push_back(glm::vec2(x + w, y + h));
192 198
 
193
-    glBegin(GL_QUADS);
194
-    glTexCoord2f(0.0f, 0.0f);
195
-    glVertex2i(xMin, yMin);
199
+    vertices.push_back(glm::vec2(x + w, y));
200
+    vertices.push_back(glm::vec2(x + w, y + h));
201
+    vertices.push_back(glm::vec2(x, y));
196 202
 
197
-    glTexCoord2f(0.0f, 1.0f);
198
-    glVertex2i(xMin, yMax);
203
+    uvs.push_back(glm::vec2(0.0f, 1.0f));
204
+    uvs.push_back(glm::vec2(0.0f, 0.0f));
205
+    uvs.push_back(glm::vec2(1.0f, 1.0f));
199 206
 
200
-    glTexCoord2f(1.0f, 1.0f);
201
-    glVertex2i(xMax, yMax);
207
+    uvs.push_back(glm::vec2(1.0f, 0.0f));
208
+    uvs.push_back(glm::vec2(1.0f, 1.0f));
209
+    uvs.push_back(glm::vec2(0.0f, 0.0f));
202 210
 
203
-    glTexCoord2f(1.0f, 0.0f);
204
-    glVertex2i(xMax, yMin);
205
-    glEnd();
211
+    Window::drawTextGL(vertices, uvs, glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), mFontTexture);
206 212
 }
207 213
 

+ 40
- 34
src/system/FontTRLE.cpp Parādīt failu

@@ -11,7 +11,9 @@
11 11
 #include <stdexcept>
12 12
 
13 13
 #include "global.h"
14
+#include "TextureManager.h"
14 15
 #include "utils/strings.h"
16
+#include "system/Window.h"
15 17
 #include "system/FontTRLE.h"
16 18
 
17 19
 #define SCALING 2.0f
@@ -21,8 +23,6 @@ unsigned int FontTRLE::mFontTexture = 0;
21 23
 int FontTRLE::offsets[106][5];
22 24
 
23 25
 void FontTRLE::shutdown() {
24
-    if (mFontInit)
25
-        glDeleteTextures(1, &mFontTexture);
26 26
 }
27 27
 
28 28
 int FontTRLE::initialize(std::string font) {
@@ -46,12 +46,8 @@ int FontTRLE::initialize(std::string font) {
46 46
         pixels[i] = pixels[i + 1] = pixels[i + 2] = (unsigned char)y;
47 47
     }
48 48
 
49
-    // ...into GL texture
50
-    glGenTextures(1, &mFontTexture);
51
-    glBindTexture(GL_TEXTURE_2D, mFontTexture);
52
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
53
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
54
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, 256, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, pixels);
49
+    mFontTexture = getTextureManager().loadBufferSlot(pixels, 256, 256,
50
+            TextureManager::ColorMode::BGRA, 32, TextureManager::TextureStorage::SYSTEM);
55 51
     delete [] pixels;
56 52
 
57 53
     // Try to load .lps file or use default glyph positions
@@ -69,8 +65,6 @@ void FontTRLE::loadLPS(std::string f) {
69 65
         return;
70 66
     }
71 67
 
72
-    //! \todo This is probably the worlds most unreliable parser...
73
-
74 68
     for (std::string line; std::getline(file, line);) {
75 69
         std::istringstream stream(line);
76 70
         int index;
@@ -93,19 +87,19 @@ void FontTRLE::loadLPS(std::string f) {
93 87
     }
94 88
 }
95 89
 
96
-void FontTRLE::writeChar(unsigned int index, unsigned int xDraw, unsigned int yDraw,
97
-                         float scale, const unsigned char color[4]) {
90
+void FontTRLE::writeChar(unsigned int index, unsigned int xDraw, unsigned int yDraw, float scale,
91
+                         std::vector<glm::vec2>& vertices, std::vector<glm::vec2>& uvs) {
98 92
     assert(mFontInit == true);
99 93
 
100
-    int width = (int)(((float)offsets[index][2]) * scale * SCALING);
101
-    int height = (int)(((float)offsets[index][3]) * scale * SCALING);
102
-    int offset = (int)(((float)offsets[index][4]) * scale * SCALING);
94
+    float width = ((float)offsets[index][2]) * scale * SCALING;
95
+    float height = ((float)offsets[index][3]) * scale * SCALING;
96
+    float offset = ((float)offsets[index][4]) * scale * SCALING;
103 97
 
104 98
     // screen coordinates
105
-    int xMin = xDraw;
106
-    int yMin = ((int)yDraw) + offset + (int)(10.0f * scale * SCALING);
107
-    int xMax = xMin + width;
108
-    int yMax = yMin + height;
99
+    float xMin = xDraw;
100
+    float yMin = yDraw + offset + (10.0f * scale * SCALING);
101
+    float xMax = xMin + width;
102
+    float yMax = yMin + height;
109 103
 
110 104
     // texture part
111 105
     float txMin = ((float)offsets[index][0]) / 256.0f;
@@ -113,19 +107,21 @@ void FontTRLE::writeChar(unsigned int index, unsigned int xDraw, unsigned int yD
113 107
     float tyMin = ((float)offsets[index][1]) / 256.0f;
114 108
     float tyMax = ((float)(offsets[index][1] + offsets[index][3])) / 256.0f;
115 109
 
116
-    // draw
117
-    glBindTexture(GL_TEXTURE_2D, mFontTexture);
118
-    glColor4f(color[0] * 256.0f, color[1] * 256.0f, color[2] * 256.0f, color[3] * 256.0f);
119
-    glBegin(GL_QUADS);
120
-    glTexCoord2f(txMin, tyMin);
121
-    glVertex2i(xMin, yMin);
122
-    glTexCoord2f(txMin, tyMax);
123
-    glVertex2i(xMin, yMax);
124
-    glTexCoord2f(txMax, tyMax);
125
-    glVertex2i(xMax, yMax);
126
-    glTexCoord2f(txMax, tyMin);
127
-    glVertex2i(xMax, yMin);
128
-    glEnd();
110
+    vertices.push_back(glm::vec2(xMin, yMax));
111
+    vertices.push_back(glm::vec2(xMin, yMin));
112
+    vertices.push_back(glm::vec2(xMax, yMax));
113
+
114
+    vertices.push_back(glm::vec2(xMax, yMin));
115
+    vertices.push_back(glm::vec2(xMax, yMax));
116
+    vertices.push_back(glm::vec2(xMin, yMin));
117
+
118
+    uvs.push_back(glm::vec2(txMin, tyMax));
119
+    uvs.push_back(glm::vec2(txMin, tyMin));
120
+    uvs.push_back(glm::vec2(txMax, tyMax));
121
+
122
+    uvs.push_back(glm::vec2(txMax, tyMin));
123
+    uvs.push_back(glm::vec2(txMax, tyMax));
124
+    uvs.push_back(glm::vec2(txMin, tyMin));
129 125
 }
130 126
 
131 127
 unsigned int FontTRLE::widthText(float scale, std::string s) {
@@ -154,6 +150,8 @@ void FontTRLE::drawText(unsigned int x, unsigned int y, float scale,
154 150
     assert(mFontInit == true);
155 151
     assert(s.length() > 0);
156 152
 
153
+    std::vector<glm::vec2> vertices;
154
+    std::vector<glm::vec2> uvs;
157 155
     for (unsigned int i = 0; i < s.length(); i++) {
158 156
         // index into offset table
159 157
         int index = s[i] - '!';
@@ -164,9 +162,12 @@ void FontTRLE::drawText(unsigned int x, unsigned int y, float scale,
164 162
         if ((index < 0) || (index > 105))
165 163
             continue; // skip unprintable chars
166 164
 
167
-        writeChar((unsigned int)index, x, y, scale, color);
165
+        writeChar((unsigned int)index, x, y, scale, vertices, uvs);
168 166
         x += (int)((float)(offsets[index][2] + 1) * scale * SCALING); // width
169 167
     }
168
+
169
+    glm::vec4 col(color[0] / 256.0f, color[1] / 256.0f, color[2] / 256.0f, color[3] / 256.0f);
170
+    Window::drawTextGL(vertices, uvs, col, mFontTexture);
170 171
 }
171 172
 
172 173
 unsigned int FontTRLE::heightText(float scale, unsigned int maxWidth, std::string s) {
@@ -210,6 +211,8 @@ void FontTRLE::drawTextWrapped(unsigned int x, unsigned int y, float scale,
210 211
     unsigned int xStart = x;
211 212
     unsigned int yMax = 0;
212 213
 
214
+    std::vector<glm::vec2> vertices;
215
+    std::vector<glm::vec2> uvs;
213 216
     for (unsigned int i = 0; i < s.length(); i++) {
214 217
         // index into offset table
215 218
         int index = s[i] - '!';
@@ -233,9 +236,12 @@ void FontTRLE::drawTextWrapped(unsigned int x, unsigned int y, float scale,
233 236
             x -= (int)((float)(offsets[index][2] + 1) * scale * SCALING);
234 237
         }
235 238
 
236
-        writeChar((unsigned int)index, x, y, scale, color);
239
+        writeChar((unsigned int)index, x, y, scale, vertices, uvs);
237 240
         x += (int)((float)(offsets[index][2] + 1) * scale * SCALING); // width
238 241
     }
242
+
243
+    glm::vec4 col(color[0] / 256.0f, color[1] / 256.0f, color[2] / 256.0f, color[3] / 256.0f);
244
+    Window::drawTextGL(vertices, uvs, col, mFontTexture);
239 245
 }
240 246
 
241 247
 int FontTRLE::defaultOffsets[106][5] = {

+ 2
- 2
src/system/SoundAL.cpp Parādīt failu

@@ -32,8 +32,8 @@ int SoundAL::initialize() {
32 32
     if (init)
33 33
         return 0;
34 34
 
35
-    ALCdevice* device = alcOpenDevice(NULL);
36
-    ALCcontext* context = alcCreateContext(device, NULL);
35
+    ALCdevice* device = alcOpenDevice(nullptr);
36
+    ALCcontext* context = alcCreateContext(device, nullptr);
37 37
     alcMakeContextCurrent(context);
38 38
 
39 39
     if (alutInitWithoutContext(nullptr, nullptr) == AL_FALSE) {

+ 264
- 127
src/system/Window.cpp Parādīt failu

@@ -5,181 +5,318 @@
5 5
  * \author xythobuz
6 6
  */
7 7
 
8
-#include <cstdio>
9
-#include <cstring>
10
-#include <cstdarg>
11
-#include <cmath>
12
-
13 8
 #include "global.h"
14
-#include "math/math.h"
9
+#include "Log.h"
10
+#include "TextureManager.h"
15 11
 #include "utils/strings.h"
16 12
 #include "system/Window.h"
17 13
 
14
+unsigned int Window::getWidth() {
15
+    return mWidth;
16
+}
17
+
18
+unsigned int Window::getHeight() {
19
+    return mHeight;
20
+}
21
+
22
+bool Window::getFullscreen() {
23
+    return mFullscreen;
24
+}
25
+
26
+bool Window::getMousegrab() {
27
+    return mMousegrab;
28
+}
29
+
30
+bool Window::getTextInput() {
31
+    return mTextInput;
32
+}
33
+
34
+// ----------------------------------------------------------------------------
35
+
36
+Shader Window::textShader;
37
+Shader Window::imguiShader;
38
+unsigned int Window::vertexArrayID = 0;
39
+
18 40
 int Window::initializeGL() {
19
-    // Print driver support information
20
-    //printf("GL Vendor  : %s\n", glGetString(GL_VENDOR));
21
-    //printf("GL Renderer: %s\n", glGetString(GL_RENDERER));
22
-    //printf("GL Version : %s\n", glGetString(GL_VERSION));
23
-
24
-    // Testing for goodies
25
-    //const char *s = (const char *)glGetString(GL_EXTENSIONS);
26
-    //if ((s != NULL) && (s[0] != '\0')) {
27
-    //! \todo MultiTexture flag
28
-    //if (strstr(s, "GL_ARB_multitexture"))
29
-    //mFlags |= Render::fMultiTexture;
30
-    //}
41
+    getLog() << "GL Ven.: " << glGetString(GL_VENDOR) << Log::endl;
42
+    getLog() << "GL Ren.: " << glGetString(GL_RENDERER) << Log::endl;
43
+    getLog() << "GL Ver.: " << glGetString(GL_VERSION) << Log::endl;
44
+    getLog() << "GLSL V.: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << Log::endl;
45
+
46
+    glGenVertexArrays(1, &vertexArrayID);
47
+	glBindVertexArray(vertexArrayID);
48
+
49
+    // Set background to black
50
+    glClearColor(BLACK[0] / 256.0f, BLACK[1] / 256.0f, BLACK[2] / 256.0f, BLACK[3] / 256.0f);
31 51
 
32 52
     // Set up Z buffer
33 53
     glEnable(GL_DEPTH_TEST);
54
+    // Accept fragment if closer to camera
34 55
     glDepthFunc(GL_LESS);
35 56
 
36 57
     // Set up culling
37
-    glEnable(GL_CULL_FACE);
38
-    glFrontFace(GL_CW);
39
-    //glFrontFace(GL_CCW);
40
-    //glCullFace(GL_FRONT);
58
+    //glEnable(GL_CULL_FACE); //! \todo Transparency?
59
+
60
+    if (textShader.compile(textShaderVertex, textShaderFragment) < 0)
61
+        return -1;
62
+    if (textShader.addUniform("screen") < 0)
63
+        return -2;
64
+    if (textShader.addUniform("textureSampler") < 0)
65
+        return -3;
66
+    if (textShader.addUniform("colorVar") < 0)
67
+        return -4;
68
+    textShader.addBuffer(2);
69
+
70
+    if (imguiShader.compile(imguiShaderVertex, imguiShaderFragment) < 0)
71
+        return -5;
72
+    if (imguiShader.addUniform("screen") < 0)
73
+        return -6;
74
+    if (imguiShader.addUniform("textureSampler") < 0)
75
+        return -7;
76
+    imguiShader.addBuffer(3);
41 77
 
42
-    // Set background to black
43
-    glClearColor(BLACK[0] / 256.0f, BLACK[1] / 256.0f, BLACK[2] / 256.0f, BLACK[3] / 256.0f);
78
+    glEnable(GL_BLEND);
79
+    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
44 80
 
45
-    // Disable lighting
46
-    glDisable(GL_LIGHTING);
81
+    return 0;
82
+}
47 83
 
48
-    // Set up alpha blending
49
-    glEnable(GL_BLEND);
50
-    glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
84
+void Window::shutdownGL() {
85
+    glDeleteVertexArrays(1, &vertexArrayID);
86
+}
51 87
 
52
-    //glEnable(GL_ALPHA_TEST); // Disable per pixel alpha blending
53
-    glAlphaFunc(GL_GREATER, 0);
88
+void Window::resizeGL() {
89
+    // new matrix?
90
+}
54 91
 
55
-    glPointSize(5.0);
92
+void Window::drawTextGL(std::vector<glm::vec2>& vertices, std::vector<glm::vec2>& uvs,
93
+                        glm::vec4 color, unsigned int texture) {
94
+    assert(vertices.size() == uvs.size());
95
+    assert((vertices.size() % 3) == 0);
56 96
 
57
-    // Setup shading
58
-    glShadeModel(GL_SMOOTH);
97
+    glBindBuffer(GL_ARRAY_BUFFER, textShader.getBuffer(0));
98
+    glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(glm::vec2), &vertices[0], GL_STATIC_DRAW);
59 99
 
60
-    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
61
-    glHint(GL_FOG_HINT, GL_NICEST);
62
-    glEnable(GL_COLOR_MATERIAL);
63
-    glEnable(GL_DITHER);
100
+    glBindBuffer(GL_ARRAY_BUFFER, textShader.getBuffer(1));
101
+    glBufferData(GL_ARRAY_BUFFER, uvs.size() * sizeof(glm::vec2), &uvs[0], GL_STATIC_DRAW);
64 102
 
65
-    // AA polygon edges
66
-    glEnable(GL_POLYGON_SMOOTH);
67
-    glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
103
+    textShader.use();
68 104
 
69
-    glDisable(GL_LINE_SMOOTH);
70
-    glDisable(GL_POINT_SMOOTH);
71
-    glDisable(GL_AUTO_NORMAL);
72
-    glDisable(GL_LOGIC_OP);
73
-    glDisable(GL_TEXTURE_1D);
74
-    glDisable(GL_STENCIL_TEST);
75
-    glDisable(GL_FOG);
105
+    glUniform2f(textShader.getUniform(0), getWindow().getWidth(), getWindow().getHeight());
76 106
 
77
-    glDisable(GL_NORMALIZE);
107
+    getTextureManager().bindTextureId(texture, TextureManager::TextureStorage::SYSTEM, 0);
108
+    glUniform1i(textShader.getUniform(1), 0);
78 109
 
79
-    //glEnableClientState(GL_VERTEX_ARRAY);
80
-    //glDisableClientState(GL_EDGE_FLAG_ARRAY);
81
-    //glDisableClientState(GL_COLOR_ARRAY);
82
-    //glDisableClientState(GL_NORMAL_ARRAY);
110
+    glUniform4fv(textShader.getUniform(2), 1, &color.r);
83 111
 
84
-    glPolygonMode(GL_FRONT, GL_FILL);
112
+    glEnableVertexAttribArray(0); // Vertices
113
+    glBindBuffer(GL_ARRAY_BUFFER, textShader.getBuffer(0));
114
+    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, nullptr);
85 115
 
86
-    glMatrixMode(GL_MODELVIEW);
116
+    glEnableVertexAttribArray(1); // UVs
117
+    glBindBuffer(GL_ARRAY_BUFFER, textShader.getBuffer(1));
118
+    glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, nullptr);
87 119
 
88
-    return 0;
120
+    glDisable(GL_DEPTH_TEST);
121
+    glDrawArrays(GL_TRIANGLES, 0, vertices.size());
122
+    glEnable(GL_DEPTH_TEST);
123
+
124
+    glDisableVertexAttribArray(0);
125
+    glDisableVertexAttribArray(1);
89 126
 }
90 127
 
91
-void Window::resizeGL() {
92
-    float fovY = 40.0f; // 45.0f
93
-    float clipNear = 10.0f; // 4.0f
94
-    float clipFar = 600000.0f; // 4000.0f
128
+// ----------------------------------------------------------------------------
95 129
 
96
-    glViewport(0, 0, mWidth, mHeight);
97
-    glMatrixMode(GL_PROJECTION);
98
-    glLoadIdentity();
130
+Shader::~Shader() {
131
+    if (programID >= 0)
132
+        glDeleteProgram(programID);
99 133
 
100
-    // Adjust clipping
101
-    GLfloat fH = tanf(fovY * OR_PI / 360.0f) * clipNear;
102
-    GLfloat fW = fH * ((GLfloat)mWidth) / ((GLfloat)mHeight);
103
-    glFrustum(-fW, fW, -fH, fH, clipNear, clipFar);
134
+    if (!buffers.empty())
135
+        glDeleteBuffers(buffers.size(), &buffers[0]);
136
+}
104 137
 
105
-    glMatrixMode(GL_MODELVIEW);
106
-    glLoadIdentity();
138
+int Shader::addUniform(const char* name) {
139
+    assert(programID >= 0);
140
+    int r = glGetUniformLocation(programID, name);
141
+    if (r < 0) {
142
+        getLog() << "Can't find GLSL Uniform \"" << name << "\"!" << Log::endl;
143
+        return -1;
144
+    }
145
+    uniforms.push_back(r);
146
+    return uniforms.size() - 1;
107 147
 }
108 148
 
109
-void Window::glEnter2D() {
110
-    glPushAttrib(GL_ENABLE_BIT);
111
-    glDisable(GL_DEPTH_TEST);
112
-    glDisable(GL_CULL_FACE);
113
-    glEnable(GL_TEXTURE_2D);
149
+unsigned int Shader::getUniform(int n) {
150
+    assert(n >= 0);
151
+    assert(n < uniforms.size());
152
+    return uniforms.at(n);
153
+}
114 154
 
115
-    /* This allows alpha blending of 2D textures with the scene */
116
-    glEnable(GL_BLEND);
117
-    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
155
+void Shader::addBuffer(int n) {
156
+    int s = buffers.size();
157
+    for (int i = 0; i < n; i++)
158
+        buffers.push_back(0);
159
+    glGenBuffers(n, &buffers[s]);
160
+}
161
+
162
+unsigned int Shader::getBuffer(int n) {
163
+    assert(n >= 0);
164
+    assert(n < buffers.size());
165
+    return buffers.at(n);
166
+}
167
+
168
+void Shader::use() {
169
+    assert(programID >= 0);
170
+    glUseProgram(programID);
171
+}
118 172
 
119
-    glViewport(0, 0, mWidth, mHeight);
173
+int Shader::compile(const char* vertex, const char* fragment) {
174
+    assert(vertex != nullptr);
175
+    assert(fragment != nullptr);
176
+
177
+    GLuint vertexID = glCreateShader(GL_VERTEX_SHADER);
178
+    GLuint fragmentID = glCreateShader(GL_FRAGMENT_SHADER);
179
+
180
+    GLint result = GL_FALSE;
181
+    GLint logLength = 0;
182
+
183
+    // Compile vertex shader
184
+    glShaderSource(vertexID, 1, &vertex, nullptr);
185
+    glCompileShader(vertexID);
186
+
187
+    // Check vertex shader
188
+    glGetShaderiv(vertexID, GL_COMPILE_STATUS, &result);
189
+    glGetShaderiv(vertexID, GL_INFO_LOG_LENGTH, &logLength);
190
+    if (logLength > 0) {
191
+        std::vector<char> message(logLength + 1);
192
+        glGetShaderInfoLog(vertexID, logLength, nullptr, &message[0]);
193
+        if (result != GL_TRUE)
194
+            getLog() << "Vertex Shader compilation error:" << Log::endl;
195
+        getLog() << &message[0] << Log::endl;
196
+        glDeleteShader(vertexID);
197
+        glDeleteShader(fragmentID);
198
+        return -1;
199
+    }
200
+
201
+    // Compile fragment shader
202
+    glShaderSource(fragmentID, 1, &fragment, nullptr);
203
+    glCompileShader(fragmentID);
204
+
205
+    // Check fragment shader
206
+    glGetShaderiv(fragmentID, GL_COMPILE_STATUS, &result);
207
+    glGetShaderiv(fragmentID, GL_INFO_LOG_LENGTH, &logLength);
208
+    if (logLength > 0) {
209
+        std::vector<char> message(logLength + 1);
210
+        glGetShaderInfoLog(fragmentID, logLength, nullptr, &message[0]);
211
+        if (result != GL_TRUE)
212
+            getLog() << "Fragment Shader compilation error:" << Log::endl;
213
+        getLog() << &message[0] << Log::endl;
214
+        glDeleteShader(vertexID);
215
+        glDeleteShader(fragmentID);
216
+        return -2;
217
+    }
218
+
219
+    // Link both shaders
220
+    programID = glCreateProgram();
221
+    glAttachShader(programID, vertexID);
222
+    glAttachShader(programID, fragmentID);
223
+    glLinkProgram(programID);
224
+
225
+    // Check resulting program
226
+    glGetProgramiv(programID, GL_LINK_STATUS, &result);
227
+    glGetProgramiv(programID, GL_INFO_LOG_LENGTH, &logLength);
228
+    if (logLength > 0) {
229
+        std::vector<char> message(logLength + 1);
230
+        glGetProgramInfoLog(programID, logLength, nullptr, &message[0]);
231
+        if (result != GL_TRUE)
232
+            getLog() << "Shader link error:" << Log::endl;
233
+        getLog() << &message[0] << Log::endl;
234
+        glDeleteShader(vertexID);
235
+        glDeleteShader(fragmentID);
236
+        glDeleteProgram(programID);
237
+        return -3;
238
+    }
239
+
240
+    glDeleteShader(vertexID);
241
+    glDeleteShader(fragmentID);
242
+    return programID;
243
+}
244
+
245
+// ----------------------------------------------------------------------------
246
+// *INDENT-OFF*
247
+
248
+const char* Window::textShaderVertex = R"!?!(
249
+#version 330 core
250
+
251
+layout(location = 0) in vec2 vertexPosition_screen;
252
+layout(location = 1) in vec2 vertexUV;
253
+
254
+out vec2 UV;
255
+
256
+uniform vec2 screen;
257
+
258
+void main() {
259
+    vec2 halfScreen = screen / 2;
260
+    vec2 vertexPosition_homogenous = (vertexPosition_screen - halfScreen) / halfScreen;
120 261
 
121
-    glMatrixMode(GL_PROJECTION);
122
-    glPushMatrix();
123
-    glLoadIdentity();
262
+    gl_Position = vec4(vertexPosition_homogenous.x, -vertexPosition_homogenous.y, 0, 1);
263
+    UV = vertexUV;
264
+}
265
+)!?!";
266
+
267
+const char* Window::textShaderFragment = R"!?!(
268
+#version 330 core
124 269
 
125
-    glOrtho(0.0, (GLdouble)mWidth, (GLdouble)mHeight, 0.0, 0.0, 1.0);
270
+in vec2 UV;
126 271
 
127
-    glMatrixMode(GL_MODELVIEW);
128
-    glPushMatrix();
129
-    glLoadIdentity();
272
+out vec4 color;
130 273
 
131
-    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
274
+uniform sampler2D textureSampler;
275
+uniform vec4 colorVar;
276
+
277
+void main() {
278
+    color = texture(textureSampler, UV) * colorVar;
132 279
 }
280
+)!?!";
281
+
282
+// --------------------------------------
133 283
 
134
-void Window::glExit2D() {
135
-    glMatrixMode(GL_MODELVIEW);
136
-    glPopMatrix();
284
+const char* Window::imguiShaderVertex = R"!?!(
285
+#version 330 core
137 286
 
138
-    glMatrixMode(GL_PROJECTION);
139
-    glPopMatrix();
287
+layout(location = 0) in vec2 vertexPosition_screen;
288
+layout(location = 1) in vec2 vertexUV;
289
+layout(location = 2) in vec4 vertexColor;
140 290
 
141
-    glPopAttrib();
291
+out vec2 UV;
292
+out vec4 FragColor;
142 293
 
143
-    glMatrixMode(GL_MODELVIEW);
294
+uniform vec2 screen;
295
+
296
+void main() {
297
+    vec2 halfScreen = screen / 2;
298
+    vec2 vertexPosition_homogenous = (vertexPosition_screen - halfScreen) / halfScreen;
299
+
300
+    gl_Position = vec4(vertexPosition_homogenous.x, -vertexPosition_homogenous.y, 0, 1);
301
+    UV = vertexUV;
302
+    FragColor = vertexColor;
144 303
 }
304
+)!?!";
145 305
 
146
-// Replaced the deprecated gluLookAt with slightly modified code from here:
147
-// http://www.khronos.org/message_boards/showthread.php/4991
148
-void Window::lookAt(float eyeX, float eyeY, float eyeZ,
149
-                    float lookAtX, float lookAtY, float lookAtZ,
150
-                    float upX, float upY, float upZ) {
151
-    // calculating the viewing vector
152
-    float f[3] = {
153
-        lookAtX - eyeX,
154
-        lookAtY - eyeY,
155
-        lookAtZ - eyeZ
156
-    };
306
+const char* Window::imguiShaderFragment = R"!?!(
307
+#version 330 core
157 308
 
158
-    // normalizing the viewing vector
159
-    float fMag = sqrtf(f[0] * f[0] + f[1] * f[1] + f[2] * f[2]);
160
-    f[0] /= fMag;
161
-    f[1] /= fMag;
162
-    f[2] /= fMag;
309
+in vec2 UV;
310
+in vec4 FragColor;
163 311
 
164
-    float s[3] = {
165
-        (f[1] * upZ) - (upY* f[2]),
166
-        (upX* f[2]) - (f[0] * upZ),
167
-        (f[0] * upY) - (upX* f[1])
168
-    };
312
+out vec4 color;
169 313
 
170
-    float u[3] = {
171
-        (s[1] * f[2]) - (f[1] * s[2]),
172
-        (f[0] * s[2]) - (s[0] * f[2]),
173
-        (s[0] * f[1]) - (f[0] * s[1])
174
-    };
314
+uniform sampler2D textureSampler;
175 315
 
176
-    float m[16] = {
177
-        s[0], u[0], -f[0], 0,
178
-        s[1], u[1], -f[1], 0,
179
-        s[2], u[2], -f[2], 0,
180
-        0,    0,     0, 1
181
-    };
182
-    glMultMatrixf(m);
183
-    glTranslatef(-eyeX, -eyeY, -eyeZ);
316
+void main() {
317
+    color = texture(textureSampler, UV) * FragColor;
184 318
 }
319
+)!?!";
320
+
321
+// *INDENT-ON*
185 322
 

+ 4
- 2
src/system/WindowGLUT.cpp Parādīt failu

@@ -69,9 +69,11 @@ int WindowGLUT::initialize() {
69 69
     int argc = 1;
70 70
     char* argv[] = { new char[11], nullptr };
71 71
     strcpy(argv[0], "OpenRaider");
72
-    glutInit(&argc, argv);
73 72
     glutInitWindowSize(mWidth, mHeight);
74
-    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
73
+    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH | GLUT_MULTISAMPLE);
74
+    glutInitContextVersion(3, 3);
75
+    glutInitContextProfile(GLUT_CORE_PROFILE);
76
+    glutInit(&argc, argv);
75 77
     glutCreateWindow(VERSION);
76 78
 
77 79
     glutReshapeFunc(WindowGLUT::reshapeCallback);

+ 17
- 10
src/system/WindowSDL.cpp Parādīt failu

@@ -22,8 +22,8 @@ WindowSDL::WindowSDL() {
22 22
     mFullscreen = false;
23 23
     mMousegrab = false;
24 24
     mTextInput = false;
25
-    mWindow = NULL;
26
-    mGLContext = NULL;
25
+    mWindow = nullptr;
26
+    mGLContext = nullptr;
27 27
 }
28 28
 
29 29
 WindowSDL::~WindowSDL() {
@@ -82,24 +82,31 @@ int WindowSDL::initialize() {
82 82
     if (mFullscreen)
83 83
         flags |= SDL_WINDOW_FULLSCREEN;
84 84
 
85
-    if ((SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5) != 0)
86
-        || (SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5) != 0)
87
-        || (SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5) != 0)
88
-        || (SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16) != 0)
89
-        || (SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1) != 0)) {
85
+    if ((SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8) != 0)
86
+        || (SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8) != 0)
87
+        || (SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8) != 0)
88
+        || (SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8) != 0)
89
+        || (SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24) != 0)
90
+        || (SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1) != 0)
91
+        || (SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1) != 0)
92
+        //|| (SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 2) != 0)
93
+        || (SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4) != 0)
94
+        || (SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3) != 0)
95
+        || (SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3) != 0)
96
+        || (SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE))) {
90 97
         std::cout << "SDL_GL_SetAttribute Error: " << SDL_GetError() << std::endl;
91 98
         return -2;
92 99
     }
93 100
 
94 101
     mWindow = SDL_CreateWindow(VERSION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
95 102
                                mWidth, mHeight, flags);
96
-    if (mWindow == NULL) {
103
+    if (mWindow == nullptr) {
97 104
         std::cout << "SDL_CreateWindow Error: " << SDL_GetError() << std::endl;
98 105
         return -3;
99 106
     }
100 107
 
101 108
     mGLContext = SDL_GL_CreateContext(mWindow);
102
-    if (mGLContext == NULL) {
109
+    if (mGLContext == nullptr) {
103 110
         std::cout << "SDL_GL_CreateContext Error: " << SDL_GetError() << std::endl;
104 111
         return -4;
105 112
     }
@@ -147,7 +154,7 @@ void WindowSDL::eventHandling() {
147 154
 
148 155
             case SDL_TEXTINPUT:
149 156
             case SDL_TEXTEDITING:
150
-                if (event.text.text != NULL)
157
+                if (event.text.text != nullptr)
151 158
                     UI::handleText(event.text.text, (event.type == SDL_TEXTEDITING));
152 159
                 break;
153 160
 

+ 1
- 1
src/utils/filesystem.cpp Parādīt failu

@@ -46,7 +46,7 @@ std::string getHomeDirectory() {
46 46
 #elif defined(_WIN32)
47 47
 
48 48
     char path[MAX_PATH];
49
-    assertEqual(SHGetFolderPath(NULL, CSIDL_PROFILE, NULL, 0, path), S_OK);
49
+    assertEqual(SHGetFolderPath(nullptr, CSIDL_PROFILE, nullptr, 0, path), S_OK);
50 50
     size_t lenPath = strlen(path);
51 51
     for (unsigned int i = 0; i < lenPath; i++)
52 52
         if (dir[i] == '\\')

+ 14
- 13
src/utils/pcx.cpp Parādīt failu

@@ -15,7 +15,7 @@
15 15
 #include "utils/pcx.h"
16 16
 
17 17
 int pcxCheck(const char* filename) {
18
-    assert(filename != NULL);
18
+    assert(filename != nullptr);
19 19
     assert(filename[0] != '\0');
20 20
 
21 21
     std::ifstream file(filename, std::ios::in | std::ios::binary);
@@ -66,14 +66,15 @@ int pcxCheck(const char* filename) {
66 66
 }
67 67
 
68 68
 int pcxLoad(const char* filename, unsigned char** image,
69
-            unsigned int* width, unsigned int* height, ColorMode* mode, unsigned int* bpp) {
70
-    assert(filename != NULL);
69
+            unsigned int* width, unsigned int* height,
70
+            TextureManager::ColorMode* mode, unsigned int* bpp) {
71
+    assert(filename != nullptr);
71 72
     assert(filename[0] != '\0');
72
-    assert(image != NULL);
73
-    assert(width != NULL);
74
-    assert(height != NULL);
75
-    assert(mode != NULL);
76
-    assert(bpp != NULL);
73
+    assert(image != nullptr);
74
+    assert(width != nullptr);
75
+    assert(height != nullptr);
76
+    assert(mode != nullptr);
77
+    assert(bpp != nullptr);
77 78
 
78 79
     std::ifstream file(filename, std::ios::in | std::ios::binary);
79 80
 
@@ -177,7 +178,7 @@ int pcxLoad(const char* filename, unsigned char** image,
177 178
     }
178 179
 
179 180
     // Read color palette
180
-    unsigned char* palette = NULL;
181
+    unsigned char* palette = nullptr;
181 182
     if (versionFive) {
182 183
         int c = file.get();
183 184
         if ((c == 12) && file) {
@@ -202,7 +203,7 @@ int pcxLoad(const char* filename, unsigned char** image,
202 203
             unsigned long baseIndex = (x + (y** width)) * 4;
203 204
             unsigned char alpha = 255, red = 0, green = 0, blue = 0;
204 205
 
205
-            if (palette != NULL) {
206
+            if (palette != nullptr) {
206 207
                 if (nPlanes == 1) {
207 208
                     red = palette[buffer[(y * totalBytes) + x] * 3];
208 209
                     green = palette[(buffer[(y * totalBytes) + x] * 3) + 1];
@@ -212,7 +213,7 @@ int pcxLoad(const char* filename, unsigned char** image,
212 213
                     delete [] buffer;
213 214
                     delete [] palette;
214 215
                     delete [] *image;
215
-                    *image = NULL;
216
+                    *image = nullptr;
216 217
                     return -10;
217 218
                 }
218 219
             } else {
@@ -229,7 +230,7 @@ int pcxLoad(const char* filename, unsigned char** image,
229 230
                     delete [] buffer;
230 231
                     delete [] palette;
231 232
                     delete [] *image;
232
-                    *image = NULL;
233
+                    *image = nullptr;
233 234
                     return -11;
234 235
                 }
235 236
             }
@@ -241,7 +242,7 @@ int pcxLoad(const char* filename, unsigned char** image,
241 242
         }
242 243
     }
243 244
 
244
-    *mode = RGBA;
245
+    *mode = TextureManager::ColorMode::RGBA;
245 246
     *bpp = 32;
246 247
 
247 248
     delete [] buffer;

+ 3
- 3
src/utils/pixel.cpp Parādīt failu

@@ -10,7 +10,7 @@
10 10
 
11 11
 unsigned char* generateColorTexture(const unsigned char* rgba, unsigned int width,
12 12
                                     unsigned int height, unsigned int bpp) {
13
-    assert(rgba != NULL);
13
+    assert(rgba != nullptr);
14 14
     assert(width > 0);
15 15
     assert(height > 0);
16 16
     assert((bpp % 8) == 0);
@@ -97,7 +97,7 @@ unsigned char* scaleBuffer(unsigned char* image, unsigned int* w, unsigned int*
97 97
                            unsigned int bpp) {
98 98
     unsigned int width = *w;
99 99
     unsigned int height = *h;
100
-    assert(image != NULL);
100
+    assert(image != nullptr);
101 101
     assert(width > 0);
102 102
     assert(height > 0);
103 103
     assert((bpp % 8) == 0);
@@ -111,7 +111,7 @@ unsigned char* scaleBuffer(unsigned char* image, unsigned int* w, unsigned int*
111 111
 
112 112
     // Check to see if scaling is needed
113 113
     if (height == original_height && width == original_width)
114
-        return NULL;
114
+        return nullptr;
115 115
 
116 116
     *w = width;
117 117
     *h = height;

+ 30
- 31
src/utils/png.cpp Parādīt failu

@@ -19,11 +19,11 @@
19 19
 int pngCheck(const char* filename) {
20 20
     png_byte header[8];
21 21
 
22
-    assert(filename != NULL);
22
+    assert(filename != nullptr);
23 23
     assert(filename[0] != '\0');
24 24
 
25 25
     FILE* fp = fopen(filename, "rb");
26
-    if (fp == NULL) {
26
+    if (fp == nullptr) {
27 27
         std::cout << "Could not open " << filename << std::endl;
28 28
         return -1;
29 29
     }
@@ -40,19 +40,20 @@ int pngCheck(const char* filename) {
40 40
 }
41 41
 
42 42
 int pngLoad(const char* filename, unsigned char** image,
43
-            unsigned int* width, unsigned int* height, ColorMode* mode, unsigned int* bpp) {
43
+            unsigned int* width, unsigned int* height,
44
+            TextureManager::ColorMode* mode, unsigned int* bpp) {
44 45
     png_byte header[8];
45 46
 
46
-    assert(filename != NULL);
47
+    assert(filename != nullptr);
47 48
     assert(filename[0] != '\0');
48
-    assert(image != NULL);
49
-    assert(width != NULL);
50
-    assert(height != NULL);
51
-    assert(mode != NULL);
52
-    assert(bpp != NULL);
49
+    assert(image != nullptr);
50
+    assert(width != nullptr);
51
+    assert(height != nullptr);
52
+    assert(mode != nullptr);
53
+    assert(bpp != nullptr);
53 54
 
54 55
     FILE* fp = fopen(filename, "rb");
55
-    if (fp == NULL) {
56
+    if (fp == nullptr) {
56 57
         std::cout << "Could not open " << filename << std::endl;
57 58
         return -1;
58 59
     }
@@ -65,7 +66,7 @@ int pngLoad(const char* filename, unsigned char** image,
65 66
         return -2;
66 67
     }
67 68
 
68
-    png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
69
+    png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
69 70
     if (!png_ptr) {
70 71
         std::cout << "png_create_read_struct returned 0." << std::endl;
71 72
         fclose(fp);
@@ -75,7 +76,7 @@ int pngLoad(const char* filename, unsigned char** image,
75 76
     png_infop info_ptr = png_create_info_struct(png_ptr);
76 77
     if (!info_ptr) {
77 78
         std::cout << "png_create_info_struct returned 0." << std::endl;
78
-        png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
79
+        png_destroy_read_struct(&png_ptr, (png_infopp)nullptr, (png_infopp)nullptr);
79 80
         fclose(fp);
80 81
         return -4;
81 82
     }
@@ -83,7 +84,7 @@ int pngLoad(const char* filename, unsigned char** image,
83 84
     png_infop end_info = png_create_info_struct(png_ptr);
84 85
     if (!end_info) {
85 86
         std::cout << "png_create_info_struct returned 0." << std::endl;
86
-        png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL);
87
+        png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) nullptr);
87 88
         fclose(fp);
88 89
         return -5;
89 90
     }
@@ -103,7 +104,7 @@ int pngLoad(const char* filename, unsigned char** image,
103 104
     png_uint_32 tmpWidth, tmpHeight;
104 105
 
105 106
     png_get_IHDR(png_ptr, info_ptr, &tmpWidth, &tmpHeight, &bit_depth, &color_type,
106
-                 NULL, NULL, NULL);
107
+                 nullptr, nullptr, nullptr);
107 108
 
108 109
     *width = tmpWidth;
109 110
     *height = tmpHeight;
@@ -129,14 +130,11 @@ int pngLoad(const char* filename, unsigned char** image,
129 130
     delete [] row_pointers;
130 131
     fclose(fp);
131 132
 
132
-    if (color_type == PNG_COLOR_TYPE_GRAY) {
133
-        *mode = GREYSCALE;
134
-        *bpp = 8;
135
-    } else if (color_type == PNG_COLOR_TYPE_RGB) {
136
-        *mode = RGB;
133
+    if (color_type == PNG_COLOR_TYPE_RGB) {
134
+        *mode = TextureManager::ColorMode::RGB;
137 135
         *bpp = 24;
138 136
     } else if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
139
-        *mode = RGBA;
137
+        *mode = TextureManager::ColorMode::RGBA;
140 138
         *bpp = 32;
141 139
     } else {
142 140
         std::cout << filename << ": Unknown libpng color type " << color_type << std::endl;
@@ -164,10 +162,11 @@ int pngLoad(const char* filename, unsigned char** image,
164 162
 }
165 163
 
166 164
 int pngSave(const char* filename, unsigned char* image,
167
-            unsigned int width, unsigned int height, ColorMode mode, unsigned int bpp) {
168
-    assert(filename != NULL);
165
+            unsigned int width, unsigned int height,
166
+            TextureManager::ColorMode mode, unsigned int bpp) {
167
+    assert(filename != nullptr);
169 168
     assert(filename[0] != '\0');
170
-    assert(image != NULL);
169
+    assert(image != nullptr);
171 170
     assert(width > 0);
172 171
     assert(height > 0);
173 172
 
@@ -177,7 +176,7 @@ int pngSave(const char* filename, unsigned char* image,
177 176
         return -1;
178 177
     }
179 178
 
180
-    png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
179
+    png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
181 180
 
182 181
     if (!png_ptr) {
183 182
         std::cout << "png_create_write_struct failed" << std::endl;
@@ -207,15 +206,15 @@ int pngSave(const char* filename, unsigned char* image,
207 206
     }
208 207
 
209 208
     int color_type;
210
-    if ((mode == GREYSCALE) && (bpp == 8)) {
211
-        color_type = PNG_COLOR_TYPE_GRAY;
212
-    } else if (((mode == RGB) || (mode == BGR)) && (bpp == 24)) {
213
-        if (mode == BGR) {
209
+    if (((mode == TextureManager::ColorMode::RGB)
210
+                || (mode == TextureManager::ColorMode::BGR)) && (bpp == 24)) {
211
+        if (mode == TextureManager::ColorMode::BGR) {
214 212
             bgr2rgb24(image, width, height);
215 213
         }
216 214
         color_type = PNG_COLOR_TYPE_RGB;
217
-    } else if (((mode == RGBA) || (mode == BGRA)) && (bpp == 32)) {
218
-        if (mode == BGRA) {
215
+    } else if (((mode == TextureManager::ColorMode::RGBA)
216
+                || (mode == TextureManager::ColorMode::BGRA)) && (bpp == 32)) {
217
+        if (mode == TextureManager::ColorMode::BGRA) {
219 218
             bgra2rgba32(image, width, height);
220 219
         }
221 220
         color_type = PNG_COLOR_TYPE_RGB_ALPHA;
@@ -252,7 +251,7 @@ int pngSave(const char* filename, unsigned char* image,
252 251
         return -8;
253 252
     }
254 253
 
255
-    png_write_end(png_ptr, NULL);
254
+    png_write_end(png_ptr, nullptr);
256 255
 
257 256
     delete [] row_pointers;
258 257
     fclose(fp);

+ 10
- 10
src/utils/tga.cpp Parādīt failu

@@ -42,7 +42,7 @@ typedef struct {
42 42
 int tgaCheck(const char* filename) {
43 43
     char buffer[10];
44 44
 
45
-    assert(filename != NULL);
45
+    assert(filename != nullptr);
46 46
     assert(filename[0] != '\0');
47 47
 
48 48
     FILE* f = fopen(filename, "rb");
@@ -73,18 +73,18 @@ int tgaLoad(const char* filename, unsigned char** image, unsigned int* width, un
73 73
     tga_t header;
74 74
     char comment[256];
75 75
     unsigned char pixel[4];
76
-    unsigned char* swap_row = NULL;
76
+    unsigned char* swap_row = nullptr;
77 77
     unsigned char tmp, packet;
78 78
     bool must_flip = 0;
79 79
     unsigned int size;
80 80
     unsigned int i, j;
81 81
 
82
-    assert(filename != NULL);
82
+    assert(filename != nullptr);
83 83
     assert(filename[0] != '\0');
84
-    assert(image != NULL);
85
-    assert(width != NULL);
86
-    assert(height != NULL);
87
-    assert(type != NULL);
84
+    assert(image != nullptr);
85
+    assert(width != nullptr);
86
+    assert(height != nullptr);
87
+    assert(type != nullptr);
88 88
 
89 89
     FILE* f = fopen(filename, "rb");
90 90
     if (!f) {
@@ -159,7 +159,7 @@ int tgaLoad(const char* filename, unsigned char** image, unsigned int* width, un
159 159
         printf("Comment: '%s'\n", comment);
160 160
     }
161 161
 
162
-    *image = NULL;
162
+    *image = nullptr;
163 163
     size = header.width * header.height;
164 164
 
165 165
     if (!size || (!(header.colormap_type == 0 && (header.image_type == 2
@@ -311,9 +311,9 @@ int tgaSave(const char* filename, unsigned char* image, unsigned int width, unsi
311 311
     //unsigned int i;
312 312
     //unsigned char tmp;
313 313
 
314
-    assert(filename != NULL);
314
+    assert(filename != nullptr);
315 315
     assert(filename[0] != '\0');
316
-    assert(image != NULL);
316
+    assert(image != nullptr);
317 317
     assert(width > 0);
318 318
     assert(height > 0);
319 319
 

+ 0
- 9
test/CMakeLists.txt Parādīt failu

@@ -25,15 +25,6 @@ add_executable (tester_loader EXCLUDE_FROM_ALL
25 25
 
26 26
 #################################################################
27 27
 
28
-add_executable (tester_math EXCLUDE_FROM_ALL
29
-    "math.cpp" "../src/math/math.cpp"
30
-    "../src/math/Vec3.cpp"
31
-)
32
-add_dependencies (check tester_math)
33
-add_test (NAME test_math COMMAND tester_math)
34
-
35
-#################################################################
36
-
37 28
 add_executable (tester_script EXCLUDE_FROM_ALL
38 29
     "Script.cpp" "../src/Script.cpp" "../src/main.cpp"
39 30
     "../src/utils/binary.cpp" "../src/Exception.cpp"

+ 0
- 34
test/math.cpp Parādīt failu

@@ -1,34 +0,0 @@
1
-/*!
2
- * \file test/math.cpp
3
- * \brief Math Unit Test
4
- *
5
- * \author xythobuz
6
- */
7
-
8
-#include <iostream>
9
-
10
-#include "global.h"
11
-#include "math/math.h"
12
-#include "math/Vec3.h"
13
-
14
-#define check(x) if (!(x)) { \
15
-    std::cout << "Test failed: " << #x << std::endl; \
16
-    return -1; \
17
-}
18
-
19
-int main() {
20
-    // math.h
21
-    check(equalEpsilon(42.23f, 42.23f));
22
-    check(!equalEpsilon(42.23f, 23.42f));
23
-
24
-    // Vec3.h
25
-    Vec3 a(42.0f, 23.0f, 66.0f);
26
-    Vec3 b(23.0f, 66.0f, 42.0f);
27
-    Vec3 result(-3390.0f, -246.0f, 2243.0f);
28
-    check(Vec3::cross(a, b) == result);
29
-
30
-    check(equalEpsilon(a * b, 5256.0f));
31
-
32
-    return 0;
33
-}
34
-

Notiek ielāde…
Atcelt
Saglabāt