Collisions are fucky but I can't be bothered to work on them as of now. I need a break from physics maths, so I'm going to start working on UI probably.
This commit is contained in:
parent
5f6fb70475
commit
66956de068
@ -41,11 +41,76 @@ float collceiling = INFINITY;
|
|||||||
|
|
||||||
float gravity = 0;
|
float gravity = 0;
|
||||||
|
|
||||||
|
bool qColl(float obesity, Vector3 futurePos, Morault::Maps::Map* map, float renderScale, Vector3 velocity) {
|
||||||
|
int currsec = -1;
|
||||||
|
Vector2 normalizedVelocity = Vector2Normalize({ velocity.x, velocity.z });
|
||||||
|
for (int i = 0; i < map->MapTriangles.size(); i++) {
|
||||||
|
|
||||||
|
if (CheckCollisionPointTriangle({ futurePos.x / renderScale, futurePos.z / renderScale }, map->MapTriangles[i].a, map->MapTriangles[i].b, map->MapTriangles[i].c)) {
|
||||||
|
currsec = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (currsec == -1) return true;
|
||||||
|
|
||||||
|
for (int i = 0; i < map->MapTriangles.size(); i++) {
|
||||||
|
// check wall collisions
|
||||||
|
if (CheckCollisionCircleLine({ futurePos.x, futurePos.z }, 300.0f, Vector2Multiply(map->MapTriangles[i].a, { renderScale,renderScale }), Vector2Multiply(map->MapTriangles[i].b, { renderScale,renderScale })) || CheckCollisionCircleLine({ futurePos.x, futurePos.z }, 300.0f, Vector2Multiply(map->MapTriangles[i].b, { renderScale,renderScale }), Vector2Multiply(map->MapTriangles[i].c, { renderScale,renderScale })) || CheckCollisionCircleLine({ futurePos.x, futurePos.z }, 300.0f, Vector2Multiply(map->MapTriangles[i].c, { renderScale,renderScale }), Vector2Multiply(map->MapTriangles[i].a, { renderScale,renderScale }))) {
|
||||||
|
|
||||||
|
if (
|
||||||
|
(map->MapTriangles[i].wallAB != "pms:none" ||
|
||||||
|
(map->MapTriangles[currsec].heightFloor < map->MapTriangles[i].heightFloor
|
||||||
|
? -(abs(map->MapTriangles[currsec].heightFloor) - abs(map->MapTriangles[i].heightFloor)) < 10 : false))
|
||||||
|
&& Vector2DotProduct({ -(map->MapTriangles[i].b.y - map->MapTriangles[i].a.y), (map->MapTriangles[i].b.x - map->MapTriangles[i].a.x) }, normalizedVelocity) > 0) {
|
||||||
|
|
||||||
|
int highestFloor = map->MapTriangles[i].heightFloor < map->MapTriangles[currsec].heightFloor ? map->MapTriangles[currsec].heightFloor : map->MapTriangles[i].heightFloor;
|
||||||
|
if (futurePos.y - 5 >= highestFloor * renderScale && map->MapTriangles[i].wallAB == "pms:none") {}
|
||||||
|
|
||||||
|
else if (CheckCollisionCircleLine({ futurePos.x, futurePos.z }, obesity, Vector2Multiply(map->MapTriangles[i].a, { renderScale,renderScale }), Vector2Multiply(map->MapTriangles[i].b, { renderScale,renderScale }))) {
|
||||||
|
// futurePos = camera.position;
|
||||||
|
|
||||||
|
// check which is highest
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
(map->MapTriangles[i].wallBC != "pms:none" ||
|
||||||
|
(map->MapTriangles[currsec].heightFloor < map->MapTriangles[i].heightFloor
|
||||||
|
? -(abs(map->MapTriangles[currsec].heightFloor) - abs(map->MapTriangles[i].heightFloor)) < 10 : false))
|
||||||
|
&& Vector2DotProduct({ -(map->MapTriangles[i].c.y - map->MapTriangles[i].b.y), (map->MapTriangles[i].c.x - map->MapTriangles[i].b.x) }, normalizedVelocity) > 0) {
|
||||||
|
int highestFloor = map->MapTriangles[i].heightFloor < map->MapTriangles[currsec].heightFloor ? map->MapTriangles[currsec].heightFloor : map->MapTriangles[i].heightFloor;
|
||||||
|
if (futurePos.y - 5 >= highestFloor * renderScale && map->MapTriangles[i].wallAB == "pms:none") {}
|
||||||
|
|
||||||
|
else if (CheckCollisionCircleLine({ futurePos.x, futurePos.z }, obesity, Vector2Multiply(map->MapTriangles[i].b, { renderScale,renderScale }), Vector2Multiply(map->MapTriangles[i].c, { renderScale,renderScale }))) {
|
||||||
|
|
||||||
|
// check which is highest
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
(map->MapTriangles[i].wallCA != "pms:none" ||
|
||||||
|
(map->MapTriangles[currsec].heightFloor < map->MapTriangles[i].heightFloor
|
||||||
|
? -(abs(map->MapTriangles[currsec].heightFloor) - abs(map->MapTriangles[i].heightFloor)) < 10 : false))
|
||||||
|
&& Vector2DotProduct({ -(map->MapTriangles[i].a.y - map->MapTriangles[i].c.y), (map->MapTriangles[i].a.x - map->MapTriangles[i].c.x) }, normalizedVelocity) > 0) {
|
||||||
|
int highestFloor = map->MapTriangles[i].heightFloor < map->MapTriangles[currsec].heightFloor ? map->MapTriangles[currsec].heightFloor : map->MapTriangles[i].heightFloor;
|
||||||
|
if (futurePos.y - 5 >= highestFloor * renderScale && map->MapTriangles[i].wallAB == "pms:none") {}
|
||||||
|
else if (CheckCollisionCircleLine({ futurePos.x, futurePos.z }, obesity, Vector2Multiply(map->MapTriangles[i].c, { renderScale,renderScale }), Vector2Multiply(map->MapTriangles[i].a, { renderScale,renderScale }))) {
|
||||||
|
|
||||||
|
// check which is highest
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void Morault::Gameplay::PlayerController::UpdatePlayerController(bool focus, Morault::Maps::Map* map, float renderScale)
|
void Morault::Gameplay::PlayerController::UpdatePlayerController(bool focus, Morault::Maps::Map* map, float renderScale)
|
||||||
{
|
{
|
||||||
|
|
||||||
Vector3 futurePos = camera.position;
|
Vector3 futurePos = camera.position;
|
||||||
|
bool correctionNecessary = false;
|
||||||
if (focus) {
|
if (focus) {
|
||||||
rotation = Vector3RotateByAxisAngle(rotation, { 0,1,0 }, -GetMouseDelta().x * 0.05 * sensitivityMultiplier);
|
rotation = Vector3RotateByAxisAngle(rotation, { 0,1,0 }, -GetMouseDelta().x * 0.05 * sensitivityMultiplier);
|
||||||
rotation.y = Clamp(rotation.y - GetMouseDelta().y * 0.3 * sensitivityMultiplier, -15, 15);
|
rotation.y = Clamp(rotation.y - GetMouseDelta().y * 0.3 * sensitivityMultiplier, -15, 15);
|
||||||
@ -66,29 +131,51 @@ void Morault::Gameplay::PlayerController::UpdatePlayerController(bool focus, Mor
|
|||||||
rotation = { 0,0,0 };
|
rotation = { 0,0,0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int currsec = -1;
|
||||||
|
|
||||||
for (int i = 0; i < map->MapTriangles.size(); i++) {
|
for (int i = 0; i < map->MapTriangles.size(); i++) {
|
||||||
|
|
||||||
if (CheckCollisionPointTriangle({ futurePos.x / renderScale, futurePos.z / renderScale }, map->MapTriangles[i].a, map->MapTriangles[i].b, map->MapTriangles[i].c)) {
|
if (CheckCollisionPointTriangle({ futurePos.x / renderScale, futurePos.z / renderScale }, map->MapTriangles[i].a, map->MapTriangles[i].b, map->MapTriangles[i].c)) {
|
||||||
collfloor = map->MapTriangles[i].heightFloor * renderScale + 5;
|
collfloor = map->MapTriangles[i].heightFloor * renderScale + 5;
|
||||||
collceiling = map->MapTriangles[i].heightCeiling * renderScale-2;
|
collceiling = map->MapTriangles[i].heightCeiling * renderScale - 2;
|
||||||
if (map->MapTriangles[i].wallAB != "pms:none") {
|
currsec = i;
|
||||||
if (CheckCollisionCircleLine({ futurePos.x, futurePos.z }, obesity, Vector2Multiply(map->MapTriangles[i].a, { renderScale,renderScale }), Vector2Multiply(map->MapTriangles[i].b, { renderScale,renderScale }))) {
|
|
||||||
futurePos = camera.position;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (map->MapTriangles[i].wallBC != "pms:none") {
|
|
||||||
if (CheckCollisionCircleLine({ futurePos.x, futurePos.z }, obesity, Vector2Multiply(map->MapTriangles[i].b, { renderScale,renderScale }), Vector2Multiply(map->MapTriangles[i].c, { renderScale,renderScale }))) {
|
|
||||||
futurePos = camera.position;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (map->MapTriangles[i].wallCA != "pms:none") {
|
|
||||||
if (CheckCollisionCircleLine({ futurePos.x, futurePos.z }, obesity, Vector2Multiply(map->MapTriangles[i].c, { renderScale,renderScale }), Vector2Multiply(map->MapTriangles[i].a, { renderScale,renderScale }))) {
|
|
||||||
futurePos = camera.position;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if(currsec != -1){
|
||||||
|
for (int i = 0; i < map->MapTriangles.size(); i++) {
|
||||||
|
// check wall collisions
|
||||||
|
if (CheckCollisionCircleLine({futurePos.x, futurePos.z}, 300.0f, Vector2Multiply(map->MapTriangles[i].a, { renderScale,renderScale }), Vector2Multiply(map->MapTriangles[i].b, { renderScale,renderScale })) || CheckCollisionCircleLine({ futurePos.x, futurePos.z }, 300.0f, Vector2Multiply(map->MapTriangles[i].b, { renderScale,renderScale }), Vector2Multiply(map->MapTriangles[i].c, { renderScale,renderScale })) || CheckCollisionCircleLine({ futurePos.x, futurePos.z }, 300.0f, Vector2Multiply(map->MapTriangles[i].c, { renderScale,renderScale }), Vector2Multiply(map->MapTriangles[i].a, { renderScale,renderScale }))) {
|
||||||
|
|
||||||
|
if (map->MapTriangles[i].wallAB != "pms:none" || (map->MapTriangles[currsec].heightFloor < map->MapTriangles[i].heightFloor ? abs(abs(map->MapTriangles[currsec].heightFloor) - abs(map->MapTriangles[i].heightFloor)) > 10 : false)) {
|
||||||
|
if (CheckCollisionCircleLine({ futurePos.x, futurePos.z }, obesity, Vector2Multiply(map->MapTriangles[i].a, { renderScale,renderScale }), Vector2Multiply(map->MapTriangles[i].b, { renderScale,renderScale }))) {
|
||||||
|
// futurePos = camera.position;
|
||||||
|
correctionNecessary = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (map->MapTriangles[i].wallBC != "pms:none" || (map->MapTriangles[currsec].heightFloor < map->MapTriangles[i].heightFloor ? abs(abs(map->MapTriangles[currsec].heightFloor) - abs(map->MapTriangles[i].heightFloor)) > 10 : false)) {
|
||||||
|
if (CheckCollisionCircleLine({ futurePos.x, futurePos.z }, obesity, Vector2Multiply(map->MapTriangles[i].b, { renderScale,renderScale }), Vector2Multiply(map->MapTriangles[i].c, { renderScale,renderScale }))) {
|
||||||
|
|
||||||
|
correctionNecessary = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (map->MapTriangles[i].wallCA != "pms:none" || (map->MapTriangles[currsec].heightFloor < map->MapTriangles[i].heightFloor ? abs(abs(map->MapTriangles[currsec].heightFloor) - abs(map->MapTriangles[i].heightFloor)) > 10 : false)) {
|
||||||
|
if (CheckCollisionCircleLine({ futurePos.x, futurePos.z }, obesity, Vector2Multiply(map->MapTriangles[i].c, { renderScale,renderScale }), Vector2Multiply(map->MapTriangles[i].a, { renderScale,renderScale }))) {
|
||||||
|
|
||||||
|
correctionNecessary = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (correctionNecessary) {
|
||||||
|
if (!qColl(obesity, futurePos, map, renderScale, Vector3Subtract(futurePos, camera.position))) futurePos = futurePos;
|
||||||
|
|
||||||
|
// else if (!qColl(obesity, Vector3Add(futurePos, Vector3Multiply(Vector3Subtract(camera.target, camera.position), {0.5, 0.5, 0.5})), map, renderScale, Vector3Subtract(futurePos, camera.position))) futurePos = Vector3Add(futurePos, Vector3Multiply(Vector3Subtract(camera.target, camera.position), { 0.01, 0.01, 0.01 }));
|
||||||
|
else futurePos = camera.position;
|
||||||
|
}
|
||||||
|
|
||||||
futurePos.y -= gravity*GetFrameTime();
|
futurePos.y -= gravity*GetFrameTime();
|
||||||
gravity += 10*GetFrameTime();
|
gravity += 10*GetFrameTime();
|
||||||
if (futurePos.y < collfloor) {
|
if (futurePos.y < collfloor) {
|
||||||
@ -100,7 +187,7 @@ void Morault::Gameplay::PlayerController::UpdatePlayerController(bool focus, Mor
|
|||||||
gravity = 0;
|
gravity = 0;
|
||||||
}
|
}
|
||||||
camera.position = futurePos;
|
camera.position = futurePos;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
camera.target = Vector3Add(camera.position, rotation);
|
camera.target = Vector3Add(camera.position, rotation);
|
||||||
|
@ -33,7 +33,7 @@ int main(int argc, char** argv) {
|
|||||||
bool running = true;
|
bool running = true;
|
||||||
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
||||||
InitWindow(1280, 720, "ProjectMorault");
|
InitWindow(1280, 720, "ProjectMorault");
|
||||||
SetTargetFPS(60);
|
// SetTargetFPS(60);
|
||||||
SetExitKey(0);
|
SetExitKey(0);
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user