polyadvent

A game engine from scratch in C
git clone git://jb55.com/polyadvent
Log | Files | Refs | README

commit 7de176b813b1554f9b2fc9c25cb7142576ddd312
parent 2802876294861f24db52913828c43f2d515bedc1
Author: William Casarin <jb55@jb55.com>
Date:   Sun, 29 Apr 2018 21:12:36 -0700

cool

Diffstat:
Msrc/camera.c | 8++++----
Msrc/node.c | 14+++++++++++++-
Msrc/render.c | 2+-
Msrc/update.c | 19+++++++++----------
4 files changed, 27 insertions(+), 16 deletions(-)

diff --git a/src/camera.c b/src/camera.c @@ -15,11 +15,11 @@ camera_follow(vec3 *cam_pos, vec3 *target_prev, vec3 *target, mat4 *cam) { cam_pos[0] = target[0]; cam_pos[1] = target[1] - 20; cam_pos[2] = target[2] + 20; - printf("cam %f %f %f looking at player %f %f %f\n", - cam_pos[0], cam_pos[1], cam_pos[2], - target[0], target[1], target[2]); + /* printf("cam %f %f %f looking at player %f %f %f\n", */ + /* cam_pos[0], cam_pos[1], cam_pos[2], */ + /* target[0], target[1], target[2]); */ - look_at(cam_pos, target, V3(0,1,0), cam); + /* look_at(cam_pos, target, V3(0,1,0), cam); */ /* cam_pos[0] = -target[0]; */ /* cam_pos[1] = -target[1]; */ /* cam_pos[2] = target[2]; */ diff --git a/src/node.c b/src/node.c @@ -38,6 +38,8 @@ int node_recalc(struct node *node) { if (node->scale[0] != 1 || node->scale[1] != 1 || node->scale[2] != 1) mat4_scale(node->mat, node->scale, node->mat); + float m = node->mirrored ? -1 : 1; + // FIXME: this seems bad? for (int i = 0; i < 3; ++i) { if (node->rot[i] != 0) { @@ -45,15 +47,25 @@ int node_recalc(struct node *node) { rotate_axis[1] = 0; rotate_axis[2] = 0; rotate_axis[i] = 1; + float x = node->pos[0]; + float y = node->pos[1]; + float z = node->pos[2]; + if (!node->mirrored) + mat4_translate(node->mat, V3(x, y, z), node->mat); mat4_rotate(node->mat, node->rot[i], rotate_axis, node->mat); + if (!node->mirrored) + mat4_translate(node->mat, V3(-x, -y, -z), node->mat); } } - float m = node->mirrored ? -1 : 1; if (node->pos[0] || node->pos[1] || node->pos[2]) mat4_translate(node->mat, V3(node->pos[0]*m,node->pos[1]*m,node->pos[2]*m), node->mat); + + /* if (node->pos[0] || node->pos[1] || node->pos[2]) */ + /* mat4_translate(node->mat, node->pos, node->mat); */ + return 1; } diff --git a/src/render.c b/src/render.c @@ -197,7 +197,7 @@ static void render_geom (struct resources *res, void render (struct game *game, struct geometry *geom) { - glClearColor( 1.0f, 1.0f, 1.0f, 1.0f ); //clear background screen to black + glClearColor( 0.5294f, 0.8078f, 0.9216f, 1.0f ); //clear background screen to black glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); check_gl(); diff --git a/src/update.c b/src/update.c @@ -33,19 +33,17 @@ void movement(struct game *game, struct node *node) { if (game->input.keystates[SDL_SCANCODE_S]) node_translate(node, V3(0,-amt,0)); - /* if (obj == game->test_resources.camera) { */ - /* if (game->input.keystates[SDL_SCANCODE_UP]) */ - /* mat4_rotate(obj, amt*0.1, (float[]){1,0,0}, obj); */ + if (game->input.keystates[SDL_SCANCODE_UP]) + node->rot[0] += amt * 0.01; - /* if (game->input.keystates[SDL_SCANCODE_RIGHT]) */ - /* mat4_rotate(obj, amt*0.1, (float[]){0,1,0}, obj); */ + if (game->input.keystates[SDL_SCANCODE_RIGHT]) + node->rot[2] -= amt * 0.01; - /* if (game->input.keystates[SDL_SCANCODE_LEFT]) */ - /* mat4_rotate(obj, -(amt*0.1), (float[]){0,1,0}, obj); */ + if (game->input.keystates[SDL_SCANCODE_LEFT]) + node->rot[2] += amt * 0.01; - /* if (game->input.keystates[SDL_SCANCODE_DOWN]) */ - /* mat4_rotate(obj, -(amt*0.1), (float[]){1,0,0}, obj); */ - /* } */ + if (game->input.keystates[SDL_SCANCODE_DOWN]) + node->rot[0] -= amt * 0.01; /* if (game->input.keystates[SDL_SCANCODE_P]) */ /* mat4_print(obj); */ @@ -88,6 +86,7 @@ void update (struct game *game, u32 dt) { PLAYER_HEIGHT; res->player.needs_recalc = 1; + node_recalc(&res->camera); camera_follow(res->camera.pos, res->player.pos, res->player.pos, res->camera.mat); res->camera.needs_recalc = 1; /* movement(game, res->camera); */