diff --git a/compile_flags.txt b/compile_flags.txt index 009888e..18a844d 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -1,3 +1,4 @@ -Idepends/raylib-cpp/include/ -Idepends/raylib/src/ -Idepends/raygui/src/ +-DRLGL_IMPLEMENTATION diff --git a/src/world.cpp b/src/world.cpp index dd125c0..1caf382 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -742,6 +742,41 @@ static void draw_circle_sector(Vector2 center, float radius, float start_angle, rlEnd(); } +static void draw_boids(World *world, Visuals *visuals) { + int boid_count = world->boids.size(); + + float boid_length = visuals->boid_edge_size * std::sqrt(3)/2; + float boid_width = visuals->boid_edge_size * 0.6; + Color color = visuals->boid_color; + + rlBegin(RL_TRIANGLES); + for (int i = 0; i < boid_count; i++) { + Boid *boid = &world->boids[i]; + + Vector2 triangle[] = { + { boid_length*2/3.0f, 0 }, + { -boid_length*1/3.0f, -boid_width/2 }, + { -boid_length*1/3.0f, boid_width/2 }, + }; + float facing = std::atan2(boid->dir.y, boid->dir.x); + float facing_cos = cos(facing); + float facing_sin = sin(facing); + for (int i = 0; i < 3; i++) { + Vector2 new_pos = boid->pos; + new_pos.x += triangle[i].x * facing_cos - triangle[i].y * facing_sin; + new_pos.y += triangle[i].x * facing_sin + triangle[i].y * facing_cos; + triangle[i] = new_pos; + } + + rlColor4ub(color.r, color.g, color.b, color.a); + rlVertex2f(triangle[0].x, triangle[0].y); + rlVertex2f(triangle[1].x, triangle[1].y); + rlVertex2f(triangle[2].x, triangle[2].y); + } + + rlEnd(); +} + static void world_draw(World *world, Visuals *visuals) { for (int i = 0; i < world->obstacles.size(); i++) { draw_obstacle(&world->obstacles[i], GRAY); @@ -761,32 +796,21 @@ static void world_draw(World *world, Visuals *visuals) { } } - float boid_length = visuals->boid_edge_size * std::sqrt(3)/2; - float boid_width = visuals->boid_edge_size * 0.6; - for (int i = 0; i < world->boids.size(); i++) { + int boid_count = world->boids.size(); + for (int i = 0; i < boid_count; i++) { Boid *boid = &world->boids[i]; - if (visuals->draw_collision_avoidance_rays) { draw_obstacle_avoidance_rays(visuals, world, boid); } - if (visuals->draw_separation_radius) { DrawCircleLines(boid->pos.x, boid->pos.y, world->separation_radius, MAGENTA); } + } - Vector2 triangle[] = { - { boid_length*2/3.0f, 0 }, - { -boid_length*1/3.0f, -boid_width/2 }, - { -boid_length*1/3.0f, boid_width/2 }, - }; - - float facing = std::atan2(boid->dir.y, boid->dir.x); - for (int i = 0; i < 3; i++) { - triangle[i] = Vector2Add(boid->pos, Vector2Rotate(triangle[i], facing)); - } - - DrawTriangle(triangle[0], triangle[1], triangle[2], visuals->boid_color); + draw_boids(world, visuals); + for (int i = 0; i < boid_count; i++) { + Boid *boid = &world->boids[i]; if (visuals->draw_boid_direction) { DrawCircle(boid->pos.x, boid->pos.y, visuals->boid_edge_size * 0.05, RED); Vector2 look_pos = Vector2Add(boid->pos, vector2_mul_value(boid->dir, visuals->boid_edge_size*1.5));