Exposed ceilings fix
This commit is contained in:
1 parent
ad1702ecc8
commit
a716bee896
5 files changed
+50
-73
No files matched your search
@@ -226,25 +226,21 @@ s32 find_wall_collisions(struct WallCollisionData *colData) {
|
||||
static struct Surface *find_ceil_from_list(struct SurfaceNode *surfaceNode, s32 x, s32 y, s32 z, f32 *pheight) {
|
||||
register struct Surface *surf;
|
||||
register s32 x1, z1, x2, z2, x3, z3;
|
||||
f32 nx, ny, nz, oo, height;
|
||||
struct Surface *ceil = NULL;
|
||||
|
||||
ceil = NULL;
|
||||
|
||||
*pheight = CELL_HEIGHT_LIMIT;
|
||||
// Stay in this loop until out of ceilings.
|
||||
while (surfaceNode != NULL) {
|
||||
surf = surfaceNode->surface;
|
||||
surfaceNode = surfaceNode->next;
|
||||
|
||||
x1 = surf->vertex1[0];
|
||||
z1 = surf->vertex1[2];
|
||||
z2 = surf->vertex2[2];
|
||||
x2 = surf->vertex2[0];
|
||||
|
||||
// Checking if point is in bounds of the triangle laterally.
|
||||
if ((z1 - z) * (x2 - x1) - (x1 - x) * (z2 - z1) > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Slight optimization by checking these later.
|
||||
x3 = surf->vertex3[0];
|
||||
z3 = surf->vertex3[2];
|
||||
@@ -254,49 +250,42 @@ static struct Surface *find_ceil_from_list(struct SurfaceNode *surfaceNode, s32
|
||||
if ((z3 - z) * (x1 - x3) - (x3 - x) * (z1 - z3) > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Determine if checking for the camera or not.
|
||||
if (gCheckingSurfaceCollisionsForCamera != 0) {
|
||||
if (surf->flags & SURFACE_FLAG_NO_CAM_COLLISION || surf->type == SURFACE_NEW_WATER || surf->type == SURFACE_NEW_WATER_BOTTOM) {
|
||||
if (surf->flags & SURFACE_FLAG_NO_CAM_COLLISION) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Ignore camera only surfaces.
|
||||
else if (surf->type == SURFACE_CAMERA_BOUNDARY || surf->type == SURFACE_NEW_WATER || surf->type == SURFACE_NEW_WATER_BOTTOM) {
|
||||
else if (surf->type == SURFACE_CAMERA_BOUNDARY) {
|
||||
continue;
|
||||
}
|
||||
|
||||
{
|
||||
f32 nx = surf->normal.x;
|
||||
f32 ny = surf->normal.y;
|
||||
f32 nz = surf->normal.z;
|
||||
f32 oo = surf->originOffset;
|
||||
f32 height;
|
||||
|
||||
// If a wall, ignore it. Likely a remnant, should never occur.
|
||||
if (ny == 0.0f) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Find the ceil height at the specific point.
|
||||
height = -(x * nx + nz * z + oo) / ny;
|
||||
|
||||
// Checks for ceiling interaction with a 78 unit buffer.
|
||||
//! (Exposed Ceilings) Because any point above a ceiling counts
|
||||
// as interacting with a ceiling, ceilings far below can cause
|
||||
// "invisible walls" that are really just exposed ceilings.
|
||||
if (y - (height - -78.0f) > 0.0f) {
|
||||
continue;
|
||||
}
|
||||
|
||||
*pheight = height;
|
||||
ceil = surf;
|
||||
break;
|
||||
}
|
||||
nx = surf->normal.x;
|
||||
ny = surf->normal.y;
|
||||
nz = surf->normal.z;
|
||||
oo = surf->originOffset;
|
||||
// If a wall, ignore it. Likely a remnant, should never occur.
|
||||
if (ny == 0.0f) {
|
||||
continue;
|
||||
}
|
||||
// Find the ceil height at the specific point.
|
||||
height = -(x * nx + nz * z + oo) / ny;
|
||||
if (height > *pheight) {
|
||||
continue;
|
||||
}
|
||||
// Checks for ceiling interaction
|
||||
if (y > height) {
|
||||
continue;
|
||||
}
|
||||
if (y >= surf->upperY) {
|
||||
continue;
|
||||
}
|
||||
*pheight = height;
|
||||
ceil = surf;
|
||||
if (height == y) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//! (Surface Cucking) Since only the first ceil is returned and not the lowest,
|
||||
// lower ceilings can be "cucked" by higher ceilings.
|
||||
return ceil;
|
||||
}
|
||||
|
||||
@@ -397,43 +386,35 @@ f32 find_floor_height_and_data(f32 xPos, f32 yPos, f32 zPos, struct FloorGeometr
|
||||
* Iterate through the list of floors and find the first floor under a given point.
|
||||
*/
|
||||
static struct Surface *find_floor_from_list(struct SurfaceNode *surfaceNode, s32 x, s32 y, s32 z, f32 *pheight) {
|
||||
f32 slopeFix = -9999999999999999.0f;
|
||||
register struct Surface *surf;
|
||||
register s32 x1, z1, x2, z2, x3, z3;
|
||||
f32 nx, ny, nz;
|
||||
f32 oo;
|
||||
f32 height;
|
||||
f32 nx, ny, nz, oo, height;
|
||||
struct Surface *floor = NULL;
|
||||
|
||||
*pheight = FLOOR_LOWER_LIMIT;
|
||||
// Iterate through the list of floors until there are no more floors.
|
||||
while (surfaceNode != NULL) {
|
||||
surf = surfaceNode->surface;
|
||||
surfaceNode = surfaceNode->next;
|
||||
|
||||
x1 = surf->vertex1[0];
|
||||
z1 = surf->vertex1[2];
|
||||
x2 = surf->vertex2[0];
|
||||
z2 = surf->vertex2[2];
|
||||
|
||||
// Check that the point is within the triangle bounds.
|
||||
if ((z1 - z) * (x2 - x1) - (x1 - x) * (z2 - z1) < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// To slightly save on computation time, set this later.
|
||||
x3 = surf->vertex3[0];
|
||||
z3 = surf->vertex3[2];
|
||||
|
||||
if ((z2 - z) * (x3 - x2) - (x2 - x) * (z3 - z2) < 0) {
|
||||
continue;
|
||||
}
|
||||
if ((z3 - z) * (x1 - x3) - (x3 - x) * (z1 - z3) < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Determine if we are checking for the camera or not.
|
||||
if (gCheckingSurfaceCollisionsForCamera != 0) {
|
||||
if (surf->flags & SURFACE_FLAG_NO_CAM_COLLISION || surf->type == SURFACE_NEW_WATER || surf->type == SURFACE_NEW_WATER_BOTTOM) {
|
||||
if (surf->flags & SURFACE_FLAG_NO_CAM_COLLISION) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -441,37 +422,33 @@ static struct Surface *find_floor_from_list(struct SurfaceNode *surfaceNode, s32
|
||||
else if (surf->type == SURFACE_CAMERA_BOUNDARY) {
|
||||
continue;
|
||||
}
|
||||
|
||||
nx = surf->normal.x;
|
||||
ny = surf->normal.y;
|
||||
nz = surf->normal.z;
|
||||
oo = surf->originOffset;
|
||||
|
||||
// If a wall, ignore it. Likely a remnant, should never occur.
|
||||
if (ny == 0.0f) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// If a wall, ignore it. Likely a remnant, should never occur.
|
||||
if (ny == 0.0f) {
|
||||
continue;
|
||||
}
|
||||
// Find the height of the floor at a given location.
|
||||
height = -(x * nx + nz * z + oo) / ny;
|
||||
if (height < *pheight) {
|
||||
continue;
|
||||
}
|
||||
// Checks for floor interaction with a 78 unit buffer.
|
||||
if (height < slopeFix) {
|
||||
if (y < (height - 78.0f)) {
|
||||
continue;
|
||||
}
|
||||
if (y - (height + -78.0f) < 0.0f) {
|
||||
continue;
|
||||
}
|
||||
|
||||
*pheight = height;
|
||||
floor = surf;
|
||||
slopeFix = height;
|
||||
if (height - 78.0f == y) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//! (Surface Cucking) Since only the first floor is returned and not the highest,
|
||||
// higher floors can be "cucked" by lower floors.
|
||||
return floor;
|
||||
}
|
||||
|
||||
|
||||
static s16 check_within_triangle_bounds(s32 x, s32 z, struct Surface *surf) {
|
||||
register s32 x1, z1, x2, z2, x3, z3;
|
||||
x1 = surf->vertex1[0];
|
||||
|
||||
+2
-2
@@ -547,7 +547,7 @@ struct Surface *resolve_and_return_wall_collisions(Vec3f pos, f32 offset, f32 ra
|
||||
f32 vec3f_find_ceil(Vec3f pos, f32 height, struct Surface **ceil) {
|
||||
UNUSED f32 unused;
|
||||
|
||||
return find_ceil(pos[0], height + 80.0f, pos[2], ceil);
|
||||
return find_ceil(pos[0], height + 3.0f, pos[2], ceil);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1348,7 +1348,7 @@ void update_mario_geometry_inputs(struct MarioState *m) {
|
||||
m->floorHeight = find_floor(m->pos[0], m->pos[1], m->pos[2], &m->floor);
|
||||
}
|
||||
|
||||
m->ceilHeight = vec3f_find_ceil(&m->pos[0], m->floorHeight, &m->ceil);
|
||||
m->ceilHeight = vec3f_find_ceil(m->pos, m->pos[1], &m->ceil);
|
||||
gasLevel = find_poison_gas_level(m->pos[0], m->pos[2]);
|
||||
m->waterLevel = find_water_level(m->pos[0], m->pos[2]);
|
||||
|
||||
|
||||
@@ -308,7 +308,7 @@ s32 perform_hanging_step(struct MarioState *m, Vec3f nextPos) {
|
||||
|
||||
m->wall = resolve_and_return_wall_collisions(nextPos, 50.0f, 50.0f);
|
||||
floorHeight = find_floor(nextPos[0], nextPos[1], nextPos[2], &floor);
|
||||
ceilHeight = vec3f_find_ceil(nextPos, floorHeight, &ceil);
|
||||
ceilHeight = vec3f_find_ceil(nextPos, nextPos[1], &ceil);
|
||||
|
||||
if (floor == NULL) {
|
||||
return HANG_HIT_CEIL_OR_OOB;
|
||||
|
||||
@@ -76,7 +76,7 @@ static u32 perform_water_full_step(struct MarioState *m, Vec3f nextPos) {
|
||||
|
||||
wall = resolve_and_return_wall_collisions(nextPos, 10.0f, 110.0f);
|
||||
floorHeight = find_floor(nextPos[0], nextPos[1], nextPos[2], &floor);
|
||||
ceilHeight = vec3f_find_ceil(nextPos, floorHeight, &ceil);
|
||||
ceilHeight = vec3f_find_ceil(nextPos, nextPos[1], &ceil);
|
||||
|
||||
if (floor == NULL) {
|
||||
return WATER_STEP_CANCELLED;
|
||||
|
||||
@@ -268,7 +268,7 @@ static s32 perform_ground_quarter_step(struct MarioState *m, Vec3f nextPos) {
|
||||
upperWall = resolve_and_return_wall_collisions(nextPos, 60.0f, 50.0f);
|
||||
|
||||
floorHeight = find_floor(nextPos[0], nextPos[1], nextPos[2], &floor);
|
||||
ceilHeight = vec3f_find_ceil(nextPos, floorHeight, &ceil);
|
||||
ceilHeight = vec3f_find_ceil(nextPos, nextPos[1], &ceil);
|
||||
|
||||
waterLevel = find_water_level(nextPos[0], nextPos[2]);
|
||||
|
||||
@@ -402,7 +402,7 @@ s32 perform_air_quarter_step(struct MarioState *m, Vec3f intendedPos, u32 stepAr
|
||||
lowerWall = resolve_and_return_wall_collisions(nextPos, 30.0f, 50.0f);
|
||||
|
||||
floorHeight = find_floor(nextPos[0], nextPos[1], nextPos[2], &floor);
|
||||
ceilHeight = vec3f_find_ceil(nextPos, floorHeight, &ceil);
|
||||
ceilHeight = vec3f_find_ceil(nextPos, nextPos[1], &ceil);
|
||||
|
||||
waterLevel = find_water_level(nextPos[0], nextPos[2]);
|
||||
|
||||
|
||||
Reference in new issue
Block a user