diff --git a/app/fpointers.cpp b/app/fpointers.cpp new file mode 100644 index 0000000..dae8518 --- /dev/null +++ b/app/fpointers.cpp @@ -0,0 +1,20 @@ +#include "../src/platform/base.hpp" + +int sum(int a, int b) { return a + b; } + +int sub(int a, int b) { return a - b; } + +int main(void) { + std::cout << "Hello Pointers" << std::endl; + f_pointer(op, int, int, int); + + op = sum; + int a = 22; + int b = 11; + + std::cout << "Sum: " << op(a, b) << std::endl; + + op = sub; + + std::cout << "Sub: " << op(a, b) << std::endl; +} diff --git a/premake/fpointers.lua b/premake/fpointers.lua new file mode 100644 index 0000000..bf9a242 --- /dev/null +++ b/premake/fpointers.lua @@ -0,0 +1,20 @@ +project "fpointers" +kind "ConsoleApp" +language "c++" +targetdir "../bin/%{cfg.buildcfg}" +objdir "../obj" + +--files {"**.hpp","**.cpp"} +files { + "../app/fpointers.cpp" +} + +filter "configurations:Debug" + defines { "DEBUG" } + symbols "On" + +filter "configurations:Release" + defines { "NDEBUG" } + optimize "On" + +filter { "system:linux" } diff --git a/src/engine/math/quaternion.cpp b/src/engine/math/quaternion.cpp new file mode 100644 index 0000000..4c13298 --- /dev/null +++ b/src/engine/math/quaternion.cpp @@ -0,0 +1,27 @@ +#include "quaternion.hpp" + +using namespace engine::math; + +quaternion::quaternion(float32 _x, float32 _y, float32 _z, float32 _w) { + x = _x; + y = _y; + z = _z; + w = _w; +}; + +quaternion::quaternion(const vector3d &v, float32 scalar) { + quaternion(v.x, v.y, v.z, scalar); +}; + +const vector3d &quaternion::GetVector() const { + return reinterpret_cast(x); +}; + +inline quaternion operator*(const quaternion &q1, const quaternion &q2) { + float32 x = q1.x * q2.w + q1.y * q2.z - q1.z * q2.y + q1.w * q2.x; + float32 y = q1.y * q2.w + q1.z * q2.x + q1.w * q2.y - q1.x * q2.z; + float32 z = q1.z * q2.w + q1.w * q2.z + q1.x * q2.y - q1.y * q2.x; + float32 w = q1.w * q2.w - q1.x * q2.x - q1.y * q2.y - q1.z * q2.z; + + return quaternion(x, y, z, w); +}; diff --git a/src/engine/math/quaternion.hpp b/src/engine/math/quaternion.hpp new file mode 100644 index 0000000..6a79479 --- /dev/null +++ b/src/engine/math/quaternion.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include "../../platform/base.hpp" +#include "vector3d.hpp" + +namespace engine::math { +struct quaternion { + float32 x, y, z, w; + quaternion() = default; + ~quaternion() = default; + quaternion(float32 _x, float32 _y, float32 _z, float32 _w); + quaternion(const vector3d &v, float32 s); + const vector3d &GetVector(void) const; +}; + +inline quaternion operator*(const quaternion &q1, const quaternion &q2); + +}; // namespace engine::math diff --git a/src/engine/math/utils.hpp b/src/engine/math/utils.hpp new file mode 100644 index 0000000..ad53db5 --- /dev/null +++ b/src/engine/math/utils.hpp @@ -0,0 +1,9 @@ +#pragma once + +// Defines a matrix in termos of float32 +#define MATRIX(n, d) float32 n[d][d] + +// Computes determinant sub block +#define DET(a, b, c, d) (a * d - b * c) + +#define INVDET(row, idet) row[0] * idet, row[1] * idet, row[2] * idet diff --git a/src/platform/dsl/pt.h b/src/platform/dsl/pt.h new file mode 100644 index 0000000..01b79ca --- /dev/null +++ b/src/platform/dsl/pt.h @@ -0,0 +1,18 @@ +/** + * Defines a set of macros to enable us to progam as if C was created by + * portuguese programmers + */ + +#define se if +#define senao else +#define enquanto while +#define para for +#define privado private +#define publico public +#define protegido protected +#define estatico static +#define constante const +#define classe class +#define estrutura struct +#define deftipo typedef +#define vazio void