added mat4_mul
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 19 Oct 2020 02:42:59 +0000 (21:42 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 19 Oct 2020 02:42:59 +0000 (21:42 -0500)
include/vecmath.h
res/shaders/planet_vert.glsl
src/sim.c
src/vecmath.c

index be7d4362c67c25e372fad0092de7d60d432ab612..0916674f4ed8fdbc9b40df5430ab4cc59588918d 100644 (file)
@@ -22,6 +22,7 @@ void mat4_ortho(mat4 *mat,
                 f32 top, f32 bottom,
                 f32 near, f32 far);
 void mat4_proj(mat4 *mat);
+void mat4_mul(mat4 a, mat4 b, mat4* out);
 
 
 #endif //VECMATH_H
index 67afc250294a01e41989dba8554a7ee6ef88217f..4c306ce27d1fe0624da75769d1145a8616a02b1b 100644 (file)
@@ -9,5 +9,5 @@ layout(location = 2) in float a_mass;
 uniform mat4 u_proj;
 
 void main() {
-       gl_Position = u_proj * vec4(a_shape_pos, 0, 1);
+       gl_Position = u_proj * vec4(a_shape_pos * a_mass + a_obj_pos, 0, 1);
 }
\ No newline at end of file
index c0170671942c0b1196b3d121dbf801c01bd7da3f..d091e1fbd9185923df750be75297cae5fd5e46da 100644 (file)
--- a/src/sim.c
+++ b/src/sim.c
@@ -56,9 +56,16 @@ init_glfw() {
        glfwSetKeyCallback(window, glfw_key_handler);
        glfwSetFramebufferSizeCallback(window, glfw_resize_handler);
     
-    //glEnable(GL_CULL_FACE);
-    //glFrontFace(GL_CW);
-    //glCullFace(GL_BACK);
+    // NOTE(Brendan): This may need to be changed if the screen orientation changes.
+    glEnable(GL_CULL_FACE);
+    glFrontFace(GL_CW);
+    glCullFace(GL_BACK);
+}
+
+internal void
+deinit_glfw() {
+       glfwDestroyWindow(window);
+       glfwTerminate();
 }
 
 internal GLuint
@@ -144,8 +151,8 @@ create_circle_mesh() {
     V2f circle_points[CIRCLE_POINT_COUNT] = {};
     foreach (i, 0, CIRCLE_POINT_COUNT) {
         f32 t = (f32) i / (f32) CIRCLE_POINT_COUNT;
-        circle_points[i].x = cos(t * 2 * PI) * 100.0f + 400.0f;
-        circle_points[i].y = sin(t * 2 * PI) * 100.0f + 200.0f;
+        circle_points[i].x = cos(t * 2 * PI) / 2.0f + 400.0f;
+        circle_points[i].y = sin(t * 2 * PI) / 2.0f + 200.0f;
     }
     
     GLsizei vertex_buffer;
@@ -169,11 +176,7 @@ create_circle_mesh() {
     return vao;
 }
 
-internal void
-deinit_opengl() {
-       glfwDestroyWindow(window);
-       glfwTerminate();
-}
+
 
 // NOTE(Brendan): dt is expected to be in units of "per second".
 internal void
@@ -231,7 +234,7 @@ main(i32 argc, char* argv[]) {
     
     loop();
     
-    deinit_opengl();
+    deinit_glfw();
     
     return 0;
 }
\ No newline at end of file
index 01b4a38f22407e120f7628c9a387c3e01e5d4f70..25af422358bc4f5c064cd80a7e9610b873c44bdc 100644 (file)
@@ -74,3 +74,18 @@ mat4_ortho(mat4 *mat,
     (*mat)[3 * 4 + 1] = -(top + bottom) / (top - bottom);
     (*mat)[3 * 4 + 2] = -(far + near) / (far - near);
 }
+
+
+void
+mat4_mul(mat4 a, mat4 b, mat4* out)
+{
+    foreach(row, 0, 4) {
+        foreach(col, 0, 4) {
+            (*out)[row * 4 + col] = 0.0f;
+            
+            foreach(i, 0, 4) {
+                (*out)[row * 4 + col] += a[row * 4 + i] + b[i * 4 + col];
+            }
+        }
+    }
+}
\ No newline at end of file