commit d4a6203a98bf458167b3b37454f0cd0dc7b6db29
parent be76dc0d0d5e50bf17b7d244d0eefe131d6ad322
Author: William Casarin <jb55@jb55.com>
Date: Tue, 1 May 2018 08:22:07 -0700
Merge branch 'master' into wip-quat-orientation
Diffstat:
6 files changed, 23 insertions(+), 12 deletions(-)
diff --git a/src/camera.c b/src/camera.c
@@ -17,7 +17,7 @@ camera_follow(vec3 *cam_pos, vec3 *target, mat4 *cam) {
/* 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/main.c b/src/main.c
@@ -45,7 +45,7 @@ int main(void)
game_init(&game);
game.terrain = &terrain;
- const double size = 1000;
+ const double size = 2000;
const double pdist = 1.7;
const double scale = 0.01;
/* printf("samples seed %d\n", seed); */
diff --git a/src/node.c b/src/node.c
@@ -31,6 +31,15 @@ void node_translate(struct node *node, vec3 *p) {
node_mark_for_recalc(node);
}
+void node_rotate(struct node *node, vec3 *p) {
+ if (vec3_isall(p, 0))
+ return;
+
+ /* printf("translating %f %f %f\n", p[0], p[1], p[2]); */
+ vec3_add(node->rot, p, node->rot);
+ node_mark_for_recalc(node);
+}
+
int node_needs_recalc(struct node *node) {
return (node->parent && node->parent->needs_recalc) || node->needs_recalc;
}
diff --git a/src/node.h b/src/node.h
@@ -9,6 +9,7 @@ struct node {
float rot[3];
float scale[3];
float mat[16];
+ float local[16];
float orientation[4];
char *label;
int needs_recalc;
@@ -24,5 +25,6 @@ void node_attach(struct node *node, struct node *to);
void node_mark_for_recalc(struct node *node);
struct node *node_init(struct node *node);
void node_translate(struct node *node, float *p);
+void node_rotate(struct node *node, float *p);
#endif /* POLYADVENT_NODE_H */
diff --git a/src/update.c b/src/update.c
@@ -35,19 +35,19 @@ static void movement(struct game *game, struct node *node) {
// TODO: mark as update
if (game->input.keystates[SDL_SCANCODE_UP])
- node->rot[0] += amt * 0.01;
+ node_rotate(node, V3(amt * 0.01,0,0));
if (game->input.keystates[SDL_SCANCODE_RIGHT])
- node->rot[2] -= amt * 0.01;
+ node_rotate(node, V3(0, 0, -amt * 0.01));
if (game->input.keystates[SDL_SCANCODE_LEFT])
- node->rot[2] += amt * 0.01;
+ node_rotate(node, V3(0, 0, amt * 0.01));
if (game->input.keystates[SDL_SCANCODE_DOWN])
- node->rot[0] -= amt * 0.01;
+ node_rotate(node, V3(-amt * 0.01, 0, 0));
- /* if (game->input.keystates[SDL_SCANCODE_P]) */
- /* mat4_print(obj); */
+ if (game->input.keystates[SDL_SCANCODE_P])
+ mat4_print(node->mat);
}
void update (struct game *game, u32 dt) {
@@ -141,7 +141,7 @@ void update (struct game *game, u32 dt) {
for (int i = 0; i < 2; ++i)
tnode->pos[i] = max(tnode->pos[i], 0);
- last_oz = tnode->pos[2] = max(tnode->pos[2], 20.0);
+ last_oz = tnode->pos[2] = max(tnode->pos[2], 5.0);
double scale = tnode->pos[2] * 0.01;
if (scale == 0) scale = 1.0;
@@ -158,7 +158,7 @@ void update (struct game *game, u32 dt) {
/* ts.o2 = fabs(sin(n*0.02) * 2); */
ts->freq = scale * 0.15;
- ts->amplitude = 1/scale;
+ ts->amplitude = 3/scale;
terrain_destroy(game->terrain);
terrain_init(game->terrain);
@@ -171,7 +171,7 @@ void update (struct game *game, u32 dt) {
/* printf("pdist %f\n", pdist); */
int n_samples =
- (game->terrain->size * game->terrain->size) * scale*scale;
+ (game->terrain->size * game->terrain->size) * scale*scale*scale;
struct point *samples =
uniform_samples(n_samples, game->terrain->size);
diff --git a/src/window.c b/src/window.c
@@ -9,7 +9,7 @@ void
handle_resize(float *camera, int width, int height) {
printf("resizing %d %d\n", width, height);
glViewport( 0, 0, width, height );
- mat4_perspective(90 /* fov */, (float)width / height, 1, 1000, camera);
+ mat4_perspective(90 /* fov */, (float)width / height, 1, 2000, camera);
/* glMatrixMode( GL_PROJECTION ); //Switch to setting the camera perspective */
/* Set the camera perspective */