Back to floats.

This commit is contained in:
2025-10-10 09:16:08 -05:00
parent c4c43b23ad
commit 349e6e7c94
16 changed files with 164 additions and 220 deletions

View File

@@ -26,54 +26,60 @@ void sceneMapUpdate(scenedata_t *data) {
}
void sceneMapRender(scenedata_t *data) {
// Look at target.
glm_vec3_scale(
RPG_CAMERA.position,
TILE_SIZE,
data->sceneMap.camera.lookat.target
);
// Center within tile
glm_vec3_add(
data->sceneMap.camera.lookat.target,
(vec3){TILE_SIZE / 2.0f, TILE_SIZE / 2.0f, TILE_SIZE / 2.0f },
data->sceneMap.camera.lookat.target
);
// Apply pixel perfect offset and camera offset
const float_t camOffset = 32.0f;
const float_t pixelPerfectOffset = tanf(
data->sceneMap.camera.perspective.fov / 2.0f
) * ((float_t)SCREEN.height / 2.0f);
for(uint8_t i = 0; i < WORLD_DIMENSIONS; i++) {
data->sceneMap.camera.lookat.target[i] = worldPosToF32(
RPG_CAMERA.position[i], TILE_SIZE
);
}
glm_vec3_copy((vec3){
data->sceneMap.camera.lookat.target[0],
data->sceneMap.camera.lookat.target[1] + camOffset,
data->sceneMap.camera.lookat.target[2] + pixelPerfectOffset
}, data->sceneMap.camera.lookat.position);
//
// Push camera
cameraPushMatrix(&data->sceneMap.camera);
// Render ents
entity_t *ent = ENTITIES;
do {
sceneMapRenderEntity(ent);
} while(++ent, ent < &ENTITIES[ENTITY_COUNT]);
spriteBatchFlush();
// Finished, pop back camera.
cameraPopMatrix();
}
void sceneMapRenderEntity(const entity_t *entity) {
void sceneMapRenderEntity(entity_t *entity) {
assertNotNull(entity, "Entity cannot be NULL");
if(entity->type == ENTITY_TYPE_NULL) return;
float_t x = worldPosToF32(entity->position[0], TILE_SIZE);
float_t y = worldPosToF32(entity->position[1], TILE_SIZE);
x -= TILE_SIZE * 0.5f;
y -= TILE_SIZE * 0.5f;
vec3 posMin, posMax;
glm_vec3_scale(entity->position, TILE_SIZE, posMin);
glm_vec3_add(posMin, (vec3){TILE_SIZE, TILE_SIZE, TILE_SIZE }, posMax);
spriteBatchPush(
NULL,
x, y,
x + TILE_SIZE, y + TILE_SIZE,
COLOR_RED,
0.0f, 0.0f,
1.0f, 1.0f
);
vec2 uv0 = { 0.0f, 0.0f };
vec2 uv1 = { 1.0f, 1.0f };
spriteBatchPush3D(NULL, posMin, posMax, COLOR_RED, uv0, uv1);
}
void sceneMapDispose(scenedata_t *data) {

View File

@@ -18,7 +18,7 @@ typedef struct {
errorret_t sceneMapInit(scenedata_t *data);
void sceneMapUpdate(scenedata_t *data);
void sceneMapRender(scenedata_t *data);
void sceneMapRenderEntity(const entity_t *entity);
void sceneMapRenderEntity(entity_t *entity);
void sceneMapDispose(scenedata_t *data);
static scene_t SCENE_MAP = {