V2f operator+(V2f a, V2f b);
V2f operator-(V2f a, V2f b);
V2f operator*(V2f a, f32 scalar);
+
+void operator+=(V2f& a, const V2f& b);
+void operator-=(V2f& a, const V2f& b);
+void operator*=(V2f& a, const f32& s);
+
f32 v2f_dot (V2f a, V2f b);
f32 v2f_smag(V2f a);
f32 v2f_mag (V2f a);
+internal Array<Body> bodies;
// NOTE(Brendan): dt is expected to be in units of "per second".
internal void
update(f64 dt)
{
+ For (bodies)
+ {
+ // it.vel *= 0.99f;
+ it.pos += it.vel * dt;
+ }
}
internal GLuint body_buffer;
-internal Array<Body> bodies;
-
internal GLuint circle_mesh;
+
internal void
draw()
{
- For(bodies)
- {
- it.pos = V2f{ randf(0, 800), randf(0, 800) };
- it.vel = V2f{ 0.0f, 0.0f };
- it.mass = randf(10.0f, 50.0f);
- }
glBindBuffer(GL_ARRAY_BUFFER, body_buffer);
glBufferSubData(GL_ARRAY_BUFFER, 0, bodies.count * sizeof(Body), bodies.data);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBindVertexArray(circle_mesh);
- glDrawElementsInstanced(GL_TRIANGLE_FAN, CIRCLE_POINT_COUNT, GL_UNSIGNED_BYTE, 0, 128);
+ glDrawElementsInstanced(GL_TRIANGLE_FAN, CIRCLE_POINT_COUNT, GL_UNSIGNED_BYTE, 0, bodies.count);
glBindVertexArray(-1);
glfwSwapBuffers(window);
GLuint ortho_mat_loc = glGetUniformLocation(program, "u_proj");
glUniformMatrix4fv(ortho_mat_loc, 1, false, (f32 *) ortho_mat);
- bodies.ensure_capacity(128);
-
- // NOTE(Brendan): Setting the count like this does not guarantee that the data will be initialized.
- bodies.count = 128;
-
- For(bodies)
+ foreach (i, 0, 128)
{
- it.pos = V2f{ randf(0, 800), randf(0, 800) };
- it.vel = V2f{ 0.0f, 0.0f };
- it.mass = randf(10.0f, 50.0f);
+ Body tmp_body;
+ tmp_body.pos = V2f{ randf(0, 800), randf(0, 800) };
+ tmp_body.vel = V2f{ randf(-50.0f, 50.0f), randf(-50.0f, 50.0f) };
+ tmp_body.mass = randf(10.0f, 50.0f);
+ bodies.push(tmp_body);
}
{
return (V2f) { .x = a.x * scalar, .y = a.y * scalar };
}
+// NOTE(Brendan): I wish these could be implicitly defined since their definitions are so easy.
+void operator+=(V2f& a, const V2f& b) { a = a + b; }
+void operator-=(V2f& a, const V2f& b) { a = a - b; }
+void operator*=(V2f& a, const f32& s) { a = a * s; }
+
f32
v2f_dot(V2f a, V2f b)
{