Bladeren bron

Render into textures, camera room tracking & target UI (all non-working)

Thomas Buck 9 jaren geleden
bovenliggende
commit
accd3ea4e8

+ 10
- 1
include/Camera.h Bestand weergeven

39
     static void setUpdateViewFrustum(bool u) { updateViewFrustum = u; }
39
     static void setUpdateViewFrustum(bool u) { updateViewFrustum = u; }
40
     static bool getUpdateViewFrustum() { return updateViewFrustum; }
40
     static bool getUpdateViewFrustum() { return updateViewFrustum; }
41
 
41
 
42
+    static void setRoom(int r) { if (room != r) dirty = true; room = r; }
43
+    static int getRoom() { return room; }
44
+
45
+    static void setShowOverlay(bool s) { showOverlay = s; }
46
+    static bool getShowOverlay() { return showOverlay; }
47
+
42
     static bool boxInFrustum(BoundingBox b);
48
     static bool boxInFrustum(BoundingBox b);
43
     static void displayFrustum(glm::mat4 MVP);
49
     static void displayFrustum(glm::mat4 MVP);
44
 
50
 
51
+    static void displayUI();
52
+
45
   private:
53
   private:
46
     static void calculateFrustumPlanes();
54
     static void calculateFrustumPlanes();
47
 
55
 
52
     static glm::mat4 projection;
60
     static glm::mat4 projection;
53
     static glm::mat4 view;
61
     static glm::mat4 view;
54
     static float rotationDeltaX, rotationDeltaY;
62
     static float rotationDeltaX, rotationDeltaY;
55
-    static bool updateViewFrustum, dirty;
63
+    static bool updateViewFrustum, dirty, showOverlay;
64
+    static int room;
56
 };
65
 };
57
 
66
 
58
 #endif
67
 #endif

+ 1
- 1
include/Mesh.h Bestand weergeven

41
          const std::vector<IndexedColoredRectangle>& coloredRectangles,
41
          const std::vector<IndexedColoredRectangle>& coloredRectangles,
42
          const std::vector<IndexedColoredRectangle>& coloredTriangles);
42
          const std::vector<IndexedColoredRectangle>& coloredTriangles);
43
     void prepare();
43
     void prepare();
44
-    void display(glm::mat4 MVP);
44
+    void display(glm::mat4 MVP, ShaderTexture* shaderTexture = nullptr);
45
 
45
 
46
   private:
46
   private:
47
     std::vector<unsigned short> indicesBuff;
47
     std::vector<unsigned short> indicesBuff;

+ 1
- 1
include/Render.h Bestand weergeven

43
     static bool getDisplayViewFrustum() { return displayViewFrustum; }
43
     static bool getDisplayViewFrustum() { return displayViewFrustum; }
44
 
44
 
45
   private:
45
   private:
46
-    static void buildRoomList(int room);
46
+    static void buildRoomList(int room = -2);
47
 
47
 
48
     static RenderMode mode;
48
     static RenderMode mode;
49
     static std::vector<Room*> roomList;
49
     static std::vector<Room*> roomList;

+ 4
- 2
include/SkeletalModel.h Bestand weergeven

11
 
11
 
12
 #include <vector>
12
 #include <vector>
13
 
13
 
14
+#include "system/Shader.h"
15
+
14
 class BoneTag {
16
 class BoneTag {
15
   public:
17
   public:
16
     BoneTag(int m, glm::vec3 o, glm::vec3 r, char f) : mesh(m), off(o), rot(r), flag(f) { }
18
     BoneTag(int m, glm::vec3 o, glm::vec3 r, char f) : mesh(m), off(o), rot(r), flag(f) { }
17
-    void display(glm::mat4 MVP);
19
+    void display(glm::mat4 MVP, ShaderTexture* shaderTexture = nullptr);
18
 
20
 
19
     glm::vec3 getOffset() { return off; }
21
     glm::vec3 getOffset() { return off; }
20
     glm::vec3 getRotation() { return rot; }
22
     glm::vec3 getRotation() { return rot; }
60
   public:
62
   public:
61
     SkeletalModel(int i) : id(i) { }
63
     SkeletalModel(int i) : id(i) { }
62
     ~SkeletalModel();
64
     ~SkeletalModel();
63
-    void display(glm::mat4 MVP, int aframe, int bframe);
65
+    void display(glm::mat4 MVP, int aframe, int bframe, ShaderTexture* shaderTexture = nullptr);
64
 
66
 
65
     int getID() { return id; }
67
     int getID() { return id; }
66
 
68
 

+ 4
- 6
include/SoundManager.h Bestand weergeven

11
 #include <vector>
11
 #include <vector>
12
 
12
 
13
 struct SoundSource {
13
 struct SoundSource {
14
-    float x, y, z;
14
+    glm::vec3 pos;
15
     int id, flags;
15
     int id, flags;
16
 
16
 
17
-    SoundSource(float _x, float _y, float _z, int i, int f)
18
-        : x(_x), y(_y), z(_z), id(i), flags(f) { }
17
+    SoundSource(glm::vec3 p, int i, int f)
18
+        : pos(p), id(i), flags(f) { }
19
 };
19
 };
20
 
20
 
21
 struct SoundDetail {
21
 struct SoundDetail {
30
     static void clear();
30
     static void clear();
31
     static int prepareSources();
31
     static int prepareSources();
32
 
32
 
33
-    static void addSoundSource(float x, float y, float z, int id, int flags);
33
+    static void addSoundSource(glm::vec3 p, int id, int flags);
34
     static void addSoundMapEntry(int id);
34
     static void addSoundMapEntry(int id);
35
     static void addSoundDetail(int sample, float volume);
35
     static void addSoundDetail(int sample, float volume);
36
     static void addSampleIndex(int index);
36
     static void addSampleIndex(int index);
37
 
37
 
38
-    static int sizeSoundMap();
39
-
40
     static int getIndex(int index, float* volume = nullptr);
38
     static int getIndex(int index, float* volume = nullptr);
41
 
39
 
42
     // index --> SoundMap --> SoundDetails --> SampleIndices --> play
40
     // index --> SoundMap --> SoundDetails --> SampleIndices --> play

+ 2
- 0
include/TextureManager.h Bestand weergeven

112
 
112
 
113
     static void display();
113
     static void display();
114
 
114
 
115
+    static unsigned int getTextureID(int n, TextureStorage s);
116
+
115
   private:
117
   private:
116
     static std::vector<unsigned int>& getIds(TextureStorage s);
118
     static std::vector<unsigned int>& getIds(TextureStorage s);
117
     static std::vector<int>& getUnits(TextureStorage s);
119
     static std::vector<int>& getUnits(TextureStorage s);

+ 24
- 5
include/system/Shader.h Bestand weergeven

35
     int boundSize;
35
     int boundSize;
36
 };
36
 };
37
 
37
 
38
+class ShaderTexture {
39
+  public:
40
+    ShaderTexture(int w = 512, int h = 512);
41
+    ~ShaderTexture();
42
+
43
+    void clear();
44
+    void bind();
45
+    int getTexture() { return texture; }
46
+
47
+  private:
48
+    int width, height;
49
+    unsigned int framebuffer, depth;
50
+    int texture;
51
+};
52
+
38
 class Shader {
53
 class Shader {
39
   public:
54
   public:
40
     Shader() : programID(-1) { }
55
     Shader() : programID(-1) { }
58
 
73
 
59
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, glm::vec4 color, unsigned int texture,
74
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, glm::vec4 color, unsigned int texture,
60
                        TextureStorage store = TextureStorage::SYSTEM, unsigned int mode = GL_TRIANGLES,
75
                        TextureStorage store = TextureStorage::SYSTEM, unsigned int mode = GL_TRIANGLES,
61
-                       Shader& shader = textShader);
76
+                       ShaderTexture* target = nullptr, Shader& shader = textShader);
62
 
77
 
63
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, unsigned int texture, glm::mat4 MVP,
78
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, unsigned int texture, glm::mat4 MVP,
64
-                       TextureStorage store = TextureStorage::GAME, Shader& shader = textureShader);
79
+                       TextureStorage store = TextureStorage::GAME, ShaderTexture* target = nullptr,
80
+                       Shader& shader = textureShader);
65
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, ShaderBuffer& indices,
81
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, ShaderBuffer& indices,
66
                        unsigned int texture, glm::mat4 MVP,
82
                        unsigned int texture, glm::mat4 MVP,
67
-                       TextureStorage store = TextureStorage::GAME, Shader& shader = textureShader);
83
+                       TextureStorage store = TextureStorage::GAME, ShaderTexture* target = nullptr,
84
+                       Shader& shader = textureShader);
68
 
85
 
69
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, glm::mat4 MVP,
86
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, glm::mat4 MVP,
70
-                       unsigned int mode = GL_TRIANGLES, Shader& shader = colorShader);
87
+                       unsigned int mode = GL_TRIANGLES, ShaderTexture* target = nullptr,
88
+                       Shader& shader = colorShader);
71
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, ShaderBuffer& indices,
89
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, ShaderBuffer& indices,
72
-                       glm::mat4 MVP, unsigned int mode = GL_TRIANGLES, Shader& shader = colorShader);
90
+                       glm::mat4 MVP, unsigned int mode = GL_TRIANGLES, ShaderTexture* target = nullptr,
91
+                       Shader& shader = colorShader);
73
 
92
 
74
   private:
93
   private:
75
     int programID;
94
     int programID;

+ 2
- 2
include/system/Sound.h Bestand weergeven

20
     static int numSources(bool atListener = false);
20
     static int numSources(bool atListener = false);
21
     static int addSource(int buffer, float volume = 1.0f, bool atListener = false, bool loop = false);
21
     static int addSource(int buffer, float volume = 1.0f, bool atListener = false, bool loop = false);
22
 
22
 
23
-    static int sourceAt(int source, float pos[3]);
24
-    static void listenAt(float pos[3], float orientation[6]);
23
+    static int sourceAt(int source, glm::vec3 pos);
24
+    static void listenAt(glm::vec3 pos, glm::vec3 at, glm::vec3 up);
25
 
25
 
26
     static void play(int source, bool atListener = false);
26
     static void play(int source, bool atListener = false);
27
     static void stopAll();
27
     static void stopAll();

+ 3
- 3
include/system/SoundAL.h Bestand weergeven

22
     static int numSources(bool atListener);
22
     static int numSources(bool atListener);
23
     static int addSource(int buffer, float volume, bool atListener, bool loop);
23
     static int addSource(int buffer, float volume, bool atListener, bool loop);
24
 
24
 
25
-    static int sourceAt(int source, float pos[3]);
26
-    static void listenAt(float pos[3], float orientation[6]);
25
+    static int sourceAt(int source, glm::vec3 pos);
26
+    static void listenAt(glm::vec3 pos, glm::vec3 at, glm::vec3 up);
27
 
27
 
28
     static void play(int source, bool atListener);
28
     static void play(int source, bool atListener);
29
     static void stopAll();
29
     static void stopAll();
43
     static std::vector<unsigned int> sources;
43
     static std::vector<unsigned int> sources;
44
     static std::vector<unsigned int> listenerSources;
44
     static std::vector<unsigned int> listenerSources;
45
 
45
 
46
-    static float lastPosition[3];
46
+    static glm::vec3 lastPosition;
47
 };
47
 };
48
 
48
 
49
 #endif
49
 #endif

+ 18
- 0
src/Camera.cpp Bestand weergeven

8
 
8
 
9
 #include <limits>
9
 #include <limits>
10
 
10
 
11
+#include "imgui/imgui.h"
12
+
11
 #include "global.h"
13
 #include "global.h"
12
 #include "RunTime.h"
14
 #include "RunTime.h"
13
 #include "system/Shader.h"
15
 #include "system/Shader.h"
56
 float Camera::rotationDeltaY = 0.75f;
58
 float Camera::rotationDeltaY = 0.75f;
57
 bool Camera::updateViewFrustum = true;
59
 bool Camera::updateViewFrustum = true;
58
 bool Camera::dirty = true;
60
 bool Camera::dirty = true;
61
+bool Camera::showOverlay = false;
62
+int Camera::room = -1;
59
 
63
 
60
 void Camera::reset() {
64
 void Camera::reset() {
61
     pos = glm::vec3(0.0f, 0.0f, 0.0f);
65
     pos = glm::vec3(0.0f, 0.0f, 0.0f);
65
     dirty = true;
69
     dirty = true;
66
     projection = glm::mat4(1.0f);
70
     projection = glm::mat4(1.0f);
67
     view = glm::mat4(1.0f);
71
     view = glm::mat4(1.0f);
72
+    room = -1;
68
 
73
 
69
     setSize(Window::getSize());
74
     setSize(Window::getSize());
70
 }
75
 }
189
     return updateViewFrustum;
194
     return updateViewFrustum;
190
 }
195
 }
191
 
196
 
197
+void Camera::displayUI() {
198
+    if (!showOverlay)
199
+        return;
200
+
201
+    if (ImGui::Begin("Camera Look-At Overlay", &showOverlay, ImVec2(0, 0), -1.0f,
202
+                     ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize
203
+                     | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings
204
+                     | ImGuiWindowFlags_AlwaysAutoResize)) {
205
+        // TODO
206
+    }
207
+    ImGui::End();
208
+}
209
+
192
 // ----------------------------------------------------------------------------
210
 // ----------------------------------------------------------------------------
193
 
211
 
194
 class FrustumPlane {
212
 class FrustumPlane {

+ 3
- 3
src/Mesh.cpp Bestand weergeven

125
     colorsBuff.clear();
125
     colorsBuff.clear();
126
 }
126
 }
127
 
127
 
128
-void Mesh::display(glm::mat4 MVP) {
128
+void Mesh::display(glm::mat4 MVP, ShaderTexture* shaderTexture) {
129
     if (indicesBuff.size() > 0) {
129
     if (indicesBuff.size() > 0) {
130
         unsigned int indexStart = 0;
130
         unsigned int indexStart = 0;
131
         unsigned int indexPos = 1;
131
         unsigned int indexPos = 1;
140
             std::vector<unsigned short> ind(indicesBuff.begin() + indexStart,
140
             std::vector<unsigned short> ind(indicesBuff.begin() + indexStart,
141
                                             indicesBuff.begin() + indexPos);
141
                                             indicesBuff.begin() + indexPos);
142
             indices.bufferData(ind);
142
             indices.bufferData(ind);
143
-            Shader::drawGL(vertices, uvs, indices, texture, MVP);
143
+            Shader::drawGL(vertices, uvs, indices, texture, MVP, TextureStorage::GAME, shaderTexture);
144
 
144
 
145
             if (indexPos < indicesBuff.size()) {
145
             if (indexPos < indicesBuff.size()) {
146
                 indexStart = indexPos;
146
                 indexStart = indexPos;
151
     }
151
     }
152
 
152
 
153
     if (indicesColor.getSize() > 0)
153
     if (indicesColor.getSize() > 0)
154
-        Shader::drawGL(verticesColor, colors, indicesColor, MVP);
154
+        Shader::drawGL(verticesColor, colors, indicesColor, MVP, GL_TRIANGLES, shaderTexture);
155
 }
155
 }
156
 
156
 

+ 26
- 9
src/Render.cpp Bestand weergeven

45
     }
45
     }
46
 
46
 
47
     if (Camera::update()) {
47
     if (Camera::update()) {
48
-        clearRoomList();
49
-        buildRoomList(-2); // TODO cache room
48
+        int r = Camera::getRoom();
49
+        if (r < 0) {
50
+            clearRoomList();
51
+            buildRoomList();
52
+        } else {
53
+            buildRoomList(r);
54
+        }
50
     }
55
     }
51
 
56
 
52
     glm::mat4 projection = Camera::getProjectionMatrix();
57
     glm::mat4 projection = Camera::getProjectionMatrix();
190
             item = 2;
195
             item = 2;
191
         else if (mode == RenderMode::Solid)
196
         else if (mode == RenderMode::Solid)
192
             item = 3;
197
             item = 3;
193
-        if (ImGui::Combo("Render Mode", &item, modeStrings, modeStringCount)) {
198
+        if (ImGui::Combo("Render Mode##render", &item, modeStrings, modeStringCount)) {
194
             if (item == 0)
199
             if (item == 0)
195
                 mode = RenderMode::LoadScreen;
200
                 mode = RenderMode::LoadScreen;
196
             else if (item == 1)
201
             else if (item == 1)
209
         }
214
         }
210
         ImGui::SameLine();
215
         ImGui::SameLine();
211
         ImGui::Checkbox("Show Frustum##render", &displayViewFrustum);
216
         ImGui::Checkbox("Show Frustum##render", &displayViewFrustum);
217
+        ImGui::SameLine();
218
+        bool showOverlay = Camera::getShowOverlay();
219
+        if (ImGui::Checkbox("Overlay", &showOverlay)) {
220
+            Camera::setShowOverlay(showOverlay);
221
+        }
222
+        if (ImGui::Button("Reset Room ID")) {
223
+            Camera::setRoom(-1);
224
+        }
212
 
225
 
213
         ImGui::Separator();
226
         ImGui::Separator();
214
         ImGui::Text("Bounding Boxes:");
227
         ImGui::Text("Bounding Boxes:");
229
 
242
 
230
         ImGui::Separator();
243
         ImGui::Separator();
231
         ImGui::Text("Renderable Objects:");
244
         ImGui::Text("Renderable Objects:");
245
+        ImGui::Text("Room: ");
246
+        ImGui::SameLine();
232
         bool showRoomGeometry = Room::getShowRoomGeometry();
247
         bool showRoomGeometry = Room::getShowRoomGeometry();
233
-        if (ImGui::Checkbox("Room Geometry##render", &showRoomGeometry)) {
248
+        if (ImGui::Checkbox("Geometry##renderroom", &showRoomGeometry)) {
234
             Room::setShowRoomGeometry(showRoomGeometry);
249
             Room::setShowRoomGeometry(showRoomGeometry);
235
         }
250
         }
236
         ImGui::SameLine();
251
         ImGui::SameLine();
237
         bool showRoomModels = Room::getShowRoomModels();
252
         bool showRoomModels = Room::getShowRoomModels();
238
-        if (ImGui::Checkbox("Room Models##render", &showRoomModels)) {
253
+        if (ImGui::Checkbox("Models##renderroom", &showRoomModels)) {
239
             Room::setShowRoomModels(showRoomModels);
254
             Room::setShowRoomModels(showRoomModels);
240
         }
255
         }
241
         ImGui::SameLine();
256
         ImGui::SameLine();
242
         bool showRoomSprites = Room::getShowRoomSprites();
257
         bool showRoomSprites = Room::getShowRoomSprites();
243
-        if (ImGui::Checkbox("Room Sprites##render", &showRoomSprites)) {
258
+        if (ImGui::Checkbox("Sprites##renderroom", &showRoomSprites)) {
244
             Room::setShowRoomSprites(showRoomSprites);
259
             Room::setShowRoomSprites(showRoomSprites);
245
         }
260
         }
246
 
261
 
262
+        ImGui::Text("Entity: ");
263
+        ImGui::SameLine();
247
         bool showEntitySprites = Entity::getShowEntitySprites();
264
         bool showEntitySprites = Entity::getShowEntitySprites();
248
-        if (ImGui::Checkbox("Entity Sprites##render", &showEntitySprites)) {
265
+        if (ImGui::Checkbox("Sprites##renderentity", &showEntitySprites)) {
249
             Entity::setShowEntitySprites(showEntitySprites);
266
             Entity::setShowEntitySprites(showEntitySprites);
250
         }
267
         }
251
         ImGui::SameLine();
268
         ImGui::SameLine();
252
         bool showEntityMeshes = Entity::getShowEntityMeshes();
269
         bool showEntityMeshes = Entity::getShowEntityMeshes();
253
-        if (ImGui::Checkbox("Entity Meshes##render", &showEntityMeshes)) {
270
+        if (ImGui::Checkbox("Meshes##renderentity", &showEntityMeshes)) {
254
             Entity::setShowEntityMeshes(showEntityMeshes);
271
             Entity::setShowEntityMeshes(showEntityMeshes);
255
         }
272
         }
256
         ImGui::SameLine();
273
         ImGui::SameLine();
257
         bool showEntityModels = Entity::getShowEntityModels();
274
         bool showEntityModels = Entity::getShowEntityModels();
258
-        if (ImGui::Checkbox("Entity Models##render", &showEntityModels)) {
275
+        if (ImGui::Checkbox("Models##renderentity", &showEntityModels)) {
259
             Entity::setShowEntityModels(showEntityModels);
276
             Entity::setShowEntityModels(showEntityModels);
260
         }
277
         }
261
 
278
 

+ 1
- 1
src/RunTime.cpp Bestand weergeven

180
         ImGui::Text("Frames per Second: %luFPS", fps);
180
         ImGui::Text("Frames per Second: %luFPS", fps);
181
         int size = history.size() - 1;
181
         int size = history.size() - 1;
182
         if (size > 0) {
182
         if (size > 0) {
183
-            static bool scroll = true;
183
+            static bool scroll = false;
184
             if (scroll) {
184
             if (scroll) {
185
                 int start = 0;
185
                 int start = 0;
186
                 if (size > 10)
186
                 if (size > 10)

+ 4
- 4
src/SkeletalModel.cpp Bestand weergeven

13
 
13
 
14
 #include <glm/gtc/matrix_transform.hpp>
14
 #include <glm/gtc/matrix_transform.hpp>
15
 
15
 
16
-void BoneTag::display(glm::mat4 MVP) {
17
-    getWorld().getMesh(mesh).display(MVP);
16
+void BoneTag::display(glm::mat4 MVP, ShaderTexture* shaderTexture) {
17
+    getWorld().getMesh(mesh).display(MVP, shaderTexture);
18
 }
18
 }
19
 
19
 
20
 // ----------------------------------------------------------------------------
20
 // ----------------------------------------------------------------------------
100
 #include <bitset>
100
 #include <bitset>
101
 #endif
101
 #endif
102
 
102
 
103
-void SkeletalModel::display(glm::mat4 MVP, int aframe, int bframe) {
103
+void SkeletalModel::display(glm::mat4 MVP, int aframe, int bframe, ShaderTexture* shaderTexture) {
104
     assertLessThan(aframe, size());
104
     assertLessThan(aframe, size());
105
     assertLessThan(bframe, get(aframe).size());
105
     assertLessThan(bframe, get(aframe).size());
106
 
106
 
157
         glm::mat4 rotate = rotZ * rotX * rotY;
157
         glm::mat4 rotate = rotZ * rotX * rotY;
158
 
158
 
159
         glm::mat4 mod = translate * rotate;
159
         glm::mat4 mod = translate * rotate;
160
-        tag.display(stack.get() * mod);
160
+        tag.display(stack.get() * mod, shaderTexture);
161
 #ifdef DEBUG_MODELS
161
 #ifdef DEBUG_MODELS
162
         Log::get(LOG_DEBUG) << "  --> get (" << cnt << ")" << Log::endl;
162
         Log::get(LOG_DEBUG) << "  --> get (" << cnt << ")" << Log::endl;
163
 #endif
163
 #endif

+ 33
- 33
src/SoundManager.cpp Bestand weergeven

31
         int index = getIndex(soundSources.at(i).id, &vol);
31
         int index = getIndex(soundSources.at(i).id, &vol);
32
         int ret = Sound::addSource(index, vol, false, true);
32
         int ret = Sound::addSource(index, vol, false, true);
33
         assertEqual(ret, i);
33
         assertEqual(ret, i);
34
-        float pos[3] = { soundSources.at(i).x, soundSources.at(i).y, soundSources.at(i).z };
34
+        glm::vec3 pos = soundSources.at(i).pos;
35
         ret = Sound::sourceAt(i, pos);
35
         ret = Sound::sourceAt(i, pos);
36
         assertEqual(ret, 0);
36
         assertEqual(ret, 0);
37
         Sound::play(i, false);
37
         Sound::play(i, false);
49
     return 0;
49
     return 0;
50
 }
50
 }
51
 
51
 
52
-void SoundManager::addSoundSource(float x, float y, float z, int id, int flags) {
53
-    soundSources.emplace_back(x, y, z, id, flags);
52
+void SoundManager::addSoundSource(glm::vec3 p, int id, int flags) {
53
+    soundSources.emplace_back(p, id, flags);
54
 }
54
 }
55
 
55
 
56
 void SoundManager::addSoundMapEntry(int id) {
56
 void SoundManager::addSoundMapEntry(int id) {
65
     sampleIndices.push_back(index);
65
     sampleIndices.push_back(index);
66
 }
66
 }
67
 
67
 
68
-int SoundManager::sizeSoundMap() {
69
-    return soundMap.size();
70
-}
71
-
72
 int SoundManager::getIndex(int index, float* volume) {
68
 int SoundManager::getIndex(int index, float* volume) {
73
     if (index <= -1)
69
     if (index <= -1)
74
         return -1;
70
         return -1;
121
 }
117
 }
122
 
118
 
123
 void SoundManager::display() {
119
 void SoundManager::display() {
124
-    if (ImGui::CollapsingHeader("Sound Map Player")) {
120
+    if (ImGui::CollapsingHeader("Sound Player")) {
125
         if (!Sound::getEnabled()) {
121
         if (!Sound::getEnabled()) {
126
             ImGui::Text("Please enable Sound first!");
122
             ImGui::Text("Please enable Sound first!");
127
             if (ImGui::Button("Enable Sound!")) {
123
             if (ImGui::Button("Enable Sound!")) {
128
                 Sound::setEnabled(true);
124
                 Sound::setEnabled(true);
129
             }
125
             }
126
+            return;
130
         } else if (Sound::numBuffers() == 0) {
127
         } else if (Sound::numBuffers() == 0) {
131
-            ImGui::Text("Please load a level!");
132
-        } else {
133
-            static int index = 0;
134
-            ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
135
-            ImGui::SliderInt("##soundslide", &index, 0, sizeSoundMap() - 1);
136
-            ImGui::PopItemWidth();
137
-            ImGui::SameLine();
138
-            if (ImGui::Button("+##soundplus", ImVec2(0, 0), true)) {
139
-                if (index < (sizeSoundMap() - 1))
140
-                    index++;
141
-                else
142
-                    index = 0;
143
-            }
144
-            ImGui::SameLine();
145
-            if (ImGui::Button("-##soundminus", ImVec2(0, 0), true)) {
146
-                if (index > 0)
147
-                    index--;
148
-                else
149
-                    index = sizeSoundMap() - 1;
150
-            }
151
-            ImGui::SameLine();
152
-            if (ImGui::Button("Play##soundplay")) {
153
-                playSound(index);
154
-            }
128
+            ImGui::Text("No Sounds currently loaded!");
129
+            return;
130
+        }
155
 
131
 
156
-            ImGui::Text("Index: %d", getIndex(index));
132
+        static int index = 0;
133
+        ImGui::Text("Map");
134
+        ImGui::SameLine();
135
+        ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
136
+        ImGui::SliderInt("##soundslide", &index, 0, soundMap.size() - 1);
137
+        ImGui::PopItemWidth();
138
+        ImGui::SameLine();
139
+        if (ImGui::Button("+##soundplus", ImVec2(0, 0), true)) {
140
+            if (index < (soundMap.size() - 1))
141
+                index++;
142
+            else
143
+                index = 0;
144
+        }
145
+        ImGui::SameLine();
146
+        if (ImGui::Button("-##soundminus", ImVec2(0, 0), true)) {
147
+            if (index > 0)
148
+                index--;
149
+            else
150
+                index = soundMap.size() - 1;
151
+        }
152
+        ImGui::SameLine();
153
+        if (ImGui::Button("Play##soundplay")) {
154
+            playSound(index);
157
         }
155
         }
156
+        ImGui::SameLine();
157
+        ImGui::Text("%d", getIndex(index));
158
     }
158
     }
159
 }
159
 }
160
 
160
 

+ 7
- 4
src/TextureManager.cpp Bestand weergeven

150
         getIds(s).push_back(id);
150
         getIds(s).push_back(id);
151
     }
151
     }
152
 
152
 
153
-    if (image == nullptr)
154
-        return slot;
155
-
156
     unsigned int glcMode;
153
     unsigned int glcMode;
157
     switch (mode) {
154
     switch (mode) {
158
         case ColorMode::BGR:
155
         case ColorMode::BGR:
164
             break;
161
             break;
165
 
162
 
166
         case ColorMode::ARGB:
163
         case ColorMode::ARGB:
167
-            argb2rgba32(image, width, height);
164
+            if (image != nullptr)
165
+                argb2rgba32(image, width, height);
168
             glcMode = GL_RGBA;
166
             glcMode = GL_RGBA;
169
             break;
167
             break;
170
 
168
 
224
     }
222
     }
225
 }
223
 }
226
 
224
 
225
+unsigned int TextureManager::getTextureID(int n, TextureStorage s) {
226
+    assertLessThan(n, getIds(s).size());
227
+    return getIds(s).at(n);
228
+}
229
+
227
 void TextureManager::addTile(TextureTile* t) {
230
 void TextureManager::addTile(TextureTile* t) {
228
     tiles.push_back(t);
231
     tiles.push_back(t);
229
 }
232
 }

+ 79
- 2
src/UI.cpp Bestand weergeven

11
 #include "Camera.h"
11
 #include "Camera.h"
12
 #include "Console.h"
12
 #include "Console.h"
13
 #include "Game.h"
13
 #include "Game.h"
14
+#include "Log.h"
14
 #include "Menu.h"
15
 #include "Menu.h"
15
 #include "Render.h"
16
 #include "Render.h"
16
 #include "RunTime.h"
17
 #include "RunTime.h"
17
 #include "SoundManager.h"
18
 #include "SoundManager.h"
18
 #include "TextureManager.h"
19
 #include "TextureManager.h"
20
+#include "World.h"
19
 #include "system/Window.h"
21
 #include "system/Window.h"
20
 #include "utils/time.h"
22
 #include "utils/time.h"
21
 #include "UI.h"
23
 #include "UI.h"
22
 
24
 
25
+#include <glm/gtc/matrix_transform.hpp>
26
+
23
 Shader UI::imguiShader;
27
 Shader UI::imguiShader;
24
 bool UI::visible = false;
28
 bool UI::visible = false;
25
 unsigned int UI::fontTex;
29
 unsigned int UI::fontTex;
242
 
246
 
243
 void UI::display() {
247
 void UI::display() {
244
     if (RunTime::getShowFPS()) {
248
     if (RunTime::getShowFPS()) {
245
-        if (ImGui::Begin("Debug Overlay", nullptr, ImVec2(0, 0), 0.3f,
249
+        if (ImGui::Begin("Debug Overlay", nullptr, ImVec2(0, 0), -1.0f,
246
                          ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize
250
                          ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize
247
                          | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings
251
                          | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings
248
                          | ImGuiWindowFlags_AlwaysAutoResize)) {
252
                          | ImGuiWindowFlags_AlwaysAutoResize)) {
249
             ImGui::Text("%d FPS", RunTime::getFPS());
253
             ImGui::Text("%d FPS", RunTime::getFPS());
250
             ImGui::Text("X: %.1f (%.2f)", Camera::getPosition().x, Camera::getRotation().x);
254
             ImGui::Text("X: %.1f (%.2f)", Camera::getPosition().x, Camera::getRotation().x);
251
             ImGui::Text("Y: %.2f (%.2f)", Camera::getPosition().y, Camera::getRotation().y);
255
             ImGui::Text("Y: %.2f (%.2f)", Camera::getPosition().y, Camera::getRotation().y);
252
-            ImGui::Text("Z: %.2f", Camera::getPosition().z);
256
+            ImGui::Text("Z: %.2f (%d)", Camera::getPosition().z, Camera::getRoom());
253
 
257
 
254
             auto window = ImGui::GetWindowSize();
258
             auto window = ImGui::GetWindowSize();
255
             auto screen = Window::getSize();
259
             auto screen = Window::getSize();
258
         ImGui::End();
262
         ImGui::End();
259
     }
263
     }
260
 
264
 
265
+    if (Game::isLoaded())
266
+        Camera::displayUI();
267
+
261
     Console::display();
268
     Console::display();
262
 
269
 
263
     if (!visible) {
270
     if (!visible) {
284
                 showStyleWindow = !showStyleWindow;
291
                 showStyleWindow = !showStyleWindow;
285
             }
292
             }
286
         }
293
         }
294
+
295
+        if (ImGui::CollapsingHeader("ShaderTexture Test")) {
296
+            static ShaderTexture* st = nullptr;
297
+            static int index = 0;
298
+            ImGui::SliderInt("SkeletalModel", &index, 0, getWorld().sizeSkeletalModel() - 1);
299
+
300
+            static glm::mat4 MVP(1.0f);
301
+            static bool dirty = true, redraw = false;
302
+            static float zoom = 1.0f;
303
+            static float pos[3];
304
+            static float rot[3];
305
+
306
+            if (ImGui::SliderFloat3("Position", pos, -100.0f, 100.0f)) {
307
+                dirty = true;
308
+            }
309
+            if (ImGui::SliderFloat3("Rotation", rot, -6.0f, 6.0f)) {
310
+                dirty = true;
311
+            }
312
+            if (ImGui::SliderFloat("Zoom", &zoom, -1.0f, 2.0f)) {
313
+                dirty = true;
314
+            }
315
+
316
+            if (dirty) {
317
+                static glm::mat4 projection = glm::perspective(45.0f, 1.0f, 0.1f, 2000.0f);
318
+
319
+                glm::mat4 scale = glm::scale(glm::mat4(1.0f), glm::vec3(zoom, zoom, zoom));
320
+                glm::mat4 rotateX = glm::rotate(glm::mat4(1.0f), rot[0], glm::vec3(1.0f, 0.0f, 0.0f));
321
+                glm::mat4 rotateY = glm::rotate(glm::mat4(1.0f), rot[1], glm::vec3(0.0f, 1.0f, 0.0f));
322
+                glm::mat4 rotateZ = glm::rotate(glm::mat4(1.0f), rot[2], glm::vec3(0.0f, 0.0f, 1.0f));
323
+                glm::mat4 rotate = rotateZ * rotateY * rotateX;
324
+                glm::mat4 translate = glm::translate(glm::mat4(1.0f), glm::vec3(pos[0], pos[1], pos[2]));
325
+                glm::mat4 view = glm::inverse(scale * rotate * translate);
326
+                MVP = projection * view;
327
+
328
+                redraw = true;
329
+                dirty = false;
330
+            }
331
+
332
+            if ((index >= 0) && (index < getWorld().sizeSkeletalModel())) {
333
+                auto& sm = getWorld().getSkeletalModel(index);
334
+                if ((sm.size() > 0) && (sm.get(0).size() > 0)) {
335
+                    if (ImGui::Button("(Re)Create ShaderTexture...")) {
336
+                        if (st != nullptr) {
337
+                            delete st;
338
+                            st = nullptr;
339
+                        }
340
+                        if (st == nullptr) {
341
+                            st = new ShaderTexture();
342
+                            redraw = true;
343
+                        }
344
+                    }
345
+                    if ((st != nullptr) && redraw) {
346
+                        st->clear();
347
+                        sm.display(MVP, 0, 0, st);
348
+                        redraw = false;
349
+                        Log::get(LOG_DEBUG) << "Rendered new ShaderTexture!" << Log::endl;
350
+                    }
351
+                } else {
352
+                    ImGui::Text("Selected SkeletalModel has no animation/frame!");
353
+                }
354
+            } else {
355
+                ImGui::Text("No SkeletalModels loaded!");
356
+            }
357
+
358
+            if (st != nullptr) {
359
+                auto bm = TextureManager::getBufferManager(st->getTexture(), TextureStorage::SYSTEM);
360
+                ImGui::Image(bm, ImVec2(ImGui::GetColumnWidth() * 2 / 3,
361
+                                        ImGui::GetColumnWidth() * 2 / 3));
362
+            }
363
+        }
287
     }
364
     }
288
     ImGui::End();
365
     ImGui::End();
289
 
366
 

+ 1
- 1
src/loader/LoaderTR2.cpp Bestand weergeven

1033
         // Unknown, 0x40, 0x80 or 0xC0
1033
         // Unknown, 0x40, 0x80 or 0xC0
1034
         uint16_t flags = file.readU16();
1034
         uint16_t flags = file.readU16();
1035
 
1035
 
1036
-        SoundManager::addSoundSource(x, y, z, soundID, flags);
1036
+        SoundManager::addSoundSource(glm::vec3(x, y, z), soundID, flags);
1037
     }
1037
     }
1038
 
1038
 
1039
     if (numSoundSources > 0)
1039
     if (numSoundSources > 0)

+ 94
- 12
src/system/Shader.cpp Bestand weergeven

53
 
53
 
54
 // ----------------------------------------------------------------------------
54
 // ----------------------------------------------------------------------------
55
 
55
 
56
+static int loadBufferSlot(unsigned char* image = nullptr,
57
+                          unsigned int width = 256, unsigned int height = 256,
58
+                          ColorMode mode = ColorMode::RGBA, unsigned int bpp = 32,
59
+                          TextureStorage s = TextureStorage::GAME,
60
+                          int slot = -1, bool filter = true);
61
+
62
+ShaderTexture::ShaderTexture(int w, int h) : width(w), height(h) {
63
+    glGenFramebuffers(1, &framebuffer);
64
+    bind();
65
+
66
+    texture = TextureManager::loadBufferSlot(nullptr, width, height, ColorMode::RGBA,
67
+              32, TextureStorage::SYSTEM, -1, false);
68
+
69
+    glGenRenderbuffers(1, &depth);
70
+    glBindRenderbuffer(GL_RENDERBUFFER, depth);
71
+    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height);
72
+    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth);
73
+
74
+    glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
75
+                         TextureManager::getTextureID(texture, TextureStorage::SYSTEM), 0);
76
+
77
+    GLenum drawBuffer = GL_COLOR_ATTACHMENT0;
78
+    glDrawBuffers(1, &drawBuffer);
79
+
80
+    assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
81
+}
82
+
83
+ShaderTexture::~ShaderTexture() {
84
+    glDeleteRenderbuffers(1, &depth);
85
+    glDeleteFramebuffers(1,  &framebuffer);
86
+
87
+    //! \TODO free texture slot
88
+}
89
+
90
+void ShaderTexture::clear() {
91
+    bind();
92
+    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
93
+}
94
+
95
+void ShaderTexture::bind() {
96
+    glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
97
+    glViewport(0, 0, width, height);
98
+}
99
+
100
+// ----------------------------------------------------------------------------
101
+
56
 Shader::~Shader() {
102
 Shader::~Shader() {
57
     if (programID >= 0)
103
     if (programID >= 0)
58
         glDeleteProgram(programID);
104
         glDeleteProgram(programID);
238
 
284
 
239
 void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, glm::vec4 color,
285
 void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, glm::vec4 color,
240
                     unsigned int texture, TextureStorage store, unsigned int mode,
286
                     unsigned int texture, TextureStorage store, unsigned int mode,
241
-                    Shader& shader) {
287
+                    ShaderTexture* target, Shader& shader) {
242
     assert(vertices.getSize() == uvs.getSize());
288
     assert(vertices.getSize() == uvs.getSize());
243
     if (mode == GL_TRIANGLES) {
289
     if (mode == GL_TRIANGLES) {
244
         assert((vertices.getSize() % 3) == 0);
290
         assert((vertices.getSize() % 3) == 0);
245
     }
291
     }
246
 
292
 
293
+    if (target == nullptr) {
294
+        glBindFramebuffer(GL_FRAMEBUFFER, 0);
295
+        glViewport(0, 0, Window::getSize().x, Window::getSize().y);
296
+    } else {
297
+        target->bind();
298
+    }
299
+
247
     shader.use();
300
     shader.use();
248
     shader.loadUniform(0, Window::getSize());
301
     shader.loadUniform(0, Window::getSize());
249
     shader.loadUniform(1, texture, store);
302
     shader.loadUniform(1, texture, store);
260
 }
313
 }
261
 
314
 
262
 void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, unsigned int texture,
315
 void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, unsigned int texture,
263
-                    glm::mat4 MVP, TextureStorage store, Shader& shader) {
316
+                    glm::mat4 MVP, TextureStorage store, ShaderTexture* target,
317
+                    Shader& shader) {
264
     assert(vertices.getSize() == uvs.getSize());
318
     assert(vertices.getSize() == uvs.getSize());
265
     assert((vertices.getSize() % 3) == 0);
319
     assert((vertices.getSize() % 3) == 0);
266
 
320
 
321
+    if (target == nullptr) {
322
+        glBindFramebuffer(GL_FRAMEBUFFER, 0);
323
+        glViewport(0, 0, Window::getSize().x, Window::getSize().y);
324
+    } else {
325
+        target->bind();
326
+    }
327
+
267
     shader.use();
328
     shader.use();
268
     shader.loadUniform(0, MVP);
329
     shader.loadUniform(0, MVP);
269
     shader.loadUniform(1, texture, store);
330
     shader.loadUniform(1, texture, store);
276
 
337
 
277
 void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, ShaderBuffer& indices,
338
 void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, ShaderBuffer& indices,
278
                     unsigned int texture, glm::mat4 MVP, TextureStorage store,
339
                     unsigned int texture, glm::mat4 MVP, TextureStorage store,
279
-                    Shader& shader) {
340
+                    ShaderTexture* target, Shader& shader) {
280
     assert(vertices.getSize() == uvs.getSize());
341
     assert(vertices.getSize() == uvs.getSize());
281
     assert((indices.getSize() % 3) == 0);
342
     assert((indices.getSize() % 3) == 0);
282
 
343
 
344
+    if (target == nullptr) {
345
+        glBindFramebuffer(GL_FRAMEBUFFER, 0);
346
+        glViewport(0, 0, Window::getSize().x, Window::getSize().y);
347
+    } else {
348
+        target->bind();
349
+    }
350
+
283
     shader.use();
351
     shader.use();
284
     shader.loadUniform(0, MVP);
352
     shader.loadUniform(0, MVP);
285
     shader.loadUniform(1, texture, store);
353
     shader.loadUniform(1, texture, store);
292
 }
360
 }
293
 
361
 
294
 void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, glm::mat4 MVP,
362
 void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, glm::mat4 MVP,
295
-                    unsigned int mode, Shader& shader) {
363
+                    unsigned int mode, ShaderTexture* target, Shader& shader) {
296
     assert(vertices.getSize() == colors.getSize());
364
     assert(vertices.getSize() == colors.getSize());
297
     if (mode == GL_TRIANGLES) {
365
     if (mode == GL_TRIANGLES) {
298
         assert((vertices.getSize() % 3) == 0);
366
         assert((vertices.getSize() % 3) == 0);
299
     }
367
     }
300
 
368
 
369
+    if (target == nullptr) {
370
+        glBindFramebuffer(GL_FRAMEBUFFER, 0);
371
+        glViewport(0, 0, Window::getSize().x, Window::getSize().y);
372
+    } else {
373
+        target->bind();
374
+    }
375
+
301
     shader.use();
376
     shader.use();
302
     shader.loadUniform(0, MVP);
377
     shader.loadUniform(0, MVP);
303
     vertices.bindBuffer(0, 3);
378
     vertices.bindBuffer(0, 3);
308
 }
383
 }
309
 
384
 
310
 void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, ShaderBuffer& indices,
385
 void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, ShaderBuffer& indices,
311
-                    glm::mat4 MVP, unsigned int mode, Shader& shader) {
386
+                    glm::mat4 MVP, unsigned int mode, ShaderTexture* target, Shader& shader) {
312
     assert(vertices.getSize() == colors.getSize());
387
     assert(vertices.getSize() == colors.getSize());
313
     if (mode == GL_TRIANGLES) {
388
     if (mode == GL_TRIANGLES) {
314
         assert((indices.getSize() % 3) == 0);
389
         assert((indices.getSize() % 3) == 0);
315
     }
390
     }
316
 
391
 
392
+    if (target == nullptr) {
393
+        glBindFramebuffer(GL_FRAMEBUFFER, 0);
394
+        glViewport(0, 0, Window::getSize().x, Window::getSize().y);
395
+    } else {
396
+        target->bind();
397
+    }
398
+
317
     shader.use();
399
     shader.use();
318
     shader.loadUniform(0, MVP);
400
     shader.loadUniform(0, MVP);
319
     vertices.bindBuffer(0, 3);
401
     vertices.bindBuffer(0, 3);
351
 
433
 
352
 in vec2 UV;
434
 in vec2 UV;
353
 
435
 
354
-out vec4 color;
436
+layout(location = 0) out vec4 color;
355
 
437
 
356
 uniform sampler2D textureSampler;
438
 uniform sampler2D textureSampler;
357
 uniform vec4 colorVar;
439
 uniform vec4 colorVar;
388
 
470
 
389
 in vec2 UV;
471
 in vec2 UV;
390
 
472
 
391
-out vec4 color;
473
+layout(location = 0) out vec4 color;
392
 
474
 
393
 uniform sampler2D textureSampler;
475
 uniform sampler2D textureSampler;
394
 
476
 
405
 layout(location = 0) in vec3 vertexPosition_modelspace;
487
 layout(location = 0) in vec3 vertexPosition_modelspace;
406
 layout(location = 1) in vec3 vertexColor;
488
 layout(location = 1) in vec3 vertexColor;
407
 
489
 
408
-out vec3 Color;
490
+out vec3 color;
409
 
491
 
410
 uniform mat4 MVP;
492
 uniform mat4 MVP;
411
 
493
 
415
                           vertexPosition_modelspace.z,
497
                           vertexPosition_modelspace.z,
416
                           1);
498
                           1);
417
     gl_Position = vec4(-pos.x, pos.yzw);
499
     gl_Position = vec4(-pos.x, pos.yzw);
418
-    Color = vertexColor;
500
+    color = vertexColor;
419
 }
501
 }
420
 )!?!";
502
 )!?!";
421
 
503
 
422
 const char* Shader::colorShaderFragment = R"!?!(
504
 const char* Shader::colorShaderFragment = R"!?!(
423
 #version 330 core
505
 #version 330 core
424
 
506
 
425
-in vec3 Color;
507
+in vec3 color;
426
 
508
 
427
-out vec4 color;
509
+layout(location = 0) out vec4 color_out;
428
 
510
 
429
 void main() {
511
 void main() {
430
-    color = vec4(Color, 1);
512
+    color_out = vec4(color, 1);
431
 }
513
 }
432
 )!?!";
514
 )!?!";
433
 
515
 

+ 3
- 3
src/system/Sound.cpp Bestand weergeven

64
 #endif
64
 #endif
65
 }
65
 }
66
 
66
 
67
-int Sound::sourceAt(int source, float pos[3]) {
67
+int Sound::sourceAt(int source, glm::vec3 pos) {
68
 #ifdef USING_AL
68
 #ifdef USING_AL
69
     return SoundAL::sourceAt(source, pos);
69
     return SoundAL::sourceAt(source, pos);
70
 #else
70
 #else
72
 #endif
72
 #endif
73
 }
73
 }
74
 
74
 
75
-void Sound::listenAt(float pos[3], float orientation[6]) {
75
+void Sound::listenAt(glm::vec3 pos, glm::vec3 at, glm::vec3 up) {
76
 #ifdef USING_AL
76
 #ifdef USING_AL
77
-    SoundAL::listenAt(pos, orientation);
77
+    SoundAL::listenAt(pos, at, up);
78
 #endif
78
 #endif
79
 }
79
 }
80
 
80
 

+ 21
- 16
src/system/SoundAL.cpp Bestand weergeven

24
 std::vector<unsigned int> SoundAL::buffers;
24
 std::vector<unsigned int> SoundAL::buffers;
25
 std::vector<unsigned int> SoundAL::sources;
25
 std::vector<unsigned int> SoundAL::sources;
26
 std::vector<unsigned int> SoundAL::listenerSources;
26
 std::vector<unsigned int> SoundAL::listenerSources;
27
-float SoundAL::lastPosition[3] = { 0.0f, 0.0f, 0.0f };
27
+glm::vec3 SoundAL::lastPosition(0.0f, 0.0f, 0.0f);
28
 
28
 
29
 int SoundAL::initialize() {
29
 int SoundAL::initialize() {
30
     if (init)
30
     if (init)
41
 
41
 
42
     init = true;
42
     init = true;
43
     setVolume(volume);
43
     setVolume(volume);
44
+
45
+    lastPosition = glm::vec3(0.0f, 0.0f, 0.0f);
46
+    glm::vec3 at(0.0f, 0.0f, -1.0f);
47
+    glm::vec3 up(0.0f, 1.0f, 0.0f);
48
+    listenAt(lastPosition, at, up);
49
+
44
     return 0;
50
     return 0;
45
 }
51
 }
46
 
52
 
81
         Log::get(LOG_ERROR) << "SoundAL: Error while deleting buffers!" << Log::endl;
87
         Log::get(LOG_ERROR) << "SoundAL: Error while deleting buffers!" << Log::endl;
82
     }
88
     }
83
 
89
 
84
-    for (int i = 0; i < 3; i++)
85
-        lastPosition[i] = 0.0f;
86
-
87
-    float orientation[6] = { 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f };
88
-    listenAt(lastPosition, orientation);
90
+    lastPosition = glm::vec3(0.0f, 0.0f, 0.0f);
91
+    glm::vec3 at(0.0f, 0.0f, -1.0f);
92
+    glm::vec3 up(0.0f, 1.0f, 0.0f);
93
+    listenAt(lastPosition, at, up);
89
 }
94
 }
90
 
95
 
91
 int SoundAL::numBuffers() {
96
 int SoundAL::numBuffers() {
133
         alSourcei(id, AL_LOOPING, AL_TRUE);
138
         alSourcei(id, AL_LOOPING, AL_TRUE);
134
 
139
 
135
     if (atListener) {
140
     if (atListener) {
136
-        alSourcefv(id, AL_POSITION, lastPosition);
141
+        alSourcefv(id, AL_POSITION, &lastPosition[0]);
137
         listenerSources.push_back(id);
142
         listenerSources.push_back(id);
138
         return listenerSources.size() - 1;
143
         return listenerSources.size() - 1;
139
     } else {
144
     } else {
142
     }
147
     }
143
 }
148
 }
144
 
149
 
145
-int SoundAL::sourceAt(int source, float pos[3]) {
150
+int SoundAL::sourceAt(int source, glm::vec3 pos) {
146
     if (!init)
151
     if (!init)
147
         return -1;
152
         return -1;
148
 
153
 
149
-    if ((source < 0) || (source >= sources.size()) || (pos == nullptr)) {
154
+    if ((source < 0) || (source >= sources.size())) {
150
         Log::get(LOG_ERROR) << "SoundAL: Can't position non-existing source!" << Log::endl;
155
         Log::get(LOG_ERROR) << "SoundAL: Can't position non-existing source!" << Log::endl;
151
         return -2;
156
         return -2;
152
     }
157
     }
153
 
158
 
154
-    alSourcefv(sources.at(source), AL_POSITION, pos);
159
+    alSourcefv(sources.at(source), AL_POSITION, &pos[0]);
155
 
160
 
156
     return 0;
161
     return 0;
157
 }
162
 }
158
 
163
 
159
-void SoundAL::listenAt(float pos[3], float orientation[6]) {
160
-    if ((!init) || (pos == nullptr) || (orientation == nullptr))
164
+void SoundAL::listenAt(glm::vec3 pos, glm::vec3 at, glm::vec3 up) {
165
+    if (!init)
161
         return;
166
         return;
162
 
167
 
163
-    alListenerfv(AL_POSITION, pos);
168
+    float orientation[6] = { at.x, at.y, at.z, up.x, up.y, up.z };
169
+    alListenerfv(AL_POSITION, &pos[0]);
164
     alListenerfv(AL_ORIENTATION, orientation);
170
     alListenerfv(AL_ORIENTATION, orientation);
165
 
171
 
166
     for (auto& s : listenerSources) {
172
     for (auto& s : listenerSources) {
167
-        alSourcefv(s, AL_POSITION, pos);
173
+        alSourcefv(s, AL_POSITION, &pos[0]);
168
     }
174
     }
169
 
175
 
170
-    for (int i = 0; i < 3; i++)
171
-        lastPosition[i] = pos[i];
176
+    lastPosition = pos;
172
 }
177
 }
173
 
178
 
174
 void SoundAL::play(int source, bool atListener) {
179
 void SoundAL::play(int source, bool atListener) {

Laden…
Annuleren
Opslaan