/apps/demos/scenery: fix world origin relation
This commit is contained in:
parent
119bd52c51
commit
55829a1bef
@ -214,8 +214,8 @@ static void process_fly_mode(State *state) {
|
||||
|
||||
/* TODO: could be baked in map format */
|
||||
static Vec3 normal_at(SceneIngame *scn, Vec2 position) {
|
||||
int const x = (int)(roundf(HALF_TERRAIN_DISTANCE + (position.x - scn->pos.x)));
|
||||
int const y = (int)(roundf(HALF_TERRAIN_DISTANCE + (position.y - scn->pos.z)));
|
||||
int const x = (int)(floorf(position.x - scn->world_center.x));
|
||||
int const y = (int)(floorf(position.y - scn->world_center.y));
|
||||
|
||||
float const height0 = heightmap[x][y];
|
||||
float const height1 = heightmap[x + 1][y];
|
||||
@ -229,8 +229,8 @@ static Vec3 normal_at(SceneIngame *scn, Vec2 position) {
|
||||
|
||||
/* TODO: don't operate on triangles, instead interpolate on quads */
|
||||
static float height_at(SceneIngame *scn, Vec2 position) {
|
||||
int const x = (int)(roundf(HALF_TERRAIN_DISTANCE + (position.x - scn->pos.x)));
|
||||
int const y = (int)(roundf(HALF_TERRAIN_DISTANCE + (position.y - scn->pos.z)));
|
||||
int const x = (int)(floorf(position.x - scn->world_center.x));
|
||||
int const y = (int)(floorf(position.y - scn->world_center.y));
|
||||
|
||||
float const height0 = heightmap[x][y];
|
||||
float const height1 = heightmap[x + 1][y];
|
||||
@ -313,6 +313,8 @@ static void generate_terrain(SceneIngame *scn) {
|
||||
heightmap[lx][ly] = height;
|
||||
}
|
||||
}
|
||||
|
||||
scn->world_center = (Vec2){ floorf(scn->pos.x - HALF_TERRAIN_DISTANCE), floorf(scn->pos.z - HALF_TERRAIN_DISTANCE) };
|
||||
}
|
||||
|
||||
|
||||
|
@ -13,6 +13,7 @@ typedef struct SceneIngame {
|
||||
Scene base;
|
||||
|
||||
Vec3 looking_direction;
|
||||
Vec2 world_center;
|
||||
|
||||
Vec3 pos;
|
||||
float yaw;
|
||||
|
Loading…
Reference in New Issue
Block a user