Browse Source

vector moved to common code

Kajetan Johannes Hammerle 1 year ago
parent
commit
d1cc8af690

+ 10 - 0
client/math/Matrix.cpp

@@ -181,4 +181,14 @@ std::ostream& operator<<(std::ostream& os, const Matrix& m) {
     os << std::defaultfloat;
     os << ")";
     return os;
+}
+
+Vector<3> operator*(const Matrix& m, const Vector<3>& v) {
+    const float* d = m.getValues();
+    Vector<3> result(
+            v[0] * d[0] + v[1] * d[4] + v[2] * d[8] + d[12],
+            v[0] * d[1] + v[1] * d[5] + v[2] * d[9] + d[13],
+            v[0] * d[2] + v[1] * d[6] + v[2] * d[10] + d[14]);
+    result *= 1.0f / (v[1] * d[3] + v[1] * d[7] + v[2] * d[11] + d[15]);
+    return result;
 }

+ 3 - 0
client/math/Matrix.h

@@ -3,6 +3,8 @@
 
 #include <iostream>
 
+#include "common/math/Vector.h"
+
 class Matrix final {
 public:
     Matrix();
@@ -35,5 +37,6 @@ private:
 };
 
 std::ostream& operator<<(std::ostream& os, const Matrix& m);
+Vector<3> operator*(const Matrix& m, const Vector<3>& v);
 
 #endif

+ 1 - 1
client/math/Plane.h

@@ -1,7 +1,7 @@
 #ifndef PLANE3D_H
 #define PLANE3D_H
 
-#include "client/math/Vector.h"
+#include "common/math/Vector.h"
 
 class Plane final {
 public:

+ 1 - 1
client/math/Quaternion.h

@@ -1,7 +1,7 @@
 #ifndef QUATERNION_H
 #define QUATERNION_H
 
-#include "client/math/Vector.h"
+#include "common/math/Vector.h"
 #include "client/math/Matrix.h"
 
 class Quaternion {

+ 0 - 2
client/rendering/RenderSettings.h

@@ -1,8 +1,6 @@
 #ifndef RENDERSETTINGS_H
 #define RENDERSETTINGS_H
 
-#include "client/math/Vector.h"
-
 struct RenderSettings final {
     RenderSettings();
     

+ 1 - 1
client/rendering/Renderer.h

@@ -3,7 +3,7 @@
 
 #include "client/rendering/wrapper/Shader.h"
 #include "client/math/MatrixStack.h"
-#include "client/math/Vector.h"
+#include "common/math/Vector.h"
 #include "client/math/Quaternion.h"
 
 class Renderer final {

+ 1 - 1
client/rendering/Vertex.h

@@ -1,7 +1,7 @@
 #ifndef VERTEX_H
 #define VERTEX_H
 
-#include "client/math/Vector.h"
+#include "common/math/Vector.h"
 
 struct Vertex final {
     Vertex();

+ 1 - 11
client/math/Vector.cpp → common/math/Vector.cpp

@@ -1,4 +1,4 @@
-#include "client/math/Vector.h"
+#include "common/math/Vector.h"
 
 template<>
 Vector<3>::Vector(float x, float y, float z) {
@@ -42,14 +42,4 @@ Vector<3> Vector<3>::cross(const Vector<3>& other) const {
             values[1] * other.values[2] - values[2] * other.values[1],
             values[2] * other.values[0] - values[0] * other.values[2],
             values[0] * other.values[1] - values[1] * other.values[0]);
-}
-
-Vector<3> operator*(const Matrix& m, const Vector<3>& v) {
-    const float* d = m.getValues();
-    Vector<3> result(
-            v[0] * d[0] + v[1] * d[4] + v[2] * d[8] + d[12],
-            v[0] * d[1] + v[1] * d[5] + v[2] * d[9] + d[13],
-            v[0] * d[2] + v[1] * d[6] + v[2] * d[10] + d[14]);
-    result *= 1.0f / (v[1] * d[3] + v[1] * d[7] + v[2] * d[11] + d[15]);
-    return result;
 }

+ 0 - 2
client/math/Vector.h → common/math/Vector.h

@@ -4,7 +4,6 @@
 #include <cmath>
 
 #include "common/utils/String.h"
-#include "client/math/Matrix.h"
 
 template<uint N>
 struct Vector final {
@@ -108,7 +107,6 @@ template<> Vector<3>& Vector<3>::setAngles(float lengthAngle, float widthAngle);
 template<> Vector<3>::Vector(float lengthAngle, float widthAngle);
 template<> Vector<3>& Vector<3>::set(float x, float y, float z);
 template<> Vector<3> Vector<3>::cross(const Vector<3>& other) const;
-Vector<3> operator*(const Matrix& m, const Vector<3>& v);
 
 template<uint N>
 String& operator+=(String& buffer, const Vector<N>& v) {

+ 4 - 0
common/utils/KDTree.cpp

@@ -0,0 +1,4 @@
+#include "KDTree.h"
+
+KDTree::KDTree() {
+}

+ 11 - 0
common/utils/KDTree.h

@@ -0,0 +1,11 @@
+#ifndef KDTREE_H
+#define KDTREE_H
+
+#include "common/math/Vector.h"
+
+class KDTree final {
+public:
+    KDTree();
+};
+
+#endif

+ 3 - 3
meson.build

@@ -2,13 +2,13 @@ project('cubes plus plus', 'cpp')
 
 # 'common/world/Chunk.cpp', 'common/world/World.cpp', 'common/utils/Face.cpp'
 
-sourcesCommon = ['common/network/Packet.cpp', 'common/block/BlockBuilder.cpp', 'common/block/Block.cpp', 'common/block/BlockRegistry.cpp', 'common/utils/HashedString.cpp', 'common/utils/String.cpp', 'common/utils/SplitString.cpp', 'common/utils/Random.cpp', 'common/world/World.cpp']
+sourcesCommon = ['common/network/Packet.cpp', 'common/block/BlockBuilder.cpp', 'common/block/Block.cpp', 'common/block/BlockRegistry.cpp', 'common/utils/HashedString.cpp', 'common/utils/String.cpp', 'common/utils/SplitString.cpp', 'common/utils/Random.cpp', 'common/world/World.cpp', 'common/math/Vector.cpp']
 
 sourcesServer = ['server/Main.cpp', 'server/network/Server.cpp', 'server/network/Client.cpp', 'server/GameServer.cpp', 'server/commands/ServerCommands.cpp', 'server/commands/CommandManager.cpp', 'server/commands/ConsoleEditor.cpp', 'server/Clock.cpp']
 
-sourcesClient = ['client/Main.cpp', 'client/rendering/WindowSize.cpp', 'client/math/Frustum.cpp', 'client/rendering/Framebuffers.cpp', 'client/rendering/wrapper/GLFWWrapper.cpp', 'client/rendering/wrapper/Window.cpp', 'client/rendering/Engine.cpp', 'client/input/Keys.cpp', 'client/rendering/wrapper/Shader.cpp', 'client/rendering/Shaders.cpp', 'client/utils/Utils.cpp', 'client/rendering/Mesh.cpp', 'client/math/Matrix.cpp', 'client/math/MatrixStack.cpp', 'client/math/Quaternion.cpp', 'client/math/Plane.cpp', 'client/Game.cpp', 'client/input/MouseButtons.cpp', 'client/rendering/FileTexture.cpp', 'client/rendering/FontRenderer.cpp', 'client/rendering/wrapper/Framebuffer.cpp', 'client/rendering/NoiseTexture.cpp', 'client/utils/Clock.cpp', 'client/input/Control.cpp', 'client/rendering/RenderSettings.cpp', 'client/rendering/wrapper/VertexBuffer.cpp', 'client/rendering/wrapper/StreamBuffer.cpp', 'client/rendering/wrapper/Texture.cpp', 'client/utils/PNGReader.cpp', 'client/rendering/wrapper/GLWrapper.cpp', 'client/rendering/Renderer.cpp', 'client/rendering/renderer/WorldRenderer.cpp', 'client/rendering/NormalTexture.cpp', 'client/math/Vector.cpp', 'client/rendering/Vertex.cpp', 'client/rendering/Triangle.cpp']
+sourcesClient = ['client/Main.cpp', 'client/rendering/WindowSize.cpp', 'client/math/Frustum.cpp', 'client/rendering/Framebuffers.cpp', 'client/rendering/wrapper/GLFWWrapper.cpp', 'client/rendering/wrapper/Window.cpp', 'client/rendering/Engine.cpp', 'client/input/Keys.cpp', 'client/rendering/wrapper/Shader.cpp', 'client/rendering/Shaders.cpp', 'client/utils/Utils.cpp', 'client/rendering/Mesh.cpp', 'client/math/Matrix.cpp', 'client/math/MatrixStack.cpp', 'client/math/Quaternion.cpp', 'client/math/Plane.cpp', 'client/Game.cpp', 'client/input/MouseButtons.cpp', 'client/rendering/FileTexture.cpp', 'client/rendering/FontRenderer.cpp', 'client/rendering/wrapper/Framebuffer.cpp', 'client/rendering/NoiseTexture.cpp', 'client/utils/Clock.cpp', 'client/input/Control.cpp', 'client/rendering/RenderSettings.cpp', 'client/rendering/wrapper/VertexBuffer.cpp', 'client/rendering/wrapper/StreamBuffer.cpp', 'client/rendering/wrapper/Texture.cpp', 'client/utils/PNGReader.cpp', 'client/rendering/wrapper/GLWrapper.cpp', 'client/rendering/Renderer.cpp', 'client/rendering/renderer/WorldRenderer.cpp', 'client/rendering/NormalTexture.cpp', 'client/rendering/Vertex.cpp', 'client/rendering/Triangle.cpp']
 
-sourcesTest = ['tests/Main.cpp', 'common/utils/String.cpp', 'common/utils/SplitString.cpp', 'client/math/Matrix.cpp', 'common/utils/HashedString.cpp', 'common/utils/Random.cpp']
+sourcesTest = ['tests/Main.cpp', 'common/utils/String.cpp', 'common/utils/SplitString.cpp', 'common/utils/HashedString.cpp', 'common/utils/Random.cpp']
 
 c_compiler = meson.get_compiler('cpp')
 readline = c_compiler.find_library('readline', required: true)

+ 0 - 3
tests/Main.cpp

@@ -2,10 +2,7 @@
 
 #include "common/utils/SplitString.h"
 #include "common/utils/Array.h"
-#include "common/utils/HashMap.h"
 #include "common/utils/List.h"
-#include "client/math/Vector.h"
-#include "client/math/Matrix.h"
 #include "common/utils/HashedString.h"
 #include "common/utils/Random.h"