starting infcubes part
[dosdemo] / src / infcubes.c
1 #include <stdio.h>
2 #include <math.h>
3 #include "demo.h"
4 #include "3dgfx.h"
5 #include "screen.h"
6 #include "cfgopt.h"
7
8 static int init(void);
9 static void destroy(void);
10 static void start(long trans_time);
11 static void draw(void);
12 static void draw_cube(void);
13
14 static struct screen scr = {
15         "infcubes",
16         init,
17         destroy,
18         start, 0,
19         draw
20 };
21
22 static float cam_theta, cam_phi;
23 static float cam_dist = 5;
24
25 struct screen *infcubes_screen(void)
26 {
27         return &scr;
28 }
29
30
31 static int init(void)
32 {
33         return 0;
34 }
35
36 static void destroy(void)
37 {
38 }
39
40 static void start(long trans_time)
41 {
42         g3d_matrix_mode(G3D_PROJECTION);
43         g3d_load_identity();
44         g3d_perspective(50.0, 1.3333333, 0.5, 100.0);
45
46         g3d_enable(G3D_LIGHTING);
47         g3d_enable(G3D_LIGHT0);
48 }
49
50 static void update(void)
51 {
52         mouse_orbit_update(&cam_theta, &cam_phi, &cam_dist);
53 }
54
55 static void draw(void)
56 {
57         update();
58
59         g3d_matrix_mode(G3D_MODELVIEW);
60         g3d_load_identity();
61         g3d_translate(0, 0, -cam_dist);
62         g3d_rotate(cam_phi, 1, 0, 0);
63         g3d_rotate(cam_theta, 0, 1, 0);
64         if(opt.sball) {
65                 g3d_mult_matrix(sball_matrix);
66         }
67
68         memset(fb_pixels, 0, fb_width * fb_height * 2);
69
70         draw_cube();
71
72         swap_buffers(fb_pixels);
73 }
74
75 static void draw_cube(void)
76 {
77         g3d_begin(G3D_QUADS);
78         g3d_normal(0, 0, 1);
79         g3d_vertex(-1, -1, 1);
80         g3d_vertex(1, -1, 1);
81         g3d_vertex(1, 1, 1);
82         g3d_vertex(-1, 1, 1);
83         g3d_normal(1, 0, 0);
84         g3d_vertex(1, -1, 1);
85         g3d_vertex(1, -1, -1);
86         g3d_vertex(1, 1, -1);
87         g3d_vertex(1, 1, 1);
88         g3d_normal(0, 0, -1);
89         g3d_vertex(1, -1, -1);
90         g3d_vertex(-1, -1, -1);
91         g3d_vertex(-1, 1, -1);
92         g3d_vertex(1, 1, -1);
93         g3d_normal(-1, 0, 0);
94         g3d_vertex(-1, -1, -1);
95         g3d_vertex(-1, -1, 1);
96         g3d_vertex(-1, 1, 1);
97         g3d_vertex(-1, 1, -1);
98         g3d_normal(0, 1, 0);
99         g3d_vertex(-1, 1, 1);
100         g3d_vertex(1, 1, 1);
101         g3d_vertex(1, 1, -1);
102         g3d_vertex(-1, 1, -1);
103         g3d_normal(0, -1, 0);
104         g3d_vertex(1, -1, 1);
105         g3d_vertex(-1, -1, 1);
106         g3d_vertex(-1, -1, -1);
107         g3d_vertex(1, -1, -1);
108         g3d_end();
109 }