This commit is contained in:
2025-11-03 19:50:23 -06:00
parent f3d985ecbc
commit d4a2e059d7
16 changed files with 329 additions and 220 deletions

View File

@@ -40,18 +40,68 @@ void sceneMapUpdate(scenedata_t *data) {
}
void sceneMapGetWorldPosition(const worldpos_t pos, vec3 outPosition) {
assertNotNull(outPosition, "Output position cannot be NULL");
outPosition[0] = pos.x * TILE_SIZE;
outPosition[1] = pos.y * TILE_SIZE;
outPosition[2] = pos.z * TILE_SIZE;
}
void sceneMapEntityGetPosition(const entity_t *entity, vec3 outPosition) {
assertNotNull(entity, "Entity cannot be NULL");
assertNotNull(outPosition, "Output position cannot be NULL");
sceneMapGetWorldPosition(entity->position, outPosition);
// Add animation offset(s)
switch(entity->animation) {
case ENTITY_ANIM_WALK:
float_t animPercentage = (
(float_t)entity->animFrame / (float_t)ENTITY_ANIM_WALK_DURATION
);
// Get facing rel, we know we moved from the inverse direction.
int8_t x, y;
entityDirGetRelative(entity->direction, &x, &y);
x = -x, y = -y;
// Add tile size times percentage to posMin/max
vec3 offset = {
x * TILE_SIZE * animPercentage,
y * TILE_SIZE * animPercentage,
0.0f
};
glm_vec3_add(outPosition, offset, outPosition);
break;
default:
break;
}
}
void sceneMapRender(scenedata_t *data) {
// Look at target.
glm_vec3_scale(
RPG_CAMERA.position,
TILE_SIZE,
data->sceneMap.camera.lookatPixelPerfect.target
);
vec3 cameraTarget;
switch(RPG_CAMERA.mode) {
case RPG_CAMERA_MODE_FREE:
sceneMapGetWorldPosition(RPG_CAMERA.free, cameraTarget);
break;
// Center within tile
glm_vec3_add(
data->sceneMap.camera.lookatPixelPerfect.target,
(vec3){TILE_SIZE / 2.0f, TILE_SIZE / 2.0f, TILE_SIZE / 2.0f },
case RPG_CAMERA_MODE_FOLLOW_ENTITY: {
const entity_t *ent = &ENTITIES[RPG_CAMERA.followEntity.followEntityId];
sceneMapEntityGetPosition(ent, cameraTarget);
break;
}
default:
glm_vec3_zero(cameraTarget);
break;
}
glm_vec3_copy(
cameraTarget,
data->sceneMap.camera.lookatPixelPerfect.target
);
@@ -74,14 +124,36 @@ void sceneMapRenderEntity(entity_t *entity) {
if(entity->type == ENTITY_TYPE_NULL) return;
vec3 posMin, posMax;
glm_vec3_scale(entity->position, TILE_SIZE, posMin);
glm_vec3_add(posMin, (vec3){TILE_SIZE, TILE_SIZE, TILE_SIZE }, posMax);
vec3 posCenter, posMin, posMax;
vec3 halfSize = { TILE_SIZE / 2.0f, TILE_SIZE / 2.0f, TILE_SIZE / 2.0f };
sceneMapEntityGetPosition(entity, posCenter);
glm_vec3_sub(posCenter, halfSize, posMin);
glm_vec3_add(posCenter, halfSize, posMax);
// TEST: Change color depending on dir.
color_t testColor;
switch(entity->direction) {
case ENTITY_DIR_NORTH:
testColor = COLOR_BLUE;
break;
case ENTITY_DIR_EAST:
testColor = COLOR_GREEN;
break;
case ENTITY_DIR_SOUTH:
testColor = COLOR_CYAN;
break;
case ENTITY_DIR_WEST:
testColor = COLOR_YELLOW;
break;
default:
testColor = COLOR_WHITE;
break;
}
vec2 uv0 = { 0.0f, 0.0f };
vec2 uv1 = { 1.0f, 1.0f };
spriteBatchPush3D(NULL, posMin, posMax, COLOR_RED, uv0, uv1);
spriteBatchPush3D(NULL, posMin, posMax, testColor, uv0, uv1);
}
void sceneMapDispose(scenedata_t *data) {