rigidbody view
[vg.git] / labs / physics.c
1 #define VG_GAME
2 #define VG_AUDIO_FORCE_COMPRESSED
3 #define VG_3D
4 #define VG_LOG_SOURCE_INFO
5 #define VG_TIMESTEP_FIXED (1.0/60.0)
6
7 #ifndef VG_RELEASE
8 #define VG_DEVWINDOW
9 #endif
10
11 #define SDL_MAIN_HANDLED
12
13 #include "vg/vg.h"
14 #include "vg/vg_camera.h"
15
16 int main( int argc, char *argv[] ){
17 vg_mem.use_libc_malloc = 0;
18 vg_set_mem_quota( 80*1024*1024 );
19 vg_enter( argc, argv, "Voyager Game Engine" );
20 return 0;
21 }
22
23 static void vg_launch_opt(void){
24 const char *arg;
25 }
26
27 static void vg_preload(void){
28 vg_audio.dsp_enabled = 0;
29 }
30
31 static void vg_load(void){
32 vg_bake_shaders();
33 }
34
35 static void vg_pre_update(void){
36 }
37
38 static void vg_fixed_update(void){
39 }
40
41 static void vg_post_update(void){
42 }
43
44 static void vg_framebuffer_resize( int w, int h ){
45 }
46
47 static void draw_origin_axis(void){
48 vg_line( (v3f){ 0.0f, 0.0f, 0.0f }, (v3f){ 1.0f, 0.0f, 0.0f }, 0xffff0000 );
49 vg_line( (v3f){ 0.0f, 0.0f, 0.0f }, (v3f){ 0.0f, 1.0f, 0.0f }, 0xff00ff00 );
50 vg_line( (v3f){ 0.0f, 0.0f, 0.0f }, (v3f){ 0.0f, 0.0f, 1.0f }, 0xff0000ff );
51 }
52
53 static void vg_render(void){
54 glBindFramebuffer( GL_FRAMEBUFFER, 0 );
55 glViewport( 0,0, vg.window_x, vg.window_y );
56 glEnable( GL_DEPTH_TEST );
57 glDisable( GL_BLEND );
58
59 glClearColor( 0.05f, 0.05f, 0.05f, 1.0f );
60 glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );
61
62 f32 x = -((f32)vg.mouse_pos[0] / (f32)vg.window_x) * VG_TAUf,
63 y = (((f32)vg.mouse_pos[1] / (f32)vg.window_y) - 0.5f)*VG_PIf;
64
65 f32 t = vg.time * 0.1f * VG_TAUf;
66
67 vg_camera cam = {
68 .angles = { -x, y, 0 },
69 .nearz = 0.01f,
70 .farz = 500.0f,
71 .fov = 90.0f,
72 .pos = { sinf(x)*10.0f*cosf(y),
73 sinf(y)*10.0f,
74 cosf(x)*10.0f*cosf(y) },
75 };
76
77 vg_camera_update_transform( &cam );
78 vg_camera_update_view( &cam );
79 vg_camera_update_projection( &cam );
80 vg_camera_finalize( &cam );
81 m4x4_copy( cam.mtx.pv, vg.pv );
82
83 m4x3f mdl;
84 m4x3_identity( mdl );
85
86 vg_rb_view_bind();
87 vg_rb_view_capsule( mdl, (sinf(t*0.2f)*0.5f+0.55f)*2.0f,
88 (sinf(t*0.33f)*0.5f+0.55f)*1.0f,
89 (v4f){1,0,0,1} );
90 vg_rb_view_box( mdl, (boxf){{-4.999,-2.001,-4.999},{4.999,-0.999,4.999}},
91 (v4f){0.8f,0.8f,0.8f,1} );
92
93 mdl[3][0] = sinf(t)*2.0f;
94 mdl[3][2] = cosf(t)*2.0f;
95 vg_rb_view_sphere( mdl, 1, (v4f){0,1,0,1} );
96
97 draw_origin_axis();
98 vg_lines_drawall();
99
100 glDisable(GL_DEPTH_TEST);
101 }
102
103 static void vg_gui(void){
104 vg_ui.wants_mouse = 1;
105 }