35 static const bool DEV_MODE =
true;
47 {
"toggleFullscreen", 5},
61 App * example =
new App( className );
74 fptr[0] = &App::showFrameRate;
75 fptr[1] = &App::showFrameTime;
76 fptr[2] = &App::showSpeed;
77 fptr[3] = &App::showResolution;
80 fptr[6] = &App::showHelp;
81 fptr[7] = &App::devMode;
82 fptr[8] = &App::switchColors;
86 handlingSpeedMultiplyer = 5 * 0.01;
90 m_showFrameRate = m_showFrameTime = m_showResolution =
true;
92 m_switchColors =
false;
97 currentSystemInfoNumber = 7;
105 systemInfoViewAngle = -25.0;
106 systemInfoViewAngle2 = -10.0;
111 cameraSystemView->setPos( 0, 0, 0 );
112 cameraSystemView->setSpeed( lightspeed * 0.2 );
165 static int planetToDraw = -1;
166 static bool showBox =
false;
168 switch( currentScreen ) {
182 unsigned char *image = 0;
184 glReadPixels( 0, 0,
getWindow()->getWidth(),
getWindow()->getHeight(), GL_RGB, GL_UNSIGNED_BYTE, image );
248 drawHelpEnvironment();
260 drawHelpMarketplace();
275 glMatrixMode( GL_PROJECTION );
279 glMatrixMode( GL_MODELVIEW );
283 glDisable( GL_TEXTURE_2D );
285 glColor3fv( colorLightGrey );
290 int messageWidth = 38 * writingWidth;
291 int messageHeight = 8 * writingHeight;
294 int buttonWidth = 90;
295 int buttonHeight = 2*writingHeight;
297 glColor3fv( colorDarkGrey );
298 Shapes::drawRect( xCenter - 2*writingWidth - buttonWidth*0.5, yCenter - messageHeight*0.5 + writingHeight + buttonHeight*0.5, 0, buttonWidth, buttonHeight);
299 Shapes::drawRect( xCenter + 2*writingWidth + buttonWidth*0.5, yCenter - messageHeight*0.5 + writingHeight + buttonHeight*0.5, 0, buttonWidth, buttonHeight);
302 bool overYes =
mouse->
isMouseOverRectCenter(xCenter - 2*writingWidth - buttonWidth*0.5,
getWindow()->getHeight() - (yCenter - messageHeight*0.5 + writingHeight + buttonHeight*0.5), buttonWidth, buttonHeight);
303 bool overNo =
mouse->
isMouseOverRectCenter(xCenter + 2*writingWidth + buttonWidth*0.5,
getWindow()->getHeight() - (yCenter - messageHeight*0.5 + writingHeight + buttonHeight*0.5), buttonWidth, buttonHeight);
306 glEnable( GL_TEXTURE_2D );
307 glEnable( GL_BLEND );
308 glColor4fv( colorWhite );
309 if( planetToDraw == -1)
312 tf2->
print( xCenter - messageWidth*0.5 + 2*writingHeight,
313 yCenter + messageHeight*0.5 - 3 * writingHeight,
318 glColor3fv( colorDarkRed );
319 tf2->
print( xCenter - 2*writingWidth - buttonWidth*0.5 - 1.5*writingWidth,
320 yCenter - messageHeight*0.5 + writingHeight + buttonHeight*0.5 - 0.5*writingHeight,
323 glColor3fv( colorWhite );
328 tf2->
print( xCenter - 2*writingWidth - buttonWidth*0.5 - 1.5*writingWidth,
329 yCenter - messageHeight*0.5 + writingHeight + buttonHeight*0.5 - 0.5*writingHeight,
333 glColor3fv( colorDarkRed );
334 tf2->
print( xCenter + 2*writingWidth + buttonWidth*0.5 - writingWidth,
335 yCenter - messageHeight*0.5 + writingHeight + buttonHeight*0.5 - 0.5*writingHeight,
338 glColor3fv( colorWhite );
343 tf2->
print( xCenter + 2*writingWidth + buttonWidth*0.5 - writingWidth,
344 yCenter - messageHeight*0.5 + writingHeight + buttonHeight*0.5 - 0.5*writingHeight,
347 glDisable( GL_BLEND );
350 glMatrixMode( GL_PROJECTION );
352 glMatrixMode( GL_MODELVIEW );
364 void App::drawCurrentSystem() {
367 if( m_showFrameTime )
369 if( m_showFrameRate )
371 if( m_showResolution )
392 glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
394 glRotatef( 90, 1, 0, 0 );
396 gluSphere( quadObj, 100, 32, 32 );
402 glClear( GL_DEPTH_BUFFER_BIT );
405 for(
unsigned int i=0; i < objects->size(); i++ ) {
410 objects->at(i)->draw();
413 glDisable( GL_CULL_FACE );
415 glDisable( GL_LIGHTING );
416 glDisable( GL_LIGHT0 );
417 glEnable( GL_BLEND );
419 glColor3fv( colorRed );
438 float winkel = acos(cosval) / ANGLE2DEG;
441 winkel = 180 - winkel;
446 Vector3 aimToLeft = aimTo + absbla * -5.0f;
447 Vector3 aimToRight = aimTo + absbla * 5.0f;
448 Vector3 aimFromLeft = aimFrom + absbla * -5;
449 Vector3 aimFromRight = aimFrom + absbla * 5;
451 glEnable( GL_BLEND );
453 glTexCoord2f( 0, 1 );
454 glVertex3f( aimFromLeft.
x, aimFromLeft.
y, aimFromLeft.
z );
455 glTexCoord2f( 0, 0 );
456 glVertex3f( aimToLeft.
x, aimToLeft.
y, aimToLeft.
z );
457 glTexCoord2f( 1, 0 );
458 glVertex3f( aimToRight.
x, aimToRight.
y, aimToRight.
z );
459 glTexCoord2f( 1, 1 );
460 glVertex3f( aimFromRight.
x, aimFromRight.
y, aimFromRight.
z );
462 Plane aimPlane =
Plane(aimToLeft, aimToRight, aimFromRight);
464 aimToLeft = aimTo + absblaOrtho * -5.0f;
465 aimToRight = aimTo + absblaOrtho * 5.0f;
466 aimFromLeft = aimFrom + absblaOrtho * -5;
467 aimFromRight = aimFrom + absblaOrtho * 5;
469 glTexCoord2f( 0, 1 );
470 glVertex3f( aimFromLeft.
x, aimFromLeft.
y, aimFromLeft.
z );
471 glTexCoord2f( 0, 0 );
472 glVertex3f( aimToLeft.
x, aimToLeft.
y, aimToLeft.
z );
473 glTexCoord2f( 1, 0 );
474 glVertex3f( aimToRight.
x, aimToRight.
y, aimToRight.
z );
475 glTexCoord2f( 1, 1 );
476 glVertex3f( aimFromRight.
x, aimFromRight.
y, aimFromRight.
z );
478 glDisable( GL_BLEND );
479 glEnable( GL_TEXTURE_2D );
481 glEnable( GL_LIGHTING );
483 glEnable( GL_CULL_FACE );
494 glEnable( GL_BLEND );
496 glDisable( GL_LIGHTING );
497 glDisable( GL_LIGHT0 );
499 glColor3fv( colorRed );
509 glTexCoord2f( 0, 1 );
510 glVertex3f( obenLinks.
x, obenLinks.
y, obenLinks.
z );
511 glTexCoord2f( 0, 0 );
512 glVertex3f( untenLinks.
x, untenLinks.
y, untenLinks.
z );
513 glTexCoord2f( 1, 0 );
514 glVertex3f( untenRechts.
x, untenRechts.
y, untenRechts.
z );
515 glTexCoord2f( 1, 1 );
516 glVertex3f( obenRechts.
x, obenRechts.
y, obenRechts.
z );
522 glTexCoord2f( 1, 1 );
523 glVertex3f( obenLinks.
x, obenLinks.
y, obenLinks.
z );
524 glTexCoord2f( 1, 0 );
525 glVertex3f( untenLinks.
x, untenLinks.
y, untenLinks.
z );
526 glTexCoord2f( 0, 0 );
527 glVertex3f( untenRechts.
x, untenRechts.
y, untenRechts.
z );
528 glTexCoord2f( 0, 1 );
529 glVertex3f( obenRechts.
x, obenRechts.
y, obenRechts.
z );
533 glEnable( GL_LIGHTING );
534 glEnable( GL_LIGHT0 );
543 setProjectionOrthogonal();
544 glEnable( GL_BLEND );
545 glColor3fv( colorWhite );
546 printInfoBox(
true );
560 glTexCoord2f( 0, 1 );
561 glVertex3f(-sightSize*2 + x, sightSize + y, 0);
562 glTexCoord2f( 0, 0 );
563 glVertex3f(-sightSize*2 + x,-sightSize + y, 0);
564 glTexCoord2f( 1, 0 );
565 glVertex3f( sightSize*2 + x,-sightSize + y, 0);
566 glTexCoord2f( 1, 1 );
567 glVertex3f( sightSize*2 + x, sightSize + y, 0);
571 glColor3fv( colorLightGrey);
578 glTexCoord2f( 0, 1 );
579 glVertex3f(-sightSize + x, sightSize + y, 0);
580 glTexCoord2f( 0, 0 );
581 glVertex3f(-sightSize + x,-sightSize + y, 0);
582 glTexCoord2f( 1, 0 );
583 glVertex3f( sightSize + x,-sightSize + y, 0);
584 glTexCoord2f( 1, 1 );
585 glVertex3f( sightSize + x, sightSize + y, 0);
589 glDisable( GL_BLEND );
601 glTexCoord2f( 0, 1 );
602 glVertex3f(-sightSize + x, sightSize + y, 0);
603 glTexCoord2f( 0, 0 );
604 glVertex3f(-sightSize + x,-sightSize + y, 0);
605 glTexCoord2f( 1, 0 );
606 glVertex3f( sightSize + x,-sightSize + y, 0);
607 glTexCoord2f( 1, 1 );
608 glVertex3f( sightSize + x, sightSize + y, 0);
610 glEnable( GL_BLEND );
613 glColor3fv( colorWhite );
614 tf2->
print( 10, 76,
"Laser heat:" );
615 laserHeatBar->
draw( 10, 55, 250, 16 );
616 glColor3fv( colorWhite );
618 speedBar->
draw( 10, 20, 250, 16 );
619 glDisable( GL_BLEND );
622 glPushAttrib( GL_ALL_ATTRIB_BITS );
623 glDisable( GL_TEXTURE_2D );
629 glEnable( GL_BLEND );
630 glEnable( GL_TEXTURE_2D );
631 glColor3fv( colorWhite );
633 glDisable( GL_BLEND );
634 glDisable( GL_TEXTURE_2D );
638 glColor3fv( colorWhite );
639 glEnable( GL_BLEND );
640 glEnable( GL_TEXTURE_2D );
654 glDisable( GL_TEXTURE_2D );
655 glDisable( GL_BLEND );
672 void App::drawGameOver() {
673 glDisable( GL_LIGHTING );
674 glDisable( GL_LIGHT0 );
675 glDisable( GL_BLEND );
676 glDisable( GL_TEXTURE_2D );
679 glClearColor( 0.0f, 0.0f, 0.0f, 0.2f );
680 glClear( GL_COLOR_BUFFER_BIT );
682 glMatrixMode( GL_MODELVIEW );
686 glTranslatef( 0.0f, 0.0f, -1.0f );
687 glColor3fv( colorWhite );
688 glRasterPos2f(-0.5,0.3);
689 bf->
print(
"Thank you for playing our Game!");
690 glRasterPos2f(-0.5, 0.15);
692 glRasterPos2f(-0.5, 0.1);
693 bf->
print(
"by Melanie Schmidt & Jan-Philipp Kappmeier");
694 glRasterPos2d(-0.5,-0.3);
696 glRasterPos2d(-0.5,-0.4);
697 bf->
print(
"Press any key to exit.");
706 void App::drawHelp() {
707 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
709 setProjectionOrthogonal();
712 glEnable( GL_BLEND );
713 glColor3fv( colorWhite );
716 printInfoLine(
"copyright 2006 - 2007, Melanie Schmidt & Jan-Philipp Kappmeier");
718 printInfoLine(
"Global keyboard commands (just press the key):" );
719 printInfoLine(
" e - show 3D environment in current system." );
720 printInfoLine(
" i - show system information for current system." );
724 printInfoLine(
"Global console commands (press RETURN, enter command, press RETURN):" );
725 printInfoLine(
" toggleFullscreen [0|1] - switch to fullscreen or back." );
726 printInfoLine(
" showFPS [0|1] - show frames per second or not." );
727 printInfoLine(
" showFrameTime [0|1] - show time per frame in milliseconds or not." );
728 printInfoLine(
" showSpeed [0|1] - show player speed in absolute values and percent of lightspeed or not." );
729 printInfoLine(
" showRes [0|1] - show current resolution or not." );
730 printInfoLine(
" devmode [0|1] - enables developer mode or disables." );
734 printInfoLine(
"To get further information, there exist different help sites for each screen." );
735 printInfoLine(
"Just type in one of the following commands at console:" );
736 printInfoLine(
" help info - gives information about the current system screen." );
737 printInfoLine(
" help local - gives information about the local systems view." );
738 printInfoLine(
" help env - gives information about the 3D environment." );
740 printInfoBox(
true );
747 glDisable( GL_BLEND );
756 void App::drawHelpEnvironment() {
757 glClear( GL_COLOR_BUFFER_BIT );
759 setProjectionOrthogonal();
762 glEnable( GL_BLEND );
763 glColor3fv( colorWhite );
766 printInfoLine(
"copyright 2006 - 2007, Melanie Schmidt & Jan-Philipp Kappmeier");
768 printInfoLine(
"Keyboard commands for 3D-environment screen (in addition to usual keys):" );
779 printInfoBox(
true );
786 glDisable( GL_BLEND );
788 restoreProjection();}
794 void App::drawHelpInfo() {
795 glClear( GL_COLOR_BUFFER_BIT );
797 setProjectionOrthogonal();
799 glEnable( GL_BLEND );
800 glColor3fv( colorWhite );
803 printInfoLine(
"copyright 2006 - 2007, Melanie Schmidt & Jan-Philipp Kappmeier");
805 printInfoLine(
"Keyboard commands for info screen (in addition to usual keys):" );
810 printInfoBox(
true );
817 glDisable( GL_BLEND );
826 void App::drawHelpLocal() {
827 glClear( GL_COLOR_BUFFER_BIT );
829 setProjectionOrthogonal();
832 glEnable( GL_BLEND );
833 glColor3fv( colorWhite );
836 printInfoLine(
"copyright 2006 - 2007, Melanie Schmidt & Jan-Philipp Kappmeier");
838 printInfoLine(
"Keyboard commands for local screen (in addition to usual keys):" );
841 printInfoLine(
"- go over a system to see information about it (only possible if system is in local range)" );
842 printInfoLine(
"- click on a system to perform jump (only possible if system is reachable)" );
843 printInfoLine(
"- confirm jump in messagebox (after clicking on a reachable system)" );
845 printInfoBox(
true );
852 glDisable( GL_BLEND );
861 void App::drawHelpMarketplace() {
862 glClear( GL_COLOR_BUFFER_BIT );
864 setProjectionOrthogonal();
867 glEnable( GL_BLEND );
868 glColor3fv( colorWhite );
871 printInfoLine(
"copyright 2006 - 2007, Melanie Schmidt & Jan-Philipp Kappmeier");
875 printInfoLine(
"Keyboard commands for marketplace screen:" );
878 printInfoLine(
"- click on tradegood button - mark the good for selling / buying " );
879 printInfoLine(
"- click on buy / sell button - buys / sells one unit of the market good" );
884 printInfoLine(
"- you can only buy goods that are available" );
885 printInfoLine(
"- you can only buy goods that fit into your cargo bay (only tonnes count)" );
886 printInfoLine(
"- you can only buy goods if you have enough money" );
888 printInfoLine(
"- you cannot buy more fuel than fits into your tank" );
891 printInfoLine(
"- you can only sell goods that you have in your cargo bay" );
894 printInfoBox(
true );
901 glDisable( GL_BLEND );
914 void App::drawLocalSystems() {
915 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
928 glMatrixMode( GL_PROJECTION );
938 glMatrixMode( GL_MODELVIEW );
957 int envWidth = maxPos.
x - minPos.
x;
958 int envHeight = maxPos.
y - minPos.
y;
964 float scaleFactor =
min( (
float)(
getWindow()->getWidth()-border) / (
float) envWidth, (
float)(
getWindow()->getHeight()-border) / (
float) envHeight );
965 float xOffset =
max( border*0.5, (
getWindow()->getWidth() - border-scaleFactor*envWidth )*0.5 );
966 float yOffset =
max( border*0.5, (
getWindow()->getHeight()- border-scaleFactor*envHeight)*0.5 );
969 float xPlus =
max( 0.0f, (
float)((
float)(
getWindow()->getWidth() -border) - ((maxPos.
x - minPos.
x) * scaleFactor + xOffset)) / scaleFactor);
970 float yPlus =
max( 0.0f, (
float)((
float)(
getWindow()->getHeight()-border) - ((maxPos.
y - minPos.
y) * scaleFactor + yOffset)) / scaleFactor);
973 max( 1.0f, minPos.
y - yPlus ),
978 for(
unsigned int i = 0; i < localSystems->size(); i++ ) {
979 Star *sun =
new Star( (localSystems->at(i).pos.x - minPos.
x) * scaleFactor + xOffset,
980 getWindow()->
getHeight()+border*0.5-((localSystems->at(i).pos.y - minPos.
y) * scaleFactor + yOffset),
993 glPushAttrib( GL_ALL_ATTRIB_BITS );
1000 glEnable( GL_BLEND );
1001 glColor3fv( colorWhite );
1014 bool alreadyHighlighted =
false;
1015 for(
unsigned int i=0; i<localSystems->size(); i++) {
1016 rectPosStart.
x = (localSystems->at(i).pos.x - minPos.
x) * scaleFactor + xOffset;
1017 rectPosEnd.
y =
getWindow()->
getHeight()+border*0.5-((localSystems->at(i).pos.y - minPos.
y) * scaleFactor + yOffset);
1018 int paintPosy = rectPosEnd.
y;
1021 rectPosStart.
y = rectPosEnd.
y - size;
1022 rectPosEnd.
x = rectPosStart.
x + width * localSystems->at(i).name.length();
1029 && !alreadyHighlighted
1033 hoveredSystem = localSystems->at(i);
1038 glColor3fv( colorRed );
1040 glColor3fv( colorYellow );
1044 localSystems->at(i).name.c_str()
1047 alreadyHighlighted =
true;
1051 glColor3fv( colorYellow );
1053 glColor3fv( colorWhite );
1056 localSystems->at(i).name.c_str()
1068 int infoPosx = (hoveredSystem.
pos.
x - minPos.
x) * scaleFactor + xOffset;
1069 int infoPosy =
getWindow()->
getHeight()+border*0.5-((hoveredSystem.
pos.
y - minPos.
y) * scaleFactor + yOffset);
1076 tf2->
print( infoPosx, infoPosy - lines++*size, economy.c_str() );
1077 tf2->
print( infoPosx, infoPosy - lines++*size,
"Population: %d", hoveredSystem.
population );
1078 tf2->
print( infoPosx, infoPosy - lines++*size,
"Productivity: %d", hoveredSystem.
productivity );
1079 tf2->
print( infoPosx, infoPosy - lines++*size,
"Technology level: %d", hoveredSystem.
techLevel );
1080 tf2->
print( infoPosx, infoPosy - lines++*size, government.c_str() );
1084 glColor3fv( colorWhite );
1089 glDisable( GL_BLEND );
1092 glDisable( GL_TEXTURE_2D );
1101 glEnable( GL_TEXTURE_2D );
1104 glMatrixMode( GL_PROJECTION );
1106 glMatrixMode( GL_MODELVIEW );
1119 void App::drawMarketplace() {
1121 glClearColor( 0.0f, 0.0f, 0.0f, 0.2f );
1122 glClear( GL_COLOR_BUFFER_BIT );
1127 size_t numOfTradegoods = mktbuttons.size();
1129 for (
unsigned int i =0; i < numOfTradegoods; i++)
1130 mktbuttons.at(i)->switchOn();
1134 float tabularheight = 0.75;
1135 float tabular = 0.05;
1136 float headlines = tabular;
1137 float buysell = tabular+0.02;
1138 float infos = buysell+0.06;
1139 float helplines = tabularheight+infos+0.03;
1140 float helplineheight = 0.02;
1144 this->setProjectionOrthogonal();
1151 unsigned int startx = wwidth / 4;
1152 unsigned int jumpy = wheight*tabularheight / (numOfTradegoods+1);
1154 for (
unsigned int i=0; i < numOfTradegoods; i++)
1156 mktbuttons.at(i)->setCenter(startx,wheight-(i+1)*jumpy-tabular*wheight);
1157 mktbuttons.at(i)->setWindowDimensions(wwidth,wheight);
1162 if (mktbuttons.size()>0)
1163 leftdrift = (mktbuttons.at(0)->getButtonWidth())/2.0f;
1166 buybutton->
setCenter(startx-leftdrift+rightdrift, wheight-(numOfTradegoods+1)*jumpy-buysell*wheight);
1169 rightdrift = leftdrift;
1172 sellbutton->
setCenter(startx-leftdrift+rightdrift, wheight-(numOfTradegoods+1)*jumpy-buysell*wheight);
1177 std::vector<bool> buyable;
1178 std::vector<bool> sellable;
1179 buyable.reserve(numOfTradegoods);
1180 sellable.reserve(numOfTradegoods);
1184 for (
unsigned int i = 0; i < numOfTradegoods-1; i++)
1186 buyable.push_back( !
World::getWorld()->tradegoodIsInTons(i) || (freeHoldspace > 0) );
1187 sellable.push_back(
true );
1193 sellable.push_back(
false);
1199 glPushAttrib( GL_ALL_ATTRIB_BITS );
1201 glEnable( GL_TEXTURE_2D );
1202 glDisable( GL_LIGHTING );
1203 glEnable( GL_BLEND );
1209 if (mktbuttons.size()>0)
1210 downdrift = (mktbuttons.at(0)->getButtonInnerHeight())/2.0f;
1214 if (mktbuttons.size()>0)
1215 rightdrift = (mktbuttons.at(0)->getButtonWidth())*0.75;
1217 glColor3fv(colorWhite);
1218 tf2->
print(startx+rightdrift, wheight-headlines*wheight-downdrift,
"Price");
1220 for (
unsigned int i=0; i < numOfTradegoods; i++)
1223 if (i < numOfTradegoods-1)
1225 price = mktplace->at(i).price;
1232 if (currentCash >= price)
1233 glColor3fv(colorGreen);
1237 glColor3fv(colorWhite);
1240 tf2->
print(startx+rightdrift, wheight-(i+1)*jumpy-tabular*wheight-downdrift,
"%3.1f",price);
1248 if (mktbuttons.size()>0)
1249 rightdrift = (mktbuttons.at(0)->getButtonWidth())*1.5;
1251 glColor3fv(colorWhite);
1252 tf2->
print(startx+rightdrift, wheight-headlines*wheight-downdrift,
"Market");
1254 for (
unsigned int i=0; i < numOfTradegoods-1; i++)
1257 if (mktplace->at(i).amount > 0)
1258 glColor3fv(colorGreen);
1261 glColor3fv(colorWhite);
1266 const char * unit = sunit.c_str();
1268 tf2->
print(startx+rightdrift, wheight-(i+1)*jumpy-tabular*wheight-downdrift,
"%d %s",mktplace->at(i).amount, unit);
1279 if (mktbuttons.size()>0)
1280 rightdrift = (mktbuttons.at(0)->getButtonWidth())*2.25;
1282 glColor3fv(colorWhite);
1283 tf2->
print(startx+rightdrift, wheight-headlines*wheight-downdrift,
"Cargo");
1285 for (
unsigned int i=0; i < numOfTradegoods; i++)
1287 if (i < numOfTradegoods-1)
1289 if (currentCargo->at(i)>0)
1290 glColor3fv(colorGreen);
1293 glColor3fv(colorWhite);
1294 sellable[i] =
false;
1298 const char * unit = sunit.c_str();
1300 tf2->
print(startx+rightdrift, wheight-(i+1)*jumpy-tabular*wheight-downdrift,
"%d %s",currentCargo->at(i),unit);
1305 glColor3fv(colorWhite);
1306 tf2->
print(startx+rightdrift, wheight-(i+1)*jumpy-tabular*wheight-downdrift,
"%3.1f %s",fuelamount,
"LY");
1311 glColor3fv(colorWhite);
1314 if (mktbuttons.size()>0)
1315 leftdrift = (mktbuttons.at(0)->getButtonWidth())/2.0f;
1320 tf2->
print(startx-leftdrift, wheight-(numOfTradegoods+1)*jumpy-infos*wheight,
"Cash: %3.1fFuel: %3.1fHoldSpace: %i",
World::getWorld()->getCurrentCash(),fuelamount,
World::getWorld()->getFreeHoldspace());
1323 tf2->
print(startx-leftdrift, wheight-helplines*wheight,
"- Click on item you want to buy / sell.");
1324 tf2->
print(startx-leftdrift, wheight-helplineheight*wheight-helplines*wheight,
"- Click on buy / sell to buy / sell one unit of the chosen tradegood.");
1328 for (
unsigned int i=0; i < numOfTradegoods; i++)
1330 if (!sellable[i] && !buyable[i])
1331 mktbuttons.at(i)->deactivateButton();
1333 mktbuttons.at(i)->activateButton();
1336 if (chosenButton > -1 && buyable[chosenButton])
1340 if (chosenButton > -1 && sellable[chosenButton])
1348 ClickableObject::clickAll();
1351 bool noButton =
true;
1352 for (
unsigned int i = 0; i < numOfTradegoods; i++)
1354 if (mktbuttons.at(i)->isClicked())
1357 if ( chosenButton == -1 )
1362 {
if ( chosenButton != i )
1364 mktbuttons.at(chosenButton)->noClick();
1389 ClickableObject::drawAll();
1391 for (
unsigned int i =0; i < numOfTradegoods; i++)
1392 mktbuttons.at(i)->switchOff();
1404 this->restoreProjection();
1415 void App::drawSystemInfo() {
1417 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
1420 float projectionSize = 1000.0f;
1421 glMatrixMode( GL_PROJECTION );
1424 static float nearClip = -1;
1425 static float clipSize;
1426 if( nearClip <= 0) {
1429 double val = (M_PI * 76.5)/ 180.0;
1430 double len1 = (projectionSize * (double)0.5) / ( cos(val) );
1433 double len2 = sqrt( (
double)(projectionSize*0.5)*(
double)(projectionSize*0.5) + len1*len1 );
1434 nearClip = (float)(len2-projectionSize*0.5);
1436 clipSize = (nearClip / len2) * projectionSize*0.5;
1438 glFrustum( -clipSize*
getWindow()->getAspect(), clipSize*
getWindow()->getAspect(), -clipSize, clipSize, nearClip, nearClip+projectionSize+1000);
1444 glMatrixMode( GL_MODELVIEW );
1449 glRotatef( systemInfoViewAngle, 1, 0, 0 );
1450 glRotatef( systemInfoViewAngle2, 0, 0, 1 );
1453 vector<PlanetInfoGraphical> planets;
1465 for(
unsigned int i = 0; i < planets.size(); i++) {
1470 size_t numberOfPlanets = planets.size();
1473 float scaleFactor = (projectionSize * 0.5) / sysSize;
1479 Star *sun =
new Star( 0, 0, 0, 2*zoomFactor*10,
star );
1485 glPushAttrib( GL_ALL_ATTRIB_BITS );
1491 for(
unsigned int i=0; i < planets.size(); i++) {
1507 glMatrixMode( GL_PROJECTION );
1509 glMatrixMode( GL_MODELVIEW );
1515 glMatrixMode(GL_PROJECTION);
1519 glMatrixMode( GL_MODELVIEW );
1524 glEnable( GL_BLEND );
1525 glColor3fv( colorRed );
1528 string name =
"Name: " + sysinfo.
name;
1530 string description =
"Description: " + sysinfo.
description;
1549 printInfoBox(
true );
1556 glDisable( GL_BLEND );
1559 glMatrixMode( GL_PROJECTION );
1561 glMatrixMode( GL_MODELVIEW );
1579 glClearColor( 0.0f, 0.0f, 0.0f, 0.2f );
1580 glClear( GL_COLOR_BUFFER_BIT );
1582 glTranslatef( 0.0f, 0.0f, -1.0f );
1583 glColor3fv( colorWhite );
1584 glRasterPos2f(-0.5,0.3);
1585 bf->
print(
"Progetto per Grafica al Calcolatore");
1586 glRasterPos2f(-0.5, 0.15);
1587 bf->
print(
"Jan-Philipp Kappmeier");
1588 glRasterPos2f(-0.5, 0.1);
1590 glRasterPos2d(-0.5,-0.3);
1591 bf->
print(
"Loading in progress. Please stand by ...");
1592 glRasterPos2d(-0.5,-0.4);
1593 bf->
print(
"Press 'help' at console for possible commands. (To show console press 'Return'.)");
1602 quadObj = gluNewQuadric();
1603 gluQuadricDrawStyle( quadObj, GLU_FILL );
1604 gluQuadricTexture( quadObj, GL_TRUE );
1617 laserHeatBar =
new HudLoadBar( 0.0f, 100.0f, 0.0f );
1622 initializeObjects();
1663 void App::initializeGFX(
void ) {
1665 glShadeModel( GL_SMOOTH );
1666 glClearDepth( 1.0f );
1667 glEnable( GL_DEPTH_TEST );
1668 glDepthFunc( GL_LEQUAL );
1669 glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
1671 glEnable( GL_TEXTURE_2D );
1672 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_COLOR );
1675 GLfloat ambient_light[] = { 0.0, 0.0, 0.0, 1.0};
1676 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient_light);
1677 GLfloat infinite[] = {0.0};
1678 glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, infinite);
1679 GLfloat one_side[] = {0.0};
1680 glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, one_side);
1683 GLfloat ambient_light_sun[] = { 0.35f, 0.35f, 0.35f, 1.0};
1684 glLightfv( GL_LIGHT0, GL_AMBIENT, ambient_light_sun );
1685 GLfloat specular_light_sun[] = { 0.0f, 0.0f, 0.0f, 1.0};
1686 glLightfv( GL_LIGHT0, GL_SPECULAR, specular_light_sun );
1694 void App::initMarketplace() {
1699 int innerBorder = 2;
1700 int outerBorder = 2;
1704 mktbuttons.reserve(numOfTradegoods+2);
1706 for (
int i=0; i < numOfTradegoods-1; i++)
1711 mktbuttons.push_back(
new Button(innerBorder,outerBorder,
mouse,
"Fuel",tf3,12));
1713 buybutton =
new Button(innerBorder,outerBorder,
mouse,
"Buy",tf3,4);
1714 sellbutton =
new Button(innerBorder,outerBorder,
mouse,
"Sell",tf3,4);
1724 void App::initializeObjects() {
1742 for(
unsigned int i=0; i <256; i++)
1754 if( !m_inputmode ) {
1766 m_inputmode =
false;
1772 performConsoleInput();
1777 setScreen( currentSystem );
1787 setScreen( localSystems );
1794 unsigned char *image = 0;
1798 glReadPixels( 0, 0,
getWindow()->getWidth(),
getWindow()->getHeight(), GL_RGB, GL_UNSIGNED_BYTE, image );
1805 sprintf_s( space,
"screenshot%d.tga", rand() );
1806 file.open( space, ios::binary );
1809 loader->
write( space );
1821 if( DEV_MODE &&
getWindow()->keyPressed( 78 ) ) {
1828 switch( currentScreen ) {
1832 performCurrentSystemInput( deltaTime );
1847 performLocalSystemsInput( deltaTime );
1850 performSystemInfoInput( deltaTime );
1855 switch( currentScreen ) {
1859 updateCurrentSystem( deltaTime );
1874 updateLocalSystems( deltaTime );
1877 updateSystemInfo( deltaTime );
1889 void App::stationWasHit(){
1891 for (
unsigned int i = 0; i < pships->size(); i++)
1893 pships->at(i)->stationWasHit();
1907 void App::updateCurrentSystem( DWORD deltaTime ) {
1928 for(
unsigned int i=0; i < objects->size(); i++ ) {
1930 float distance = v.
length();
1932 if( distance <shieldDist) {
1940 for(
unsigned i=0; i < ships->size(); i++ ) {
1941 ships->at(i)->update( deltaTime );
1942 if( ships->at(i)->isShooting() ) {
1957 for(
unsigned int i=0; i < ships->size()+1; i++ ) {
1964 if (i < ships->size())
1966 myPos = ships->
at(i)->getPos();
1967 myRadius = ships->at(i)->getRadius();
1971 myPos = myStation->
getPos();
1983 scalar = scalar / v.
length();
1984 Vector3 projectionPosition = p + v * scalar;
1985 Vector3 distance = projectionPosition - c;
1986 float distanceToRay = distance.
length();
1987 if( distanceToRay < myRadius ) {
1994 pfact = (projectionPosition.
x - p.x) / v.
x;
1996 pfact = (projectionPosition.
y - p.y) / v.
y;
1998 pfact = (projectionPosition.
z - p.z) / v.
z;
2001 if (i < ships->size())
2002 ships->at(i)->receiveHitFront( deltaTime );
2004 this->stationWasHit();
2019 void App::updateSystemInfo( DWORD deltaTime ) {
2022 void App::updateLocalSystems( DWORD deltaTime ) {
2029 void App::performConsoleInput() {
2031 if(
getWindow()->keyPressed( VK_BACK ) ) {
2035 for(
int i = 32; i < 128; i++) {
2038 if( i > 64 && i < 92 && !
getWindow()->keyPressed( 16 ) ) {
2054 void App::performCurrentSystemInput( DWORD deltaTime ) {
2093 if(
getWindow()->keyPressed( VK_UP ) ) {
2094 player->
pitch( deltaTime * handlingSpeedMultiplyer );
2096 if(
getWindow()->keyPressed( VK_DOWN ) ) {
2097 player->
pitch( -(
float)deltaTime * handlingSpeedMultiplyer );
2099 if(
getWindow()->keyPressed( VK_RIGHT ) ) {
2100 player->
roll( deltaTime * handlingSpeedMultiplyer );
2102 if(
getWindow()->keyPressed( VK_LEFT ) ) {
2103 player->
roll( -(
float)deltaTime * handlingSpeedMultiplyer );
2120 player->
moveUp( deltaTime * handlingSpeedMultiplyer * 100);
2133 void App::performLocalSystemsInput( DWORD deltaTime ) {
2142 void App::performSystemInfoInput( DWORD deltaTime ) {
2145 currentSystemInfoNumber = currentSystemInfoNumber++%256;
2152 if(
getWindow()->keyPressed( VK_UP ) ) {
2153 systemInfoViewAngle++;
2156 if(
getWindow()->keyPressed( VK_DOWN ) ) {
2157 systemInfoViewAngle--;
2160 if(
getWindow()->keyPressed( VK_RIGHT ) ) {
2161 systemInfoViewAngle2++;
2164 if(
getWindow()->keyPressed( VK_LEFT ) ) {
2165 systemInfoViewAngle2--;
2205 glClear( GL_COLOR_BUFFER_BIT );
2210 glMatrixMode( GL_PROJECTION );
2214 glMatrixMode( GL_MODELVIEW );
2219 glEnable( GL_BLEND );
2220 glColor3fv( colorWhite );
2226 printInfoLine(
"Textures to load: %d ", planets->size() + 1 );
2228 for(
unsigned int i=0; i < planets->size(); i++ ) {
2229 glClear( GL_COLOR_BUFFER_BIT );
2232 printInfoBox(
false );
2237 glClear( GL_COLOR_BUFFER_BIT );
2241 printInfoBox(
false );
2248 for(
unsigned int i=0; i < planets->size(); i++ ) {
2249 glClear( GL_COLOR_BUFFER_BIT );
2252 printInfoLine(
"%7.2f percent done.", (100 * ((
float)(i) / ((
float)planets->size()+1.0)) ) );
2253 printInfoBox(
true );
2258 glClear( GL_COLOR_BUFFER_BIT );
2261 printInfoLine(
"%7.2f percent done.", (100 * ((
float)(planets->size()) / ((
float)planets->size()+1.0)) ) );
2262 printInfoBox(
true );
2273 printInfoBox(
true );
2277 glDisable( GL_BLEND );
2280 glMatrixMode( GL_PROJECTION );
2282 glMatrixMode( GL_MODELVIEW );
2312 void App::setScreen(
Screens screen ) {
2315 if( screen == currentSystem && inStation ) {
2342 currentScreen = screen;
2355 if( inputstring == NULL )
2358 va_start( ap, inputstring );
2359 vsprintf_s( text, inputstring, ap );
2363 string textString( text );
2364 this->infoBoxLines.push_back(textString);
2373 void App::printInfoBox(
bool clear ) {
2374 static const int gap = 10;
2376 for(
unsigned int i=0; i<infoBoxLines.size(); i++)
2377 tf2->
print(gap,
getWindow()->getHeight() - gap - ++infoOutputLine*size, &infoBoxLines.at(i));
2379 infoBoxLines.clear();
2388 void App::showFrameRate() {
2391 m_showFrameRate =
true;
2392 else if( opt ==
'0' )
2393 m_showFrameRate =
false;
2405 void App::showFrameTime() {
2408 m_showFrameTime =
true;
2409 else if( opt ==
'0' )
2410 m_showFrameTime =
false;
2422 void App::showSpeed() {
2426 else if( opt ==
'0' )
2427 m_showSpeed =
false;
2439 void App::showResolution() {
2442 m_showResolution =
true;
2443 else if( opt ==
'0' )
2444 m_showResolution =
false;
2456 void App::showHelp() {
2458 if( option ==
"" ) {
2462 if( option ==
"local" ) {
2466 if( option ==
"info" ) {
2470 if( option ==
"env" ) {
2474 if( option ==
"mkt" ) {
2488 void App::devMode() {
2494 }
else if( opt ==
'0' ) {
2513 void App::switchColors() {
2516 m_switchColors =
true;
2519 }
else if( opt ==
'0' ) {
2520 m_switchColors =
false;
2544 void App::setProjectionOrthogonal(
void ) {
2545 glMatrixMode( GL_PROJECTION );
2549 glMatrixMode( GL_MODELVIEW );
2562 void App::restoreProjection(
void ) {
2563 glMatrixMode( GL_PROJECTION );
2565 glMatrixMode( GL_MODELVIEW );