Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

Menu.cpp

Go to the documentation of this file.
00001 
00007 #include "Menu.h"
00008 
00009 /********************************************************************
00010  * Constructor
00011  */
00012 Menu::Menu() {
00013         unsigned int i;
00014 
00015         for (i=0; i<MENU_OBJECTS; i++) {
00016                 m_objects[i] = NULL;
00017         }
00018 }
00019 
00020 /********************************************************************
00021  * Constructor
00022  */
00023 Menu::~Menu() {
00024         unload();
00025 }
00026 
00027 /********************************************************************
00028  * Load
00029  */
00030 bool Menu::load(Application *parent) {
00031         if (parent != NULL)
00032                 m_parent = parent;
00033 
00034         unsigned int i;
00035 
00036         g_music.play(50);
00037 
00038         //---------------------------------------------------------
00039         // Textures
00040         //---------------------------------------------------------
00041         if ((m_textures[MENU_TEX_CUBEMAP] = m_parent->renderer->addCubemap(
00042                                                                                 "data\\textures\\cubemaps\\stars\\test.bmp",
00043                                                                                 "data\\textures\\cubemaps\\stars\\test.bmp",
00044                                                                                 "data\\textures\\cubemaps\\stars\\test.bmp",
00045                                                                                 "data\\textures\\cubemaps\\stars\\test.bmp",
00046                                                                                 "data\\textures\\cubemaps\\stars\\test.bmp",
00047                                                                                 "data\\textures\\cubemaps\\stars\\test.bmp")) == TEXTURE_NONE) return false;
00048 
00049         if ((m_textures[MENU_TEX_PARTICLE] = m_parent->renderer->addTexture("data\\textures\\particles\\flare.bmp")) == TEXTURE_NONE) return false;
00050         if ((m_textures[MENU_TEX_SELECTION] = m_parent->renderer->addTexture("data\\textures\\menu\\selection.bmp")) == TEXTURE_NONE) return false;
00051 
00052         if ((m_textures[MENU_TEX_SERVER_NAME] = m_parent->renderer->addTexture("data\\textures\\menu\\input_server_name.bmp")) == TEXTURE_NONE) return false;
00053         if ((m_textures[MENU_TEX_PLAYER_NAME] = m_parent->renderer->addTexture("data\\textures\\menu\\input_player_name.bmp")) == TEXTURE_NONE) return false;
00054         if ((m_textures[MENU_TEX_MAX_PLAYERS] = m_parent->renderer->addTexture("data\\textures\\menu\\input_max_players.bmp")) == TEXTURE_NONE) return false;
00055         if ((m_textures[MENU_TEX_PORT_NUMBER] = m_parent->renderer->addTexture("data\\textures\\menu\\input_port_number.bmp")) == TEXTURE_NONE) return false;
00056         if ((m_textures[MENU_TEX_SUBMIT] = m_parent->renderer->addTexture("data\\textures\\menu\\input_submit.bmp")) == TEXTURE_NONE) return false;
00057         if ((m_textures[MENU_TEX_SERVER_IP] = m_parent->renderer->addTexture("data\\textures\\menu\\input_server_address.bmp")) == TEXTURE_NONE) return false;
00058 
00059         //---------------------------------------------------------
00060         // Objects
00061         //---------------------------------------------------------
00062         if (!loadModels()) return false;
00063 
00064         m_objects[MENU_OBJ_CUBEMAP] = new Cubemap(1.0f);
00065         m_objects[MENU_OBJ_BOX] = new Box(1.05f);
00066         m_objects[MENU_OBJ_SPHERE] = new Sphere(0.0f, 0.0f, 0.0f, 1.0f, 26);
00067         m_objects[MENU_OBJ_TUBE] = new Tube(18, 1.25f, 0.4f);
00068         m_objects[MENU_OBJ_PLANET] = new Sphere(0.0f, 0.0f, 0.0f, 0.5f, 16);
00069 
00070 
00071         //---------------------------------------------------------
00072         // Sounds
00073         //---------------------------------------------------------
00074         m_sounds[MENU_SOUND_SELECT].load("data\\sounds\\menu\\select.wav");
00075         m_sounds[MENU_SOUND_DOSELECT].load("data\\sounds\\menu\\doselect.wav");
00076 
00077 
00078         if (m_parent->renderer->lockFlags & LF_SHADING) {
00079                 if ((m_shader = m_parent->renderer->addShader("data\\shaders\\specular.cg")) == SHADER_NONE) return false;
00080         }
00081 
00082 
00083         //---------------------------------------------------------
00084         // Menus (main, create etc)
00085         //---------------------------------------------------------
00086         if (!loadMain()) return false;
00087         if (!loadCreate()) return false;
00088         if (!loadJoin()) return false;
00089         if (!loadSettings()) return false;
00090 
00091 
00092         //---------------------------------------------------------
00093         // Sun
00094         //---------------------------------------------------------
00095         m_vSun = Vec3(0.0f, 0.0f, -180.0f);
00096         m_particleSystem.loadPreset(PARTICLESYSTEM_SUN);
00097         m_particleSystem.start();
00098 
00099         if (GL_NV_occlusion_query_supported)
00100                 glGenOcclusionQueriesNV(1, &query);
00101 
00102 
00103         //---------------------------------------------------------
00104         // Planets
00105         //---------------------------------------------------------
00106         float n;
00107         srand(GetTickCount());
00108         for (i=0; i<MENU_PLANETS; i++) {
00109                 n = (float)i + 1.0f;
00110                 m_planets[i].dist = (RANDOM_NUM+1.0f)*85.0f;
00111                 m_planets[i].speed = 0.0010f*(RANDOM_NUM+1.0f) - m_planets[i].dist/100000.0f;
00112                 m_planets[i].speed *= 0.4f;
00113                 m_planets[i].rotation = Vec3(   RANDOM_NUM*50.0f - 25.0f,
00114                                                                                 RANDOM_NUM*50.0f - 25.0f,
00115                                                                                 RANDOM_NUM*50.0f - 25.0f
00116                                                                         );
00117         }
00118 
00119         m_parent->camera.setPosition(Vec3(-1.0f, 20.0f, 60.0f));
00120         m_parent->camera.setPitch(45.0f);
00121         m_parent->camera.setHeading(0.0f);
00122 
00123         //m_vLights[0] = Vec3(3.0f, 5.0f, 8.0f);
00124 
00125         // Disable all old lights
00126         for (i=0; i<GL_MAX_LIGHTS; i++) {
00127                 glDisable(GL_LIGHT0+i);
00128         }
00129 
00130         m_lights[0].pos = m_vSun;
00131         m_lights[0].clr = Vec3(1.0f, 1.0f, 1.0f);
00132 
00133         m_lights[1].pos = Vec3(3.0f, 5.0f, 8.0f);
00134         m_lights[1].clr = Vec3(0.7f, 0.7f, 0.8f);
00135 
00136         m_menu = MENU_MAIN;
00137         m_selection = MENU_MAIN_JOIN;
00138 
00139         m_selModel = 0;
00140 
00141         g_drawConsole = false;
00142         g_showFPS = false;
00143 
00144         // Disable all old lights
00145         //for (i=0; i<GL_MAX_LIGHTS; i++) {
00146         //      glDisable(GL_LIGHT0+i);
00147         //}
00148 
00149         LOG_SUCCESS(("Menu loaded"));
00150         m_loaded = true;
00151         return true;
00152 }
00153 
00154 /********************************************************************
00155  * Load main
00156  */
00157 bool Menu::loadMain() {
00158         if ((m_mainTextures[MENU_MAIN_CREDITS] = m_parent->renderer->addTexture("data\\textures\\planets\\planet1.bmp")) == TEXTURE_NONE) return false;
00159         if ((m_mainTextures[MENU_MAIN_CREATE] = m_parent->renderer->addTexture("data\\textures\\planets\\planet2.bmp")) == TEXTURE_NONE) return false;
00160         if ((m_mainTextures[MENU_MAIN_JOIN] = m_parent->renderer->addTexture("data\\textures\\planets\\planet3.bmp")) == TEXTURE_NONE) return false;
00161         if ((m_mainTextures[MENU_MAIN_SETTINGS] = m_parent->renderer->addTexture("data\\textures\\planets\\planet4.bmp")) == TEXTURE_NONE) return false;
00162         if ((m_mainTextures[MENU_MAIN_EXIT] = m_parent->renderer->addTexture("data\\textures\\planets\\planet5.bmp")) == TEXTURE_NONE) return false;
00163 
00164         int offset = MENU_MAIN_SELECTIONS;
00165         if ((m_mainTextures[MENU_MAIN_CREDITS + offset] = m_parent->renderer->addTexture("data\\textures\\menu\\credits.bmp")) == TEXTURE_NONE) return false;
00166         if ((m_mainTextures[MENU_MAIN_CREATE + offset] = m_parent->renderer->addTexture("data\\textures\\menu\\creategame.bmp")) == TEXTURE_NONE) return false;
00167         if ((m_mainTextures[MENU_MAIN_JOIN + offset] = m_parent->renderer->addTexture("data\\textures\\menu\\joingame.bmp")) == TEXTURE_NONE) return false;
00168         if ((m_mainTextures[MENU_MAIN_SETTINGS + offset] = m_parent->renderer->addTexture("data\\textures\\menu\\settings.bmp")) == TEXTURE_NONE) return false;
00169         if ((m_mainTextures[MENU_MAIN_EXIT + offset] = m_parent->renderer->addTexture("data\\textures\\menu\\exit.bmp")) == TEXTURE_NONE) return false;
00170 
00171         m_vMain[MENU_MAIN_CREDITS]      = Vec3(-7.5f, 2.0f,-6.0f);
00172         m_vMain[MENU_MAIN_CREATE]       = Vec3(-4.0f,-2.0f,-2.0f);
00173         m_vMain[MENU_MAIN_JOIN]         = Vec3( 0.0f, 0.0f, 4.0f);
00174         m_vMain[MENU_MAIN_SETTINGS]     = Vec3( 3.0f, 2.5f,-4.0f);
00175         m_vMain[MENU_MAIN_EXIT]         = Vec3( 4.0f, 1.5f, 4.0f);
00176 
00177         return true;
00178 }
00179 
00180 /********************************************************************
00181  * Load create
00182  */
00183 bool Menu::loadCreate() {
00184         m_vCreate = Vec3(20.0f, 17.5f, -125.0f);
00185 
00186         m_inputs[MENU_INPUT_CREATE_SERVER_NAME].type = MENU_INPUT_TYPE_STR;
00187         m_inputs[MENU_INPUT_CREATE_SERVER_NAME].str = "DeFacto";
00188         m_inputs[MENU_INPUT_CREATE_SERVER_NAME].strMin = 3;
00189         m_inputs[MENU_INPUT_CREATE_SERVER_NAME].strMax = 31;
00190         
00191         m_inputs[MENU_INPUT_CREATE_PORT].type = MENU_INPUT_TYPE_STR_INT;
00192         m_inputs[MENU_INPUT_CREATE_PORT].str = "22560";
00193         m_inputs[MENU_INPUT_CREATE_PORT].valMin = 1024;
00194         m_inputs[MENU_INPUT_CREATE_PORT].valMax = 65536;
00195         m_inputs[MENU_INPUT_CREATE_PORT].strMax = 5;
00196 
00197         m_inputs[MENU_INPUT_CREATE_MAX_PLAYERS].type = MENU_INPUT_TYPE_INT;
00198         m_inputs[MENU_INPUT_CREATE_MAX_PLAYERS].val = 8;
00199         m_inputs[MENU_INPUT_CREATE_MAX_PLAYERS].valMin = 2;
00200         m_inputs[MENU_INPUT_CREATE_MAX_PLAYERS].valMax = 16;
00201 
00202         m_inputs[MENU_INPUT_CREATE_PLAYER_NAME].type = MENU_INPUT_TYPE_STR;
00203         m_inputs[MENU_INPUT_CREATE_PLAYER_NAME].str = "Player 1";
00204         m_inputs[MENU_INPUT_CREATE_PLAYER_NAME].strMin = 3;
00205         m_inputs[MENU_INPUT_CREATE_PLAYER_NAME].strMax = 15;
00206 
00207         m_inputs[MENU_INPUT_CREATE_SUBMIT].type = MENU_INPUT_TYPE_SUBMIT;
00208         m_inputs[MENU_INPUT_CREATE_MODEL].type = MENU_INPUT_TYPE_MODEL;
00209 
00210         m_selected[MENU_CREATE] = MENU_INPUT_CREATE_INPUT_MIN;
00211 
00212         return true;
00213 }
00214 
00215 /********************************************************************
00216  * Load join
00217  */
00218 bool Menu::loadJoin() {
00219         m_vJoin = Vec3(-10.0f, -48.0f, -106.0f);
00220 
00221         m_inputs[MENU_INPUT_JOIN_SERVER_IP].type = MENU_INPUT_TYPE_STR;
00222         m_inputs[MENU_INPUT_JOIN_SERVER_IP].str = "";
00223         m_inputs[MENU_INPUT_JOIN_SERVER_IP].strMin = 3;
00224         m_inputs[MENU_INPUT_JOIN_SERVER_IP].strMax = 63;
00225         
00226         m_inputs[MENU_INPUT_JOIN_PORT].type = MENU_INPUT_TYPE_STR_INT;
00227         m_inputs[MENU_INPUT_JOIN_PORT].str = "22560";
00228         m_inputs[MENU_INPUT_JOIN_PORT].valMin = 1024;
00229         m_inputs[MENU_INPUT_JOIN_PORT].valMax = 65536;
00230         m_inputs[MENU_INPUT_JOIN_PORT].strMax = 5;
00231 
00232         m_inputs[MENU_INPUT_JOIN_PLAYER_NAME].type = MENU_INPUT_TYPE_STR;
00233         m_inputs[MENU_INPUT_JOIN_PLAYER_NAME].str = "Player 2";
00234         m_inputs[MENU_INPUT_JOIN_PLAYER_NAME].strMin = 3;
00235         m_inputs[MENU_INPUT_JOIN_PLAYER_NAME].strMax = 15;
00236 
00237         m_inputs[MENU_INPUT_JOIN_SUBMIT].type = MENU_INPUT_TYPE_SUBMIT;
00238         m_inputs[MENU_INPUT_JOIN_MODEL].type = MENU_INPUT_TYPE_MODEL;
00239 
00240         m_selected[MENU_JOIN] = MENU_INPUT_JOIN_INPUT_MIN;
00241 
00242         return true;
00243 }
00244 
00245 /********************************************************************
00246  * Load settings
00247  */
00248 bool Menu::loadSettings() {
00249         m_vSettings = Vec3(-26.0f, -11.0f, -245.0f);
00250 
00251         return true;
00252 }
00253 
00254 /********************************************************************
00255  * Unload
00256  */
00257 bool Menu::unload() {
00258         if (!m_loaded)
00259                 return false;
00260 
00261         unsigned int i;
00262 
00263         //---------------------------------------------------------
00264         // Textures
00265         //---------------------------------------------------------
00266         for (i=0; i<MENU_TEXTURES; i++) {
00267                 m_parent->renderer->deleteTexture(m_textures[i]);
00268         }
00269 
00270         for (i=0; i<MODELS; i++) {
00271                 m_parent->renderer->deleteTexture(m_texModels[i]);
00272         }
00273 
00274         //---------------------------------------------------------
00275         // Objects
00276         //---------------------------------------------------------
00277         for (i=0; i<MENU_OBJECTS; i++) {
00278                 if (m_objects[i]) {
00279                         m_objects[i]->clearVertexBuffer();
00280                         delete m_objects[i];
00281                 }
00282                 m_objects[i] = NULL;
00283         }
00284 
00285         //---------------------------------------------------------
00286         // Sounds
00287         //---------------------------------------------------------
00288         for (i=0; i<MENU_SOUNDS; i++) {
00289                 m_sounds[i].unload();
00290         }
00291 
00292 
00293         //---------------------------------------------------------
00294         // Menues
00295         //---------------------------------------------------------
00296         unloadMain();
00297         unloadCreate();
00298         unloadJoin();
00299         unloadSettings();
00300 
00301 
00302         //---------------------------------------------------------
00303         // Common
00304         //---------------------------------------------------------
00305         if (m_parent->renderer->lockFlags & LF_SHADING) {
00306                 m_parent->renderer->deleteShader(m_shader);
00307         }
00308 
00309         LOG_SUCCESS(("Menu unloaded"));
00310         m_loaded = false;
00311         return true;
00312 }
00313 
00314 /********************************************************************
00315  * Unload main
00316  */
00317 bool Menu::unloadMain() {
00318         unsigned int i;
00319 
00320         //---------------------------------------------------------
00321         // Textures
00322         //---------------------------------------------------------
00323         for (i=0; i<MENU_MAIN_TEXTURES; i++) {
00324                 m_parent->renderer->deleteTexture(m_mainTextures[i]);
00325         }
00326         return true;
00327 }
00328 
00329 /********************************************************************
00330  * Unload create
00331  */
00332 bool Menu::unloadCreate() {
00333         return true;
00334 }
00335 
00336 /********************************************************************
00337  * Unload join
00338  */
00339 bool Menu::unloadJoin() {
00340         return true;
00341 }
00342 
00343 /********************************************************************
00344  * Unload settings
00345  */
00346 bool Menu::unloadSettings() {
00347         return true;
00348 }
00349 
00350 /********************************************************************
00351  * Update
00352  */
00353 bool Menu::update() {
00354         if (!m_loaded)
00355                 return false;
00356 
00357         updateMain();
00358         updateCreate();
00359         updateJoin();
00360         updateSettings();
00361         updateCredits();
00362 
00363         return true;
00364 }
00365 
00366 /********************************************************************
00367  * Update main
00368  */
00369 void Menu::updateMain() {
00370         if (m_menu != MENU_MAIN)
00371                 return;
00372 
00373         if (m_parent->keys[VK_LEFT] || m_parent->keys[VK_DOWN]) {
00374                 m_selection--;
00375                 if (m_selection < 0) m_selection = MENU_MAIN_SELECTIONS-1;
00376                 m_sounds[MENU_SOUND_SELECT].play();
00377                 m_parent->keys[VK_LEFT] = false;
00378                 m_parent->keys[VK_DOWN] = false;
00379         }
00380 
00381         if (m_parent->keys[VK_RIGHT] || m_parent->keys[VK_UP]) {
00382                 m_selection++;
00383                 if (m_selection > MENU_MAIN_SELECTIONS-1) m_selection = 0;
00384                 m_sounds[MENU_SOUND_SELECT].play();
00385                 m_parent->keys[VK_RIGHT] = false;
00386                 m_parent->keys[VK_UP] = false;
00387         }
00388 
00389         if (m_parent->keys[13]) {
00390                 menuMainSelect();
00391                 m_sounds[MENU_SOUND_DOSELECT].play();
00392                 m_parent->keys[13] = false;
00393         }
00394 
00395         if (m_parent->keys[VK_ESCAPE]) {
00396                 PostMessage(m_parent->hWnd, WM_CLOSE, 0, 0);
00397                 m_parent->keys[VK_ESCAPE] = false;
00398         }
00399 
00400         Vec3 pos = m_vMain[m_selection] + Vec3( 0.0f, 0.5f, 8.0f);
00401 
00402         setCamera(pos, 0.0f, 0.0f);
00403 
00404         m_vSelection = m_vMain[m_selection];
00405 }
00406 
00407 /********************************************************************
00408  * Update create
00409  */
00410 void Menu::updateCreate() {
00411 
00412         if (m_menu != MENU_CREATE)
00413                 return;
00414 
00415         if (m_parent->keys[VK_UP]) {
00416                 m_selected[MENU_CREATE]--;
00417                 if (m_selected[MENU_CREATE] < MENU_INPUT_CREATE_INPUT_MIN) m_selected[MENU_CREATE] = MENU_INPUT_CREATE_INPUT_MAX;
00418                 m_sounds[MENU_SOUND_SELECT].play();
00419                 m_parent->keys[VK_UP] = false;
00420         }
00421 
00422         if (m_parent->keys[VK_DOWN]) {
00423                 m_selected[MENU_CREATE]++;
00424                 if (m_selected[MENU_CREATE] > MENU_INPUT_CREATE_INPUT_MAX) m_selected[MENU_CREATE] = MENU_INPUT_CREATE_INPUT_MIN;
00425                 m_sounds[MENU_SOUND_SELECT].play();
00426                 m_parent->keys[VK_DOWN] = false;
00427         }
00428 
00429         if (m_parent->keys[VK_ESCAPE]) {
00430                 m_menu = MENU_MAIN;
00431                 m_parent->keys[VK_ESCAPE] = false;
00432         }
00433 
00434         if (m_parent->keys[VK_LEFT]) {
00435                 handleChar(VK_LEFT);
00436                 m_parent->keys[VK_LEFT] = false;
00437         }
00438 
00439         if (m_parent->keys[VK_RIGHT]) {
00440                 handleChar(VK_RIGHT);
00441                 m_parent->keys[VK_RIGHT] = false;
00442         }
00443 
00444         Vec3 pos = Vec3(30.0f, 15.0f, -120.0f);
00445         setCamera(pos, 0.0f, -45.0f);
00446 }
00447 
00448 /********************************************************************
00449  * Update join
00450  */
00451 void Menu::updateJoin() {
00452 
00453         if (m_menu != MENU_JOIN)
00454                 return;
00455 
00456 
00457         if (m_parent->keys[VK_UP]) {
00458                 m_selected[MENU_JOIN]--;
00459                 if (m_selected[MENU_JOIN] < MENU_INPUT_JOIN_INPUT_MIN) m_selected[MENU_JOIN] = MENU_INPUT_JOIN_INPUT_MAX;
00460                 m_sounds[MENU_SOUND_SELECT].play();
00461                 m_parent->keys[VK_UP] = false;
00462         }
00463 
00464         if (m_parent->keys[VK_DOWN]) {
00465                 m_selected[MENU_JOIN]++;
00466                 if (m_selected[MENU_JOIN] > MENU_INPUT_JOIN_INPUT_MAX) m_selected[MENU_JOIN] = MENU_INPUT_JOIN_INPUT_MIN;
00467                 m_sounds[MENU_SOUND_SELECT].play();
00468                 m_parent->keys[VK_DOWN] = false;
00469         }
00470 
00471         if (m_parent->keys[VK_ESCAPE]) {
00472                 m_menu = MENU_MAIN;
00473                 m_parent->keys[VK_ESCAPE] = false;
00474         }
00475 
00476         if (m_parent->keys[VK_LEFT]) {
00477                 handleChar(VK_LEFT);
00478                 m_parent->keys[VK_LEFT] = false;
00479         }
00480 
00481         if (m_parent->keys[VK_RIGHT]) {
00482                 handleChar(VK_RIGHT);
00483                 m_parent->keys[VK_RIGHT] = false;
00484         }
00485 
00486         Vec3 pos = Vec3(-20.0f, -50.0f, -100.0f);
00487         setCamera(pos, -20.0f, 40.0f);
00488 }
00489 
00490 /********************************************************************
00491  * Update settings
00492  */
00493 void Menu::updateSettings() {
00494 
00495         if (m_menu != MENU_SETTINGS)
00496                 return;
00497 
00498         if (m_parent->keys[VK_ESCAPE]) {
00499                 m_menu = MENU_MAIN;
00500                 m_parent->keys[VK_ESCAPE] = false;
00501         }
00502 
00503         Vec3 pos = Vec3(-40.0f, -15.0f, -250.0f);
00504         setCamera(pos, 0.0f, 130.0f);
00505 }
00506 
00507 /********************************************************************
00508  * Update credits
00509  */
00510 void Menu::updateCredits() {
00511         if (m_menu != MENU_CREDITS)
00512                 return;
00513 
00514         static int trail = 2;
00515 
00516         if (m_parent->keys[VK_ESCAPE]) {
00517                 m_menu = MENU_MAIN;
00518                 m_parent->keys[VK_ESCAPE] = false;
00519         }
00520 
00521         if (m_camDist < 5.0f) {
00522                 trail++;
00523                 if (trail > 2) trail = 0;
00524         }
00525 
00526         Vec3 pos;
00527         switch (trail) {
00528                 case 0:
00529                         pos = Vec3(180.0f, 50.0f, -180.0f);
00530                         setCamera(pos, 35.0f, -90.0f, true);
00531                         break;
00532 
00533                 case 1:
00534                         pos = Vec3(0.0f, -25.0f, -300.0f);
00535                         setCamera(pos, -20.0f, -180.0f, true);
00536                         break;
00537 
00538                 case 2:
00539                         pos = Vec3(0.0f, 200.0f, -180.0f);
00540                         setCamera(pos, 90.0f, 0.0f, true);
00541                         break;
00542         }
00543 }
00544 
00545 /********************************************************************
00546  * Draw frame
00547  */
00548 bool Menu::drawFrame() {
00549         if (!m_loaded)
00550                 return false;
00551 
00552         float camHeading;
00553         float camPitch;
00554 
00555         camHeading = m_parent->camera.getHeading();
00556         camPitch = m_parent->camera.getPitch();
00557 
00558         m_parent->camera.setHeading(camHeading+sinf(g_time*0.0005f)*1.0f);
00559         m_parent->camera.setPitch(camPitch+sinf(g_time*0.00075f)*cosf(g_time*0.0005f)*1.0f);
00560 
00561         unsigned int i;
00562         m_inview = 0;
00563 
00564         for (i=0; i<MENU_LIGHTS; i++) {
00565                 glLightfv(GL_LIGHT0+i, GL_AMBIENT, m_lights[i].clr*0.2f);
00566                 glLightfv(GL_LIGHT0+i, GL_DIFFUSE, m_lights[i].clr);
00567                 glLightfv(GL_LIGHT0+i, GL_POSITION, Vec4(m_lights[i].pos, 0.5f));
00568                 glLightf(GL_LIGHT0+i, GL_CONSTANT_ATTENUATION, 1.0f);
00569                 glLightf(GL_LIGHT0+i, GL_LINEAR_ATTENUATION, 0.0f);
00570                 glLightf(GL_LIGHT0+i, GL_QUADRATIC_ATTENUATION, 0.0f);
00571                 glEnable(GL_LIGHT0+i);
00572         }
00573 
00574 
00575         glEnable(GL_CULL_FACE);
00576         glCullFace(GL_BACK);
00577 
00578         glDisable(GL_LIGHTING);
00579         //---------------------------------------------------------
00580         // Cube map
00581         //---------------------------------------------------------
00582         m_parent->camera.setPrespective(0.0f, false);
00583         m_parent->camera.setProjection(90.0f, g_width, g_height, 1.0f, 100.0f);
00584 
00585         glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
00586         
00587         glPushMatrix();
00588         {
00589                 m_parent->renderer->setTextures(m_textures[MENU_TEX_CUBEMAP]);
00590                 m_parent->renderer->setDepthFunc(DEPTH_NONE);
00591                 m_parent->renderer->apply();
00592 
00593                 glScalef(15.0f, -15.0f, 15.0f);
00594                 m_objects[MENU_OBJ_CUBEMAP]->draw();
00595         }
00596         glPopMatrix();
00597 
00598         m_parent->camera.setProjection(45.0f, g_width, g_height, 1.0f, 500.0f);
00599 
00600 
00601         //---------------------------------------------------------
00602         // Camera
00603         //---------------------------------------------------------
00604         m_parent->camera.setPrespective(g_frameTime*0.001f);
00605         m_parent->camera.updateFrustum();
00606 
00607 
00608         glEnable(GL_LIGHTING);
00609         //---------------------------------------------------------
00610         // Planets
00611         //---------------------------------------------------------
00612         Vec3 pos;
00613         for (i=0; i<MENU_PLANETS; i++) {
00614                 float sinfr = sinf(m_planets[i].speed*g_time);
00615                 pos.x = sinf(m_planets[i].speed*g_time)*m_planets[i].dist + sinfr*m_planets[i].rotation.x;;
00616                 pos.y = sinfr*m_planets[i].rotation.y;
00617                 pos.z = cosf(m_planets[i].speed*g_time)*m_planets[i].dist + sinfr*m_planets[i].rotation.z;
00618 
00619                 pos = pos + m_vSun;
00620 
00621                 if (m_parent->camera.sphereInFrustum(pos, 0.5f)) {
00622                         m_parent->renderer->setTextures(m_mainTextures[1+i%3]);
00623                         m_parent->renderer->apply();
00624 
00625                         glPushMatrix();
00626                                 glTranslatef(pos.x, pos.y, pos.z);
00627                                 m_objects[MENU_OBJ_PLANET]->draw();
00628                         glPopMatrix();
00629                         m_inview++;
00630                 }
00631         }
00632 
00633 
00634         //---------------------------------------------------------
00635         // Menus
00636         //---------------------------------------------------------
00637         drawMain();
00638         drawCreate();
00639         drawJoin();
00640         drawSettings();
00641         drawCredits();
00642 
00643 
00644         glDisable(GL_CULL_FACE);
00645 
00646         glDisable(GL_LIGHTING);
00647         //---------------------------------------------------------
00648         // Sun (particles)
00649         //---------------------------------------------------------
00650         glPushMatrix();
00651         {
00652                 m_parent->renderer->setDepthFunc(LEQUAL);
00653                 m_parent->renderer->setMask(COLOR);
00654                 m_parent->renderer->setTextures(m_textures[MENU_TEX_PARTICLE]);
00655                 m_parent->renderer->setBlending(ONE, ONE);
00656                 m_parent->renderer->apply();
00657 
00658                 glTranslatef(m_vSun.x,m_vSun.y, m_vSun.z);
00659                 glScalef(100.8f, 100.8f, 100.8f);
00660 
00661                 // ----- billboard (very very ugly) -----
00662                 Vec3 camPos = m_parent->camera.getPosition();
00663                 Vec3 camUp = m_parent->camera.getUp().normalize();
00664 
00665                 Vec3 camProj = camPos - m_vSun;
00666                 camProj.y = 0.0f;
00667 
00668                 Vec3 lookAt = Vec3(0.0f, 0.0f, 1.0f);
00669 
00670                 camProj = camProj.normalize();
00671 
00672                 Vec3 upAux = lookAt^camProj;
00673 
00674                 float angle = dot(lookAt, camProj);
00675                 if (angle < 0.9999f && angle > -0.9999f)
00676                         glRotatef(acosf(angle)*180.0f/PI, upAux.x, upAux.y, upAux.z);
00677 
00678                 Vec3 toCam = (camPos - m_vSun).normalize();
00679 
00680                 angle = dot(camProj, toCam);
00681 
00682                 if (angle < 0.9999f && angle > -0.9999f) {
00683                         if (toCam.y < 0.0f)
00684                                 glRotatef(cosf(angle)*180.0f/PI, 1.0f, 0.0f, 0.0f);
00685                         else
00686                                 glRotatef(cosf(angle)*180.0f/PI, -1.0f, 0.0f, 0.0f);
00687                 }
00688 
00689                 //-------
00690 
00691                 if (GL_NV_occlusion_query_supported) {
00692                         //glEnable(GL_DEPTH_TEST);
00693                         glBeginOcclusionQueryNV(query);
00694                         m_particleSystem.drawAndUpdate(&m_parent->camera, g_frameTime*0.001f, false, false);
00695                         glEndOcclusionQueryNV();
00696                         glFinish();
00697                         //glDisable(GL_DEPTH_TEST);
00698                 }
00699                 else {
00700                         m_particleSystem.drawAndUpdate(&m_parent->camera, g_frameTime*0.001f, false, false);
00701                 }
00702 
00703         }
00704         glPopMatrix();
00705         glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
00706 
00707         //---------------------------------------------------------
00708         // Selection
00709         //---------------------------------------------------------
00710         this->drawSelection();
00711 
00712         //---------------------------------------------------------
00713         // Sun (corona)
00714         //---------------------------------------------------------
00715         if (GL_NV_occlusion_query_supported) {
00716                 glPushMatrix();
00717                 {
00718                         m_parent->renderer->setDepthFunc(DEPTH_NONE);
00719                         m_parent->renderer->setTextures(m_textures[MENU_TEX_PARTICLE]);
00720                         m_parent->renderer->setMask(COLOR);
00721                         m_parent->renderer->setBlending(SRC_ALPHA, ONE);
00722                         m_parent->renderer->apply();
00723 
00724                         int nPixels = 0;
00725                         glGetOcclusionQueryivNV(query, GL_PIXEL_COUNT_NV, &nPixels);
00726 
00727                         glTranslatef(m_vSun.x, m_vSun.y, m_vSun.z);
00728                         glScalef(20.0f, 20.0f, 20.0f);
00729                         glColor3fv(Vec3(1,0.8f,0.1f) * (1.0f - expf(-nPixels * 1 / 10000.0f)));
00730 
00731                         float dx = 1.0f;
00732                         float dy = 1.0f;
00733                         glBegin(GL_QUADS);
00734                                 glNormal3f( 0.0f, 0.0f, 1.0f);
00735                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, 0.0f);
00736                                 glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, 0.0f);
00737                                 glVertex3f(-1.0f,-1.0f, 0.0f);
00738 
00739                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, 1.0f);
00740                                 glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, 1.0f);
00741                                 glVertex3f(-1.0f, 1.0f, 0.0f);
00742                                 
00743                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0f, 1.0f);
00744                                 glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0f, 1.0f);
00745                                 glVertex3f( 1.0f, 1.0f, 0.0f);
00746                                 
00747                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0f, 0.0f);
00748                                 glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0f, 0.0f);
00749                                 glVertex3f( 1.0f,-1.0f, 0.0f);
00750                         glEnd();
00751                 }
00752                 glPopMatrix();
00753 
00754                 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
00755         }
00764         m_parent->camera.setHeading(camHeading);
00765         m_parent->camera.setPitch(camPitch);
00766 
00767         m_parent->renderer->apply();
00768 
00769         return true;
00770 }
00771 
00772 /********************************************************************
00773  * Draw main
00774  */
00775 void Menu::drawMain() {
00776         unsigned int i;
00777 
00778         //glCullFace(GL_BACK);
00779 
00780         for (i=0; i<MENU_MAIN_SELECTIONS; i++) {
00781                 if (m_parent->camera.sphereInFrustum(m_vMain[i], 1.0f)) {
00782                         glPushMatrix();
00783                         {
00784                                 glTranslatef(m_vMain[i].x, m_vMain[i].y, m_vMain[i].z);
00785                                 glRotatef(g_time*0.003*(float)(i+1), 0.0f, 1.0f, 0.0f);
00786                                 m_parent->renderer->setMask(ALL);
00787                                 m_parent->renderer->setDepthFunc(LEQUAL);
00788                                 //m_parent->renderer->setShader(m_shader);
00789                                 m_parent->renderer->setTextures(m_mainTextures[i]);
00790                                 //m_parent->renderer->setTextures(m_texSphere[0]);
00791                                 m_parent->renderer->apply();
00792 
00793                                 //m_parent->renderer->changeShaderConstant3f("camPos", m_parent->camera.getPosition());
00794                                 //m_parent->renderer->changeShaderConstant3f("lightPos", m_vLights[0]);
00795 
00796                                 m_objects[MENU_OBJ_SPHERE]->draw();
00797 
00798                                 if (m_menu == MENU_MAIN) {
00799                                         glDisable(GL_LIGHTING);
00800                                         glDisable(GL_CULL_FACE);
00801                                         m_parent->renderer->setMask(COLOR);
00802                                         m_parent->renderer->setBlending(SRC_ALPHA, ONE);
00803                                         m_parent->renderer->setTextures(m_mainTextures[i+MENU_MAIN_SELECTIONS]);
00804                                         m_parent->renderer->apply();
00805 
00806                                         glRotatef(g_time*0.03f, 0.0f, 1.0f, 0.0f);
00807                                         m_objects[MENU_OBJ_TUBE]->draw();
00808                                         glEnable(GL_CULL_FACE);
00809                                         glEnable(GL_LIGHTING);
00810                                 }
00811                         }
00812                         glPopMatrix();
00813                         m_inview++;
00814                 }
00815         }
00816 
00817 }
00818 
00819 /********************************************************************
00820  * Draw selection
00821  */
00822 void Menu::drawSelection() {
00823         static float angle = 0.0f;
00824 
00825         angle += g_frameTime*0.03f;
00826         if (angle > 360.0f)
00827                 angle = 0.0f;
00828 
00829         if (m_menu == MENU_MAIN && m_selection != MENU_SELECTION_NONE) {
00830                 glPushMatrix();
00831                 glTranslatef(m_vSelection.x, m_vSelection.y, m_vSelection.z);
00832                 glRotatef(angle, 0.78f, 1.0f, 0.12f);
00833                 m_parent->renderer->setBlending(ONE, ONE);
00834                 m_parent->renderer->setMask(COLOR);
00835                 m_parent->renderer->setTextures(m_textures[MENU_TEX_SELECTION]);
00836                 m_parent->renderer->apply();
00837 
00838                 m_objects[MENU_OBJ_BOX]->draw();
00839                 glPopMatrix();
00840         }
00841 }
00842 
00843 /********************************************************************
00844  * Draw create
00845  */
00846 void Menu::drawCreate() {
00847 
00848         unsigned int i;
00849 
00850         if (m_parent->camera.sphereInFrustum(m_vCreate, 1.0f)) {
00851                 glPushMatrix();
00852                 {
00853                         glTranslatef(m_vCreate.x, m_vCreate.y, m_vCreate.z);
00854                         glRotatef(g_time*0.005, 0.0f, 1.0f, 0.0f);
00855                         m_parent->renderer->setMask(ALL);
00856                         m_parent->renderer->setDepthFunc(LEQUAL);
00857                         m_parent->renderer->setTextures(m_mainTextures[0]);
00858                         m_parent->renderer->apply();
00859 
00860                         m_objects[MENU_OBJ_SPHERE]->draw();
00861 
00862                         if (m_menu == MENU_CREATE) {
00863                                 glDisable(GL_LIGHTING);
00864                                 glDisable(GL_CULL_FACE);
00865                                 m_parent->renderer->setMask(COLOR);
00866                                 m_parent->renderer->setBlending(SRC_ALPHA, ONE);
00867                                 m_parent->renderer->setTextures(m_mainTextures[MENU_MAIN_CREATE + MENU_MAIN_SELECTIONS]);
00868                                 m_parent->renderer->apply();
00869 
00870                                 glRotatef(g_time*0.03f, 0.0f, 1.0f, 0.0f);
00871                                 m_objects[MENU_OBJ_TUBE]->draw();
00872                                 glEnable(GL_CULL_FACE);
00873                                 glEnable(GL_LIGHTING);
00874                         }
00875 
00876                 }
00877                 glPopMatrix();
00878                 m_inview++;
00879         }
00880 
00881         
00882         if (m_menu != MENU_CREATE || m_camDist > 80.0f)
00883                 return;
00884 
00885         glDisable(GL_LIGHTING);
00886         glDisable(GL_CULL_FACE);
00887 
00888 
00889         float ox = 135.0f;
00890         float oy = 257.0f;
00891         float selSize = 10.0f;
00892         Vec2 selPos;
00893 
00894         // select box
00895         selPos.x = ox - 25.0f;
00896 
00897         switch (m_selected[MENU_CREATE]) {
00898                 case MENU_INPUT_CREATE_SERVER_NAME:
00899                         selPos.y = oy + 12.5f;
00900                         break;
00901 
00902                 case MENU_INPUT_CREATE_PORT:
00903                         selPos.y = oy + 37.5f;
00904                         break;
00905 
00906                 case MENU_INPUT_CREATE_MAX_PLAYERS:
00907                         selPos.y = oy + 62.5f;
00908                         break;
00909 
00910                 case MENU_INPUT_CREATE_PLAYER_NAME:
00911                         selPos.y = oy + 112.5f;
00912                         break;
00913 
00914                 case MENU_INPUT_CREATE_SUBMIT:
00915                         selPos.y = oy + 212.5f;
00916                         break;
00917 
00918                 case MENU_INPUT_CREATE_MODEL:
00919                         selPos.y = oy + 162.0f;
00920                         selPos.x = ox + 19.0f + 55.0f*(float)m_selModel;
00921                         selSize = 25.0f;
00922                         break;
00923 
00924                 default:
00925                         break;
00926         }
00927 
00928         m_parent->defaultFont->startTextMode();
00929         m_parent->defaultFont->setColor(0.0f, 7.0f, 0.0f, 1.0f);
00930         m_parent->defaultFont->print(115.0f+ox, 18.0f+oy, "%s", m_inputs[MENU_INPUT_CREATE_SERVER_NAME].str);
00931         m_parent->defaultFont->print(115.0f+ox, 43.0f+oy, "%s", m_inputs[MENU_INPUT_CREATE_PORT].str);
00932         m_parent->defaultFont->print(115.0f+ox, 68.0f+oy, "%d", m_inputs[MENU_INPUT_CREATE_MAX_PLAYERS].val);
00933         m_parent->defaultFont->print(115.0f+ox, 118.0f+oy, "%s", m_inputs[MENU_INPUT_CREATE_PLAYER_NAME].str);
00934 
00935         glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
00936         drawLabel(MENU_TEX_SERVER_NAME, ox, oy);
00937         drawLabel(MENU_TEX_PORT_NUMBER, ox, 25.0f+oy);
00938         drawLabel(MENU_TEX_MAX_PLAYERS, ox, 50.0f+oy);
00939         drawLabel(MENU_TEX_PLAYER_NAME, ox, 100.0f+oy);
00940         drawLabel(MENU_TEX_SUBMIT, ox, 200.0f+oy);
00941 
00942         drawSelect(selPos, selSize);
00943 
00944         for (i=0; i<MODELS; i++) {
00945                 if (i == m_selModel)
00946                         drawQuad(m_texModels[i], ox+55.0f*(float)i-5.0f, oy+135.0f, 50.0f, 50.0f);
00947                 else
00948                         drawQuad(m_texModels[i], ox+55.0f*(float)i, oy+140.0f, 40.0f, 40.0f);
00949         }
00950 
00951         m_parent->defaultFont->endTextMode();
00952 
00953         glEnable(GL_CULL_FACE);
00954         glEnable(GL_LIGHTING);
00955 }
00956 
00957 /********************************************************************
00958  * Draw join
00959  */
00960 void Menu::drawJoin() {
00961         unsigned int i;
00962 
00963         if (m_parent->camera.sphereInFrustum(m_vJoin, 1.0f)) {
00964                 glPushMatrix();
00965                 {
00966                         glTranslatef(m_vJoin.x, m_vJoin.y, m_vJoin.z);
00967                         glRotatef(g_time*0.005, 0.0f, 1.0f, 0.0f);
00968                         m_parent->renderer->setMask(ALL);
00969                         m_parent->renderer->setDepthFunc(LEQUAL);
00970                         m_parent->renderer->setTextures(m_mainTextures[1]);
00971                         m_parent->renderer->apply();
00972 
00973                         m_objects[MENU_OBJ_SPHERE]->draw();
00974 
00975                         if (m_menu == MENU_JOIN) {
00976                                 glDisable(GL_LIGHTING);
00977                                 glDisable(GL_CULL_FACE);
00978                                 m_parent->renderer->setMask(COLOR);
00979                                 m_parent->renderer->setBlending(SRC_ALPHA, ONE);
00980                                 m_parent->renderer->setTextures(m_mainTextures[MENU_MAIN_JOIN + MENU_MAIN_SELECTIONS]);
00981                                 m_parent->renderer->apply();
00982 
00983                                 glRotatef(g_time*0.03f, 0.0f, 1.0f, 0.0f);
00984                                 m_objects[MENU_OBJ_TUBE]->draw();
00985                                 glEnable(GL_CULL_FACE);
00986                                 glEnable(GL_LIGHTING);
00987                         }
00988 
00989                 }
00990                 glPopMatrix();
00991                 m_inview++;
00992         }
00993 
00994         if (m_menu != MENU_JOIN || m_camDist > 80.0f)
00995                 return;
00996 
00997         glDisable(GL_LIGHTING);
00998         glDisable(GL_CULL_FACE);
00999 
01000 
01001         float ox = 135.0f;
01002         float oy = 257.0f;
01003         float selSize = 10.0f;
01004         Vec2 selPos;
01005 
01006         // select box
01007         selPos.x = ox - 25.0f;
01008 
01009         switch (m_selected[MENU_JOIN]) {
01010                 case MENU_INPUT_JOIN_SERVER_IP:
01011                         selPos.y = oy + 12.5f;
01012                         break;
01013 
01014                 case MENU_INPUT_JOIN_PORT:
01015                         selPos.y = oy + 37.5f;
01016                         break;
01017 
01018                 case MENU_INPUT_JOIN_PLAYER_NAME:
01019                         selPos.y = oy + 87.5f;
01020                         break;
01021 
01022                 case MENU_INPUT_JOIN_SUBMIT:
01023                         selPos.y = oy + 187.5f;
01024                         break;
01025 
01026                 case MENU_INPUT_JOIN_MODEL:
01027                         selPos.y = oy + 142.0f;
01028                         selPos.x = ox + 19.0f + 55.0f*(float)m_selModel;
01029                         selSize = 25.0f;
01030                         break;
01031 
01032                 default:
01033                         break;
01034         }
01035 
01036         m_parent->defaultFont->startTextMode();
01037         m_parent->defaultFont->setColor(0.0f, 7.0f, 0.0f, 1.0f);
01038         m_parent->defaultFont->print(135.0f+ox, 18.0f+oy, "%s", m_inputs[MENU_INPUT_JOIN_SERVER_IP].str);
01039         m_parent->defaultFont->print(135.0f+ox, 43.0f+oy, "%s", m_inputs[MENU_INPUT_JOIN_PORT].str);
01040         m_parent->defaultFont->print(135.0f+ox, 93.0f+oy, "%s", m_inputs[MENU_INPUT_JOIN_PLAYER_NAME].str);
01041 
01042         glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
01043         drawLabel(MENU_TEX_SERVER_IP, ox, oy);
01044         drawLabel(MENU_TEX_PORT_NUMBER, ox, 25.0f+oy);
01045         drawLabel(MENU_TEX_PLAYER_NAME, ox, 75.0f+oy);
01046         drawLabel(MENU_TEX_SUBMIT, ox, 175.0f+oy);
01047 
01048         drawSelect(selPos, selSize);
01049 
01050         for (i=0; i<MODELS; i++) {
01051                 if (i == m_selModel)
01052                         drawQuad(m_texModels[i], ox+55.0f*(float)i-5.0f, oy+115.0f, 50.0f, 50.0f);
01053                 else
01054                         drawQuad(m_texModels[i], ox+55.0f*(float)i, oy+120.0f, 40.0f, 40.0f);
01055         }
01056 
01057         m_parent->defaultFont->endTextMode();
01058 
01059         glEnable(GL_CULL_FACE);
01060         glEnable(GL_LIGHTING);
01061 }
01062 
01063 /********************************************************************
01064  * Draw settings
01065  */
01066 void Menu::drawSettings() {
01067 
01068         if (m_parent->camera.sphereInFrustum(m_vSettings, 1.0f)) {
01069                 glPushMatrix();
01070                 {
01071                         glTranslatef(m_vSettings.x, m_vSettings.y, m_vSettings.z);
01072                         glRotatef(g_time*0.005, 0.0f, 1.0f, 0.0f);
01073                         m_parent->renderer->setMask(ALL);
01074                         m_parent->renderer->setDepthFunc(LEQUAL);
01075                         m_parent->renderer->setTextures(m_mainTextures[2]);
01076                         m_parent->renderer->apply();
01077 
01078                         m_objects[MENU_OBJ_SPHERE]->draw();
01079 
01080                         //if (m_menu == MENU_SETTINGS) {
01081                                 glDisable(GL_LIGHTING);
01082                                 glDisable(GL_CULL_FACE);
01083                                 m_parent->renderer->setMask(COLOR);
01084                                 m_parent->renderer->setBlending(SRC_ALPHA, ONE);
01085                                 m_parent->renderer->setTextures(m_mainTextures[MENU_MAIN_SETTINGS + MENU_MAIN_SELECTIONS]);
01086                                 m_parent->renderer->apply();
01087 
01088                                 glRotatef(g_time*0.03f, 0.0f, 1.0f, 0.0f);
01089                                 m_objects[MENU_OBJ_TUBE]->draw();
01090                                 glEnable(GL_CULL_FACE);
01091                                 glEnable(GL_LIGHTING);
01092                         //}
01093 
01094                 }
01095                 glPopMatrix();
01096                 m_inview++;
01097         }
01098 
01099         if (m_menu != MENU_SETTINGS || m_camDist > 80.0f)
01100                 return;
01101 }
01102 
01103 /********************************************************************
01104  * Draw credits
01105  */
01106 void Menu::drawCredits() {
01107         if (m_menu != MENU_CREDITS)
01108                 return;
01109 
01110         glDisable(GL_LIGHTING);
01111 
01112         m_parent->defaultFont->startTextMode();
01113 
01114 
01115         m_parent->defaultFont->setColor(1.0f, 1.0f, 1.0f, 1.0f);
01116 
01117         m_parent->defaultFont->print((float)g_width/2.0f-75.0f, 125.0f, "DeFacto [reloaded]");
01118         m_parent->defaultFont->print((float)g_width/2.0f-85.0f, 175.0f, "and some nice text...");
01119 
01120         m_parent->defaultFont->endTextMode();
01121 
01122         glEnable(GL_LIGHTING);
01123 }
01124 
01125 /********************************************************************
01126  * Menu select
01127  */
01128 void Menu::menuMainSelect() {
01129         switch (m_selection) {
01130                 //---------------------------------------------------------
01131                 // Credits
01132                 //---------------------------------------------------------
01133                 case MENU_MAIN_CREDITS:
01134                         m_menu = MENU_CREDITS;
01135                         break;
01136 
01137                 //---------------------------------------------------------
01138                 // Create
01139                 //---------------------------------------------------------
01140                 case MENU_MAIN_CREATE:
01141                         m_menu = MENU_CREATE;
01142                         break;
01143 
01144                 //---------------------------------------------------------
01145                 // Join
01146                 //---------------------------------------------------------
01147                 case MENU_MAIN_JOIN:
01148                         m_menu = MENU_JOIN;
01149                         break;
01150 
01151                 //---------------------------------------------------------
01152                 // Settings
01153                 //---------------------------------------------------------
01154                 case MENU_MAIN_SETTINGS:
01155                         m_menu = MENU_SETTINGS;
01156                         break;
01157 
01158                 //---------------------------------------------------------
01159                 // Exit
01160                 //---------------------------------------------------------
01161                 case MENU_MAIN_EXIT:
01162                         PostMessage(m_parent->hWnd, WM_CLOSE, 0, 0);
01163                         break;
01164         }
01165 }
01166 
01167 /********************************************************************
01168  * Set camera
01169  */
01170 void Menu::setCamera(Vec3 pos, float pitch, float heading, bool soft) {
01171         Vec3 camPos = m_parent->camera.getPosition();
01172         float camPitch = m_parent->camera.getPitch();
01173         float camHeading = m_parent->camera.getHeading();
01174 
01175         Vec3 distVec = camPos - pos;
01176         float dist = distVec.length();
01177         m_camDist = dist;
01178         if (dist > 0.01f) {
01179                 if (soft)
01180                         pos = camPos - distVec.normalize() * g_frameTime * (dist < 5.0f ? dist : 5.0f) * 0.002f;
01181                 else
01182                         pos = camPos - distVec.normalize() * g_frameTime * (dist < 60.0f ? dist : 60.0f) * 0.002f;
01183         }
01184 
01185         dist = camHeading - heading;
01186         float absDist = (dist < 0.0f) ? -dist : dist;
01187         if (absDist > 0.01f) {
01188                 if (soft)
01189                         heading = camHeading - g_frameTime * (dist < 0.0f ? -0.002f : 0.002f) * (absDist < 1.5f ? absDist : 1.5f);
01190                 else
01191                         heading = camHeading - g_frameTime * (dist < 0.0f ? -0.002f : 0.002f) * (absDist < 25.0f ? absDist : 25.0f);
01192         }
01193 
01194         dist = camPitch - pitch;
01195         absDist = (dist < 0.0f) ? -dist : dist;
01196         if (absDist > 0.01f) {
01197                 if (soft)
01198                         pitch = camPitch - g_frameTime * (dist < 0.0f ? -0.002f : 0.002f) * (absDist < 2.5f ? absDist : 2.5f);
01199                 else
01200                         pitch = camPitch - g_frameTime * (dist < 0.0f ? -0.002f : 0.002f) * (absDist < 25.0f ? absDist : 25.0f);
01201         }
01202 
01203         m_parent->camera.setPosition(pos);
01204         m_parent->camera.setHeading(heading);
01205         m_parent->camera.setPitch(pitch);
01206 }
01207 
01208 /********************************************************************
01209  * Draw label
01210  */
01211 void Menu::drawLabel(TextureID tex, float x, float y) {
01212         float w = 200.0f;
01213         float h = w/8.0f;
01214 
01215         m_parent->renderer->setMask(COLOR);
01216         //m_parent->renderer->setDepthFunc(DEPTH_NONE);
01217         m_parent->renderer->setBlending(ONE, ONE);
01218         m_parent->renderer->setTextures(m_textures[tex]);
01219         m_parent->renderer->apply();
01220 
01221         glBegin(GL_QUADS);
01222                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 1);
01223                 glVertex2f(x, y);
01224 
01225                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 0);
01226                 glVertex2f(x, y+h);
01227 
01228                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 0);
01229                 glVertex2f(x+w, y+h);
01230 
01231                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 1);
01232                 glVertex2f(x+w, y);
01233         glEnd();
01234 }
01235 
01236 
01237 /********************************************************************
01238  * Draw select
01239  */
01240 void Menu::drawSelect(Vec2 pos, float size) {
01241         //float size = 10.0f;
01242 
01243         m_parent->renderer->setMask(COLOR);
01244         //m_parent->renderer->setDepthFunc(DEPTH_NONE);
01245         m_parent->renderer->setBlending(ONE, ONE);
01246         m_parent->renderer->setTextures(m_textures[MENU_TEX_SELECTION]);
01247         m_parent->renderer->apply();
01248 
01249         glPushMatrix();
01250 
01251         glTranslatef(pos.x, pos.y, 0.0f);
01252         glRotatef(g_time*0.1f, 0.0f, 0.0f, 1.0f);
01253         glBegin(GL_QUADS);
01254                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 1);
01255                 glVertex2f(-size, -size);
01256 
01257                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 0);
01258                 glVertex2f(-size, size);
01259 
01260                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 0);
01261                 glVertex2f(size, size);
01262 
01263                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 1);
01264                 glVertex2f(size, -size);
01265         glEnd();
01266 
01267         glPopMatrix();
01268 }
01269 
01270 /********************************************************************
01271  * Handle keys
01272  */
01273 void Menu::handleChar(char ch) {
01274         if (m_menu != MENU_CREATE && m_menu != MENU_JOIN)
01275                 return;
01276 
01277         SMenuInput *input;
01278 
01279         input = &m_inputs[m_selected[m_menu]];
01280 
01281         int pos = 0;
01282 
01283         switch (input->type) {
01284                 //---------------------------------------------------------
01285                 // Integer input
01286                 //---------------------------------------------------------
01287                 case MENU_INPUT_TYPE_INT:
01288                         if (ch == VK_LEFT)
01289                                 input->val--;
01290                         else if (ch == VK_RIGHT)
01291                                 input->val++;
01292 
01293                         if (input->val < input->valMin)
01294                                 input->val = input->valMin;
01295                         else if (input->val > input->valMax)
01296                                 input->val = input->valMax;
01297 
01298                         break;
01299 
01300                 //---------------------------------------------------------
01301                 // String input
01302                 //---------------------------------------------------------
01303                 case MENU_INPUT_TYPE_STR:
01304                         pos = input->str.getLength();
01305 
01306                         if (ch == VK_BACK) {
01307                                 if (pos > 0)
01308                                         input->str.remove(--pos, 1);
01309                                 return;
01310                         }
01311                         else if (pos >= input->strMax)
01312                                 return;
01313                         else if (!isprint(ch))
01314                                 return;
01315 
01316                         input->str.insert(pos++, (const char *)&ch, 1);
01317                         break;
01318 
01319                 //---------------------------------------------------------
01320                 // String Integer input
01321                 //---------------------------------------------------------
01322                 case MENU_INPUT_TYPE_STR_INT:
01323                         pos = input->str.getLength();
01324 
01325                         if (ch == VK_BACK) {
01326                                 if (pos > 0)
01327                                         input->str.remove(--pos, 1);
01328                                 return;
01329                         }
01330                         else if (pos >= input->strMax)
01331                                 return;
01332                         else if (!isprint(ch) || ch < '0' || ch > '9')
01333                                 return;
01334 
01335                         input->str.insert(pos++, (const char *)&ch, 1);
01336                         break;
01337 
01338                 //---------------------------------------------------------
01339                 // Submit input
01340                 //---------------------------------------------------------
01341                 case MENU_INPUT_TYPE_SUBMIT:
01342                         if (ch != 13)
01343                                 return;
01344 
01345                         if (m_menu == MENU_CREATE) {
01346                                 int len = strlen(m_inputs[MENU_INPUT_CREATE_SERVER_NAME].str);
01347                                 if (len < m_inputs[MENU_INPUT_CREATE_SERVER_NAME].strMin) {
01348                                         m_inputs[MENU_INPUT_CREATE_SERVER_NAME].str = "DeFacto server";
01349                                 }
01350 
01351                                 len = strlen(m_inputs[MENU_INPUT_CREATE_PLAYER_NAME].str);
01352                                 if (len < m_inputs[MENU_INPUT_CREATE_PLAYER_NAME].strMin) {
01353                                         m_inputs[MENU_INPUT_CREATE_PLAYER_NAME].str = "Player 1";
01354                                 }
01355 
01356                                 //len = m_inputs[MENU_INPUT_CREATE_PORT].val;
01357                                 //if (len < m_inputs[MENU_INPUT_CREATE_PORT].valMin || len > m_inputs[MENU_INPUT_CREATE_PORT].valMax) {
01358                                 //      m_inputs[MENU_INPUT_CREATE_PORT].val = m_inputs[MENU_INPUT_CREATE_PORT].valMax;
01359                                 //}
01360 
01361                                 // start server, jump to galaxy selection
01362                                 g_gameInfo.isServer = true;
01363                                 if (gne) delete gne;
01364                                 gne = NULL;
01365                                 gne = new Gne();
01366                                 gne->init(true);
01367                                 gne->setPort(atoi(m_inputs[MENU_INPUT_CREATE_PORT].str));
01368                                 gne->setMaxPlayers(m_inputs[MENU_INPUT_CREATE_MAX_PLAYERS].val);
01369                                 gne->setPlayerInfoSelf((char *)(const char *)m_inputs[MENU_INPUT_CREATE_PLAYER_NAME].str);
01370                                 gne->startServer();
01371                                 g_myPlayerID = gne->getPlayerIdSelf();
01372 
01373                                 Player *p;
01374                                 p = gne->getPlayerById(g_myPlayerID);
01375                                 strcpy(g_players[g_myPlayerID].name, p->getName());
01376                                 g_players[g_myPlayerID].model = m_selModel;
01377 
01378                                 console.addEx(Vec3(0.0f, 0.0f, 1.0f), "Server started");
01379                                 g_selectedScene = SCENE_JOIN;
01380 
01381                         }
01382                         else if (m_menu == MENU_JOIN) {
01383                                 int len = strlen(m_inputs[MENU_INPUT_JOIN_SERVER_IP].str);
01384                                 if (len < m_inputs[MENU_INPUT_JOIN_SERVER_IP].strMin) {
01385                                         m_inputs[MENU_INPUT_JOIN_SERVER_IP].str = "defacto.mine.nu";
01386                                 }
01387 
01388                                 len = strlen(m_inputs[MENU_INPUT_JOIN_PLAYER_NAME].str);
01389                                 if (len < m_inputs[MENU_INPUT_JOIN_PLAYER_NAME].strMin) {
01390                                         m_inputs[MENU_INPUT_JOIN_PLAYER_NAME].str = "Player 2";
01391                                 }
01392 
01393                                 // setup client and join
01394                                 g_gameInfo.isServer = false;
01395                                 if (gne) delete gne;
01396                                 gne = NULL;
01397                                 gne = new Gne();
01398                                 gne->init(false);
01399                                 gne->setPort(atoi(m_inputs[MENU_INPUT_CREATE_PORT].str));
01400                                 //gne->setMaxPlayers(15);
01401                                 gne->setPlayerInfoSelf((char *)(const char *)m_inputs[MENU_INPUT_JOIN_PLAYER_NAME].str);
01402 
01403                                 if (gne->joinServer((char *)(const char *)m_inputs[MENU_INPUT_JOIN_SERVER_IP].str) == -1) {
01404                                         console.addEx(Vec3(1.0f, 0.0f, 0.0f), "Failed to join server '%s'", (char *)(const char *)m_inputs[MENU_INPUT_JOIN_SERVER_IP].str);
01405                                 }
01406                                 else {
01407                                         g_myPlayerID = gne->getPlayerIdSelf();
01408                                         Player *p;
01409                                         p = gne->getPlayerById(g_myPlayerID);
01410                                         strcpy(g_players[g_myPlayerID].name, p->getName());
01411                                         g_players[g_myPlayerID].model = m_selModel;
01412 
01413                                         gne->updatePlayersFromServer();
01414                                         console.addEx(Vec3(0.0f, 0.0f, 1.0f), "Joining server '%s'", (char *)(const char *)m_inputs[MENU_INPUT_JOIN_SERVER_IP].str);
01415                                         g_selectedScene = SCENE_JOIN;
01416                                 }
01417 
01418                         }
01419                         break;
01420 
01421                 //---------------------------------------------------------
01422                 // Model selection
01423                 //---------------------------------------------------------
01424                 case MENU_INPUT_TYPE_MODEL:
01425                         if (ch == VK_LEFT)
01426                                 m_selModel--;
01427                         else if (ch == VK_RIGHT)
01428                                 m_selModel++;
01429 
01430                         if (m_selModel < 0)
01431                                 m_selModel = MODELS-1;
01432                         else if (m_selModel > MODELS-1)
01433                                 m_selModel = 0;
01434 
01435                         break;
01436                 default:
01437                         break;
01438         };
01439 }
01440 
01441 /********************************************************************
01442  * Load models
01443  */
01444 bool Menu::loadModels() {
01445         if (!setModel(MODEL_ROBOT1, "robot1.txt", "robot1.bmp", "robot1.bmp")) return false;
01446         if (!setModel(MODEL_ROBOT2, "robot1.txt", "robot2.bmp", "robot2.bmp")) return false;
01447         if (!setModel(MODEL_VIPER,      "viper.txt", "viper.bmp", "viper.bmp")) return false;
01448 
01449         return true;
01450 }
01451 
01452 /********************************************************************
01453  * Set model
01454  */
01455 bool Menu::setModel(unsigned int model, const char *file, const char *skin, const char *avatar) {
01456         g_allModels[model].isSet = true;
01457         strcpy(g_allModels[model].file, file);
01458 
01459         sprintf(g_allModels[model].skin, "data\\textures\\skins\\%s", skin);
01460         sprintf(g_allModels[model].avatar, "data\\textures\\avatars\\%s", avatar);
01461 
01462         if ((m_texModels[model] = m_parent->renderer->addTexture(g_allModels[model].avatar)) == TEXTURE_NONE) return false;
01463 
01464         return true;
01465 }
01466 
01467 /********************************************************************
01468  * Draw quad
01469  */
01470 void Menu::drawQuad(TextureID tex, float x, float y, float w, float h) {
01471         //float w = 200.0f;
01472         //float h = w/8.0f;
01473 
01474         m_parent->renderer->setMask(COLOR);
01475         //m_parent->renderer->setDepthFunc(DEPTH_NONE);
01476         m_parent->renderer->setBlending(ONE, ONE);
01477         m_parent->renderer->setTextures(tex);
01478         m_parent->renderer->apply();
01479 
01480         glBegin(GL_QUADS);
01481                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 1);
01482                 glVertex2f(x, y);
01483 
01484                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 0);
01485                 glVertex2f(x, y+h);
01486 
01487                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 0);
01488                 glVertex2f(x+w, y+h);
01489 
01490                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 1);
01491                 glVertex2f(x+w, y);
01492         glEnd();
01493 }

Generated on Sun Jun 5 15:47:04 2005 for Defacto by  doxygen 1.4.3