physics and rendering fixes
This commit is contained in:
@@ -224,16 +224,91 @@ static void test_physicsWorldStepMultiColumnFootprint(void **state) {
|
||||
assert_int_equal(memoryGetAllocatedCount(), 0);
|
||||
}
|
||||
|
||||
static void test_physicsWorldStepRampTreatedAsFlatGround(void **state) {
|
||||
static void test_physicsWorldStepClimbsRampGoingUp(void **state) {
|
||||
testMapReset();
|
||||
testMapSetTile(0, 0, 0, TILE_SHAPE_GROUND);
|
||||
testMapSetTile(1, 0, 0, TILE_SHAPE_RAMP_EAST);
|
||||
for(worldunit_t x = 2; x < 6; x++) {
|
||||
testMapSetTile(x, 0, 1, TILE_SHAPE_GROUND);
|
||||
}
|
||||
|
||||
physicsworld_t world;
|
||||
physicsWorldInit(&world, 20.0f, 40.0f);
|
||||
|
||||
physicsbody_t body;
|
||||
const vec3 position = { 0.0f, 0.0f, 0.0f };
|
||||
const vec3 extents = { 1.0f, 1.0f, 1.0f };
|
||||
physicsBodyInit(&body, position, extents);
|
||||
body.velocity[0] = 1.0f;
|
||||
|
||||
for(uint32_t i = 0; i < 400; i++) {
|
||||
physicsWorldStep(&world, &body, DUSK_TIME_STEP, NULL, 0);
|
||||
|
||||
// Ground height is driven by the body's center (not its corner
|
||||
// position), so a 1-wide body barely touching a taller neighbouring
|
||||
// column isn't yanked onto that column's full height - see
|
||||
// physicsWorldResolveAxisZ. While the center is over the ramp tile,
|
||||
// height should track how far across it smoothly, not snap flat.
|
||||
const float_t centerX = body.position[0] + 0.5f;
|
||||
if(centerX >= 1.0f && centerX < 2.0f) {
|
||||
const float_t expected = centerX - 1.0f;
|
||||
assert_float_equal(body.position[2], expected, 0.005f);
|
||||
}
|
||||
}
|
||||
|
||||
// Fully across, resting on the elevated ground one layer up.
|
||||
assert_float_equal(body.position[0], 5.0f, 0.001f);
|
||||
assert_float_equal(body.position[2], 1.0f, 0.005f);
|
||||
assert_true(body.grounded);
|
||||
|
||||
assert_int_equal(memoryGetAllocatedCount(), 0);
|
||||
}
|
||||
|
||||
static void test_physicsWorldStepDescendsRampGoingDown(void **state) {
|
||||
testMapReset();
|
||||
testMapSetTile(0, 0, 1, TILE_SHAPE_GROUND);
|
||||
testMapSetTile(1, 0, 0, TILE_SHAPE_RAMP_WEST);
|
||||
for(worldunit_t x = 2; x < 6; x++) {
|
||||
testMapSetTile(x, 0, 0, TILE_SHAPE_GROUND);
|
||||
}
|
||||
|
||||
physicsworld_t world;
|
||||
physicsWorldInit(&world, 0.0f, 40.0f);
|
||||
physicsWorldInit(&world, 20.0f, 40.0f);
|
||||
|
||||
physicsbody_t body;
|
||||
const vec3 position = { 0.0f, 0.0f, 1.0f };
|
||||
const vec3 extents = { 1.0f, 1.0f, 1.0f };
|
||||
physicsBodyInit(&body, position, extents);
|
||||
body.velocity[0] = 1.0f;
|
||||
|
||||
for(uint32_t i = 0; i < 400; i++) {
|
||||
physicsWorldStep(&world, &body, DUSK_TIME_STEP, NULL, 0);
|
||||
|
||||
// Never falls through as a hole while crossing the ramp - descent
|
||||
// may lag slightly behind the ideal slope (gravity closes the gap
|
||||
// each step, see physicsWorldStep's documented limitation) but must
|
||||
// stay close to it, never dropping toward the void below.
|
||||
assert_true(body.position[2] >= -0.2f);
|
||||
}
|
||||
|
||||
// Fully across, resting on the lower ground.
|
||||
assert_float_equal(body.position[0], 5.0f, 0.001f);
|
||||
assert_float_equal(body.position[2], 0.0f, 0.005f);
|
||||
assert_true(body.grounded);
|
||||
|
||||
assert_int_equal(memoryGetAllocatedCount(), 0);
|
||||
}
|
||||
|
||||
static void test_physicsWorldStepFlatGroundUnaffectedByRampLogic(
|
||||
void **state
|
||||
) {
|
||||
testMapReset();
|
||||
for(worldunit_t x = 0; x < 6; x++) {
|
||||
testMapSetTile(x, 0, 0, TILE_SHAPE_GROUND);
|
||||
}
|
||||
|
||||
physicsworld_t world;
|
||||
physicsWorldInit(&world, 20.0f, 40.0f);
|
||||
|
||||
physicsbody_t body;
|
||||
const vec3 position = { 0.0f, 0.0f, 0.0f };
|
||||
@@ -246,7 +321,6 @@ static void test_physicsWorldStepRampTreatedAsFlatGround(void **state) {
|
||||
assert_float_equal(body.position[2], 0.0f, 0.0001f);
|
||||
}
|
||||
|
||||
assert_float_equal(body.velocity[0], 5.0f, 0.0001f);
|
||||
assert_true(body.position[0] > 1.5f);
|
||||
|
||||
assert_int_equal(memoryGetAllocatedCount(), 0);
|
||||
@@ -346,7 +420,9 @@ int main(void) {
|
||||
cmocka_unit_test(test_physicsWorldStepTerminalVelocityClamp),
|
||||
cmocka_unit_test(test_physicsWorldStepBlockedByCeiling),
|
||||
cmocka_unit_test(test_physicsWorldStepMultiColumnFootprint),
|
||||
cmocka_unit_test(test_physicsWorldStepRampTreatedAsFlatGround),
|
||||
cmocka_unit_test(test_physicsWorldStepClimbsRampGoingUp),
|
||||
cmocka_unit_test(test_physicsWorldStepDescendsRampGoingDown),
|
||||
cmocka_unit_test(test_physicsWorldStepFlatGroundUnaffectedByRampLogic),
|
||||
cmocka_unit_test(test_physicsWorldStepBlockedByOtherBody),
|
||||
cmocka_unit_test(test_physicsWorldStepBlockedByNearestOfMultipleBodies),
|
||||
cmocka_unit_test(test_physicsWorldResolveBodyOverlapIgnoresSelfAndNull),
|
||||
|
||||
Reference in New Issue
Block a user