10 static int ginit(void);
11 static void gdestroy(void);
12 static int gstart(void);
13 static void gstop(void);
14 static void gdisplay(void);
15 static void greshape(int x, int y);
16 static void gkeyb(int key, int press);
17 static void gmouse(int bn, int press, int x, int y);
18 static void gmotion(int x, int y);
20 struct game_screen scr_game = {
25 gkeyb, gmouse, gmotion
28 static float cam_theta, cam_phi = 20, cam_dist = 10;
29 static float cam_pan[3];
31 static struct goat3d *gscn;
35 static int ginit(void)
39 if(!(gscn = goat3d_create()) || goat3d_load(gscn, "data/track1.g3d")) {
43 dlist = glGenLists(1);
44 glNewList(dlist, GL_COMPILE);
45 num = goat3d_get_node_count(gscn);
46 for(i=0; i<num; i++) {
47 struct goat3d_node *node = goat3d_get_node(gscn, i);
48 if(goat3d_get_node_type(node) == GOAT3D_NODE_MESH) {
49 struct goat3d_mesh *mesh = goat3d_get_node_object(node);
51 glEnableClientState(GL_VERTEX_ARRAY);
52 glVertexPointer(3, GL_FLOAT, 0, goat3d_get_mesh_attribs(mesh, GOAT3D_MESH_ATTR_VERTEX));
54 nfaces = goat3d_get_mesh_face_count(mesh) / 3;
55 glDrawElements(GL_TRIANGLES, nfaces * 3, GL_UNSIGNED_INT, goat3d_get_mesh_faces(mesh));
57 glDisableClientState(GL_VERTEX_ARRAY);
66 static void gdestroy(void)
71 static int gstart(void)
76 static void gstop(void)
80 static void gdisplay(void)
82 glMatrixMode(GL_MODELVIEW);
84 glTranslatef(0, 0, -cam_dist);
85 glRotatef(cam_phi, 1, 0, 0);
86 glRotatef(cam_theta, 0, 1, 0);
87 glTranslatef(cam_pan[0], cam_pan[1], cam_pan[2]);
92 static void greshape(int x, int y)
96 static void gkeyb(int key, int press)
100 static void gmouse(int bn, int press, int x, int y)
104 static void gmotion(int x, int y)
106 int dx = x - mouse_x;
107 int dy = y - mouse_y;
109 if(!(dx | dy)) return;
112 cam_theta += dx * 0.5;
114 if(cam_phi < -90) cam_phi = -90;
115 if(cam_phi > 90) cam_phi = 90;
118 float up[3], right[3];
119 float theta = cam_theta * M_PI / 180.0f;
120 float phi = cam_phi * M_PI / 180.0f;
122 up[0] = -sin(theta) * sin(phi);
124 up[2] = cos(theta) * sin(phi);
125 right[0] = cos(theta);
127 right[2] = sin(theta);
129 cam_pan[0] += (right[0] * dx + up[0] * dy) * 0.01;
130 cam_pan[1] += up[1] * dy * 0.01;
131 cam_pan[2] += (right[2] * dx + up[2] * dy) * 0.01;
134 cam_dist += dy * 0.1;
135 if(cam_dist < 0) cam_dist = 0;