89 lines
3.1 KiB
C
89 lines
3.1 KiB
C
#include "../libsuicmez/libsuicmez.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdbool.h>
|
|
#include <string.h>
|
|
|
|
void* gc_alloc(const TypeInfo* type, size_t size);
|
|
void gc_init(void);
|
|
void gc_shutdown(void);
|
|
|
|
// Helper for allocating arrays
|
|
static void* suic_alloc_array(const TypeInfo* type, size_t elem_size, size_t len, void* init_data) {
|
|
void* ptr = gc_alloc(type, elem_size * len);
|
|
if (init_data) memcpy(ptr, init_data, elem_size * len);
|
|
return ptr;
|
|
}
|
|
|
|
// Helper for allocating structs
|
|
static void* suic_alloc_struct(const TypeInfo* type, size_t size, void* init_data) {
|
|
void* ptr = gc_alloc(type, size);
|
|
if (init_data) memcpy(ptr, init_data, size);
|
|
return ptr;
|
|
}
|
|
|
|
|
|
|
|
|
|
int suic_main(void);
|
|
|
|
|
|
int suic_main(void) {
|
|
suic_init_window(800, 600, suic_alloc_array(NULL, sizeof(char), 27, "3D Physics Game - Improved"));
|
|
suic_set_target_fps(60);
|
|
suic_ode_init();
|
|
void* world = suic_ode_world_create();
|
|
void* null_space = (struct unit**) 0;
|
|
void* space = suic_ode_simple_space_create(null_space);
|
|
suic_ode_world_set_gravity(world, 0.000000, -9.810000, 0.000000);
|
|
void* contactgroup = suic_ode_joint_group_create(0);
|
|
void* body = suic_ode_body_create(world);
|
|
suic_ode_body_set_box_mass(body, 1.000000, 1.000000, 1.000000, 1.000000);
|
|
suic_ode_body_set_position(body, 0.000000, 5.000000, 0.000000);
|
|
void* geom = suic_ode_create_box_geom(space, 1.000000, 1.000000, 1.000000);
|
|
suic_ode_geom_set_body(geom, body);
|
|
void* ground_geom = suic_ode_create_plane_geom(space, 0.000000, 1.000000, 0.000000, 0.000000);
|
|
float camera_pos_x = 0.000000;
|
|
float camera_pos_y = 2.000000;
|
|
float camera_pos_z = 10.000000;
|
|
float cube_x = 0.000000;
|
|
float cube_y = 0.000000;
|
|
float cube_z = 0.000000;
|
|
int frame_count = 0;
|
|
while ((suic_window_should_close() == false)) {
|
|
suic_ode_space_collide(world, space, contactgroup);
|
|
suic_ode_world_step(world, (1.000000 / 60.000000));
|
|
suic_ode_joint_group_empty(contactgroup);
|
|
suic_ode_body_get_position(body, &cube_x, &cube_y, &cube_z);
|
|
suic_begin_drawing();
|
|
suic_clear_background(135, 206, 235, 255);
|
|
suic_begin_mode3d(camera_pos_x, camera_pos_y, camera_pos_z, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 45.000000, 0);
|
|
suic_draw_cube(0.000000, -1.000000, 0.000000, 20.000000, 0.100000, 20.000000, 34, 139, 34, 255);
|
|
suic_draw_cube(cube_x, cube_y, cube_z, 1.000000, 1.000000, 1.000000, 255, 0, 0, 255);
|
|
suic_draw_cube_wires(cube_x, cube_y, cube_z, 1.000000, 1.000000, 1.000000, 0, 0, 0, 255);
|
|
suic_end_mode3d();
|
|
suic_end_drawing();
|
|
frame_count = (frame_count + 1);
|
|
}
|
|
suic_ode_geom_destroy(ground_geom);
|
|
suic_ode_geom_destroy(geom);
|
|
suic_ode_body_destroy(body);
|
|
suic_ode_joint_group_destroy(contactgroup);
|
|
suic_ode_space_destroy(space);
|
|
suic_ode_world_destroy(world);
|
|
suic_ode_close();
|
|
suic_close_window();
|
|
return 0;
|
|
}
|
|
|
|
int main(int argc, char* argv[]) {
|
|
// Initialize GC
|
|
gc_init();
|
|
// init globals
|
|
// init event loop
|
|
int result = suic_main();
|
|
// Shutdown GC
|
|
gc_shutdown();
|
|
return result;
|
|
}
|
|
|