1 /*=============================================================================
2 Asteroids3D - a first person game of blowing up asteroids
3 Copyright © Jan Engelhardt <jengelh [at] gmx de>, 2003 - 2006
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public
16 License along with this program kit; if not, write to:
17 Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 =============================================================================*/
20 #include <GL/glut.h>
21 #include "asteroids3D.h"
22
23 // Functions
24 static void init_debug_axes(void);
25 static void init_debug_grid(void);
26
27 // Variables
28 static const unsigned int cubenet_cells = 4;
29 static const double cubenet_width = 25;
30 static int axes_dl, cubenet_dl;
31
32 //-----------------------------------------------------------------------------
init_debug(void)33 void init_debug(void)
34 {
35 init_debug_axes();
36 init_debug_grid();
37 return;
38 }
39
init_debug_axes(void)40 static void init_debug_axes(void)
41 {
42 static const float
43 high_red[] = {1.0, 0.0, 0.0, 1.0},
44 low_red[] = {0.3, 0.0, 0.0, 1.0},
45 high_green[] = {0.0, 1.0, 0.0, 1.0},
46 low_green[] = {0.0, 0.3, 0.0, 1.0},
47 high_blue[] = {0.0, 0.0, 1.0, 1.0},
48 low_blue[] = {0.0, 0.0, 0.4, 1.0},
49 white[] = {1.0, 1.0, 1.0, 1.0},
50 ad[] = {0.0, 0.0, 0.0, 0.1},
51 normal[] = {0.0, 0.0, 0.0, 1.0};
52 const double k = 33;
53
54 axes_dl = glGenLists(1);
55 glNewList(axes_dl, GL_COMPILE);
56
57 glLineWidth(3);
58 glPointSize(6);
59 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ad);
60 glBegin(GL_LINES);
61 // x axis RED
62 glMaterialfv(GL_FRONT, GL_EMISSION, high_red);
63 glVertex3f(k, 0, 0);
64 glVertex3f(0, 0, 0);
65
66 glMaterialfv(GL_FRONT, GL_EMISSION, low_red);
67 glVertex3f(-k, 0, 0);
68 glVertex3f(0, 0, 0);
69
70 // y axis GREEN
71 glMaterialfv(GL_FRONT, GL_EMISSION, high_green);
72 glVertex3f(0, k, 0);
73 glVertex3f(0, 0, 0);
74
75 glMaterialfv(GL_FRONT, GL_EMISSION, low_green);
76 glVertex3f(0, -k, 0);
77 glVertex3f(0, 0, 0);
78
79 // z axis BLUE
80 glMaterialfv(GL_FRONT, GL_EMISSION, high_blue);
81 glVertex3f(0, 0, k);
82 glVertex3f(0, 0, 0);
83
84 glMaterialfv(GL_FRONT, GL_EMISSION, low_blue);
85 glVertex3f(0, 0, -k);
86 glVertex3f(0, 0, 0);
87 glEnd();
88
89 glBegin(GL_POINTS);
90 glMaterialfv(GL_FRONT, GL_EMISSION, white);
91 glVertex3d(k, 0, 0);
92 glVertex3d(0, k, 0);
93 glVertex3d(0, 0, k);
94 glVertex3d(-k, 0, 0);
95 glVertex3d(0, -k, 0);
96 glVertex3d(0, 0, -k);
97 glEnd();
98
99 glMaterialfv(GL_FRONT, GL_EMISSION, normal);
100 glLineWidth(1);
101 glPointSize(1);
102 glEndList();
103 return;
104 }
105
init_debug_grid(void)106 static void init_debug_grid(void)
107 {
108 static const float
109 cl_gray[] = {0.35, 0.4, 0.35, 1},
110 ad[] = {0.0, 0.0, 0.0, 1};
111 const double s = cubenet_width, hs = cubenet_width / 2;
112 int x, y, z;
113
114 cubenet_dl = glGenLists(1);
115 glNewList(cubenet_dl, GL_COMPILE);
116
117 glLineWidth(1);
118 glDisable(GL_LINE_SMOOTH);
119 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ad);
120 glMaterialfv(GL_FRONT, GL_EMISSION, cl_gray);
121 glPushMatrix();
122 glTranslated(-hs - s, -hs - s, -hs - s);
123
124 for (x = 0; x < cubenet_cells; ++x)
125 for (y = 0; y < cubenet_cells; ++y)
126 for (z = 0; z < cubenet_cells; ++z) {
127 glPushMatrix();
128 glTranslated(s * x, s * y, s * z);
129 glutWireCube(25);
130 glPopMatrix();
131 }
132
133 glPopMatrix();
134 glEnable(GL_LINE_SMOOTH);
135 glEndList();
136 return;
137 }
138
draw_debug_axes(void)139 void draw_debug_axes(void)
140 {
141 glCallList(axes_dl);
142 return;
143 }
144
draw_debug_grid(void)145 void draw_debug_grid(void)
146 {
147 const double d = cubenet_width;
148 int x = static_cast(int, pos.x / d) * d,
149 y = static_cast(int, pos.y / d) * d,
150 z = static_cast(int, pos.z / d) * d;
151
152 glPushMatrix();
153 glTranslated(x, y, z);
154 glCallList(cubenet_dl);
155 glPopMatrix();
156 return;
157 }
158