AnoPlib - Animlets are not Particles library
|
00001 /* ************************************************************************* 00002 @file AnoP.h 00003 @project AnoPlib 00004 @module AnoPexamples 00005 @brief Some examples 00006 @date 25.04.2009 00007 @copyright Daniel Krajzewicz 00008 @licence GPL 00009 @author Daniel Krajzewicz 00010 @email d.krajzewicz@googlemail.com 00011 ------------------------------------------------------------------ 00012 AnoPlib - small "animlet" library, see http://sf.net/projects/anoplib 00013 Copyright (C) 2009-2010 Daniel Krajzewicz 00014 00015 This program is free software: you can redistribute it and/or modify 00016 it under the terms of the GNU General Public License as published by 00017 the Free Software Foundation, either version 3 of the License, or 00018 (at your option) any later version. 00019 00020 This program is distributed in the hope that it will be useful, 00021 but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 GNU General Public License for more details. 00024 00025 You should have received a copy of the GNU General Public License 00026 along with this program. If not, see <http://www.gnu.org/licenses/>. 00027 ------------------------------------------------------------------ 00028 Remarks: 00029 ------------------------------------------------------------------ 00030 ToDo: 00031 * *********************************************************************** */ 00032 /* ========================================================================= 00033 * included modules 00034 * ======================================================================= */ 00035 #ifdef _WIN32 00036 #include <windows.h> 00037 #include <glut.h> 00038 #else 00039 #include <GL/glut.h> 00040 #endif 00041 00042 #include <stdio.h> 00043 #include <string.h> 00044 #include <algorithm> 00045 #include <AnoP.h> 00046 #include <AnoPhelpers.h> 00047 #include <math.h> 00048 #include <iostream> 00049 #include <vector> 00050 // examples 00051 #include <AnoPemergency1.h> 00052 #include <AnoPflashlight1.h> 00053 #include <AnoPstarfield1.h> 00054 #include <AnoPtentacle1.h> 00055 #include <AnoPwavelogo1.h> 00056 #include <AnoPwavepropagation1.h> 00057 00058 00059 /* ========================================================================= 00060 * used namespaces 00061 * ======================================================================= */ 00062 using namespace std; 00063 00064 00065 /* ========================================================================= 00066 * global variables 00067 * ======================================================================= */ 00068 // glut window 00069 int win; 00070 00071 // "Anop" text (actually "ANOP") 00072 string anopText[] = { 00073 " xxxx xx xx xxxx xxxxx ", 00074 " xxxxxx xx xx xxxxxx xxxxxx ", 00075 " xx xx xxx xx xx xx xx xx ", 00076 " xx xx xxx xx xx xx xx xx ", 00077 " xxxxxx xxxxxx xx xx xxxxxx ", 00078 " xxxxxx xxxxxx xx xx xxxxx ", 00079 " xx xx xx xxx xx xx xx ", 00080 " xx xx xx xxx xx xx xx ", 00081 " xx xx xx xx xxxxxx xx ", 00082 " xx xx xx xx xxxx xx " 00083 }; 00084 00085 // pointers to AnoP examples 00086 vector<AnoP::AnoPsystemBase*> anop; 00087 00088 // index of currently shown system 00089 int shown = 0; 00090 00091 // some performance measuring variables 00092 int frame=0,currentTime,timebase=0; 00093 00094 // a text buffer 00095 char s[11]; 00096 00097 00098 /* ========================================================================= 00099 * glut stuff 00100 * ======================================================================= */ 00101 void menu(int value){ 00102 if(value == 0){ 00103 glutDestroyWindow(win); 00104 exit(0); 00105 } else { 00106 shown = value - 1; 00107 } 00108 glutPostRedisplay(); 00109 } 00110 00111 00112 void 00113 display(void) 00114 { 00115 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 00116 anop[shown]->renderAll(0, 0); 00117 frame++; 00118 currentTime=glutGet(GLUT_ELAPSED_TIME); 00119 if (currentTime - timebase > 1000) { 00120 sprintf(s,"FPS:%4.2f", frame*1000.0/(currentTime-timebase)); 00121 timebase = currentTime; 00122 frame = 0; 00123 } 00124 glutSetWindowTitle( s ); 00125 glutSwapBuffers(); 00126 } 00127 00128 00129 void 00130 init() 00131 { 00132 /* Enable a single OpenGL light. */ 00133 glDisable(GL_LIGHT0); 00134 glDisable(GL_LIGHTING); 00135 /* Use depth buffering for hidden surface elimination. */ 00136 glEnable(GL_DEPTH_TEST); 00137 glEnable(GL_ALPHA_TEST); 00138 /* Setup the view of the cube. */ 00139 glMatrixMode(GL_PROJECTION); 00140 glLoadIdentity(); 00141 glMatrixMode(GL_MODELVIEW); 00142 glLoadIdentity(); 00143 glTranslated(-1,-1,0); 00144 glScaled(1./20, 1./20, 1.); 00145 glTranslated(0,15,0); 00146 } 00147 00148 00149 void createMenu(void){ 00150 glutCreateMenu(menu); 00151 glutAddMenuEntry("Wireless#1", 1); 00152 glutAddMenuEntry("Wave Logo#1", 2); 00153 glutAddMenuEntry("Starfield#1", 3); 00154 glutAddMenuEntry("Emergency#1", 4); 00155 glutAddMenuEntry("Signal#1", 5); 00156 glutAddMenuEntry("Tentacle#1", 6); 00157 glutAddMenuEntry("Quit", 0); 00158 glutAttachMenu(GLUT_RIGHT_BUTTON); 00159 } 00160 00161 00162 /* ========================================================================= 00163 * main 00164 * ======================================================================= */ 00165 int 00166 main(int argc, char **argv) 00167 { 00168 AnoPhelpers::init(); 00169 // wireless effect 00170 AnoPwavepropagation1 *awp = new AnoPwavepropagation1(5); 00171 for(int i=0; i<5; ++i) { 00172 wireless1Struct s; 00173 s.pos[0] = (double) rand() / (double) (RAND_MAX-1) * 400.; 00174 s.pos[1] = (double) rand() / (double) (RAND_MAX-1) * 400.; 00175 s.step = (double) rand() / (double) (RAND_MAX-1) * 500.; 00176 awp->addAnimlet(s); 00177 } 00178 anop.push_back(awp); 00179 // wave effect 00180 AnoPwavelogo1 *awl = new AnoPwavelogo1(1); 00181 for(unsigned int y=0; y<10; ++y) { 00182 for(unsigned int x=0; x<anopText[y].length(); ++x) { 00183 if(anopText[y][x]!=' ') { 00184 waveStruct s; 00185 s.step = ((x+y)*10)%360; 00186 s.pos[0] = x; 00187 s.pos[1] = 10-y; 00188 awl->addAnimlet(s); 00189 } 00190 } 00191 } 00192 anop.push_back(awl); 00193 // starfield effect 00194 AnoPstarfield1 *asf = new AnoPstarfield1(1000); 00195 for(int i=0; i<1000; ++i) { 00196 starfield1Struct s; 00197 s.pos[0] = (double) rand() / (double) (RAND_MAX-1) * 40.; 00198 s.pos[1] = (double) rand() / (double) (RAND_MAX-1) * 10.; 00199 s.speed = (double) rand() / (double) (RAND_MAX-1) * .1; 00200 asf->addAnimlet(s); 00201 } 00202 anop.push_back(asf); 00203 // emergency effect 00204 AnoPemergency1 *ae = new AnoPemergency1(10); 00205 for(int i=0; i<10; ++i) { 00206 emergency1Struct s; 00207 s.pos[0] = (double) rand() / (double) (RAND_MAX-1) * 400.; 00208 s.pos[1] = (double) rand() / (double) (RAND_MAX-1) * 400.; 00209 s.step = (double) rand() / (double) (RAND_MAX-1) * 360.; 00210 ae->addAnimlet(s); 00211 } 00212 anop.push_back(ae); 00213 // red signal effect 00214 AnoPflashlight1 *afl = new AnoPflashlight1(40); 00215 for(int i=0; i<40; ++i) { 00216 flashSignal1Struct s; 00217 s.pos[0] = 10 * double(i); 00218 s.pos[1] = 10 * double(i); 00219 s.step = i * 10; 00220 afl->addAnimlet(s); 00221 } 00222 anop.push_back(afl); 00223 // tentacle 00224 AnoPtentacle1 *at = new AnoPtentacle1(40); 00225 for(int i=0; i<40; ++i) { 00226 at->addAnimlet(i); 00227 } 00228 anop.push_back(at); 00229 // run 00230 glutInit(&argc, argv); 00231 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); 00232 win = glutCreateWindow("AnoPlib examples"); 00233 glutDisplayFunc(display); 00234 glutIdleFunc(display); 00235 createMenu(); 00236 glClearColor(0.0,0.0,0.0,0.0); 00237 init(); 00238 glutMainLoop(); 00239 AnoPhelpers::close(); 00240 return 0; 00241 }