1 /* about.c */
2 
3 /* Help -> About... */
4 
5 /* fsv - 3D File System Visualizer
6  * Copyright (C)1999 Daniel Richard G. <skunk@mit.edu>
7  * Copyright (C)2009-2011 Yury P. Fedorchenko <yuryfdr@users.sf.net>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23 
24 
25 #include "common.h"
26 #include "about.h"
27 
28 #include <GL/gl.h>
29 
30 #include "animation.h"
31 #include "geometry.h"
32 #include "ogl.h"
33 #include "tmaptext.h"
34 
35 
36 /* Interval normalization macro */
37 #define INTERVAL_PART(x,x0,x1)	(((x) - (x0)) / ((x1) - (x0)))
38 
39 
40 /* Normalized time variable (in range [0, 1]) */
41 static double about_part;
42 
43 /* Display list for "fsv" geometry */
44 static GLuint fsv_dlist = NULL_DLIST;
45 
46 /* TRUE while giving About presentation */
47 static boolean about_active = FALSE;
48 
49 
50 /* Draws the "fsv" 3D letters */
51 static void
draw_fsv(void)52 draw_fsv( void )
53 {
54 	double dy, p, q;
55 
56 	if (about_part < 0.5) {
57 		/* Set up a black, all-encompassing fog */
58 		glEnable( GL_FOG );
59 		glFogi( GL_FOG_MODE, GL_LINEAR );
60 		glFogf( GL_FOG_START, 200.0 );
61 		glFogf( GL_FOG_END, 1800.0 );
62 	}
63 
64 	/* Set up projection matrix */
65 	glMatrixMode( GL_PROJECTION );
66 	glPushMatrix( );
67 	glLoadIdentity( );
68 	dy = 80.0 / ogl_aspect_ratio( );
69 	glFrustum( - 80.0, 80.0, - dy, dy, 80.0, 2000.0 );
70 
71 	/* Set up modelview matrix */
72 	glMatrixMode( GL_MODELVIEW );
73 	glPushMatrix( );
74 	glLoadIdentity( );
75 	if (about_part < 0.5) {
76 		/* Spinning and approaching fast */
77 		p = INTERVAL_PART(about_part, 0.0, 0.5);
78 		q = pow( 1.0 - p, 1.5 );
79 		glTranslated( 0.0, 0.0, -150.0 - 1800.0 * q );
80 		glRotated( 900.0 * q, 0.0, 1.0, 0.0 );
81 	}
82 	else if (about_part < 0.625) {
83 		/* Holding still for a moment */
84 		glTranslated( 0.0, 0.0, -150.0 );
85 	}
86 	else if (about_part < 0.75) {
87 		/* Flipping up and back */
88 		p = INTERVAL_PART(about_part, 0.625, 0.75);
89 		q = 1.0 - SQR(1.0 - p);
90 		glTranslated( 0.0, 40.0 * q, -150.0 - 50.0 * q );
91 		glRotated( 365.0 * q, 1.0, 0.0, 0.0 );
92 	}
93 	else {
94 		/* Holding still again */
95 		glTranslated( 0.0, 40.0, -200.0 );
96 		glRotated( 5.0, 1.0, 0.0, 0.0 );
97 	}
98 
99 	/* Draw "fsv" geometry, using a display list if possible */
100 	if (fsv_dlist == NULL_DLIST) {
101 		fsv_dlist = glGenLists( 1 );
102 		glNewList( fsv_dlist, GL_COMPILE_AND_EXECUTE );
103 		geometry_gldraw_fsv( );
104 		glEndList( );
105 	}
106 	else
107 		glCallList( fsv_dlist );
108 
109 	/* Restore previous matrices */
110 	glMatrixMode( GL_PROJECTION );
111 	glPopMatrix( );
112 	glMatrixMode( GL_MODELVIEW );
113 	glPopMatrix( );
114 
115 	glDisable( GL_FOG );
116 }
117 
118 
119 /* Draws the lines of text */
120 static void
draw_text(void)121 draw_text( void )
122 {
123         XYZvec tpos;
124 	XYvec tdims;
125 	double dy, p, q;
126 
127 	if (about_part < 0.625)
128 		return;
129 
130 	/* Set up projection matrix */
131 	glMatrixMode( GL_PROJECTION );
132 	glPushMatrix( );
133 	glLoadIdentity( );
134 	dy = 1.0 / ogl_aspect_ratio( );
135 	glFrustum( - 1.0, 1.0, - dy, dy, 1.0, 205.0 );
136 
137 	/* Set up modelview matrix */
138 	glMatrixMode( GL_MODELVIEW );
139 	glPushMatrix( );
140 	glLoadIdentity( );
141 
142         if (about_part < 0.75)
143 		p = INTERVAL_PART(about_part, 0.625, 0.75);
144 	else
145 		p = 1.0;
146 	q = (1.0 - SQR(1.0 - p));
147 
148 	text_pre( );
149 
150 	tdims.x = 400.0;
151 	tdims.y = 18.0;
152 	tpos.x = 0.0;
153 	tpos.y = -35.0; /* -35 */
154 	tpos.z = -200.0 * q;
155 	glColor3f( 1.0, 1.0, 1.0 );
156 	text_draw_straight( _("fsv2 - 3D File System Visualizer"), &tpos, &tdims );
157 
158 	tdims.y = 15.0;
159 	tpos.y = 40.0 * q - 95.0; /* -55 */
160 	text_draw_straight("Version " VERSION, &tpos, &tdims );
161 
162 	tdims.y = 12.0;
163 	tpos.y = 100.0 * q - 180.0; /* -80 */
164 	glColor3f( 0.5, 0.5, 0.5 );
165 	text_draw_straight( _("Copyright ©2009-2011 by Yury P. Fedorchenko"), &tpos, &tdims );
166 	tpos.y = 100.0 * q - 195.0; /* -80 */
167 	text_draw_straight( _("Copyright (C)1999 by Daniel Richard G."), &tpos, &tdims );
168 
169 	/*tpos.y = 140.0 * q - 235.0;
170 	text_draw_straight( "<skunk@mit.edu>", &tpos, &tdims );*/
171 
172 	/* Finally, fade in the home page URL */
173 	if (about_part > 0.75) {
174 		tpos.y = -115.0;
175 		p = INTERVAL_PART(about_part, 0.75, 1.0);
176 		q = SQR(SQR(p));
177 		glColor3f( q, q, 0.0 );
178 		text_draw_straight( "http://www.fedorchenko.net/fsv2.php", &tpos, &tdims );
179 		tpos.y = -125.0;
180 		text_draw_straight( "___________________________________", &tpos, &tdims );
181 	}
182 
183 	text_post( );
184 
185 	/* Restore previous matrices */
186 	glMatrixMode( GL_PROJECTION );
187 	glPopMatrix( );
188 	glMatrixMode( GL_MODELVIEW );
189 	glPopMatrix( );
190 }
191 
192 
193 /* Progress callback; keeps viewport updated during presentation */
194 static void
about_progress_cb(Morph * unused)195 about_progress_cb( Morph *unused )
196 {
197 	globalsc.need_redraw = TRUE;
198 }
199 
200 
201 /* Control routine */
202 boolean
about(AboutMesg mesg)203 about( AboutMesg mesg )
204 {
205 	switch (mesg) {
206 		case ABOUT_BEGIN:
207 		/* Begin the presentation */
208 		morph_break( &about_part );
209 		about_part = 0.0;
210 		morph_full( &about_part, MORPH_LINEAR, 1.0, 8.0, about_progress_cb, about_progress_cb, NULL );
211 		about_active = TRUE;
212 		break;
213 
214 		case ABOUT_END:
215 		if (!about_active)
216 			return FALSE;
217 		/* We now return you to your regularly scheduled program */
218 		morph_break( &about_part );
219 		if (fsv_dlist != NULL_DLIST) {
220 			glDeleteLists( fsv_dlist, 1 );
221 			fsv_dlist = NULL_DLIST;
222 		}
223 		redraw( );
224 		about_active = FALSE;
225 		return TRUE;
226 
227 		case ABOUT_DRAW:
228 		/* Draw all presentation elements */
229 		draw_fsv( );
230 		draw_text( );
231 		break;
232 
233 		case ABOUT_CHECK:
234 		/* Return current presentation status */
235 		return about_active;
236 
237 		SWITCH_FAIL
238 	}
239 
240 	return FALSE;
241 }
242 
243 
244 /* end about.c */
245