erm
This commit is contained in:
parent
0db35dc0b2
commit
4f206dfa99
4 changed files with 560 additions and 298 deletions
24
imgui.ini
24
imgui.ini
|
@ -6,3 +6,27 @@ Size=400,400
|
|||
Pos=158,170
|
||||
Size=316,183
|
||||
|
||||
[Window][peak]
|
||||
Pos=60,60
|
||||
Size=344,200
|
||||
|
||||
[Window][0]
|
||||
Pos=245,24
|
||||
Size=436,96
|
||||
|
||||
[Window][1]
|
||||
Pos=54,171
|
||||
Size=68,54
|
||||
|
||||
[Window][2]
|
||||
Pos=243,100
|
||||
Size=68,54
|
||||
|
||||
[Window][3]
|
||||
Pos=60,60
|
||||
Size=68,54
|
||||
|
||||
[Window][4]
|
||||
Pos=60,60
|
||||
Size=68,54
|
||||
|
||||
|
|
252
src/main.cpp
252
src/main.cpp
|
@ -7,7 +7,9 @@
|
|||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <optional>
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
#include "imgui.h"
|
||||
#include "imgui_stdlib.h"
|
||||
|
@ -106,9 +108,7 @@ std::ostream &operator<<(std::ostream &os, const Vector2 &obj) {
|
|||
return os;
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct Player {
|
||||
struct Player : Collider {
|
||||
raylib::Camera3D cam;
|
||||
|
||||
rl::Vector3 accel;
|
||||
|
@ -117,8 +117,37 @@ struct Player {
|
|||
|
||||
rl::Vector3 rotEul;
|
||||
|
||||
Player() : cam((Vector3){0, 0, 0}) {
|
||||
//
|
||||
RecPrism hitBox;
|
||||
|
||||
Player() : cam((Vector3) {0, 0, 0}), hitBox(0, rl::Vector3(20, 20, 20)) {
|
||||
hitBox.movable = true;
|
||||
cam.SetFovy(70);
|
||||
}
|
||||
|
||||
rl::Vector3 GetVelocity() const {
|
||||
return velocity;
|
||||
}
|
||||
|
||||
void SetVelocity(rl::Vector3 in) {
|
||||
velocity = in;
|
||||
hitBox.SetVelocity(in);
|
||||
}
|
||||
|
||||
rl::Vector3 GetPos() const {
|
||||
return pos;
|
||||
}
|
||||
|
||||
void SetPos(rl::Vector3 in) {
|
||||
pos = in;
|
||||
hitBox.SetPos(in);
|
||||
}
|
||||
|
||||
bool CanMove() const {
|
||||
return hitBox.CanMove();
|
||||
}
|
||||
|
||||
rl::Vector3 FindFurthestPoint(rl::Vector3 dir) const {
|
||||
return hitBox.FindFurthestPoint(dir);
|
||||
}
|
||||
|
||||
rl::Quaternion Rotation() {
|
||||
|
@ -128,6 +157,8 @@ struct Player {
|
|||
rl::Vector3 forward = Vector3RotateByQuaternion((Vector3) {0, 0, -1}, Rotation());
|
||||
rl::Vector3 up = (Vector3) {0, 1, 0};
|
||||
rl::Vector3 left = Vector3RotateByAxisAngle(forward, up, M_PI_2);
|
||||
|
||||
if (IsCursorHidden()) {
|
||||
if (IsKeyDown(KEY_W)) {
|
||||
// accel += forward * 5;
|
||||
accel += rl::Vector3(forward.x, 0, forward.z).Normalize() * 5;
|
||||
|
@ -153,34 +184,38 @@ struct Player {
|
|||
accel -= up * 5;
|
||||
}
|
||||
|
||||
if (IsKeyDown(KEY_J)) {
|
||||
if (velocity.y < 15) {
|
||||
velocity.y = 15;
|
||||
};
|
||||
}
|
||||
|
||||
if (IsKeyDown(KEY_H)) {
|
||||
velocity = 0;
|
||||
}
|
||||
|
||||
|
||||
//target = Vector3RotateByAxisAngle(target, (Vector3){0, 1, 0}, -GetMouseDelta().x * 0.02 * DEG2RAD);
|
||||
//target = Vector3RotateByAxisAngle(target, (Vector3){1, 0, 0}, GetMouseDelta().y * 0.1 * DEG2RAD);
|
||||
|
||||
// target = Vector3RotateByAxisAngle(target, (Vector3){0, 1, 0}, -GetMouseDelta().x * 0.02 *
|
||||
// DEG2RAD); target = Vector3RotateByAxisAngle(target, (Vector3){1, 0, 0}, GetMouseDelta().y *
|
||||
// 0.1 * DEG2RAD);
|
||||
|
||||
rotEul.z -= GetMouseDelta().y * 0.02 * DEG2RAD;
|
||||
rotEul.y -= GetMouseDelta().x * 0.02 * DEG2RAD;
|
||||
}
|
||||
|
||||
|
||||
// rotation = QuaternionMultiply(rotation, QuaternionFromAxisAngle((Vector3) {1,0,0} , -GetMouseDelta().y * 0.02 * DEG2RAD));
|
||||
// rotation = QuaternionNormalize(rotation);
|
||||
// rotation = QuaternionMultiply(rotation, QuaternionFromAxisAngle((Vector3) {1,0,0} ,
|
||||
// -GetMouseDelta().y * 0.02 * DEG2RAD)); rotation = QuaternionNormalize(rotation);
|
||||
// cam.SetTarget(pos + Vector3RotateByQuaternion((Vector3) {0, 0, -1}, rotation));
|
||||
|
||||
// forward = Vector3RotateByQuaternion((Vector3) {0, 0, -1}, rotation);
|
||||
// up = Vector3RotateByQuaternion((Vector3) {0, 1, 0}, rotation);
|
||||
// left = Vector3RotateByAxisAngle(forward, cam.GetUp(), M_PI_2);
|
||||
|
||||
// rotation = QuaternionMultiply(rotation, QuaternionFromAxisAngle((Vector3) {0,1,0}, -GetMouseDelta().x * 0.02 * DEG2RAD));
|
||||
// rotation = QuaternionNormalize(rotation);
|
||||
// rotation = QuaternionMultiply(rotation, QuaternionFromAxisAngle((Vector3) {0,1,0}, -GetMouseDelta().x
|
||||
// * 0.02 * DEG2RAD)); rotation = QuaternionNormalize(rotation);
|
||||
// cam.SetTarget(pos + Vector3RotateByQuaternion((Vector3) {0, 0, -1}, rotation));
|
||||
|
||||
// zero roll
|
||||
|
||||
|
||||
// std::cout << GetMouseDelta() << std::endl;
|
||||
}
|
||||
|
||||
|
@ -191,9 +226,37 @@ struct Player {
|
|||
accel = Vector3Zero();
|
||||
cam.SetPosition(pos);
|
||||
cam.SetTarget(pos + Vector3RotateByQuaternion((Vector3) {0, 0, -1}, Rotation()));
|
||||
hitBox.pos = pos;
|
||||
}
|
||||
};
|
||||
|
||||
std::optional<Collider *> GetSelectedCollider(std::vector<Collider *> list, Collider *user, Ray wr) {
|
||||
// std::cout << GetMousePosition() << std::endl;
|
||||
|
||||
ColRay checkray = ColRay(wr.position, wr.direction);
|
||||
// std::cout << wr.position << " dir: " << wr.direction << std::endl;
|
||||
|
||||
float closest_dist = FLT_MAX;
|
||||
Collider *selected_object = NULL;
|
||||
for (auto obj : list) {
|
||||
if (obj != user) {
|
||||
auto res = GJK(*obj, checkray);
|
||||
if (res) {
|
||||
float dist = (obj->GetPos() - checkray.origin).Length();
|
||||
if (dist < closest_dist) {
|
||||
closest_dist = dist;
|
||||
selected_object = obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (selected_object == NULL) {
|
||||
return std::optional<Collider *>();
|
||||
}
|
||||
return selected_object;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
@ -205,8 +268,7 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
// SetConfigFlags(FLAG_MSAA_4X_HINT | FLAG_WINDOW_RESIZABLE);
|
||||
|
||||
raylib::Window window(screenWidth, screenHeight, "shooter",
|
||||
FLAG_MSAA_4X_HINT | FLAG_WINDOW_RESIZABLE);
|
||||
raylib::Window window(screenWidth, screenHeight, "shooter", FLAG_MSAA_4X_HINT | FLAG_WINDOW_RESIZABLE);
|
||||
window.SetTargetFPS(244);
|
||||
rlImGuiSetup(true);
|
||||
DisableCursor();
|
||||
|
@ -224,10 +286,17 @@ int main(int argc, char *argv[]) {
|
|||
bool showDemoWindow = true;
|
||||
|
||||
Player user;
|
||||
user.pos = rl::Vector3 {0, 0, 200};
|
||||
user.pos = rl::Vector3{0, 100, 0};
|
||||
|
||||
RecPrism peak(Vector3Zero(), (Vector3) {50, 50, 50});
|
||||
RecPrism peakduo((Vector3) {45, 0, 0} , (Vector3) {50, 50, 50} );
|
||||
|
||||
std::vector<Collider *> PhysObjs;
|
||||
|
||||
std::vector<Collider *> OpenConfigs;
|
||||
|
||||
PhysObjs.push_back(&user);
|
||||
PhysObjs.push_back(&peak);
|
||||
|
||||
while (!window.ShouldClose()) // Detect window close button or ESC key, or a quit from the menu
|
||||
{
|
||||
if (IsWindowResized()) {
|
||||
|
@ -249,63 +318,148 @@ int main(int argc, char *argv[]) {
|
|||
// GetMouseWheelMove()*2.0f); // Move to target (zoom)
|
||||
|
||||
user.KeyControl();
|
||||
user.accel.y -= 9.8;
|
||||
user.UpdatePhysics();
|
||||
|
||||
for (size_t i = 0; i < PhysObjs.size(); i++) {
|
||||
for (size_t j = i; j < PhysObjs.size(); j++) {
|
||||
auto collide = GJK(*PhysObjs[i], *PhysObjs[j]);
|
||||
if (collide) {
|
||||
Collider *ObjA = PhysObjs[i];
|
||||
Collider *ObjB = PhysObjs[j];
|
||||
auto response = EPA(collide.value(), *PhysObjs[i], *PhysObjs[j]);
|
||||
if (PhysObjs[i]->CanMove() && PhysObjs[j]->CanMove()) { // untested
|
||||
|
||||
auto halfresp = response / 2;
|
||||
PhysObjs[i]->SetPos(PhysObjs[i]->GetPos() - halfresp);
|
||||
|
||||
auto dot = ObjA->GetVelocity().DotProduct((-halfresp).Normalize());
|
||||
dot = dot > 0 ? 0 : dot;
|
||||
ObjA->SetVelocity(ObjA->GetVelocity() -
|
||||
((-halfresp).Normalize() * dot));
|
||||
|
||||
PhysObjs[j]->SetPos(PhysObjs[j]->GetPos() + halfresp);
|
||||
auto dot2 = ObjB->GetVelocity().DotProduct(halfresp.Normalize());
|
||||
dot2 = dot2 > 0 ? 0 : dot2;
|
||||
ObjB->SetVelocity(ObjB->GetVelocity() - ((halfresp).Normalize() * dot));
|
||||
|
||||
} else if (PhysObjs[j]->CanMove()) {
|
||||
PhysObjs[j]->SetPos(PhysObjs[j]->GetPos() + response);
|
||||
|
||||
auto velo = ObjB->GetVelocity();
|
||||
|
||||
auto dot = velo.DotProduct(response.Normalize());
|
||||
dot = dot > 0 ? 0 : dot;
|
||||
velo = velo - (response.Normalize() * dot * 1);
|
||||
|
||||
ObjB->SetVelocity(velo);
|
||||
} else if (PhysObjs[i]->CanMove()) {
|
||||
PhysObjs[i]->SetPos(PhysObjs[i]->GetPos() + (-response));
|
||||
auto velo = ObjA->GetVelocity();
|
||||
|
||||
auto dot = velo.DotProduct((-response).Normalize());
|
||||
dot = dot > 0 ? 0 : dot;
|
||||
velo = velo - ((-response).Normalize() * dot * 1);
|
||||
ObjA->SetVelocity(velo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (IsKeyDown(KEY_LEFT_SHIFT)) {
|
||||
if (IsCursorHidden()) {
|
||||
EnableCursor();
|
||||
}
|
||||
} else {
|
||||
DisableCursor();
|
||||
}
|
||||
if (IsKeyDown(KEY_Q)) {
|
||||
|
||||
|
||||
|
||||
|
||||
// std::cout << "PrevRot: " << peak.rotation.ToString() << std::endl;
|
||||
|
||||
peak.rotation = QuaternionMultiply(peak.rotation, QuaternionFromAxisAngle((Vector3) {0, 1, 0}, 0.01));
|
||||
peak.rotation =
|
||||
QuaternionMultiply(peak.rotation, QuaternionFromAxisAngle((Vector3) {0, 1, 0}, 0.01));
|
||||
|
||||
// std::cout << "NewRot: " << n.ToString() << std::endl;
|
||||
|
||||
|
||||
}
|
||||
|
||||
if(IsKeyDown(KEY_L)) {
|
||||
peak.pos.x += 0.1;
|
||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) {
|
||||
Ray wr = GetScreenToWorldRay(GetMousePosition(), user.cam);
|
||||
auto out = GetSelectedCollider(PhysObjs, &user, wr);
|
||||
|
||||
bool contains = false;
|
||||
for (auto obj : OpenConfigs) {
|
||||
contains = contains || (obj == out);
|
||||
}
|
||||
if(IsKeyDown(KEY_J)) {
|
||||
peak.pos.x -= 0.1;
|
||||
if (!contains && out) {
|
||||
// print("Here\n");
|
||||
OpenConfigs.push_back(out.value());
|
||||
}
|
||||
if(IsKeyDown(KEY_I)) {
|
||||
peak.pos.z -= 0.1;
|
||||
}
|
||||
|
||||
if(IsKeyDown(KEY_K)) {
|
||||
peak.pos.z += 0.1;
|
||||
}
|
||||
// if(IsKeyDown(KEY_L)) {
|
||||
// peak.pos.x += 0.1;
|
||||
// }
|
||||
// if(IsKeyDown(KEY_J)) {
|
||||
// peak.pos.x -= 0.1;
|
||||
// }
|
||||
// if(IsKeyDown(KEY_I)) {
|
||||
// peak.pos.z -= 0.1;
|
||||
// }
|
||||
|
||||
// if(IsKeyDown(KEY_K)) {
|
||||
// peak.pos.z += 0.1;
|
||||
// }
|
||||
|
||||
outputTexture.BeginMode();
|
||||
ClearBackground(BLACK);
|
||||
user.cam.BeginMode();
|
||||
DrawSphere((Vector3) {0, 0, -300}, 20, RED);
|
||||
|
||||
// auto opt = GJK(peak, peakduo);
|
||||
// if (opt) {
|
||||
// //peakduo.Draw(RED);
|
||||
// peak.Draw(RED);
|
||||
// auto vec = EPA(opt.value(), peak, peakduo);
|
||||
// //DrawRay(Ray{peakduo.pos, vec}, BLUE);
|
||||
// peakduo.pos += vec;
|
||||
// } else {
|
||||
// peakduo.Draw();
|
||||
// peak.Draw();
|
||||
// }
|
||||
|
||||
auto opt = GJK(peak, peakduo);
|
||||
if (opt) {
|
||||
peakduo.Draw(RED);
|
||||
peak.Draw(RED);
|
||||
auto vec = EPA(opt.value(), peak, peakduo);
|
||||
//DrawRay(Ray{peakduo.pos, vec}, BLUE);
|
||||
peakduo.pos += vec;
|
||||
} else {
|
||||
peakduo.Draw();
|
||||
peak.Draw();
|
||||
}
|
||||
peak.Draw(BLUE);
|
||||
user.cam.EndMode();
|
||||
|
||||
rlImGuiBegin();
|
||||
|
||||
for (size_t i = 0; i < OpenConfigs.size(); i++) {
|
||||
|
||||
if (ImGui::Begin(std::to_string(i).c_str())) {
|
||||
auto pos = OpenConfigs[i]->GetPos();
|
||||
ImGui::InputFloat3("pos", &pos.x);
|
||||
OpenConfigs[i]->SetPos(pos);
|
||||
|
||||
auto sizeable = dynamic_cast<RecPrism*>(OpenConfigs[i]);
|
||||
if (sizeable) {
|
||||
ImGui::InputFloat3("size", &sizeable->size.x);
|
||||
|
||||
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
|
||||
rlImGuiEnd();
|
||||
|
||||
outputTexture.EndMode();
|
||||
|
||||
window.BeginDrawing();
|
||||
DrawTexturePro(outputTexture.texture,
|
||||
DrawTexturePro(
|
||||
outputTexture.texture,
|
||||
(Rectangle) {0, 0, static_cast<float>(outputTexture.texture.width),
|
||||
static_cast<float>(-outputTexture.texture.height)},
|
||||
(Rectangle){0, 0, static_cast<float>(window.GetWidth()),
|
||||
static_cast<float>(window.GetHeight())},
|
||||
(Rectangle) {0, 0, static_cast<float>(window.GetWidth()), static_cast<float>(window.GetHeight())},
|
||||
(Vector2) {0, 0}, 0, WHITE);
|
||||
|
||||
window.EndDrawing();
|
||||
|
|
92
src/phys.cpp
92
src/phys.cpp
|
@ -25,8 +25,26 @@ PointCloud::PointCloud(const std::vector<rl::Vector3>& in) : Points(in) {
|
|||
|
||||
RecPrism::RecPrism(rl::Vector3 v1, rl::Vector3 v2) : model(GenMeshCube(v2.x, v2.y, v2.z)) {
|
||||
pos = v1;
|
||||
velocity = 0;
|
||||
size = v2;
|
||||
rotation = QuaternionIdentity();
|
||||
movable = false;
|
||||
}
|
||||
|
||||
rl::Vector3 RecPrism::GetPos() const {
|
||||
return pos;
|
||||
}
|
||||
|
||||
void RecPrism::SetPos(rl::Vector3 in) {
|
||||
pos = in;
|
||||
}
|
||||
|
||||
rl::Vector3 RecPrism::GetVelocity() const {
|
||||
return velocity;
|
||||
}
|
||||
|
||||
void RecPrism::SetVelocity(rl::Vector3 in) {
|
||||
velocity = in;
|
||||
}
|
||||
|
||||
void RecPrism::Draw(rl::Color color) {
|
||||
|
@ -55,6 +73,40 @@ void RecPrism::Draw(rl::Color color) {
|
|||
}
|
||||
}
|
||||
|
||||
bool RecPrism::CanMove() const {
|
||||
return movable;
|
||||
}
|
||||
|
||||
Collider::~Collider() {}
|
||||
|
||||
ColRay::ColRay(rl::Vector3 pos, rl::Vector3 dir) : origin(pos), direction(dir.Normalize()) {}
|
||||
|
||||
bool ColRay::CanMove() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void ColRay::SetPos(rl::Vector3 in) {}
|
||||
|
||||
rl::Vector3 ColRay::GetPos() const {
|
||||
return origin;
|
||||
}
|
||||
|
||||
void ColRay::SetVelocity(rl::Vector3 in) {}
|
||||
|
||||
rl::Vector3 ColRay::GetVelocity() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
rl::Vector3 ColRay::FindFurthestPoint(rl::Vector3 dir) const {
|
||||
if (SameDirection(dir, direction)) {
|
||||
return origin + (direction*100000);
|
||||
} else {
|
||||
return origin;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
rl::Vector3 RecPrism::FindFurthestPoint(rl::Vector3 dir) const {
|
||||
// Get Verts
|
||||
if (size == Vector3Zero()) {
|
||||
|
@ -306,8 +358,10 @@ std::ostream& operator<<(std::ostream& out, const Triangle& p) {
|
|||
}
|
||||
|
||||
bool operator<(const rl::Vector3& a, const rl::Vector3& b) {
|
||||
if (a.x != b.x) return a.x < b.x;
|
||||
if (a.y != b.y) return a.y < b.y;
|
||||
if (a.x != b.x)
|
||||
return a.x < b.x;
|
||||
if (a.y != b.y)
|
||||
return a.y < b.y;
|
||||
return a.z < b.z;
|
||||
}
|
||||
|
||||
|
@ -327,13 +381,16 @@ Edge::Edge() {
|
|||
}
|
||||
|
||||
bool Edge::operator<(const Edge& b) const { // TODO: better
|
||||
if(x != b.x) return x < b.x;
|
||||
if (x != b.x)
|
||||
return x < b.x;
|
||||
return y < b.y;
|
||||
}
|
||||
|
||||
bool Triangle::operator<(const Triangle& b) const { // TODO: better
|
||||
if(this->a != b.a) return this->a < b.a;
|
||||
if(this->b != b.b) return this->b < b.b;
|
||||
if (this->a != b.a)
|
||||
return this->a < b.a;
|
||||
if (this->b != b.b)
|
||||
return this->b < b.b;
|
||||
return this->c < b.c;
|
||||
}
|
||||
|
||||
|
@ -353,8 +410,6 @@ Polytope::Polytope(Simplex S) {
|
|||
void Polytope::Extend(rl::Vector3 p) {
|
||||
std::set<Edge> edges;
|
||||
|
||||
|
||||
|
||||
std::queue<Triangle> rem;
|
||||
for (auto face : faces) {
|
||||
if (SameDirection(face.Normal(), p)) {
|
||||
|
@ -379,17 +434,15 @@ void Polytope::Extend(rl::Vector3 p) {
|
|||
for (auto edge : edges) {
|
||||
auto adding = Triangle(edge.x, edge.y, p);
|
||||
faces.insert(adding);
|
||||
std::cout << "adding: " << adding << "count: " << i << std::endl;
|
||||
// std::cout << "adding: " << adding << "count: " << i << std::endl;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
rl::Vector3 EPA(Simplex S, const Collider& a, const Collider& b) {
|
||||
Polytope p(S);
|
||||
|
||||
std::cout << "BEGIN" << std::endl;
|
||||
// std::cout << "BEGIN" << std::endl;
|
||||
|
||||
while (true) {
|
||||
// Find closest face
|
||||
|
@ -398,7 +451,7 @@ rl::Vector3 EPA(Simplex S, const Collider& a, const Collider& b) {
|
|||
|
||||
for (auto face : p.faces) {
|
||||
auto temp = Pointtoplane(face, 0);
|
||||
std::cout << "dist: " << temp << " " << face << std::endl;
|
||||
// std::cout << "dist: " << temp << " " << face << std::endl;
|
||||
if (temp < dist) {
|
||||
dist = temp;
|
||||
nearest = face;
|
||||
|
@ -406,28 +459,21 @@ rl::Vector3 EPA(Simplex S, const Collider& a, const Collider& b) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
auto normal = nearest.Normal();
|
||||
// DrawLine3D(rl::Vector3(0), normal*1000, GREEN);
|
||||
auto supportPoint = Support(a, b, normal);
|
||||
|
||||
// std::cout << "dist to farthest hull" << supportPoint.Dotproduct(normal) - dist << std::endl;
|
||||
if (abs(supportPoint.DotProduct(normal) - dist) < 0.1) { // if distance between face and point on face is same
|
||||
if (abs(supportPoint.DotProduct(normal) - dist) <
|
||||
0.1) { // if distance between face and point on face is same
|
||||
// return supportPoint.Project(normal);
|
||||
// DrawTriangle3D(nearest.a, nearest.b, nearest.c, GREEN);
|
||||
std::cout << "END" << std::endl;
|
||||
// std::cout << "END" << std::endl;
|
||||
return normal * Pointtoplane(nearest, 0);
|
||||
} else {
|
||||
// extend
|
||||
std::cout << "extending" << std::endl;
|
||||
// std::cout << "extending" << std::endl;
|
||||
p.Extend(supportPoint);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
38
src/phys.hpp
38
src/phys.hpp
|
@ -31,6 +31,33 @@ struct PointCloud {
|
|||
|
||||
struct Collider {
|
||||
virtual rl::Vector3 FindFurthestPoint(rl::Vector3 dir) const = 0;
|
||||
virtual bool CanMove() const = 0;
|
||||
virtual void SetPos(rl::Vector3 in) = 0;
|
||||
virtual rl::Vector3 GetPos() const = 0;
|
||||
|
||||
virtual void SetVelocity(rl::Vector3 in) = 0;
|
||||
virtual rl::Vector3 GetVelocity() const = 0;
|
||||
virtual ~Collider() = 0;
|
||||
};
|
||||
|
||||
struct ColRay : Collider {
|
||||
rl::Vector3 origin;
|
||||
rl::Vector3 direction;
|
||||
|
||||
ColRay(rl::Vector3 pos, rl::Vector3 dir);
|
||||
|
||||
bool CanMove() const;
|
||||
|
||||
void SetPos(rl::Vector3 in);
|
||||
rl::Vector3 GetPos() const;
|
||||
|
||||
rl::Vector3 FindFurthestPoint(rl::Vector3 dir) const;
|
||||
|
||||
rl::Vector3 GetVelocity() const;
|
||||
void SetVelocity(rl::Vector3 in);
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
struct RecPrism : Collider {
|
||||
|
@ -38,12 +65,23 @@ struct RecPrism : Collider {
|
|||
rl::Vector3 size;
|
||||
rl::Quaternion rotation;
|
||||
rl::Model model;
|
||||
rl::Vector3 velocity;
|
||||
|
||||
bool movable;
|
||||
|
||||
void Draw(rl::Color color = BLUE);
|
||||
|
||||
RecPrism(rl::Vector3 v1, rl::Vector3 v2);
|
||||
|
||||
bool CanMove() const;
|
||||
|
||||
void SetPos(rl::Vector3 in);
|
||||
rl::Vector3 GetPos() const;
|
||||
|
||||
rl::Vector3 FindFurthestPoint(rl::Vector3 dir) const;
|
||||
|
||||
rl::Vector3 GetVelocity() const;
|
||||
void SetVelocity(rl::Vector3 in);
|
||||
};
|
||||
|
||||
rl::Vector3 Support(const Collider& a, const Collider& b, rl::Vector3 dir);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue