1 /*
2 Copyright (C) 2003 Cedric Cellier, Dominique Lavault
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17 */
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <math.h>
21 #include "draw.h"
22 #include "modes.h"
23 #include "slist.h"
24 #include "log.h"
25 #include "opengl.h"
26 #include "geom.h"
27 
28 /* DEBUG MODE */
29 
30 static GLfloat camera[16] = {
31 	1,0,0,0,
32 	0,1,0,0,
33 	0,0,1,0,
34 	0,-2,-6,1
35 };
36 static GLfloat projection[16];
37 static double angle=0;
38 
39 static mesh *test_mesh;
40 
m1_display(void)41 void m1_display(void) {
42 	static csg_union_of_partial_products *uopp = NULL;
43 	double ca, sa;
44 	if (NULL==uopp) {
45 		csg_union_of_products *uop;
46 		enigm *e = gltv_slist_get(enigms, 0);
47 		uop = csg_union_of_products_new(e->root);
48 		if (uop) {
49 			uopp = csg_union_of_partial_products_new(uop);
50 		} else {
51 			gltv_log_fatal("m1_display: Cannot get union of products");
52 		}
53 		if (NULL==uopp) {
54 			gltv_log_fatal("m1_display: Cannot get union of partial products");
55 		}
56 		glClearColor(0.18, 0.28, 0.28, 0.0);
57 		glMatrixMode(GL_PROJECTION);
58 		glLoadIdentity();
59 		glFrustum(-1,1, -1,1, 1,1000);
60 		glMatrixMode(GL_MODELVIEW);
61 		glGetFloatv(GL_PROJECTION_MATRIX, projection);
62 		geom_set_current_projection(projection);
63 		test_mesh = data_load_mesh("num_cylinder.mesh", 0);
64 		if (NULL==test_mesh) gltv_log_fatal("mode1: Cannot load mesh");
65 		glColor3f(.2,.5,.5);
66 	}
67 	ca = cos(angle);
68 	sa = sin(angle);
69 	camera[0] = ca;
70 	camera[2] = sa;
71 	camera[8] = -sa;
72 	camera[10] = ca;
73 	angle += .015;
74 	glStencilMask(~0);
75 	glDepthMask(1);
76 	glColorMask(1,1,1,1);
77 	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
78 	glLoadMatrixf(camera);
79 	geom_set_current_modelview(camera);
80 	draw_union_of_partial_products(uopp);
81 	// and a test_mesh
82 //	draw_mesh(test_mesh);
83 }
84