diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..412420d --- /dev/null +++ b/.clang-format @@ -0,0 +1,33 @@ +# +# You can add options here to match your desired format. +# For reference, see the following URL: +# https://clang.llvm.org/docs/ClangFormatStyleOptions.html +# +# To start braces on a new line, you can add: +# BreakBeforeBraces: Allman +# +# To use tabs to indent, change the indent width to 8, and add: +# UseTab: ForIndentation +# + +# Use C/C++ as the language +Language: Cpp + +# Inherit our style from LLVM +BasedOnStyle: LLVM + +# Use 4 spaces as our indent width +IndentWidth: 8 +UseTab: ForIndentation + +# Reformat lines to be under 80 characters +ColumnLimit: 120 + +# Do not allow single-line functions (unless empty) +AllowShortFunctionsOnASingleLine: Empty + + +DerivePointerAlignment: false +ReferenceAlignment: Left +SpaceAfterCStyleCast: true + diff --git a/imgui.ini b/imgui.ini new file mode 100644 index 0000000..3d673f6 --- /dev/null +++ b/imgui.ini @@ -0,0 +1,8 @@ +[Window][Debug##Default] +Pos=13,60 +Size=400,400 + +[Window][player] +Pos=158,170 +Size=316,183 + diff --git a/libraylib.a b/libraylib.a new file mode 100644 index 0000000..498a430 Binary files /dev/null and b/libraylib.a differ diff --git a/src/namespaces.hpp b/src/namespaces.hpp new file mode 100644 index 0000000..6bee3e7 --- /dev/null +++ b/src/namespaces.hpp @@ -0,0 +1 @@ +namespace rl = raylib; diff --git a/src/phys.cpp b/src/phys.cpp new file mode 100644 index 0000000..d0ac32b --- /dev/null +++ b/src/phys.cpp @@ -0,0 +1,129 @@ +#include "phys.hpp" +#include "raylib-cpp/include/Camera3D.hpp" +#include "raylib-cpp/include/Model.hpp" +#include "raylib-cpp/include/Vector3.hpp" +#include +#include +#include +#include +#include +#include +#include + +PointCloud::PointCloud() : Points() { + return; +} + +PointCloud::PointCloud(const std::vector& in) : Points(in) { + return; +} + +RecPrism::RecPrism(rl::Vector3 v1, rl::Vector3 v2) : model(GenMeshCube(v2.x, v2.y, v2.z)) { + pos = v1; + size = v2; + rotation = QuaternionIdentity(); +} + +void RecPrism::Draw(rl::Color color) { + model.SetTransform(QuaternionToMatrix(rotation)); + DrawModel(model, pos, 1.0, BLUE); + + //DrawSphere(pos, 10, GREEN); + + std::array vectors; + + vectors[0] = (Vector3) {size.x/2, size.y/2, size.z/2}; + vectors[1] = (Vector3) {-size.x/2, -size.y/2, -size.z/2}; + vectors[2] = (Vector3) {-size.x/2, size.y/2, size.z/2}; + vectors[3] = (Vector3) {size.x/2, -size.y/2, size.z/2}; + vectors[4] = (Vector3) {size.x/2, size.y/2, -size.z/2}; + vectors[5] = (Vector3) {-size.x/2, -size.y/2, size.z/2}; + vectors[6] = (Vector3) {size.x/2, -size.y/2, -size.z/2}; + vectors[7] = (Vector3) {-size.x/2, size.y/2, -size.z/2}; + + for (size_t i = 0; i < 8; i++) { + vectors[i] = pos + Vector3RotateByQuaternion(vectors[i], rotation); + } + + for (auto v : vectors) { + DrawSphere(v, 10, RED); + } + +} + +rl::Vector3 RecPrism::FindFurthestPoint(rl::Vector3 dir) const { + // Get Verts + if (size == Vector3Zero()) { + return pos; + } + + std::array vectors; + + + vectors[0] = (Vector3) {size.x/2, size.y/2, size.z/2}; + vectors[1] = (Vector3) {-size.x/2, -size.y/2, -size.z/2}; + vectors[2] = (Vector3) {-size.x/2, size.y/2, size.z/2}; + vectors[3] = (Vector3) {size.x/2, -size.y/2, size.z/2}; + vectors[4] = (Vector3) {size.x/2, size.y/2, -size.z/2}; + vectors[5] = (Vector3) {-size.x/2, -size.y/2, size.z/2}; + vectors[6] = (Vector3) {size.x/2, -size.y/2, -size.z/2}; + vectors[7] = (Vector3) {-size.x/2, size.y/2, -size.z/2}; + + for (size_t i = 0; i < 8; i++) { + vectors[i] = pos + Vector3RotateByQuaternion(vectors[i], rotation); + } + + rl::Vector3 maxpoint; + float maxdist = FLT_MIN; + for (auto v : vectors) { + float dist = v.DotProduct(dir); + if (dist > maxdist) { + maxdist = dist; + maxpoint = v; + } + } + + return maxpoint; +} + +rl::Vector3 Support(const Collider& a, const Collider& b, rl::Vector3 dir) { + return a.FindFurthestPoint(dir) - b.FindFurthestPoint(-dir); +} + +Simplex& Simplex::operator=(std::initializer_list list) { + assert(list.size() <= 4); + for (auto p : list) { + points.push_back(p); + } + return *this; +} + +Simplex::Simplex() {} + +void Simplex::push(rl::Vector3 point) { + points.push_back(point); +} + +rl::Vector3& Simplex::operator[](size_t i) { + + return points[i]; +} + + +bool GJK(const Collider& a, const Collider& b) { + rl::Vector3 support = Support(a, b, rl::Vector3(1,0,0)); + + Simplex points; + points.push(support); + + rl::Vector3 dir = -support; + + while(true) { + support = Support(a, b, dir); + + if (support.DotProduct(dir) <= 0) { + return false; + } + + } +} diff --git a/src/phys.hpp b/src/phys.hpp new file mode 100644 index 0000000..bde266e --- /dev/null +++ b/src/phys.hpp @@ -0,0 +1,66 @@ +#ifndef PHYS_H +#define PHYS_H + +#include "raylib-cpp/include/Color.hpp" +#include "raylib-cpp/include/Model.hpp" +#include "raylib-cpp/include/Vector3.hpp" +#include "raylib-cpp/include/Vector4.hpp" +#include +#include +#include +#include + +namespace rl = raylib; + +struct PointCloud { + std::vector Points; // chosen because of fast iteration + + void extracted(); + // Generate Em + + // Create from existing vector + PointCloud(const std::vector& in); + + PointCloud(); +}; + +struct Collider { + virtual rl::Vector3 FindFurthestPoint(rl::Vector3 dir) const = 0; +}; + +struct RecPrism : Collider { + rl::Vector3 pos; //Center + rl::Vector3 size; + rl::Quaternion rotation; + rl::Model model; + + void Draw(rl::Color color = BLUE); + + RecPrism(rl::Vector3 v1, rl::Vector3 v2); + + rl::Vector3 FindFurthestPoint(rl::Vector3 dir) const; +}; + +rl::Vector3 Support(const Collider& a, const Collider& b, rl::Vector3 dir); + +struct Simplex { + + Simplex(); + + std::vector points; + + Simplex& operator=(std::initializer_list list); + + void push(rl::Vector3 point); + + rl::Vector3& operator[](size_t i); +}; + +bool GJK(const Collider& a, const Collider& b); + +#endif + +/* TODO: + Fix rects (use quaternions and transform ig) + GJK !! + */