Skip to content

Instantly share code, notes, and snippets.

@ThomasParistech
Created September 27, 2023 22:17
Show Gist options
  • Save ThomasParistech/a2d9b6a710026c4392602c837b1841bf to your computer and use it in GitHub Desktop.
Save ThomasParistech/a2d9b6a710026c4392602c837b1841bf to your computer and use it in GitHub Desktop.
#include <glm/glm.hpp>
#include <GLFW/glfw3.h>
void draw_boid(const glm::vec3& position, const glm::vec3& speed) {
const glm::vec3& speed_dir = glm::normalize(speed);
const glm::vec3 color (0.5 * (1 + speed_dir.x),
0.5 * (1 + speed_dir.y),
0.5 * (1 + speed_dir.z));
glPushMatrix();
glTranslatef(position.x, position.y, position.z);
// Rotate around normal of the plane containing both X-Axis and boid speed
glm::vec3 axeRot = glm::cross(glm::vec3(1.0f, 0.0f, 0.0f), speed);
const float angle = glm::degrees(std::atan2(glm::length(axeRot), speed.x));
glRotatef(angle, axeRot.x, axeRot.y, axeRot.z);
draw_box(glm::vec3(0.6, 0.1, 0.1), color);
glTranslatef(0.6, 0, 0);
draw_pyramid(glm::vec3(0.4, 0.1, 0.1), glm::vec3(1.0, 1.0, 0.0));
glPopMatrix();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment