perlin2d, sample terrain render
This commit is contained in:
@ -11,7 +11,8 @@ static void ingame_tick(struct state *state) {
|
||||
world_drawdef(scn->world);
|
||||
player_calc(scn->player);
|
||||
|
||||
static t_camera cam = { .pos = { 0, 0, 1 }, .target = { 0, 0, -1 }, .up = { 0, 1, 0 }, .fov = (float)M_PI_2 };
|
||||
static t_camera cam = { .pos = { 32, 0, 1 }, .up = { 0, 1, 0 }, .fov = (float)M_PI_2 };
|
||||
cam.target = m_vec_norm(((t_fvec3){ -1, 0, 1 }));
|
||||
|
||||
if (input_is_action_pressed(&ctx.input, "player_left"))
|
||||
cam.pos.x -= 0.01f;
|
||||
@ -42,21 +43,29 @@ static void ingame_tick(struct state *state) {
|
||||
|
||||
set_camera(&cam);
|
||||
|
||||
unfurl_triangle("/assets/big-violet.png",
|
||||
(t_fvec3){ -1, -1, 0 },
|
||||
(t_fvec3){ 1, -1, 0 },
|
||||
(t_fvec3){ 1, 1, 0 },
|
||||
(t_shvec2){ 0, 2048 },
|
||||
(t_shvec2){ 2048, 2048 },
|
||||
(t_shvec2){ 2048, 0 });
|
||||
for (int y = 64; --y;)
|
||||
for (int x = 64; --x;) {
|
||||
float d0 = sample_perlin_2d((t_fvec2){x, y}, 0.2, 5) * 8 - 6;
|
||||
float d1 = sample_perlin_2d((t_fvec2){x + 1, y}, 0.2, 5) * 8 - 6;
|
||||
float d2 = sample_perlin_2d((t_fvec2){x + 1, y - 1}, 0.2, 5) * 8 - 6;
|
||||
float d3 = sample_perlin_2d((t_fvec2){x, y - 1}, 0.2, 5) * 8 - 6;
|
||||
|
||||
unfurl_triangle("/assets/big-violet.png",
|
||||
(t_fvec3){ 1, 1, 0 },
|
||||
(t_fvec3){ -1, 1, 0 },
|
||||
(t_fvec3){ -1, -1, 0 },
|
||||
(t_shvec2){ 2048, 0 },
|
||||
(t_shvec2){ 0, 0 },
|
||||
(t_shvec2){ 0, 2048 });
|
||||
unfurl_triangle("/assets/grass.gif",
|
||||
(t_fvec3){ x, d0, y },
|
||||
(t_fvec3){ x + 1, d1, y },
|
||||
(t_fvec3){ x, d3, y - 1 },
|
||||
(t_shvec2){ 0, 768 },
|
||||
(t_shvec2){ 1024, 768 },
|
||||
(t_shvec2){ 1024, 0 });
|
||||
|
||||
unfurl_triangle("/assets/grass.gif",
|
||||
(t_fvec3){ x + 1, d1, y },
|
||||
(t_fvec3){ x + 1, d2, y - 1 },
|
||||
(t_fvec3){ x, d3, y - 1 },
|
||||
(t_shvec2){ 1024, 0 },
|
||||
(t_shvec2){ 0, 0 },
|
||||
(t_shvec2){ 0, 768 });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user