diff options
| author | Aldrik Ramaekers <aldrikboy@gmail.com> | 2024-11-23 21:52:24 +0100 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrikboy@gmail.com> | 2024-11-23 21:52:24 +0100 |
| commit | 6f7374c2fa58c8692b51018864b802e6b876d305 (patch) | |
| tree | a7e8ead757e9f4de1920395336dcac1c8a989576 /src/scenery.c | |
A new start
Diffstat (limited to 'src/scenery.c')
| -rw-r--r-- | src/scenery.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/scenery.c b/src/scenery.c new file mode 100644 index 0000000..9e647d6 --- /dev/null +++ b/src/scenery.c @@ -0,0 +1,53 @@ +
+
+static void update_render_path(world* world, boat_route *route)
+{
+ boat_route_point prev_point = route->points[route->current_point];
+ boat_route_point next_point = route->points[route->current_point + (route->reversed ? -1 : 1)];
+
+ float dist = sqrt(pow(prev_point.x - next_point.x, 2) + pow(prev_point.y - next_point.y, 2));
+ float time_between_points = (dist*1000000.0f);
+
+ float percentage = route->current_point_duration/time_between_points;
+
+ vec2f start_pos = {area.x + (prev_point.x*area.w), area.y + (prev_point.y*area.h)};
+ vec2f end_pos = {area.x + (next_point.x*area.w), area.y + (next_point.y*area.h)};
+
+ float currx = start_pos.x - (start_pos.x - end_pos.x)*percentage;
+ float curry = start_pos.y - (start_pos.y - end_pos.y)*percentage;
+
+ vec2f map_pos = {currx*zoom+camera_x, curry*zoom+camera_y};
+
+ float rad = atan2(end_pos.y-start_pos.y, end_pos.x-start_pos.x);
+
+ gl_render_set_rotation(-rad);
+ renderer->render_image(img_boat, map_pos.x-3, map_pos.y-3, 6, 6);
+ gl_render_set_rotation(0.0f);
+
+ route->current_point_duration += (frame_delta*1000.0f)*world->simulation_speed;
+ if (route->current_point_duration > time_between_points) {
+ if (!route->reversed) route->current_point++;
+ else route->current_point--;
+ route->current_point_duration = 0;
+ }
+ if (!route->reversed && route->current_point >= route->count-1) route->reversed = true;
+ if (route->reversed && route->current_point <= 0) route->reversed = false;
+}
+
+void update_render_scenery(world* world) {
+
+ renderer->render_set_scissor(main_window, area.x,area.y,area.w,area.h);
+ for (s32 i = 0; i < world->boat_routes.length; i++) {
+ boat_route* route = array_at(&world->boat_routes, i);
+ update_render_path(world, route);
+ }
+ renderer->render_reset_scissor();
+
+
+#if 0
+ static s32 count = 0;
+ if (is_left_down() && count++ % 10 == 0) {
+ printf("%f, %f,\n", (_global_mouse.x-area.x)/(float)area.w, (_global_mouse.y-area.y)/(float)area.h);
+ }
+#endif
+}
\ No newline at end of file |
