65 lines
1.7 KiB
C
65 lines
1.7 KiB
C
#define LREF_H_IMPLEMENTATION
|
|
#include "lref.h"
|
|
#include "track_wrapper/track_wrapper.h"
|
|
|
|
#include <raylib.h>
|
|
|
|
int main(int argc, char** argv) {
|
|
if (argc < 3) return EXIT_FAILURE;
|
|
uint32_t index = atoi(argv[1]);
|
|
struct simulation sim = simulation_new();
|
|
load_sol_track(&sim, argv[2], index);
|
|
bool playing = false;
|
|
|
|
const int screenWidth = 800;
|
|
const int screenHeight = 450;
|
|
|
|
InitWindow(screenWidth, screenHeight, "lref test frontend");
|
|
|
|
Camera2D camera = { 0 };
|
|
camera.offset = (Vector2){screenWidth/2.0f, screenHeight/2.0f};
|
|
camera.rotation = 0.0f;
|
|
camera.zoom = 4.0f;
|
|
|
|
SetTargetFPS(40);
|
|
|
|
while (!WindowShouldClose()) {
|
|
Vector2 camera_target = {0};
|
|
for (int i = 0; i < POINT_COUNT; i++) {
|
|
camera_target.x += sim.bosh.points[i].x;
|
|
camera_target.y += sim.bosh.points[i].y;
|
|
}
|
|
camera_target.x /= POINT_COUNT;
|
|
camera_target.y /= POINT_COUNT;
|
|
camera.target = camera_target;
|
|
if (IsKeyPressed(KEY_SPACE)) {
|
|
playing = !playing;
|
|
}
|
|
BeginDrawing();
|
|
ClearBackground(WHITE);
|
|
BeginMode2D(camera);
|
|
{// draw bosh
|
|
for (int i = 0; i < BONE_COUNT; i++) {
|
|
struct bone bone = sim.bosh.bones[i];
|
|
struct point A = sim.bosh.points[bone.a];
|
|
struct point B = sim.bosh.points[bone.b];
|
|
DrawLineV((Vector2){A.x, A.y}, (Vector2){B.x, B.y}, BLACK);
|
|
}
|
|
}
|
|
{// draw lines
|
|
for (size_t i = 0; i < sim.line_count; i++) {
|
|
struct line line = sim.lines[i];
|
|
DrawLineV((Vector2){line.x1, line.y1}, (Vector2){line.x2, line.y2}, BLACK);
|
|
}
|
|
}
|
|
EndMode2D();
|
|
EndDrawing();
|
|
|
|
if (playing || IsKeyPressed(KEY_RIGHT)) simulation_step_frame(&sim);
|
|
}
|
|
|
|
CloseWindow();
|
|
|
|
return 0;
|
|
}
|