66#include <malloc.h>
77#include <gl_includes.h>
88#include <cglm/cglm.h>
9- #include "sim/aabb .h"
9+ #include "sim/cube .h"
1010#include "sim/body.h"
1111#include "common/defines.h"
1212#include "viewer/window.h"
1313#include "viewer/shader.h"
1414#include "viewer/color.h"
1515#include "viewer/camera.h"
16- #include "viewer/aabb .h"
16+ #include "viewer/cube .h"
1717#include "viewer/body.h"
1818#include "viewer/model.h"
1919
@@ -25,10 +25,10 @@ const color_t WINDOW_BACKGROUND_COLOR = COLOR_PURPLE;
2525#include "shaders/matrix_vertex.h"
2626#include "shaders/uniform_color_fragment.h"
2727
28- static GLfloat box1_vertices [ BBOX_VERTEX_ARRAY_SIZE ];
29- static GLuint box1_indices [ BBOX_INDEX_ARRAY_SIZE ];
30- static GLfloat box2_vertices [ BBOX_VERTEX_ARRAY_SIZE ];
31- static GLuint box2_indices [ BBOX_INDEX_ARRAY_SIZE ];
28+ static GLfloat cube1_vertices [ CCUBE_VERTEX_ARRAY_SIZE ];
29+ static GLuint cube1_indices [ CCUBE_INDEX_ARRAY_SIZE ];
30+ static GLfloat cube2_vertices [ CCUBE_VERTEX_ARRAY_SIZE ];
31+ static GLuint cube2_indices [ CCUBE_INDEX_ARRAY_SIZE ];
3232
3333#define CAMERA_MOVE_SPEED 0.05
3434#define CAMERA_ROTATE_SPEED 0.0025
@@ -45,14 +45,13 @@ int graphic_main(void) {
4545 return result ;
4646 }
4747
48- bbox_t box1 , box2 ;
49- bbox_make (& box1 , 0 , 0 , 0 , 3 , 3 , 3 );
50- bbox_make (& box2 , 0 , 0 , 0 , 2 , 2 , 2 );
48+ ccube_t cube1 = ccube_make (VEC3_ZERO , QUATERNION_NOROTATION , 3 , 3 , 3 );
49+ ccube_t cube2 = ccube_make (VEC3_ZERO , QUATERNION_NOROTATION , 2 , 2 , 2 );
5150 body_t body1 , body2 ;
52- body_make (& body1 , vec3_make (1 , 0 , 0 ), VEC3_ZERO , vec3_make (0 , 1 , 0 ), VEC3_ZERO , 1 , 0 , 0 );
53- body_make (& body2 , vec3_make (0 , 10 , 0 ), VEC3_ZERO , vec3_make (0 , -0.5 , 0 ), VEC3_ZERO , 1 , 0 , 0 );
54- bbox_gen_vertices ( box1 , box1_vertices , box1_indices );
55- bbox_gen_vertices ( box2 , box2_vertices , box2_indices );
51+ body_make (& body1 , vec3_make (1 , -5 , 0 ), VEC3_ZERO , vec3_make (0 , 1 , 0 ), VEC3_ZERO , 1 , 0 , 0 );
52+ body_make (& body2 , vec3_make (0 , 5 , 0 ), VEC3_ZERO , vec3_make (0 , -1 , 0 ), VEC3_ZERO , 1 , 0 , 0 );
53+ ccube_gen_vertices ( cube1 , cube1_vertices , cube1_indices );
54+ ccube_gen_vertices ( cube2 , cube2_vertices , cube2_indices );
5655
5756 l_printf ("Building shaders...\n" );
5857
@@ -93,8 +92,8 @@ int graphic_main(void) {
9392
9493 l_printf ("Shaders successfully built!\n" );
9594
96- model_t box1_model = model_from_indices (box1_vertices , 3 , BBOX_VERTEX_ARRAY_SIZE , MODEL_BUFFER_STATIC , box1_indices , BBOX_INDEX_ARRAY_SIZE , MODEL_BUFFER_STATIC , MODEL_DRAW_TRIANGLES );
97- model_t box2_model = model_from_indices (box2_vertices , 3 , BBOX_VERTEX_ARRAY_SIZE , MODEL_BUFFER_STATIC , box2_indices , BBOX_INDEX_ARRAY_SIZE , MODEL_BUFFER_STATIC , MODEL_DRAW_TRIANGLES );
95+ model_t box1_model = model_from_indices (cube1_vertices , 3 , CCUBE_VERTEX_ARRAY_SIZE , MODEL_BUFFER_STATIC , cube1_indices , CCUBE_INDEX_ARRAY_SIZE , MODEL_BUFFER_STATIC , MODEL_DRAW_TRIANGLES );
96+ model_t box2_model = model_from_indices (cube2_vertices , 3 , CCUBE_VERTEX_ARRAY_SIZE , MODEL_BUFFER_STATIC , cube2_indices , CCUBE_INDEX_ARRAY_SIZE , MODEL_BUFFER_STATIC , MODEL_DRAW_TRIANGLES );
9897
9998 color_t color1 = COLOR_GREEN ;
10099 color_t color2 = COLOR_BLUE ;
@@ -134,12 +133,12 @@ int graphic_main(void) {
134133 phy_body_add_gravity_force (& body1 , & body2 );
135134
136135#ifndef NOCOLLISION
137- if (bbox_is_bbox_inside ( box1 , box2 )) {
136+ if (ccube_is_ccube_inside ( cube1 , cube2 )) {
138137 // a and b are colliding; find normal
139138 // and do collision forces
140- vec3_t b_closest_a = box2 .position ;
141- bbox_clamp_point_within_bounds ( box1 , & b_closest_a );
142- vec3_t normal_a_b = bbox_get_surface_normal ( box1 , b_closest_a );
139+ vec3_t b_closest_a = cube2 .position ;
140+ ccube_clamp_point_within_cube ( cube1 , & b_closest_a );
141+ vec3_t normal_a_b = ccube_get_surface_normal ( cube1 , b_closest_a );
143142 phy_calculate_normal_force (& normal_a_b , body1 , normal_a_b );
144143 phy_body_add_collision_forces (& body1 , & body2 , normal_a_b , b_closest_a );
145144 }
@@ -149,8 +148,10 @@ int graphic_main(void) {
149148 phy_body_step (& body2 );
150149 }
151150
152- box1 .position = body1 .position ;
153- box2 .position = body2 .position ;
151+ cube1 .position = body1 .position ;
152+ glm_euler_xyz_quat (vec3_to_cglm (body1 .rotation ), vec4_to_cglm (cube1 .rotation ));
153+ cube2 .position = body2 .position ;
154+ glm_euler_xyz_quat (vec3_to_cglm (body2 .rotation ), vec4_to_cglm (cube2 .rotation ));
154155
155156 // move camera up and down
156157 if (window_is_key_down (window , GLFW_KEY_E )) {
0 commit comments