Browse Source

libs moved to own folder, refactoring, frustum unbound from size
reference

Kajetan Johannes Hammerle 2 years ago
parent
commit
dd285eb5da

+ 2 - 2
.gitmodules

@@ -1,8 +1,8 @@
 [submodule "enet"]
-	path = enet
+	path = libs/enet
 	url = https://git.hammerle.me/kjhammerle/enet.git
 [submodule "lodepng"]
-	path = lodepng
+	path = libs/lodepng
 	url = https://github.com/lvandeve/lodepng.git
 [submodule "glfw"]
 	path = subprojects/glfw

+ 0 - 1
Main.cpp

@@ -1,4 +1,3 @@
-#include "ecs/Components.h"
 #include "math/Vector.h"
 #include "rendering/Window.h"
 #include "tests/ArrayListTests.h"

+ 0 - 0
ecs/Components.h → data/Components.h


+ 2 - 2
images/ImageReader.cpp → io/ImageReader.cpp

@@ -1,6 +1,6 @@
-#include "lodepng/lodepng.h"
+#include "libs/lodepng/lodepng.h"
 
-#include "images/ImageReader.h"
+#include "io/ImageReader.h"
 #include "utils/Cleaner.h"
 
 static void cleanRawData(ColorChannel*& c) {

+ 0 - 0
images/ImageReader.h → io/ImageReader.h


+ 0 - 0
enet → libs/enet


+ 0 - 0
lodepng → libs/lodepng


+ 5 - 6
math/Frustum.cpp

@@ -1,13 +1,11 @@
 #include "math/Frustum.h"
 #include "math/MathConstants.h"
 
-Frustum::Frustum(float fieldOfView, float nearClip, float farClip,
-                 const Size& size)
-    : size(size), fieldOfView(fieldOfView), nearClip(nearClip),
-      farClip(farClip) {
+Frustum::Frustum(float fieldOfView, float nearClip, float farClip)
+    : fieldOfView(fieldOfView), nearClip(nearClip), farClip(farClip) {
 }
 
-Matrix& Frustum::updateProjection() {
+Matrix& Frustum::updateProjection(const Size& size) {
     float tan = tanf(fieldOfView * (0.5f * M_PI / 180.0f));
     float q = 1.0f / tan;
     float aspect = static_cast<float>(size.width) / size.height;
@@ -22,7 +20,8 @@ Matrix& Frustum::updateProjection() {
 }
 
 void Frustum::updatePlanes(const Vector3& pos, const Vector3& right,
-                           const Vector3& up, const Vector3& front) {
+                           const Vector3& up, const Vector3& front,
+                           const Size& size) {
     float tan = tanf(fieldOfView * (0.5f * M_PI / 180.0f));
     float aspect = static_cast<float>(size.width) / size.height;
 

+ 5 - 6
math/Frustum.h

@@ -9,7 +9,6 @@
 
 class Frustum final {
     Matrix projection;
-    const Size& size;
     Array<Plane, 6> planes;
 
 public:
@@ -17,9 +16,11 @@ public:
     float nearClip;
     float farClip;
 
-    Frustum(float fieldOfView, float nearClip, float farClip, const Size& size);
-    Matrix& updateProjection();
-    void updatePlanes(const Vector3& pos, const Vector3& right, const Vector3& up, const Vector3& front);
+    Frustum(float fieldOfView, float nearClip, float farClip);
+    Matrix& updateProjection(const Size& size);
+    void updatePlanes(const Vector3& pos, const Vector3& right,
+                      const Vector3& up, const Vector3& front,
+                      const Size& size);
 
     bool isInside(const Vector3& pos) const;
     bool isInside(const Vector3& pos, float radius) const;
@@ -29,8 +30,6 @@ public:
         s.append("(fieldOfView = ").append(fieldOfView);
         s.append(", nearClip = ").append(nearClip);
         s.append(", farClip = ").append(farClip);
-        s.append(", width = ").append(size.width);
-        s.append(", height = ").append(size.height);
         s.append(')');
     }
 };

+ 2 - 2
meson.build

@@ -1,7 +1,7 @@
 project('gamingcore', 'cpp', default_options : ['default_library=static'])
 
 src = [
-    'images/ImageReader.cpp',
+    'io/ImageReader.cpp',
     'math/Frustum.cpp',
     'math/Matrix.cpp',
     'math/Plane.cpp',
@@ -27,7 +27,7 @@ src = [
     'utils/Random.cpp',
     'utils/Size.cpp',
     'wrapper/GL.cpp',
-    'lodepng/lodepng.cpp',
+    'libs/lodepng/lodepng.cpp',
 ]
 
 src_tests = [

+ 1 - 1
network/ENet.h

@@ -1,7 +1,7 @@
 #ifndef ENET_H
 #define ENET_H
 
-#include "enet/include/enet.h"
+#include "libs/enet/include/enet.h"
 
 class ENet final {
     friend class Client;

+ 1 - 1
rendering/FileTexture.cpp

@@ -1,5 +1,5 @@
 #include "rendering/FileTexture.h"
-#include "images/ImageReader.h"
+#include "io/ImageReader.h"
 
 Error FileTexture::load(const char* path, int maxMipMaps) {
     ImageReader::Image image;

+ 1 - 1
tests/ComponentsTests.cpp

@@ -1,5 +1,5 @@
 #include "tests/ComponentsTests.h"
-#include "ecs/Components.h"
+#include "data/Components.h"
 #include "tests/Test.h"
 
 typedef Components<int> IntComponent;

+ 56 - 41
tests/FrustumTests.cpp

@@ -1,61 +1,76 @@
 #include "tests/FrustumTests.h"
-#include "tests/Test.h"
 #include "math/Frustum.h"
+#include "tests/Test.h"
 #include "utils/StringBuffer.h"
 
 typedef StringBuffer<250> String;
 
 static void testToString(Test& test) {
-    Size size(200, 100);
-    Frustum f(60.0f, 0.1f, 1000.0f, size);
+    Frustum f(60.0f, 0.1f, 1000.0f);
     test.checkEqual(String("("
-            "fieldOfView = 60.00, "
-            "nearClip = 0.10, "
-            "farClip = 1000.00, "
-            "width = 200, "
-            "height = 100)"), String(f), "to string");
+                           "fieldOfView = 60.00, "
+                           "nearClip = 0.10, "
+                           "farClip = 1000.00)"),
+                    String(f), "to string");
 }
 
 static void testPointIsInside(Test& test) {
     Size size(200, 100);
-    Frustum f(60.0f, 0.1f, 1000.0f, size);
-    f.updatePlanes(Vector3(0.0f, 0.0f, 0.0f),
-            Vector3(1.0f, 0.0f, 0.0f),
-            Vector3(0.0f, 1.0f, 0.0f),
-            Vector3(0.0f, 0.0f, 1.0f));
-    
-    test.checkEqual(true, f.isInside(Vector3(0.0f, 0.0f, 5.0f)), "point is inside 1");
-    test.checkEqual(false, f.isInside(Vector3(0.0f, 0.0f, 1004.0f)), "point is inside 2");
-    test.checkEqual(false, f.isInside(Vector3(0.0f, 0.0f, -5.0f)), "point is inside 3");
-    test.checkEqual(false, f.isInside(Vector3(0.0f, 50.0f, 5.0f)), "point is inside 4");
-    test.checkEqual(false, f.isInside(Vector3(0.0f, -50.0f, 5.0f)), "point is inside 5");
-    test.checkEqual(false, f.isInside(Vector3(50.0f, 0.0f, 5.0f)), "point is inside 6");
-    test.checkEqual(false, f.isInside(Vector3(-50.0f, 0.0f, 5.0f)), "point is inside 7");
+    Frustum f(60.0f, 0.1f, 1000.0f);
+    f.updatePlanes(Vector3(0.0f, 0.0f, 0.0f), Vector3(1.0f, 0.0f, 0.0f),
+                   Vector3(0.0f, 1.0f, 0.0f), Vector3(0.0f, 0.0f, 1.0f), size);
+
+    test.checkEqual(true, f.isInside(Vector3(0.0f, 0.0f, 5.0f)),
+                    "point is inside 1");
+    test.checkEqual(false, f.isInside(Vector3(0.0f, 0.0f, 1004.0f)),
+                    "point is inside 2");
+    test.checkEqual(false, f.isInside(Vector3(0.0f, 0.0f, -5.0f)),
+                    "point is inside 3");
+    test.checkEqual(false, f.isInside(Vector3(0.0f, 50.0f, 5.0f)),
+                    "point is inside 4");
+    test.checkEqual(false, f.isInside(Vector3(0.0f, -50.0f, 5.0f)),
+                    "point is inside 5");
+    test.checkEqual(false, f.isInside(Vector3(50.0f, 0.0f, 5.0f)),
+                    "point is inside 6");
+    test.checkEqual(false, f.isInside(Vector3(-50.0f, 0.0f, 5.0f)),
+                    "point is inside 7");
 }
 
 static void testSphereIsInside(Test& test) {
     Size size(200, 100);
-    Frustum f(60.0f, 0.1f, 1000.0f, size);
-    f.updatePlanes(Vector3(0.0f, 0.0f, 0.0f),
-            Vector3(1.0f, 0.0f, 0.0f),
-            Vector3(0.0f, 1.0f, 0.0f),
-            Vector3(0.0f, 0.0f, 1.0f));
-    
-    test.checkEqual(true, f.isInside(Vector3(0.0f, 0.0f, 5.0f), 3.0f), "sphere is inside 1");
-    test.checkEqual(false, f.isInside(Vector3(0.0f, 0.0f, 1004.0f), 3.0f), "sphere is inside 2");
-    test.checkEqual(false, f.isInside(Vector3(0.0f, 0.0f, -5.0f), 3.0f), "sphere is inside 3");
-    test.checkEqual(false, f.isInside(Vector3(0.0f, 50.0f, 5.0f), 3.0f), "sphere is inside 4");
-    test.checkEqual(false, f.isInside(Vector3(0.0f, -50.0f, 5.0f), 3.0f), "sphere is inside 5");
-    test.checkEqual(false, f.isInside(Vector3(50.0f, 0.0f, 5.0f), 3.0f), "sphere is inside 6");
-    test.checkEqual(false, f.isInside(Vector3(-50.0f, 0.0f, 5.0f), 3.0f), "sphere is inside 7");
+    Frustum f(60.0f, 0.1f, 1000.0f);
+    f.updatePlanes(Vector3(0.0f, 0.0f, 0.0f), Vector3(1.0f, 0.0f, 0.0f),
+                   Vector3(0.0f, 1.0f, 0.0f), Vector3(0.0f, 0.0f, 1.0f), size);
+
+    test.checkEqual(true, f.isInside(Vector3(0.0f, 0.0f, 5.0f), 3.0f),
+                    "sphere is inside 1");
+    test.checkEqual(false, f.isInside(Vector3(0.0f, 0.0f, 1004.0f), 3.0f),
+                    "sphere is inside 2");
+    test.checkEqual(false, f.isInside(Vector3(0.0f, 0.0f, -5.0f), 3.0f),
+                    "sphere is inside 3");
+    test.checkEqual(false, f.isInside(Vector3(0.0f, 50.0f, 5.0f), 3.0f),
+                    "sphere is inside 4");
+    test.checkEqual(false, f.isInside(Vector3(0.0f, -50.0f, 5.0f), 3.0f),
+                    "sphere is inside 5");
+    test.checkEqual(false, f.isInside(Vector3(50.0f, 0.0f, 5.0f), 3.0f),
+                    "sphere is inside 6");
+    test.checkEqual(false, f.isInside(Vector3(-50.0f, 0.0f, 5.0f), 3.0f),
+                    "sphere is inside 7");
 
-    test.checkEqual(true, f.isInside(Vector3(0.0f, 0.0f, 5.0f), 3.0f), "sphere is inside 8");
-    test.checkEqual(true, f.isInside(Vector3(0.0f, 0.0f, 1004.0f), 50.0f), "sphere is inside 9");
-    test.checkEqual(true, f.isInside(Vector3(0.0f, 0.0f, -5.0f), 50.0f), "sphere is inside 10");
-    test.checkEqual(true, f.isInside(Vector3(0.0f, 50.0f, 5.0f), 50.0f), "sphere is inside 11");
-    test.checkEqual(true, f.isInside(Vector3(0.0f, -50.0f, 5.0f), 50.0f), "sphere is inside 12");
-    test.checkEqual(true, f.isInside(Vector3(50.0f, 0.0f, 5.0f), 50.0f), "sphere is inside 13");
-    test.checkEqual(true, f.isInside(Vector3(-50.0f, 0.0f, 5.0f), 50.0f), "sphere is inside 14");
+    test.checkEqual(true, f.isInside(Vector3(0.0f, 0.0f, 5.0f), 3.0f),
+                    "sphere is inside 8");
+    test.checkEqual(true, f.isInside(Vector3(0.0f, 0.0f, 1004.0f), 50.0f),
+                    "sphere is inside 9");
+    test.checkEqual(true, f.isInside(Vector3(0.0f, 0.0f, -5.0f), 50.0f),
+                    "sphere is inside 10");
+    test.checkEqual(true, f.isInside(Vector3(0.0f, 50.0f, 5.0f), 50.0f),
+                    "sphere is inside 11");
+    test.checkEqual(true, f.isInside(Vector3(0.0f, -50.0f, 5.0f), 50.0f),
+                    "sphere is inside 12");
+    test.checkEqual(true, f.isInside(Vector3(50.0f, 0.0f, 5.0f), 50.0f),
+                    "sphere is inside 13");
+    test.checkEqual(true, f.isInside(Vector3(-50.0f, 0.0f, 5.0f), 50.0f),
+                    "sphere is inside 14");
 }
 
 void FrustumTests::test() {

+ 1 - 1
tests/ImageReaderTests.cpp

@@ -1,5 +1,5 @@
 #include "tests/ImageReaderTests.h"
-#include "images/ImageReader.h"
+#include "io/ImageReader.h"
 #include "tests/Test.h"
 #include "utils/StringBuffer.h"