mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-13 15:01:49 +00:00
cleanup a bit
This commit is contained in:
parent
546bbcb4e2
commit
8b48dcbf5a
1 changed files with 27 additions and 24 deletions
|
|
@ -66,21 +66,23 @@ static void calc_collision(
|
||||||
aabb = aabb + offset;
|
aabb = aabb + offset;
|
||||||
aabb.b.y -= stepHeight + E * 2;
|
aabb.b.y -= stepHeight + E * 2;
|
||||||
|
|
||||||
if ((box->position[nx] - pos[nx]) * sign > 0.0f && box->getAABB().intersects(aabb)) {
|
if ((box->position[nx] - pos[nx]) * sign <= 0.0f || !box->getAABB().intersects(aabb)) {
|
||||||
float newnegx = box->position[nx] - boxhalf[nx] - half[nx];
|
continue;
|
||||||
float newposx = box->position[nx] + boxhalf[nx] + half[nx];
|
}
|
||||||
float newx;
|
|
||||||
if ((glm::abs(newnegx - pos[nx]) - glm::abs(newposx - pos[nx]))*sign < 0.0f) {
|
float newnegx = box->position[nx] - boxhalf[nx] - half[nx];
|
||||||
newx = sign > 0 ? newnegx : newposx;
|
float newposx = box->position[nx] + boxhalf[nx] + half[nx];
|
||||||
} else {
|
float newx;
|
||||||
continue;
|
if ((glm::abs(newnegx - pos[nx]) - glm::abs(newposx - pos[nx]))*sign < 0.0f) {
|
||||||
}
|
newx = sign > 0 ? newnegx : newposx;
|
||||||
if ((pos[nx] - newx) * sign > 0.0f) {
|
} else {
|
||||||
if (vel[nx] * sign > 0.0f) {
|
continue;
|
||||||
vel[nx] = 0.0f;
|
}
|
||||||
}
|
if ((pos[nx] - newx) * sign > 0.0f) {
|
||||||
pos[nx] = newx;
|
if (vel[nx] * sign > 0.0f) {
|
||||||
|
vel[nx] = 0.0f;
|
||||||
}
|
}
|
||||||
|
pos[nx] = newx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (vel[nx] * sign <= 0.0f && hitbox.groundVelocity[nx] * sign <= 0.0f) {
|
if (vel[nx] * sign <= 0.0f && hitbox.groundVelocity[nx] * sign <= 0.0f) {
|
||||||
|
|
@ -148,10 +150,10 @@ static bool calc_collision_neg_y(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
groundVelocty = {};
|
groundVelocty = {};
|
||||||
for (int ix = 0; ix <= glm::ceil((half.x-E)*2); ix++) {
|
for (int ix = 0; ix <= glm::ceil((half.x - E) * 2); ix++) {
|
||||||
glm::vec3 coord;
|
glm::vec3 coord;
|
||||||
coord.x = (pos.x-half.x+E) + ix;
|
coord.x = (pos.x - half.x + E) + ix;
|
||||||
for (int iz = 0; iz <= glm::ceil((half.z-E)*2); iz++){
|
for (int iz = 0; iz <= glm::ceil((half.z - E) * 2); iz++) {
|
||||||
coord.z = (pos.z - half.z + E) + iz;
|
coord.z = (pos.z - half.z + E) + iz;
|
||||||
coord.y = pos.y - half.y - E * 2;
|
coord.y = pos.y - half.y - E * 2;
|
||||||
|
|
||||||
|
|
@ -161,7 +163,8 @@ static bool calc_collision_neg_y(
|
||||||
scale.z = 1.0f - E * 4.0f;
|
scale.z = 1.0f - E * 4.0f;
|
||||||
aabb.scale(scale);
|
aabb.scale(scale);
|
||||||
|
|
||||||
if (const auto obstacle = chunks.isObstacleAt(coord.x, coord.y, coord.z, aabb)) {
|
if (const auto obstacle =
|
||||||
|
chunks.isObstacleAt(coord.x, coord.y, coord.z, aabb)) {
|
||||||
float newy = std::floor(coord.y) + half.y + obstacle->max().y;
|
float newy = std::floor(coord.y) + half.y + obstacle->max().y;
|
||||||
if (newy >= pos.y) {
|
if (newy >= pos.y) {
|
||||||
vel.y = 0.0f;
|
vel.y = 0.0f;
|
||||||
|
|
@ -206,12 +209,12 @@ void PhysicsSolver::calcCollisions(
|
||||||
boxAABB.scale(glm::vec3(1.0f - E * 4, 1.0f + E * 2, 1.0f - E * 4));
|
boxAABB.scale(glm::vec3(1.0f - E * 4, 1.0f + E * 2, 1.0f - E * 4));
|
||||||
boxAABB = boxAABB.translated(pos);
|
boxAABB = boxAABB.translated(pos);
|
||||||
|
|
||||||
for (int ix = 0; ix <= glm::ceil((half.x-E)*2); ix++) {
|
for (int ix = 0; ix <= glm::ceil((half.x - E) * 2); ix++) {
|
||||||
float x = (pos.x-half.x+E) + ix;
|
float x = (pos.x - half.x + E) + ix;
|
||||||
for (int iz = 0; iz <= glm::ceil((half.z-E)*2); iz++) {
|
for (int iz = 0; iz <= glm::ceil((half.z - E) * 2); iz++) {
|
||||||
float z = (pos.z-half.z+E) + iz;
|
float z = (pos.z - half.z + E) + iz;
|
||||||
float y = (pos.y+half.y+E) + 0.5f;
|
float y = (pos.y + half.y + E) + 0.5f;
|
||||||
if (auto aabb = chunks.isObstacleAt(x,y,z, boxAABB)){
|
if (auto aabb = chunks.isObstacleAt(x, y, z, boxAABB)) {
|
||||||
float newy = std::floor(y) - half.y + aabb->min().y - E;
|
float newy = std::floor(y) - half.y + aabb->min().y - E;
|
||||||
if (pos.y >= newy) {
|
if (pos.y >= newy) {
|
||||||
vel.y = 0.0f;
|
vel.y = 0.0f;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue