mrrp
This commit is contained in:
parent
c7e92a159b
commit
c1f1ba7dbf
6 changed files with 237 additions and 0 deletions
33
.clang-format
Normal file
33
.clang-format
Normal file
|
@ -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
|
||||||
|
|
8
imgui.ini
Normal file
8
imgui.ini
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
[Window][Debug##Default]
|
||||||
|
Pos=13,60
|
||||||
|
Size=400,400
|
||||||
|
|
||||||
|
[Window][player]
|
||||||
|
Pos=158,170
|
||||||
|
Size=316,183
|
||||||
|
|
BIN
libraylib.a
Normal file
BIN
libraylib.a
Normal file
Binary file not shown.
1
src/namespaces.hpp
Normal file
1
src/namespaces.hpp
Normal file
|
@ -0,0 +1 @@
|
||||||
|
namespace rl = raylib;
|
129
src/phys.cpp
Normal file
129
src/phys.cpp
Normal file
|
@ -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 <array>
|
||||||
|
#include <cassert>
|
||||||
|
#include <cfloat>
|
||||||
|
#include <initializer_list>
|
||||||
|
#include <raylib.h>
|
||||||
|
#include <raymath.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
PointCloud::PointCloud() : Points() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PointCloud::PointCloud(const std::vector<rl::Vector3>& 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<rl::Vector3, 8> 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<rl::Vector3, 8> 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<rl::Vector3> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
66
src/phys.hpp
Normal file
66
src/phys.hpp
Normal file
|
@ -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 <initializer_list>
|
||||||
|
#include <raylib-cpp/include/raylib-cpp.hpp>
|
||||||
|
#include <raylib.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace rl = raylib;
|
||||||
|
|
||||||
|
struct PointCloud {
|
||||||
|
std::vector<rl::Vector3> Points; // chosen because of fast iteration
|
||||||
|
|
||||||
|
void extracted();
|
||||||
|
// Generate Em
|
||||||
|
|
||||||
|
// Create from existing vector
|
||||||
|
PointCloud(const std::vector<rl::Vector3>& 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<rl::Vector3> points;
|
||||||
|
|
||||||
|
Simplex& operator=(std::initializer_list<rl::Vector3> 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 !!
|
||||||
|
*/
|
Loading…
Add table
Add a link
Reference in a new issue