| Autor |
Nachricht |
Trulli
Mitglied
Benutzerprofil
Anmeldungsdatum: 11.10.2004
Beiträge: 162
|
Trulli Mitglied
03:09:40 18.10.2005 Titel: |
vertex glListBase |
Zitieren |
Versteht jemand den Code?
| C++: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 | #include "TheWorldOf.h"
CTREPPEN::CTREPPEN()
{
//drawTreppe(positionX, positionZ, ebene, richtung, stufen, breite, hoehe, laenge, rotary);
}
void CTREPPEN::setUpTreppe(float positionX, float positionZ, float ebene, float stufen, float breite, float hoehe, float laenge, float rotary)
{
this->positionX = positionX;
this->positionZ = positionZ;
this->ebene = ebene;
this->stufen = stufen;
this->breite = breite;
this->hoehe = hoehe;
this->laenge = laenge;
this->rotary = rotary;
}
void CTREPPEN::drawTreppe(float ebene, float myTallSize)
{
glPushMatrix ();
glTranslatef(positionX,0,positionZ);
glRotatef(-rotary,0,1.0f,0);
float steps = hoehe/stufen;
float tiefe = laenge/stufen;
for (float up = 0; up < stufen; up++)
{
glBegin(GL_POLYGON);
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(breite,0.0); glVertex3f(0,(up*steps) + this->ebene + ebene + myTallSize,(up*tiefe));
glTexCoord2f(breite,steps); glVertex3f(0,(up*steps)+ steps + this->ebene + ebene + myTallSize,(up*tiefe));
glTexCoord2f(0.0,steps); glVertex3f(breite,(up*steps)+ steps + this->ebene + ebene + myTallSize,(up*tiefe));
glTexCoord2f(0.0,0.0); glVertex3f(breite,(up*steps) + this->ebene + ebene + myTallSize,(up*tiefe));
glEnd();
glBegin(GL_POLYGON);
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(0.0,0.0); glVertex3f(breite,(up*steps) + steps + this->ebene + ebene + myTallSize,(up*tiefe));
glTexCoord2f(0.0,steps); glVertex3f(breite,(up*steps) + steps + this->ebene + ebene + myTallSize,(up*tiefe)+tiefe);
glTexCoord2f(breite,steps); glVertex3f(0,(up*steps) + steps + this->ebene + ebene + myTallSize,(up*tiefe)+tiefe);
glTexCoord2f(breite,0.0); glVertex3f(0,(up*steps) + steps + this->ebene + ebene + myTallSize,(up*tiefe));
glEnd();
}
glPopMatrix ();
}
AnsiString ausgabestr = "";
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration for WndProc
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma argsused
vector<AnsiString> explode(AnsiString splitter, AnsiString textus)
{
vector<AnsiString> arr;
int spl = splitter.Length();
int y = 1;
for(int x=1;x<textus.Length()+2;x++)
if(textus.SubString(x,splitter.Length()) == splitter || x == textus.Length()+1)
{
arr.resize(arr.size()+1);
arr[arr.size()-1] = textus.SubString(y,x-y);
y = x + spl;
}
return arr;
}
void leseTexturFile(AnsiString Filename, vector<AnsiString> *TNames)
{
int iFileHandle;
int iFileLength;
int iBytesRead;
char *pszBuffer;
AnsiString str = "";
try
{
iFileHandle = FileOpen(Filename, fmOpenRead);
iFileLength = FileSeek(iFileHandle,0,2);
FileSeek(iFileHandle,0,0);
pszBuffer = new char[iFileLength+1];
iBytesRead = FileRead(iFileHandle, pszBuffer, iFileLength);
FileClose(iFileHandle);
for (int i=0;i<iBytesRead;i++)
{
str = str + pszBuffer[i];
}
delete [] pszBuffer;
}
catch(...)
{
Application->MessageBox("Can't perform one of the following file operations: Open, Seek, Read, Close.", "File Error", IDOK);
}
vector<AnsiString> arr = explode("\r\n", str);
for(unsigned int x=0; x<arr.size(); x++){
if(arr[x].SubString(1,2) == "//")
TNames->push_back(arr[x].SubString(3,arr[x].Length()-2));
}
//return TNames;
}
void readstr(FILE *f,char *string)
{
do
{
fgets(string, 255, f);
} while ((string[0] == '/') || (string[0] == '\n'));
return;
}
int in_array(vector<AnsiString> arr, AnsiString str)
{
for(unsigned int x=0; x<arr.size(); x++)
if(arr[x] == str) return x;
return -1;
}
GLvoid BuildFont(GLvoid) // Build Our Bitmap Font
{
HFONT font; // Windows font ID
HFONT oldfont; // Used for good house keeping
base = glGenLists(96); // Storage for 96 characters
font = CreateFont( -16, // Height of font
0, // Width of font
0, // Angle of escapement
0, // Orientation angle
FW_BOLD, // Font weight
FALSE, // Italic
FALSE, // Underline
FALSE, // Strikeout
ANSI_CHARSET, // Character set identifier
OUT_TT_PRECIS, // Output precision
CLIP_DEFAULT_PRECIS, // Clipping precision
ANTIALIASED_QUALITY, // Output quality
FF_DONTCARE|DEFAULT_PITCH, // Family and pitch
"Courier New"); // Font name
oldfont = (HFONT)SelectObject(hDC, font); // Selects the font we want
wglUseFontBitmaps(hDC, 32, 96, base); // Builds 96 characters starting at character 32
SelectObject(hDC, oldfont); // Selects the font we want
DeleteObject(font); // Delete the font
}
GLvoid KillFont(GLvoid) // Delete the font list
{
glDeleteLists(base, 96); // Delete all 96 characters
}
GLvoid glPrint(const char *fmt, ...) // Custom GL "Print" routine
{
char text[256]; // Holds our string
va_list ap; // Pointer to list of arguments
if (fmt == NULL) // If there's no text
return; // Do nothing
va_start(ap, fmt); // Parses the string for variables
vsprintf(text, fmt, ap); // And converts symbols to actual numbers
va_end(ap); // Results are stored in text
glPushAttrib(GL_LIST_BIT); // Pushes the display list bits
glListBase(base - 32); // Sets the base character to 32
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws the display list text
glPopAttrib(); // Pops the display list bits
}
void getLastPosition()
{
//Letzte Position wieder aufnehemen
int iFileHandle = FileOpen("reinspeichertext.txt", fmOpenRead);
int iFileLength = FileSeek(iFileHandle,0,2);
FileSeek(iFileHandle,0,0);
char *pszBuffer = new char[iFileLength+1];
int iBytesRead = FileRead(iFileHandle, pszBuffer, iFileLength);
FileClose(iFileHandle);
AnsiString s = "";
for(int i=0; i< iFileLength; i++)
s = s + pszBuffer[i];
vector<AnsiString>arr = explode(" ", s);
xpos = StrToFloat(Trim(arr[0]));
zpos = StrToFloat(Trim(arr[1]));
yrot = StrToFloat(Trim(arr[2]));
ylook = yrot;
}
bool Pointtest(VERTiX P1,VERTiX P2,VERTiX P3, float xp, float zp)
{
VERTiX temp1,temp2,temp3;
float Test1,Test2;
temp1.x=P1.x-xp,
temp1.z=P1.z-zp,
temp2.x=P3.x-xp,
temp2.z=P3.z-zp,
temp3.x=P2.x-xp,
temp3.z=P2.z-zp;
Test1=temp1.x * temp2.z-temp1.z*temp2.x;
Test2=temp2.x * temp3.z-temp2.z*temp3.x;
if((Test1>0 && Test2>0)||(Test1<0 && Test2<0))
{Test2=temp3.x * temp1.z-temp3.z*temp1.x;
if((Test1>0 && Test2>0)||(Test1<0 && Test2<0)){
//statusString = "!";
return true;
}else{
//statusString = "-";
return false ;
}
}
else{
//statusString = "-";
return false;
}
}
int terraVertIndex(float xp, float zp)
{
double fraction, integer;
fraction = modf(xp, &integer);
int X = integer;
fraction = modf(zp, &integer);
int Z = integer;
VERTS v;
int von = (X*Z)-3;
if (von < 0) von = 0;
for (int x=0; x<sector1.numtriangle; x++)
{
v = sector1.triangle[x];
if (Pointtest(v.vertex[0],v.vertex[1],v.vertex[2], xp, zp)){
return x;
}
}
}
float getHeight(SECTOR sector1, float ix, float iz, int index, int name)
{
float x1,y1,z1,x2,y2,z2,x3,y3,z3;
float ret;
VERTS v;
v = sector1.triangle[index];
x1 = v.vertex[0].x;
y1 = v.vertex[0].y;
z1 = v.vertex[0].z;
x2 = v.vertex[1].x;
y2 = v.vertex[1].y;
z2 = v.vertex[1].z;
x3 = v.vertex[2].x;
y3 = v.vertex[2].y;
z3 = v.vertex[2].z;
int fall = 0;
float lambda1, lambda2;
if (x2 != x1){
lambda2 = ( (iz-z1) - (ix-x1)*(z2-z1)/(x2-x1) )/( (z3-z1) - (x3-x1)*(z2-z1)/(x2-x1) );
ret = y1 + (y2-y1)/(x2-x1)*(ix-x1) +( (y3-y1)-(x3-x1)*(y2-y1)/(x2-x1) )*lambda2;
fall = 1;
}else{
lambda2 = (ix-x1)/(x3-x2);
lambda1 = ( (iz-z1) - (z3-z1)*lambda2 )/(z2-z1);
ret = y1 + (y2-y1) * lambda1 + (y3-y1)*lambda2;
fall = 2;
}
//if (name > 1 && (yRoll[name-1] > ret + 0.3 || yRoll[name-1] < ret + 0.3 || yRoll[name-1] > ret - 0.3 || yRoll[name-1] < ret - 0.3))
//ret = yRoll[name-1];
//ausgabestr = ausgabestr + st;
//if (name == 0)
//ausgabestr = ausgabestr + AnsiString(fall) + ": " + FloatToStrF(ret,0,3,3) + " \t N: " + AnsiString(N) + " \t x3: " + FloatToStrF(x3,0,3,3) + " \t y3: " + FloatToStrF(y3,0,3,3) + " \t z3: " + FloatToStrF(z3,0,3,3) + " \t xp: " + FloatToStrF(ix,0,3,3) + " \t zp: " + FloatToStrF(iz,0,3,3) + "\r\n";
//statusString = "return: " + FloatToStrF(ret,0,4,4) + " & N: " + AnsiString(N) + " & xpos: " + FloatToStrF(ix,0,4,4) + " & zpos: " + FloatToStrF(iz,0,4,4);
return ret;
}
void SetupWorld()
{
getLastPosition();
long L;
TColor TC;
int w,h;
Graphics::TBitmap *bit = new Graphics::TBitmap;
bit->LoadFromFile("Data\\Ebenen\\Scenen\\Scene1\\terrain001.bmp");
w = bit->Width;
h = bit->Height;
vector<vector<float> > high;
high.resize(w);
for(int x=0; x<w; x++){
high[x].resize(h);
for (int z=0; z<h; z++){
TC = bit->Canvas->Pixels[x][z];
L = ColorToRGB(TC);
high[x][z] = L/25.6;
}
}
delete bit;
sector1.numtriangle = (w*h)*2;
sector1.triangle = new VERTS[sector1.numtriangle];
int count = 0;
GLfloat tX, tZ;
for (int loopX = 0; loopX < w-1; loopX++)
{
for (int loopZ = 0; loopZ < h-1; loopZ++)
{
tX = ((0.01)*loopX);
tZ = h-((0.01)*loopZ);
sector1.triangle[count].typ = 0;
sector1.triangle[count].matX = loopX;
sector1.triangle[count].index = count;
//sector1.triangle[count].matY = loopY;
sector1.triangle[count].matZ = loopZ;
sector1.triangle[count].vertex[0].x = -loopX;
sector1.triangle[count].vertex[0].y = high[loopX][loopZ];
sector1.triangle[count].vertex[0].z = -loopZ;
sector1.triangle[count].vertex[0].u = tX+(0.01);
sector1.triangle[count].vertex[0].v = tZ-(0.00);
sector1.triangle[count].vertex[1].x = -loopX;
sector1.triangle[count].vertex[1].y = high[loopX][loopZ+1];
sector1.triangle[count].vertex[1].z = -loopZ - 1;
sector1.triangle[count].vertex[1].u = tX+(0.01);
sector1.triangle[count].vertex[1].v = tZ-(0.01);
sector1.triangle[count].vertex[2].x = -loopX - 1;
sector1.triangle[count].vertex[2].y = high[loopX+1][loopZ+1];
sector1.triangle[count].vertex[2].z = -loopZ - 1;
sector1.triangle[count].vertex[2].u = tX+(0.02);
sector1.triangle[count].vertex[2].v = tZ-(0.01);
count++;
sector1.triangle[count].index = count;
sector1.triangle[count].typ = 0;
sector1.triangle[count].vertex[0].x = -loopX;
sector1.triangle[count].vertex[0].y = high[loopX][loopZ];
sector1.triangle[count].vertex[0].z = -loopZ;
sector1.triangle[count].vertex[0].u = tX+(0.01);
sector1.triangle[count].vertex[0].v = tZ-(0.00);
sector1.triangle[count].vertex[1].x = -loopX - 1;
sector1.triangle[count].vertex[1].y = high[loopX+1][loopZ+1];
sector1.triangle[count].vertex[1].z = -loopZ - 1;
sector1.triangle[count].vertex[1].u = tX+(0.02);
sector1.triangle[count].vertex[1].v = tZ-(0.01);
sector1.triangle[count].vertex[2].x = -loopX - 1;
sector1.triangle[count].vertex[2].y = high[loopX+1][loopZ];
sector1.triangle[count].vertex[2].z = -loopZ;
sector1.triangle[count].vertex[2].u = tX+(0.02);
sector1.triangle[count].vertex[2].v = tZ-(0.00);
sector1.triangle[count].matX = loopX;
//sector1.triangle[count].matY = loopY;
sector1.triangle[count].matZ = loopZ;
count++;
}
}
int N;
float up;
balls.baelle = new BALL[2];
balls.baelle[0].xRoll = -8.22;
balls.baelle[0].zRoll = -8.22;
N = terraVertIndex(balls.baelle[0].xRoll, balls.baelle[0].zRoll);
up = getHeight(sector1, balls.baelle[0].xRoll, balls.baelle[0].zRoll, N, 0);
balls.baelle[0].yRoll = 0;
balls.baelle[0].oldY = up;
balls.baelle[0].xDir = 0.03;
balls.baelle[0].zDir = 0.06;
balls.baelle[0].speed = 2;
balls.baelle[0].xStart = balls.baelle[0].xRoll;
balls.baelle[0].zStart = balls.baelle[0].zRoll;
balls.baelle[0].liveStatus = 0;
balls.baelle[0].gravitation = 5; //Je größer desto leichter
balls.baelle[1].xRoll = -6.22;
balls.baelle[1].zRoll = -6.22;
N = terraVertIndex(balls.baelle[1].xRoll, balls.baelle[1].zRoll);
up = getHeight(sector1, balls.baelle[1].xRoll, balls.baelle[1].zRoll, N, 1);
balls.baelle[1].yRoll = 0;
balls.baelle[1].oldY = up;
balls.baelle[1].xDir = 0.08;
balls.baelle[1].zDir = 0.06;
balls.baelle[1].speed = 3;
balls.baelle[1].xStart = balls.baelle[1].xRoll;
balls.baelle[1].zStart = balls.baelle[1].zRoll;
balls.baelle[1].liveStatus = 1;
balls.baelle[1].gravitation = 5; //Je größer desto leichter
high.clear();
delete &high;
return;
}
AUX_RGBImageRec *LoadBMP(char *Filename) // Loads a bitmap image
{
FILE *File=NULL; // File handle
if (!Filename) // Make sure a filename was given
{
return NULL; // If not return NULL
}
File=fopen(Filename,"r"); // Check to see if the file exists
if (File) // Does the file exist?
{
fclose(File); // Close the handle
return auxDIBImageLoad(Filename); // Load the bitmap and return a pointer
}
return NULL; // If load failed return NULL
}
int LoadGLTextures() // Load bitmaps and convert to textures
{
int Status = false; // Status indicator
AUX_RGBImageRec *TextureImage[1]; // Create storage space for the texture
memset(TextureImage,0,sizeof(void *)*1); // Set the pointer to NULL
for (unsigned int f=0; f<1; f++)
{
vector<AnsiString> arr;
arr.push_back("Data/Texturen/Scenen/Scene1/Mauer1.bmp");
arr.push_back("Data/Texturen/Scenen/Scene1/Mauer2.bmp");
arr.push_back("Data/Texturen/Scenen/Scene1/Mauer3.bmp");
arr.push_back("Data/Texturen/Scenen/Scene1/Kachel1.bmp");
arr.push_back("Data/Texturen/Scenen/Scene1/black.bmp");
arr.push_back("Data/Texturen/Scenen/Scene1/karoGray.bmp");
for (unsigned int x=0; x<6; x++)
{
if (TextureImage[0]=LoadBMP(arr[x].c_str()))
{
Status = true; // Set the status to TRUE
glGenTextures(3, &textureX[x][0]); // Create three textures
// Niedrigste Qualität
glBindTexture(GL_TEXTURE_2D, textureX[x][0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
// Mittlere Qualität
glBindTexture(GL_TEXTURE_2D, textureX[x][1]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
// Hohe Qualität
glBindTexture(GL_TEXTURE_2D, textureX[x][2]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
}else{
return false;
}
//Bitmap aus dem RAM löschen
if (TextureImage[0]){
if (TextureImage[0]->data){
free(TextureImage[0]->data);
}
free(TextureImage[0]);
}
}
}
return Status; // Return the status
}
int LoadGLTerraTexture() // Load bitmaps and convert to textures
{
int Status = false; // Status indicator
AUX_RGBImageRec *TextureImage[1]; // Create storage space for the texture
memset(TextureImage,0,sizeof(void *)*1); // Set the pointer to NULL
TextureImage[0]=LoadBMP("Data\\Texturen\\Scenen\\Scene1\\terraCol001.bmp");
Status = true; // Set the status to TRUE
glGenTextures(3, &terraTexture[0][0]); // Create three textures
// Niedrigste Qualität
glBindTexture(GL_TEXTURE_2D, terraTexture[0][0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
// Mittlere Qualität
glBindTexture(GL_TEXTURE_2D, terraTexture[0][1]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
// Hohe Qualität
glBindTexture(GL_TEXTURE_2D, terraTexture[0][2]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
//Bitmap aus dem RAM löschen
if (TextureImage[0]){
if (TextureImage[0]->data){
free(TextureImage[0]->data);
}
free(TextureImage[0]);
}
return Status; // Return the status
}
GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize and initialize the GL window
{
if (height == 0) // Prevent a divide by zero by
{
height = 1; // Making height equal One
}
glViewport(0, 0, width, height); // Reset the current viewport
glMatrixMode(GL_PROJECTION); // Select the projection matrix
glLoadIdentity(); // Reset the projection matrix
// Calculate the aspect ratio of the window
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW); // Select the modelview matrix
glLoadIdentity(); // Reset the modelview matrix
}
// Loads the .RAW file and stores it in pHeightMap
void LoadRawFile(LPSTR strName, int nSize, BYTE *pHeightMap)
{
FILE *pFile = NULL;
// Open the file in read / binary mode.
pFile = fopen( strName, "rb" );
// Check to see if we found the file and could open it
if ( pFile == NULL )
{
// Display error message and stop the function
MessageBox(NULL, "Can't Find The Height Map!", "Error", MB_OK);
return;
}
fread( pHeightMap, 1, nSize, pFile );
// After we read the data, it's a good idea to check if everything read fine
int result = ferror( pFile );
// Check if we received an error
if (result)
{
MessageBox(NULL, "Failed To Get Data!", "Error", MB_OK);
}
// Close the file.
fclose(pFile);
}
int InitGL(GLvoid) // All setup for OpenGL goes here
{
glShadeModel(GL_SMOOTH);
leseTexturFile("Data/Ebenen/Scenen/Scene1/Ebenen.txt", &ebenenFileNames);
//if (!LoadGLTextures()) // Jump to texture loading routine
//{
// return false; // If texture didn't load return FALSE
//}
if (!LoadGLTerraTexture())
{
return false;
}
glEnable(GL_TEXTURE_2D); // Enable texture mapping
glBlendFunc(GL_SRC_ALPHA,GL_ONE); // Set the blending function for translucency
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This will clear the background color to black
glClearDepth(1.0); // Enables clearing of the depth buffer
// GL_LEQUAL ,oder GL_LESS(war am Anfang so)
glDepthFunc(GL_LEQUAL); // The type of depth test to do
glEnable(GL_DEPTH_TEST); // Enables depth testing
glShadeModel(GL_SMOOTH); // Enables smooth color shading
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really nice perspective calculations
glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);
glEnable(GL_LIGHT1);
//sphere
quadratic=gluNewQuadric();
gluQuadricTexture(quadratic, GL_TRUE);
BuildFont(); // Build the font
SetupWorld();
return TRUE; // Initialization went OK
}
void getPolygon()
{
//AnsiString s = "";
//s = s + "xpos: " + FloatToStrF(xpos, 0,7,4) + ", zpos: " + FloatToStrF(zpos, 0,7,4) + ", yrot: " + FloatToStrF(yrot, 0,7,4);
//statusString = s;
}
float ballSchub(float z)
{
z = z*(-1);
if (z < 0 && z > -0.05) return -0.05;
if (z > 0 && z < 0.05) return 0.05;
//balls.baelle[x].zDir = balls.baelle[x].zDir*(-1);
}
int DrawGLScene(GLvoid) // Here's where we do all the drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1.0f,1.0f,1.0f);
glTranslatef(0.0f,0.0f,0.0f);
glLoadIdentity();
float a_q, b_q, c_q, d_q, e_q;
GLfloat xtrans = -xpos;
GLfloat ztrans = -zpos;
GLfloat ytrans = -walkbias-0.25f;
GLfloat sceneroty = 360.0f - yrot;
ylook = sceneroty; //Nur zum speichern und laden
glRotatef(lookupdown,1.0f,0.0,0.0);
glRotatef(sceneroty,0,1.0f,0);
glBindTexture(GL_TEXTURE_2D, terraTexture[0][filter]);
glTranslatef(xtrans, ytrans, ztrans);
for (int loop = 0; loop < sector1.numtriangle; loop++)
{
glBegin(GL_TRIANGLES);
glNormal3f( 0.0f, 0.0f, 1.0f);
for (int v=0; v<3; v++){
a_q = sector1.triangle[loop].vertex[v].x;
b_q = sector1.triangle[loop].vertex[v].y+ebene+terraUp;
c_q = sector1.triangle[loop].vertex[v].z;
d_q = sector1.triangle[loop].vertex[v].u;
e_q = sector1.triangle[loop].vertex[v].v;
glTexCoord2f(d_q,e_q); glVertex3f(a_q,b_q,c_q);
}
glEnd();
}
bp = true;
glBindTexture(GL_TEXTURE_2D, textureX[0][filter]);
for (int x=0; x<1; x++){
switch(balls.baelle[x].liveStatus)
{
case 0: glColor3f(0.0f,0.6f,0.3f);
break;
case 1: glColor3f(1.0f,1.0f,1.0f);
break;
default: glColor3f(1.0f,1.0f,1.0f);
}
//Dauerbremse
//balls.baelle[x].xDir = balls.baelle[x].xDir - (balls.baelle[x].xDir/7000);
//balls.baelle[x].zDir = balls.baelle[x].zDir - (balls.baelle[x].zDir/7000);
float nextX = balls.baelle[x].xRoll + balls.baelle[x].xDir;
float nextZ = balls.baelle[x].zRoll + balls.baelle[x].zDir;
if(nextX == balls.baelle[x].xRoll && nextZ == balls.baelle[x].zRoll)
{
balls.baelle[x].xRoll = balls.baelle[x].xStart;
balls.baelle[x].zRoll = balls.baelle[x].zStart;
balls.baelle[x].xDir = balls.baelle[x].xStart;
balls.baelle[x].zDir = balls.baelle[x].zStart;
break;
}
GLfloat up;
if(nextX*(-1) > 1 && nextX*(-1) < 99 && nextZ*(-1) > 1 && nextZ*(-1) < 99){
int N = terraVertIndex(nextX, nextZ);
up = getHeight(sector1, nextX, nextZ, N, x+1);
}
try{
balls.baelle[x].xDir = balls.baelle[x].xDir+(((balls.baelle[x].oldY-up)*balls.baelle[x].xDir)/balls.baelle[x].gravitation);
if(balls.baelle[x].oldY-up >= 0.2 && balls.baelle[x].oldY-up <= -0.2)
balls.baelle[x].xDir = balls.baelle[x].xDir*(-1);
}catch(...){
balls.baelle[x].xDir = balls.baelle[x].xDir*(-1);
}
try{
balls.baelle[x].zDir = balls.baelle[x].zDir+(((balls.baelle[x].oldY-up)*balls.baelle[x].zDir)/balls.baelle[x].gravitation);
if(balls.baelle[x].oldY-up >= 0.2 && balls.baelle[x].oldY-up <= -0.2)
balls.baelle[x].zDir = balls.baelle[x].zDir*(-1);
}catch(...){
balls.baelle[x].zDir = balls.baelle[x].zDir*(-1);
}
if (balls.baelle[x].xRoll < -99 || balls.baelle[x].xRoll > 1)
balls.baelle[x].xDir = balls.baelle[x].xDir*(-1);
if (balls.baelle[x].zRoll < -99 || balls.baelle[x].zRoll > 1)
balls.baelle[x].zDir = balls.baelle[x].zDir*(-1);
balls.baelle[x].xRoll = balls.baelle[x].xRoll + balls.baelle[x].xDir;
balls.baelle[x].zRoll = balls.baelle[x].zRoll + balls.baelle[x].zDir;
if (recorder == true){
ausgabestr = ausgabestr + "oY: " + FloatToStrF(balls.baelle[x].oldY,0,4,4) + "\tu: " + FloatToStrF(up,0,4,4) + "\txR: " + FloatToStrF(balls.baelle[x].xRoll,0,4,4) + "\tzR: " + FloatToStrF(balls.baelle[x].zRoll,0,4,4) + "\txD: " + FloatToStrF(balls.baelle[x].xDir,0,4,4) + "\tzD: " + FloatToStrF(balls.baelle[x].zDir,0,4,4) + "\r\n";
}
balls.baelle[x].oldY = up;
try{
glPushMatrix();
glTranslatef(balls.baelle[x].xRoll,balls.baelle[x].yRoll+up+(terraUp-ebene)+0.22,balls.baelle[x].zRoll);
gluSphere(quadratic,0.22,32,32);
glPopMatrix();
}catch(...){}
}
glColor3f(1.0f,1.0f,1.0f);
bp = false;
statusString = FloatToStrF(balls.baelle[0].xRoll ,0,4,4) + " : " + FloatToStrF(balls.baelle[0].zRoll,0,4,4);
//glLoadIdentity();
/*
//Statusleiste zeichnen
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, textureX[4][filter]);
glBegin(GL_QUADS);
glNormal3f( 0.0f, 0.0f, 0.001f);
glTexCoord2f(0,0); glVertex3f(-0.5,-0.5,-0.125);
glTexCoord2f(50,0); glVertex3f(-0.5,-0.0425,-0.125);
glTexCoord2f(50,50); glVertex3f(0.5,-0.0425,-0.125);
glTexCoord2f(0,50); glVertex3f(0.5,-0.5,-0.125);
glEnd();
glPopMatrix();
*/
glLoadIdentity();
//glPushMatrix();
//gettime(&mTime);
//mTime.ti_sec;
glTranslatef(0.0f,0.0f,-0.73f); // Move one unit into the screen
// Pulsing colors based on text position
//glColor3f(1.0f*float(cos(cnt1)),1.0f*float(sin(cnt2)),1.0f-0.5f*float(cos(cnt1+cnt2)));
glBindTexture(GL_TEXTURE_2D, textureX[6][filter]);
// Position the text on the screen
glRasterPos2f(-0.45f+0.05f*float(cos(cnt1)), 0.35f*float(sin(cnt2)));
//glRasterPos2f(-0.45f+0.05f*float(cos(cnt1)), -0.2458f);
//statusString = FloatToStrF(yRoll[0],0,3,3);// + " : " + FloatToStrF(yRoll[0],0,3,3) + " : " + FloatToStrF(zRoll[0],0,3,3) + " ~ " + FloatToStrF(xpos,0,3,3) + " : " + FloatToStrF(terraUp,0,3,3) + " : " + FloatToStrF(zpos,0,3,3);
glPrint(statusString.c_str(), cnt1);
//glPopMatrix();
return true; // Everything went OK
}
GLvoid KillGLWindow(GLvoid) // Properly kill the window
{
AnsiString as = "";
as = as + FloatToStrF(xpos, 0,7,4) + " ";
as = as + FloatToStrF(zpos, 0,7,4) + " ";
as = as + FloatToStrF(ylook, 0,7,4) + " ";
as = as + FloatToStrF(heading, 0,7,4);
int iFileHandle;
int iLength;
iFileHandle = FileCreate("reinspeichertext.txt");
FileWrite(iFileHandle, as.c_str(), as.Length());
FileClose(iFileHandle);
if (fullscreen) // Are we in fullscreen mode?
{
ChangeDisplaySettings(NULL,0); // If so switch back to the desktop
ShowCursor(true); // Show mouse pointer
}
if (hRC) // Do we have a rendering context?
{
if (!wglMakeCurrent(NULL,NULL)) // Are we able to release the DC and RC contexts?
{
MessageBox(NULL,"Release of DC and RC failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
}
if (!wglDeleteContext(hRC)) // Are we able to delete the RC?
{
MessageBox(NULL,"Release rendering context failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
}
hRC = NULL; // Set RC to NULL
}
if (hDC && !ReleaseDC(hWnd,hDC)) // Are we able to release the DC
{
MessageBox(NULL,"Release device context failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hDC = NULL; // Set DC to NULL
}
if (hWnd && !DestroyWindow(hWnd)) // Are we able to destroy the window?
{
MessageBox(NULL,"Could not release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hWnd = NULL; // Set hWnd to NULL
}
if (!UnregisterClass("OpenGL",hInstance)) // Are we able to unregister class
{
MessageBox(NULL,"Could not unregister class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hInstance = NULL; // Set hInstance to NULL
}
}
/* This Code Creates Our OpenGL Window. Parameters Are:
* title - Title To Appear At The Top Of The Window
* width - Width Of The GL Window Or Fullscreen Mode
* height - Height Of The GL Window Or Fullscreen Mode
* bits - Number Of Bits To Use For Color (8/16/24/32)
* fullscreenflag - Use Fullscreen Mode (TRUE) Or Windowed Mode (FALSE)*/
BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
{
WindowRect.left = (long)0; // Set left value to 0
WindowRect.right = (long)width; // Set right value to requested width
WindowRect.top = (long)0; // Set top value to 0
WindowRect.bottom = (long)height; // Set bottom value to requested height
fullscreen = fullscreenflag; // Set the global fullscreen flag
hInstance = GetModuleHandle(NULL); // Grab an instance for our window
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw on size, and own DC for window
wc.lpfnWndProc = (WNDPROC) WndProc; // WndProc handles messages
wc.cbClsExtra = 0; // No extra window data
wc.cbWndExtra = 0; // No extra window data
wc.hInstance = hInstance; // Set the Instance
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load the default icon
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load the arrow pointer
wc.hbrBackground = NULL; // No background required for GL
wc.lpszMenuName = NULL; // We don't want a menu
wc.lpszClassName = "OpenGL"; // Set the class name
if (!RegisterClass(&wc)) // Attempt to register the window class
{
MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false; // Return FALSE
}
if (fullscreen) // Attempt fullscreen mode?
{
DEVMODE dmScreenSettings; // Device mode
memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); // Makes sure memory's cleared
dmScreenSettings.dmSize = sizeof(dmScreenSettings); // Size of the devmode structure
dmScreenSettings.dmPelsWidth = width; // Selected screen width
dmScreenSettings.dmPelsHeight = height; // Selected screen height
dmScreenSettings.dmBitsPerPel = bits; // Selected bits per pixel
dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
// Try to set selected mode and get results. NOTE: CDS_FULLSCREEN gets rid of start bar.
if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
{
// If the mode fails, offer two options. Quit or use windowed mode.
if (MessageBox(NULL,"The requested fullscreen mode is not supported by\nyour video card. Use windowed mode instead?","Acjhtuig",MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
{
fullscreen = false; // Windowed mode selected. Fullscreen = FALSE
}
else
{
// Pop up a message box letting user know the program is closing.
MessageBox(NULL,"Program will now close.","ERROR",MB_OK|MB_ICONSTOP);
return false; // Return FALSE
}
}
}
if (fullscreen) // Are We Still In Fullscreen Mode?
{
dwExStyle = WS_EX_APPWINDOW; // Window extended style
dwStyle = WS_POPUP; // Windows style
ShowCursor(false); // Hide mouse pointer
}
else
{
dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window extended style
dwStyle=WS_OVERLAPPEDWINDOW; // Windows style
}
AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); // Adjust window to true requested size
// Create the window
if (!(hWnd = CreateWindowEx(dwExStyle, // Extended Style For The Window
"OpenGL", // Class name
title, // Window title
dwStyle | // Defined window style
WS_CLIPSIBLINGS | // Required window style
WS_CLIPCHILDREN, // Required window style
0, 0, // Window position
WindowRect.right-WindowRect.left, // Calculate window width
WindowRect.bottom-WindowRect.top, // Calculate window height
NULL, // No parent window
NULL, // No menu
hInstance, // Instance
NULL))) // Dont pass anything to WM_CREATE
{
KillGLWindow(); // Reset the display
MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false; // Return FALSE
}
static PIXELFORMATDESCRIPTOR pfd = // pfd tells windows how we want things to be
{
sizeof(PIXELFORMATDESCRIPTOR), // Size of this pixel format descriptor
1, // Version number
PFD_DRAW_TO_WINDOW | // Format must support window
PFD_SUPPORT_OPENGL | // Format must support OpenGL
PFD_DOUBLEBUFFER, // Must support double buffering
PFD_TYPE_RGBA, // Request an RGBA format
bits, // Select our color depth
0, 0, 0, 0, 0, 0, // Color bits ignored
0, // No alpha buffer
0, // Shift bit ignored
0, // No accumulation buffer
0, 0, 0, 0, // Accumulation bits ignored
16, // 16Bit Z-Buffer (Depth buffer)
0, // No stencil buffer
0, // No auxiliary buffer
PFD_MAIN_PLANE, // Main drawing layer
0, // Reserved
0, 0, 0 // Layer masks ignored
};
if (!(hDC=GetDC(hWnd))) // Did we get a device context?
{
KillGLWindow(); // Reset the display
MessageBox(NULL,"Can't create a GL device context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false; // Return FALSE
}
if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) // Did windows find a matching pixel format?
{
KillGLWindow(); // Reset the display
MessageBox(NULL,"Can't find a suitable pixelformat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false; // Return FALSE
}
if(!SetPixelFormat(hDC,PixelFormat,&pfd)) // Are we able to set the pixel format?
{
KillGLWindow(); // Reset the display
MessageBox(NULL,"Can't set the pixelformat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false; // Return FALSE
}
if (!(hRC=wglCreateContext(hDC))) // Are we able to get a rendering context?
{
KillGLWindow(); // Reset the display
MessageBox(NULL,"Can't create a GL rendering context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false; // Return FALSE
}
if(!wglMakeCurrent(hDC,hRC)) // Try to activate the rendering context
{
KillGLWindow(); // Reset the display
MessageBox(NULL,"Can't activate the GL rendering context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false; // Return FALSE
}
ShowWindow(hWnd,SW_SHOW); // Show the window
SetForegroundWindow(hWnd); // Slightly higher priority
SetFocus(hWnd); // Sets keyboard focus to the window
ReSizeGLScene(width, height); // Set up our perspective GL screen
if (!InitGL()) // Initialize our newly created GL window
{
KillGLWindow(); // Reset the display
MessageBox(NULL,"Initialization failed.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false; // Return FALSE
}
return true; // Success
}
LRESULT CALLBACK WndProc(HWND hWnd, // Handle for this window
UINT uMsg, // Message for this window
WPARAM wParam, // Additional message information
LPARAM lParam) // Additional message information
{
switch (uMsg) // Check for windows messages
{
case WM_ACTIVATE: // Watch for window activate message
{
if (!HIWORD(wParam)) // Check minimization state
{
active = true; // Program is active
}
else
{
active = false; // Program is no longer active
}
return 0; // Return to the message loop
}
case WM_SYSCOMMAND: // Intercept system commands
{
switch (wParam) // Check system calls
{
case SC_SCREENSAVE: // Screensaver trying to start?
case SC_MONITORPOWER: // Monitor trying to enter powersave?
return 0; // Prevent from happening
}
break; // Exit
}
case WM_CLOSE: // Did we receive a close message?
{
PostQuitMessage(0); // Send a quit message
return 0; // Jump back
}
case WM_KEYDOWN: // Is a key being held down?
{
keys[wParam] = true; // If so, mark it as TRUE
return 0; // Jump back
}
case WM_KEYUP: // Has a key been released?
{
keys[wParam] = false; // If so, mark it as FALSE
return 0; // Jump back
}
case WM_SIZE: // Resize the OpenGL window
{
ReSizeGLScene(LOWORD(lParam),HIWORD(lParam)); // LoWord = Width, HiWord = Height
return 0; // Jump back
}
case WM_LBUTTONDOWN:
{
mouse_x = LOWORD(lParam);
mouse_y = HIWORD(lParam);
click_x = LOWORD(lParam);
click_y = HIWORD(lParam);
//if (recorder == true){
int iFileHandle;
int iLength;
iFileHandle = FileCreate("reinspeichertext3.txt");
FileWrite(iFileHandle, ausgabestr.c_str(), ausgabestr.Length());
FileClose(iFileHandle);
//}
getPolygon();
}
case WM_RBUTTONDOWN:
{
if (recorder == false) {
ausgabestr = ausgabestr + "\r\n\t+++NEU+++\r\n";
recorder = true;
}else {
recorder = false;
}
}
case WM_MOUSEMOVE:
{
//float WWidth = ((WindowRect.right - WindowRect.left)/2);
//mouse_x = LOWORD(lParam);
//float mo = (mouse_x - WWidth);
//heading -= mo/100;
//yrot = lastYrot;
//if(mouse_x--) yrot -= 1.0f;
//mouse_y = HIWORD(lParam);
}
}
// Pass all unhandled messages to DefWindowProc
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg; // Windows message structure
bool done = false; // Bool variable to exit loop
// Ask the user which screen mode they prefer
if (MessageBox(NULL,"Would you like to run in fullscreen mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO)
{
fullscreen = false; // Windowed mode
}
// Create our OpenGL window
if (!CreateGLWindow("The Worldt of Tomorrow",640,480,16,fullscreen))
{
return 0; // Quit if window was not created
}
while(!done) // Loop that runs while done = FALSE
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // Is there a message waiting?
{
if (msg.message == WM_QUIT) // Have we received a quit message?
{
done = true; // If so done = TRUE
}
else // If not, deal with window messages
{
TranslateMessage(&msg); // Translate the message
DispatchMessage(&msg); // Dispatch the message
}
}
else // If there are no messages
{
// Draw the scene. Watch for ESC key and quit messages from DrawGLScene()
if ((active && !DrawGLScene()) || keys[VK_ESCAPE]) // Active? Was there a quit received?
{
done = true; // ESC or DrawGLScene signalled a quit
}
else // Not time to quit, update screen
{
SwapBuffers(hDC); // Swap buffers (double buffering)
if (keys['B'] && !bp)
{
bp = true;
blend = !blend;
if (!blend)
{
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
}
else
{
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
}
}
if (!keys['B'])
{
bp = false;
}
if (keys['L'] && !lp)
{
lp=TRUE;
light=!light;
if (!light)
{
glDisable(GL_LIGHTING);
}
else
{
glEnable(GL_LIGHTING);
}
}
if (!keys['L'])
{
lp = false;
}
if (!keys['B'])
{
bp = false;
}
if (keys['F'] && !fp)
{
fp = true;
filter+=1;
if (filter>2)
{
filter=0;
}
}
if (!keys['F'])
{
fp = false;
}
if (keys[VK_PRIOR])
{
z-=0.02f;
}
if (keys[VK_NEXT])
{
z+=0.02f;
}
if (keys['S'])
{
xpos = 0.0f;
zpos = 8.0f;
yrot = 0.0f;
}
if (keys['W'])
{
xpos = 0.0f;
zpos = -8.0f;
yrot = 180.0f;
}
if (keys['D'])
{
xpos = 8.0f;
zpos = 0.0f;
yrot = 90.0f;
}
if (keys['A'])
{
xpos = -8.0f;
zpos = 0.0f;
yrot = 270.0f;
}
if (keys['U'])
{
if(ebene < 0.0125f)
ebene += 0.0125f;
}
if (keys['J'])
{
ebene -= 0.0125f;
}
if (keys[VK_UP] || keys[104])
{
if(xpos*(-1) > 1 && xpos*(-1) < 99 && zpos*(-1) > 0 && zpos*(-1) < 99){
int N = terraVertIndex(xpos, zpos);
float up = -getHeight(sector1, xpos, zpos, N, 0);
if (up - terraUp > -0.03){
oldTerraUp = terraUp;
oldXpos = xpos;
oldZpos = zpos;
terraUp = up;
xpos -= (float)sin(heading*piover180) * 0.05f;
zpos -= (float)cos(heading*piover180) * 0.05f;
/*if (walkbiasangle >= 359.0f) walkbiasangle = 0.0f;
else walkbiasangle+= 10;
walkbias = (float)sin(walkbiasangle * piover180)/20.0f;
}*/
}else{
terraUp = oldTerraUp;
xpos = oldXpos;
zpos = oldZpos;
}
}
}
if (keys[VK_DOWN] || keys[98])
{
if(xpos*(-1) > 1 && xpos*(-1) < 99 && zpos*(-1) > 0 && zpos*(-1) < 99){
int N = terraVertIndex(xpos, zpos);
terraUp = -getHeight(sector1, xpos, zpos, N, 0);
}
//scaleValue -= (float)sin(heading*piover180) * 0.05f;//Landscape //Highmapping
xpos += (float)sin(heading*piover180) * 0.05f;
zpos += (float)cos(heading*piover180) * 0.05f;
/*if (walkbiasangle <= 1.0f)
{
walkbiasangle = 359.0f;
}
else
{
walkbiasangle-= 10;
}
walkbias = (float)sin(walkbiasangle * piover180)/20.0f; */
}
if (keys[VK_RIGHT] || keys[102])
{
heading -= 1.0f;
yrot = heading;
}
if (keys[VK_LEFT] || keys[100])
{
heading += 1.0f;
yrot = heading;
}
if (keys[103])
{
xpos += 0.02f;
zpos -= 0.02f;
}
if (keys[105])
{
xpos -= 0.02f;
zpos += 0.02f;
}
if (keys[101]) //Adere Positionen
{
xpos = -1.5f;
zpos = 0.1f;
yrot = 270.0f;
walkbiasangle = 270.0f;
walkbias = (float)sin(walkbiasangle * piover180)/20.0f;
}
if (keys[VK_PRIOR])
{
lookupdown-= 1.0f;
}
if (keys[VK_NEXT])
{
lookupdown+= 1.0f;
}
if (keys[VK_F1]) // Is F1 neing pressed?
{
keys[VK_F1] = false; // If so make key FALSE
KillGLWindow(); // Kill our current window
fullscreen = !fullscreen; // Toggle fullscreen / windowed mode
// Recreate our OpenGL window
if (!CreateGLWindow("The Worldt of Tomorrow",640,480,16,fullscreen))
{
return 0; // Quit if window was not created
}
}
}
}
}
// Shutdown
KillGLWindow(); // Kill the window
glDeleteTextures(4,terraTexture[0]);
delete &ausgabestr;
delete &statusString;
delete §or1;
delete &balls;
return (msg.wParam); // Exit the program
}
//--------------------------------------------------------------------------- | | |
Zuletzt bearbeitet von Trulli am 03:10:33 18.10.2005, insgesamt 1-mal bearbeitet |
|
 |
TGGC
Mitglied
Benutzerprofil
Anmeldungsdatum: 30.04.2001
Beiträge: 6901
|
TGGC Mitglied
07:20:59 18.10.2005 Titel: |
|
Zitieren |
|
 |
Pellaeon
Mitglied
Benutzerprofil
Anmeldungsdatum: 30.05.2005
Beiträge: 2554
|
Pellaeon Mitglied
08:26:05 18.10.2005 Titel: |
|
Zitieren |
Gehts nicht genauer, was du wissen willst? ^^
Is halt ein kleines WinAPI-Programm, dass OpenGL benutzt, und das noch nicht mal besonders gut.^^
Ratefrage: Ich las da TBitmap, tippe also mal auf Borland C++ Builder^^ |
|
|
|
 |
ChockoCookie
Mitglied
Benutzerprofil
Anmeldungsdatum: 06.01.2004
Beiträge: 387
|
ChockoCookie Mitglied
11:15:13 18.10.2005 Titel: |
|
Zitieren |
Was TGGC damit sagen will: Niemand, der keinen persönlichen Vorteil darin erkennen kann, den Code für dich zu verstehen, ließt sich das hier durch. Und solche Altruisten gibt es nur sehr selten. |
_________________ morgen
|
|
 |
|
Nächstes Thema anzeigen
Vorheriges Thema anzeigen
Sie können Beiträge in dieses Forum schreiben. Sie können auf Beiträge in diesem Forum antworten. Sie können Ihre Beiträge in diesem Forum nicht bearbeiten. Sie können Ihre Beiträge in diesem Forum nicht löschen. Sie können an Umfragen in diesem Forum nicht mitmachen.
|
|
|
|
|