From b66b42d8b2b23ff5e2444362bce331be3f32d017 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Mon, 17 Jan 2022 15:03:57 +0100 Subject: [PATCH] Fix trees --- src/server/trees.c | 3 +-- src/server/voxelctx.c | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/server/trees.c b/src/server/trees.c index ab3ddae..5d4fa5e 100644 --- a/src/server/trees.c +++ b/src/server/trees.c @@ -71,8 +71,7 @@ static void oak_tree_part(Voxelctx *ctx, f32 n) voxelctx_s(ctx, 4.0f); voxelctx_x(ctx, 0.1f); voxelctx_light(ctx, voxelctx_random(ctx, 0.0f, 0.1f)); - // voxelctx_cylinder(ctx, NODE_OAK_WOOD, true); - voxelctx_cube(ctx, NODE_OAK_WOOD, true); + voxelctx_cylinder(ctx, NODE_OAK_WOOD, true); voxelctx_pop(ctx); if (i == (int) (n - 2.0f)) { diff --git a/src/server/voxelctx.c b/src/server/voxelctx.c index ef854a6..5aba2d7 100644 --- a/src/server/voxelctx.c +++ b/src/server/voxelctx.c @@ -18,7 +18,7 @@ static VoxelctxState *create_state(VoxelctxState *old) state->pos[0] = 0.0f; state->pos[1] = 0.0f; state->pos[2] = 0.0f; - state->pos[3] = 1.0f; + state->pos[3] = 0.0f; state->scale[0] = 1.0f; state->scale[1] = 1.0f; state->scale[2] = 1.0f; @@ -102,13 +102,12 @@ void voxelctx_x(Voxelctx *ctx, f32 value) apply_translation(ctx, (v3f32) {value, 0.0f, 0.0f}); } -// swap y and z -void voxelctx_z(Voxelctx *ctx, f32 value) +void voxelctx_y(Voxelctx *ctx, f32 value) { apply_translation(ctx, (v3f32) {0.0f, value, 0.0f}); } -void voxelctx_y(Voxelctx *ctx, f32 value) +void voxelctx_z(Voxelctx *ctx, f32 value) { apply_translation(ctx, (v3f32) {0.0f, 0.0f, value}); } @@ -118,13 +117,12 @@ void voxelctx_rx(Voxelctx *ctx, f32 value) mat4x4_rotate_X(VOXELCTXSTATE(ctx).mat, VOXELCTXSTATE(ctx).mat, value * M_PI / 180.0f); } -// swap y and z -void voxelctx_rz(Voxelctx *ctx, f32 value) +void voxelctx_ry(Voxelctx *ctx, f32 value) { mat4x4_rotate_Y(VOXELCTXSTATE(ctx).mat, VOXELCTXSTATE(ctx).mat, value * M_PI / 180.0f); } -void voxelctx_ry(Voxelctx *ctx, f32 value) +void voxelctx_rz(Voxelctx *ctx, f32 value) { mat4x4_rotate_Z(VOXELCTXSTATE(ctx).mat, VOXELCTXSTATE(ctx).mat, value * M_PI / 180.0f); } @@ -143,13 +141,12 @@ void voxelctx_sx(Voxelctx *ctx, f32 value) apply_scale(ctx, (v3f32) {value, 1.0f, 1.0f}); } -// swap y and z -void voxelctx_sz(Voxelctx *ctx, f32 value) +void voxelctx_sy(Voxelctx *ctx, f32 value) { apply_scale(ctx, (v3f32) {1.0f, value, 1.0f}); } -void voxelctx_sy(Voxelctx *ctx, f32 value) +void voxelctx_sz(Voxelctx *ctx, f32 value) { apply_scale(ctx, (v3f32) {1.0f, 1.0f, value}); } @@ -230,15 +227,21 @@ void voxelctx_cube(Voxelctx *ctx, Node node, bool use_color) s32 v[3]; for (int i = 0; i < 3; i++) - v[i] = floor(VOXELCTXSTATE(ctx).pos[0] + 0.5f + v[i] = floor(VOXELCTXSTATE(ctx).pos[i] + mix(corners[0][i], corners[4][i], (f32) x / (f32) max_len / 2.0f) + mix(corners[0][i], corners[2][i], (f32) y / (f32) max_len / 2.0f) + mix(corners[0][i], corners[1][i], (f32) z / (f32) max_len / 2.0f)); - mapgen_set_node(v3s32_add(ctx->pos, (v3s32) {v[0], v[1], v[2]}), CREATE_NODE, ctx->mgs, ctx->changed_blocks); + mapgen_set_node(v3s32_add(ctx->pos, (v3s32) {v[0], v[2], v[1]}), CREATE_NODE, ctx->mgs, ctx->changed_blocks); } } + +void voxelctx_cylinder(Voxelctx *ctx, Node node, bool use_color) +{ + voxelctx_cube(ctx, node, use_color); +} + /* void voxelctx_cylinder(Voxelctx *ctx, Node node, bool use_color) { -- 2.44.0