Boids/C: Difference between revisions

m
tweaks
(boids + opengl)
 
m (tweaks)
Line 84:
typedef struct {
vec position, heading, newheading;
flt speed;
} boid_t;
 
Line 284 ⟶ 285:
int i;
for (i = 0; i < N; i++)
vmuladd_to(&boids[i].position, &boids[i].heading, msec * MOVE_SPEEDboids[i].speed);
 
vec average = {{0,0,0}};
Line 365 ⟶ 366:
 
glTranslatef(b->position.x[0], b->position.x[1], b->position.x[2]);
 
flt yaw = atan2(b->heading.x[1], b->heading.x[0]) / PI * 180 - 90;
float *x = b->heading.x;
flt yaw = atan2(b->heading.x[1], b->heading.x[0]) / PI * 180 - 90;
glRotatef(yaw, 0, 0, 1);
 
flt rxy = sqrt(x[0] * x[0] + x[1] * x[1]);
flt pitch = atan2(x[2], rxy) / PI * 180;
glRotatef(pitch, 1, 0, 0);
 
glBegin(GL_TRIANGLES);
Line 533 ⟶ 540:
flt z = (((flt)rand() / RAND_MAX) + .5) * IDEAL_HEIGHT + ground_height(x, y);
boids[i].position = (vec){{x, y, z}};
boids[i].speed = (0.98 + 0.04 * rand() / RAND_MAX) * MOVE_SPEED;
}
 
Anonymous user