Load.cpp 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  1. #include "Load.h"
  2. #include <Array.h>
  3. #include <AsynchronCall.h>
  4. #include <Datei.h>
  5. #include <DateiSystem.h>
  6. #include <GraphicsApi.h>
  7. #include <M3Datei.h>
  8. #include <Text.h>
  9. #include <Textur.h>
  10. #include "Globals.h"
  11. #include "Initialisierung.h"
  12. #include "ServerSelection.h"
  13. void createDefaultCube(Bildschirm* zScreen)
  14. {
  15. Model3DData* data = zScreen->zGraphicsApi()->createModel("cube");
  16. data->setAmbientFactor(0.f);
  17. data->setDiffusFactor(1.f);
  18. data->setSpecularFactor(0.f);
  19. float size = 1;
  20. float left, right, top, bottom;
  21. // Calculate the screen coordinates of the left side of the bitmap.
  22. right = (float)((-size / 2.0));
  23. // Calculate the screen coordinates of the right side of the bitmap.
  24. left = right + (float)size;
  25. // Calculate the screen coordinates of the top of the bitmap.
  26. top = (float)(size / 2.0);
  27. // Calculate the screen coordinates of the bottom of the bitmap.
  28. bottom = top - (float)size;
  29. float front = -size / 2;
  30. float back = front + size;
  31. Vertex3D* vertecies = new Vertex3D[24];
  32. for (int i = 0; i < 24; i++)
  33. vertecies[i].knochenId = 0;
  34. // front side
  35. vertecies[0].pos = Vec3<float>(left, front, top);
  36. vertecies[0].tPos = Vec2<float>(0.f, 0.f);
  37. vertecies[1].pos = Vec3<float>(right, front, top);
  38. vertecies[1].tPos = Vec2<float>(1.f, 0.f);
  39. vertecies[2].pos = Vec3<float>(left, front, bottom);
  40. vertecies[2].tPos = Vec2<float>(0.f, 1.f);
  41. vertecies[3].pos = Vec3<float>(right, front, bottom);
  42. vertecies[3].tPos = Vec2<float>(1.f, 1.f);
  43. // back side
  44. vertecies[4].pos = Vec3<float>(right, back, top);
  45. vertecies[4].tPos = Vec2<float>(0.0f, 0.0f);
  46. vertecies[5].pos = Vec3<float>(left, back, top);
  47. vertecies[5].tPos = Vec2<float>(1.0f, 0.0f);
  48. vertecies[6].pos = Vec3<float>(right, back, bottom);
  49. vertecies[6].tPos = Vec2<float>(0.0f, 1.0f);
  50. vertecies[7].pos = Vec3<float>(left, back, bottom);
  51. vertecies[7].tPos = Vec2<float>(1.0f, 1.0f);
  52. // left side
  53. vertecies[8].pos = Vec3<float>(left, back, top);
  54. vertecies[8].tPos = Vec2<float>(0.f, 0.f);
  55. vertecies[9].pos = Vec3<float>(left, front, top);
  56. vertecies[9].tPos = Vec2<float>(1.f, 0.f);
  57. vertecies[10].pos = Vec3<float>(left, back, bottom);
  58. vertecies[10].tPos = Vec2<float>(0.f, 1.f);
  59. vertecies[11].pos = Vec3<float>(left, front, bottom);
  60. vertecies[11].tPos = Vec2<float>(1.f, 1.f);
  61. // right side
  62. vertecies[12].pos = Vec3<float>(right, front, top);
  63. vertecies[12].tPos = Vec2<float>(0.0f, 0.0f);
  64. vertecies[13].pos = Vec3<float>(right, back, top);
  65. vertecies[13].tPos = Vec2<float>(1.0f, 0.0f);
  66. vertecies[14].pos = Vec3<float>(right, front, bottom);
  67. vertecies[14].tPos = Vec2<float>(0.0f, 1.0f);
  68. vertecies[15].pos = Vec3<float>(right, back, bottom);
  69. vertecies[15].tPos = Vec2<float>(1.0f, 1.0f);
  70. // top side
  71. vertecies[16].pos = Vec3<float>(left, back, top);
  72. vertecies[16].tPos = Vec2<float>(0.f, 0.f);
  73. vertecies[17].pos = Vec3<float>(right, back, top);
  74. vertecies[17].tPos = Vec2<float>(1.f, 0.f);
  75. vertecies[18].pos = Vec3<float>(left, front, top);
  76. vertecies[18].tPos = Vec2<float>(0.f, 1.f);
  77. vertecies[19].pos = Vec3<float>(right, front, top);
  78. vertecies[19].tPos = Vec2<float>(1.f, 1.f);
  79. // botom side
  80. vertecies[20].pos = Vec3<float>(left, front, bottom);
  81. vertecies[20].tPos = Vec2<float>(0.0f, 0.0f);
  82. vertecies[21].pos = Vec3<float>(right, front, bottom);
  83. vertecies[21].tPos = Vec2<float>(1.0f, 0.0f);
  84. vertecies[22].pos = Vec3<float>(left, back, bottom);
  85. vertecies[22].tPos = Vec2<float>(0.0f, 1.0f);
  86. vertecies[23].pos = Vec3<float>(right, back, bottom);
  87. vertecies[23].tPos = Vec2<float>(1.0f, 1.0f);
  88. data->setVertecies(vertecies, 24);
  89. // the order of the polygons has to be NORTH (front), EAST (left), SOUTH
  90. // (back), WEST (right), TOP, BOTTOM according to the Area definition
  91. // front side
  92. Polygon3D* p
  93. = new Polygon3D(); // looking from (0,0,0) to (1,0,0) to see this side
  94. p->indexAnz = 6;
  95. p->indexList = new int[p->indexAnz];
  96. p->indexList[0] = 0;
  97. p->indexList[1] = 1;
  98. p->indexList[2] = 2;
  99. p->indexList[3] = 1;
  100. p->indexList[4] = 3;
  101. p->indexList[5] = 2;
  102. data->addPolygon(p);
  103. // left side
  104. p = new Polygon3D(); // looking from (0,0,0) to (0,1,0) to see this side
  105. p->indexAnz = 6;
  106. p->indexList = new int[p->indexAnz];
  107. p->indexList[0] = 0 + 8;
  108. p->indexList[1] = 1 + 8;
  109. p->indexList[2] = 2 + 8;
  110. p->indexList[3] = 1 + 8;
  111. p->indexList[4] = 3 + 8;
  112. p->indexList[5] = 2 + 8;
  113. data->addPolygon(p);
  114. // back side
  115. p = new Polygon3D(); // looking from (0,0,0) to (-1,0,0) to see this side
  116. p->indexAnz = 6;
  117. p->indexList = new int[p->indexAnz];
  118. p->indexList[0] = 0 + 4;
  119. p->indexList[1] = 1 + 4;
  120. p->indexList[2] = 2 + 4;
  121. p->indexList[3] = 1 + 4;
  122. p->indexList[4] = 3 + 4;
  123. p->indexList[5] = 2 + 4;
  124. data->addPolygon(p);
  125. // right side
  126. p = new Polygon3D(); // looking from (0,0,0) to (0,-1,0) to see this side
  127. p->indexAnz = 6;
  128. p->indexList = new int[p->indexAnz];
  129. p->indexList[0] = 0 + 12;
  130. p->indexList[1] = 1 + 12;
  131. p->indexList[2] = 2 + 12;
  132. p->indexList[3] = 1 + 12;
  133. p->indexList[4] = 3 + 12;
  134. p->indexList[5] = 2 + 12;
  135. data->addPolygon(p);
  136. // top side
  137. p = new Polygon3D(); // looking from (0,0,0) to (0,0,-1) to see this side
  138. p->indexAnz = 6;
  139. p->indexList = new int[p->indexAnz];
  140. p->indexList[0] = 0 + 16;
  141. p->indexList[1] = 1 + 16;
  142. p->indexList[2] = 2 + 16;
  143. p->indexList[3] = 1 + 16;
  144. p->indexList[4] = 3 + 16;
  145. p->indexList[5] = 2 + 16;
  146. data->addPolygon(p);
  147. // botom side
  148. p = new Polygon3D(); // looking from (0,0,0) to (0,0,1) to see this side
  149. p->indexAnz = 6;
  150. p->indexList = new int[p->indexAnz];
  151. p->indexList[0] = 0 + 20;
  152. p->indexList[1] = 1 + 20;
  153. p->indexList[2] = 2 + 20;
  154. p->indexList[3] = 1 + 20;
  155. p->indexList[4] = 3 + 20;
  156. p->indexList[5] = 2 + 20;
  157. data->addPolygon(p);
  158. data->calculateNormals();
  159. data->release();
  160. }
  161. void createCubeItem(Bildschirm* zScreen)
  162. {
  163. Framework::Model3DData* data
  164. = window->zBildschirm()->zGraphicsApi()->createModel("itemCube");
  165. data->setAmbientFactor(0.8f);
  166. data->setDiffusFactor(0.1f);
  167. data->setSpecularFactor(0.1f);
  168. float size = 0.2f;
  169. float left, right, top, bottom;
  170. // Calculate the screen coordinates of the left side of the bitmap.
  171. left = (float)((-size / 2.0));
  172. // Calculate the screen coordinates of the right side of the bitmap.
  173. right = left + (float)size;
  174. // Calculate the screen coordinates of the top of the bitmap.
  175. top = (float)(size / 2.0);
  176. // Calculate the screen coordinates of the bottom of the bitmap.
  177. bottom = top - (float)size;
  178. float front = -size / 2;
  179. float back = front + size;
  180. Vertex3D* vertecies = new Vertex3D[24];
  181. for (int i = 0; i < 24; i++)
  182. vertecies[i].knochenId = 0;
  183. // front side
  184. vertecies[0].pos = Vec3<float>(left, front, top);
  185. vertecies[0].tPos = Vec2<float>(0.f, 0.f);
  186. vertecies[1].pos = Vec3<float>(right, front, top);
  187. vertecies[1].tPos = Vec2<float>(1.f, 0.f);
  188. vertecies[2].pos = Vec3<float>(left, front, bottom);
  189. vertecies[2].tPos = Vec2<float>(0.f, 1.f);
  190. vertecies[3].pos = Vec3<float>(right, front, bottom);
  191. vertecies[3].tPos = Vec2<float>(1.f, 1.f);
  192. // back side
  193. vertecies[4].pos = Vec3<float>(right, back, top);
  194. vertecies[4].tPos = Vec2<float>(0.0f, 0.0f);
  195. vertecies[5].pos = Vec3<float>(left, back, top);
  196. vertecies[5].tPos = Vec2<float>(1.0f, 0.0f);
  197. vertecies[6].pos = Vec3<float>(right, back, bottom);
  198. vertecies[6].tPos = Vec2<float>(0.0f, 1.0f);
  199. vertecies[7].pos = Vec3<float>(left, back, bottom);
  200. vertecies[7].tPos = Vec2<float>(1.0f, 1.0f);
  201. // left side
  202. vertecies[8].pos = Vec3<float>(left, back, top);
  203. vertecies[8].tPos = Vec2<float>(0.f, 0.f);
  204. vertecies[9].pos = Vec3<float>(left, front, top);
  205. vertecies[9].tPos = Vec2<float>(1.f, 0.f);
  206. vertecies[10].pos = Vec3<float>(left, back, bottom);
  207. vertecies[10].tPos = Vec2<float>(0.f, 1.f);
  208. vertecies[11].pos = Vec3<float>(left, front, bottom);
  209. vertecies[11].tPos = Vec2<float>(1.f, 1.f);
  210. // right side
  211. vertecies[12].pos = Vec3<float>(right, front, top);
  212. vertecies[12].tPos = Vec2<float>(0.0f, 0.0f);
  213. vertecies[13].pos = Vec3<float>(right, back, top);
  214. vertecies[13].tPos = Vec2<float>(1.0f, 0.0f);
  215. vertecies[14].pos = Vec3<float>(right, front, bottom);
  216. vertecies[14].tPos = Vec2<float>(0.0f, 1.0f);
  217. vertecies[15].pos = Vec3<float>(right, back, bottom);
  218. vertecies[15].tPos = Vec2<float>(1.0f, 1.0f);
  219. // top side
  220. vertecies[16].pos = Vec3<float>(left, back, top);
  221. vertecies[16].tPos = Vec2<float>(0.f, 0.f);
  222. vertecies[17].pos = Vec3<float>(right, back, top);
  223. vertecies[17].tPos = Vec2<float>(1.f, 0.f);
  224. vertecies[18].pos = Vec3<float>(left, front, top);
  225. vertecies[18].tPos = Vec2<float>(0.f, 1.f);
  226. vertecies[19].pos = Vec3<float>(right, front, top);
  227. vertecies[19].tPos = Vec2<float>(1.f, 1.f);
  228. // botom side
  229. vertecies[20].pos = Vec3<float>(left, front, bottom);
  230. vertecies[20].tPos = Vec2<float>(0.0f, 0.0f);
  231. vertecies[21].pos = Vec3<float>(right, front, bottom);
  232. vertecies[21].tPos = Vec2<float>(1.0f, 0.0f);
  233. vertecies[22].pos = Vec3<float>(left, back, bottom);
  234. vertecies[22].tPos = Vec2<float>(0.0f, 1.0f);
  235. vertecies[23].pos = Vec3<float>(right, back, bottom);
  236. vertecies[23].tPos = Vec2<float>(1.0f, 1.0f);
  237. data->setVertecies(vertecies, 24);
  238. // the order of the polygons has to be NORTH (front), EAST (left), SOUTH
  239. // (back), WEST (right), TOP, BOTTOM according to the Area definition front
  240. // side
  241. Polygon3D* p = new Polygon3D();
  242. p->indexAnz = 6;
  243. p->indexList = new int[p->indexAnz];
  244. p->indexList[0] = 0;
  245. p->indexList[1] = 2;
  246. p->indexList[2] = 1;
  247. p->indexList[3] = 1;
  248. p->indexList[4] = 2;
  249. p->indexList[5] = 3;
  250. data->addPolygon(p);
  251. // left side
  252. p = new Polygon3D();
  253. p->indexAnz = 6;
  254. p->indexList = new int[p->indexAnz];
  255. p->indexList[0] = 0 + 8;
  256. p->indexList[1] = 2 + 8;
  257. p->indexList[2] = 1 + 8;
  258. p->indexList[3] = 1 + 8;
  259. p->indexList[4] = 2 + 8;
  260. p->indexList[5] = 3 + 8;
  261. data->addPolygon(p);
  262. // back side
  263. p = new Polygon3D();
  264. p->indexAnz = 6;
  265. p->indexList = new int[p->indexAnz];
  266. p->indexList[0] = 0 + 4;
  267. p->indexList[1] = 2 + 4;
  268. p->indexList[2] = 1 + 4;
  269. p->indexList[3] = 1 + 4;
  270. p->indexList[4] = 2 + 4;
  271. p->indexList[5] = 3 + 4;
  272. data->addPolygon(p);
  273. // right side
  274. p = new Polygon3D();
  275. p->indexAnz = 6;
  276. p->indexList = new int[p->indexAnz];
  277. p->indexList[0] = 0 + 12;
  278. p->indexList[1] = 2 + 12;
  279. p->indexList[2] = 1 + 12;
  280. p->indexList[3] = 1 + 12;
  281. p->indexList[4] = 2 + 12;
  282. p->indexList[5] = 3 + 12;
  283. data->addPolygon(p);
  284. // top side
  285. p = new Polygon3D();
  286. p->indexAnz = 6;
  287. p->indexList = new int[p->indexAnz];
  288. p->indexList[0] = 0 + 16;
  289. p->indexList[1] = 2 + 16;
  290. p->indexList[2] = 1 + 16;
  291. p->indexList[3] = 1 + 16;
  292. p->indexList[4] = 2 + 16;
  293. p->indexList[5] = 3 + 16;
  294. data->addPolygon(p);
  295. // botom side
  296. p = new Polygon3D();
  297. p->indexAnz = 6;
  298. p->indexList = new int[p->indexAnz];
  299. p->indexList[0] = 0 + 20;
  300. p->indexList[1] = 2 + 20;
  301. p->indexList[2] = 1 + 20;
  302. p->indexList[3] = 1 + 20;
  303. p->indexList[4] = 2 + 20;
  304. p->indexList[5] = 3 + 20;
  305. data->addPolygon(p);
  306. data->calculateNormals();
  307. data->release();
  308. }
  309. void createPlayer(Bildschirm* zScreen)
  310. {
  311. Framework::Model3DData* data
  312. = window->zBildschirm()->zGraphicsApi()->createModel("player");
  313. data->setAmbientFactor(0.8f);
  314. data->setDiffusFactor(0.1f);
  315. data->setSpecularFactor(0.1f);
  316. float size = 0.8f;
  317. float left, right, top, bottom;
  318. // Calculate the screen coordinates of the left side of the bitmap.
  319. left = (float)((size / 2.0) * -1);
  320. // Calculate the screen coordinates of the right side of the bitmap.
  321. right = left + (float)size;
  322. // Calculate the screen coordinates of the top of the bitmap.
  323. top = (float)(size / 2.0);
  324. // Calculate the screen coordinates of the bottom of the bitmap.
  325. bottom = top - (float)size;
  326. float front = -1.5f / 2;
  327. float back = front + 1.5f;
  328. Vertex3D* vertecies = new Vertex3D[24];
  329. for (int i = 0; i < 24; i++)
  330. vertecies[i].knochenId = 0;
  331. vertecies[0].pos = Vec3<float>(left, top, front);
  332. vertecies[0].tPos = Vec2<float>(0.f, 0.f);
  333. vertecies[1].pos = Vec3<float>(right, top, front);
  334. vertecies[1].tPos = Vec2<float>(1.f, 0.f);
  335. vertecies[2].pos = Vec3<float>(left, bottom, front);
  336. vertecies[2].tPos = Vec2<float>(0.f, 1.f);
  337. vertecies[3].pos = Vec3<float>(right, bottom, front);
  338. vertecies[3].tPos = Vec2<float>(1.f, 1.f);
  339. vertecies[4].pos = Vec3<float>(left, top, back);
  340. vertecies[4].tPos = Vec2<float>(0.0f, 0.0f);
  341. vertecies[5].pos = Vec3<float>(right, top, back);
  342. vertecies[5].tPos = Vec2<float>(1.0f, 0.0f);
  343. vertecies[6].pos = Vec3<float>(left, bottom, back);
  344. vertecies[6].tPos = Vec2<float>(0.0f, 1.0f);
  345. vertecies[7].pos = Vec3<float>(right, bottom, back);
  346. vertecies[7].tPos = Vec2<float>(1.0f, 1.0f);
  347. vertecies[8].pos = Vec3<float>(left, top, front);
  348. vertecies[8].tPos = Vec2<float>(1.f, 0.f);
  349. vertecies[9].pos = Vec3<float>(right, top, front);
  350. vertecies[9].tPos = Vec2<float>(0.f, 0.f);
  351. vertecies[10].pos = Vec3<float>(left, bottom, front);
  352. vertecies[10].tPos = Vec2<float>(1.f, 1.f);
  353. vertecies[11].pos = Vec3<float>(right, bottom, front);
  354. vertecies[11].tPos = Vec2<float>(0.f, 1.f);
  355. vertecies[12].pos = Vec3<float>(left, top, back);
  356. vertecies[12].tPos = Vec2<float>(0.0f, 0.0f);
  357. vertecies[13].pos = Vec3<float>(right, top, back);
  358. vertecies[13].tPos = Vec2<float>(1.0f, 0.0f);
  359. vertecies[14].pos = Vec3<float>(left, bottom, back);
  360. vertecies[14].tPos = Vec2<float>(0.0f, 1.0f);
  361. vertecies[15].pos = Vec3<float>(right, bottom, back);
  362. vertecies[15].tPos = Vec2<float>(1.0f, 1.0f);
  363. vertecies[16].pos = Vec3<float>(left, top, front);
  364. vertecies[16].tPos = Vec2<float>(0.f, 1.f);
  365. vertecies[17].pos = Vec3<float>(right, top, front);
  366. vertecies[17].tPos = Vec2<float>(1.f, 1.f);
  367. vertecies[18].pos = Vec3<float>(left, bottom, front);
  368. vertecies[18].tPos = Vec2<float>(0.f, 0.f);
  369. vertecies[19].pos = Vec3<float>(right, bottom, front);
  370. vertecies[19].tPos = Vec2<float>(1.f, 0.f);
  371. vertecies[20].pos = Vec3<float>(left, top, back);
  372. vertecies[20].tPos = Vec2<float>(0.0f, 0.0f);
  373. vertecies[21].pos = Vec3<float>(right, top, back);
  374. vertecies[21].tPos = Vec2<float>(1.0f, 0.0f);
  375. vertecies[22].pos = Vec3<float>(left, bottom, back);
  376. vertecies[22].tPos = Vec2<float>(0.0f, 1.0f);
  377. vertecies[23].pos = Vec3<float>(right, bottom, back);
  378. vertecies[23].tPos = Vec2<float>(1.0f, 1.0f);
  379. data->setVertecies(vertecies, 24);
  380. // the order of the polygons has to be NORTH, EAST, SOUTH, WEST, TOP, BOTTOM
  381. // according to the Area definition down side
  382. Polygon3D* p = new Polygon3D();
  383. p->indexAnz = 6;
  384. p->indexList = new int[p->indexAnz];
  385. p->indexList[0] = 6 + 16;
  386. p->indexList[1] = 2 + 16;
  387. p->indexList[2] = 3 + 16;
  388. p->indexList[3] = 6 + 16;
  389. p->indexList[4] = 3 + 16;
  390. p->indexList[5] = 7 + 16;
  391. data->addPolygon(p);
  392. // right side
  393. p = new Polygon3D();
  394. p->indexAnz = 6;
  395. p->indexList = new int[p->indexAnz];
  396. p->indexList[0] = 1 + 8;
  397. p->indexList[1] = 7 + 8;
  398. p->indexList[2] = 3 + 8;
  399. p->indexList[3] = 1 + 8;
  400. p->indexList[4] = 5 + 8;
  401. p->indexList[5] = 7 + 8;
  402. data->addPolygon(p);
  403. // top side
  404. p = new Polygon3D();
  405. p->indexAnz = 6;
  406. p->indexList = new int[p->indexAnz];
  407. p->indexList[0] = 4 + 16;
  408. p->indexList[1] = 1 + 16;
  409. p->indexList[2] = 0 + 16;
  410. p->indexList[3] = 4 + 16;
  411. p->indexList[4] = 5 + 16;
  412. p->indexList[5] = 1 + 16;
  413. data->addPolygon(p);
  414. // left side
  415. p = new Polygon3D();
  416. p->indexAnz = 6;
  417. p->indexList = new int[p->indexAnz];
  418. p->indexList[0] = 0 + 8;
  419. p->indexList[1] = 2 + 8;
  420. p->indexList[2] = 6 + 8;
  421. p->indexList[3] = 0 + 8;
  422. p->indexList[4] = 6 + 8;
  423. p->indexList[5] = 4 + 8;
  424. data->addPolygon(p);
  425. // back side
  426. p = new Polygon3D();
  427. p->indexAnz = 6;
  428. p->indexList = new int[p->indexAnz];
  429. p->indexList[0] = 4;
  430. p->indexList[1] = 6;
  431. p->indexList[2] = 7;
  432. p->indexList[3] = 4;
  433. p->indexList[4] = 7;
  434. p->indexList[5] = 5;
  435. data->addPolygon(p);
  436. // front side
  437. p = new Polygon3D();
  438. p->indexAnz = 6;
  439. p->indexList = new int[p->indexAnz];
  440. p->indexList[0] = 0;
  441. p->indexList[1] = 3;
  442. p->indexList[2] = 2;
  443. p->indexList[3] = 0;
  444. p->indexList[4] = 1;
  445. p->indexList[5] = 3;
  446. data->addPolygon(p);
  447. data->calculateNormals();
  448. data->release();
  449. }
  450. void createGrass(Bildschirm* zScreen)
  451. {
  452. Model3DData* data = zScreen->zGraphicsApi()->createModel("grass");
  453. data->setAmbientFactor(0.f);
  454. data->setDiffusFactor(1.f);
  455. data->setSpecularFactor(0.f);
  456. float size = 1;
  457. float left, right, top, bottom;
  458. // Calculate the screen coordinates of the left side of the bitmap.
  459. right = (float)((-size / 2.0));
  460. // Calculate the screen coordinates of the right side of the bitmap.
  461. left = right + (float)size;
  462. // Calculate the screen coordinates of the top of the bitmap.
  463. top = (float)(size / 2.0);
  464. // Calculate the screen coordinates of the bottom of the bitmap.
  465. bottom = top - (float)size;
  466. float front = -size / 2;
  467. float back = front + size;
  468. Vertex3D* vertecies = new Vertex3D[32];
  469. for (int i = 0; i < 32; i++)
  470. vertecies[i].knochenId = 0;
  471. // first y plane
  472. vertecies[0].pos = Vec3<float>(left, front + 0.2f, top);
  473. vertecies[0].tPos = Vec2<float>(0.01f, 0.01f);
  474. vertecies[1].pos = Vec3<float>(right, front + 0.2f, top);
  475. vertecies[1].tPos = Vec2<float>(0.99f, 0.01f);
  476. vertecies[2].pos = Vec3<float>(left, front + 0.2f, bottom);
  477. vertecies[2].tPos = Vec2<float>(0.01f, 0.99f);
  478. vertecies[3].pos = Vec3<float>(right, front + 0.2f, bottom);
  479. vertecies[3].tPos = Vec2<float>(0.99f, 0.99f);
  480. // second y plane
  481. vertecies[4].pos = Vec3<float>(left, front + 0.4f, top);
  482. vertecies[4].tPos = Vec2<float>(0.01f, 0.01f);
  483. vertecies[5].pos = Vec3<float>(right, front + 0.4f, top);
  484. vertecies[5].tPos = Vec2<float>(0.99f, 0.01f);
  485. vertecies[6].pos = Vec3<float>(left, front + 0.4f, bottom);
  486. vertecies[6].tPos = Vec2<float>(0.01f, 0.99f);
  487. vertecies[7].pos = Vec3<float>(right, front + 0.4f, bottom);
  488. vertecies[7].tPos = Vec2<float>(0.99f, 0.99f);
  489. // third y plane
  490. vertecies[8].pos = Vec3<float>(left, front + 0.6f, top);
  491. vertecies[8].tPos = Vec2<float>(0.01f, 0.01f);
  492. vertecies[9].pos = Vec3<float>(right, front + 0.6f, top);
  493. vertecies[9].tPos = Vec2<float>(0.99f, 0.01f);
  494. vertecies[10].pos = Vec3<float>(left, front + 0.6f, bottom);
  495. vertecies[10].tPos = Vec2<float>(0.01f, 0.99f);
  496. vertecies[11].pos = Vec3<float>(right, front + 0.6f, bottom);
  497. vertecies[11].tPos = Vec2<float>(0.99f, 0.99f);
  498. // forth y plane
  499. vertecies[12].pos = Vec3<float>(left, front + 0.8f, top);
  500. vertecies[12].tPos = Vec2<float>(0.01f, 0.01f);
  501. vertecies[13].pos = Vec3<float>(right, front + 0.8f, top);
  502. vertecies[13].tPos = Vec2<float>(0.99f, 0.01f);
  503. vertecies[14].pos = Vec3<float>(left, front + 0.8f, bottom);
  504. vertecies[14].tPos = Vec2<float>(0.01f, 0.99f);
  505. vertecies[15].pos = Vec3<float>(right, front + 0.8f, bottom);
  506. vertecies[15].tPos = Vec2<float>(0.99f, 0.99f);
  507. // first x plane
  508. vertecies[16].pos = Vec3<float>(right + 0.2f, front, top);
  509. vertecies[16].tPos = Vec2<float>(0.01f, 0.01f);
  510. vertecies[17].pos = Vec3<float>(right + 0.2f, back, top);
  511. vertecies[17].tPos = Vec2<float>(0.99f, 0.01f);
  512. vertecies[18].pos = Vec3<float>(right + 0.2f, front, bottom);
  513. vertecies[18].tPos = Vec2<float>(0.01f, 0.99f);
  514. vertecies[19].pos = Vec3<float>(right + 0.2f, back, bottom);
  515. vertecies[19].tPos = Vec2<float>(0.99f, 0.99f);
  516. // second x plane
  517. vertecies[20].pos = Vec3<float>(right + 0.4f, front, top);
  518. vertecies[20].tPos = Vec2<float>(0.01f, 0.01f);
  519. vertecies[21].pos = Vec3<float>(right + 0.4f, back, top);
  520. vertecies[21].tPos = Vec2<float>(0.99f, 0.01f);
  521. vertecies[22].pos = Vec3<float>(right + 0.4f, front, bottom);
  522. vertecies[22].tPos = Vec2<float>(0.01f, 0.99f);
  523. vertecies[23].pos = Vec3<float>(right + 0.4f, back, bottom);
  524. vertecies[23].tPos = Vec2<float>(0.99f, 0.99f);
  525. // third x plane
  526. vertecies[24].pos = Vec3<float>(right + 0.6f, front, top);
  527. vertecies[24].tPos = Vec2<float>(0.01f, 0.01f);
  528. vertecies[25].pos = Vec3<float>(right + 0.6f, back, top);
  529. vertecies[25].tPos = Vec2<float>(0.99f, 0.01f);
  530. vertecies[26].pos = Vec3<float>(right + 0.6f, front, bottom);
  531. vertecies[26].tPos = Vec2<float>(0.01f, 0.99f);
  532. vertecies[27].pos = Vec3<float>(right + 0.6f, back, bottom);
  533. vertecies[27].tPos = Vec2<float>(0.99f, 0.99f);
  534. // forth x plane
  535. vertecies[28].pos = Vec3<float>(right + 0.8f, front, top);
  536. vertecies[28].tPos = Vec2<float>(0.01f, 0.01f);
  537. vertecies[29].pos = Vec3<float>(right + 0.8f, back, top);
  538. vertecies[29].tPos = Vec2<float>(0.99f, 0.01f);
  539. vertecies[30].pos = Vec3<float>(right + 0.8f, front, bottom);
  540. vertecies[30].tPos = Vec2<float>(0.01f, 0.99f);
  541. vertecies[31].pos = Vec3<float>(right + 0.8f, back, bottom);
  542. vertecies[31].tPos = Vec2<float>(0.99f, 0.99f);
  543. for (int i = 0; i < 16; i++)
  544. {
  545. vertecies[i].normal = Vec3<float>(0, 1, 0);
  546. }
  547. for (int i = 16; i < 32; i++)
  548. {
  549. vertecies[i].normal = Vec3<float>(1, 0, 0);
  550. }
  551. data->setVertecies(vertecies, 32);
  552. Polygon3D* p = new Polygon3D();
  553. p->indexAnz = 6 * 8;
  554. p->indexList = new int[p->indexAnz];
  555. for (int i = 0; i < 8; i++)
  556. {
  557. p->indexList[i * 6 + 0] = 0 + i * 4;
  558. p->indexList[i * 6 + 1] = 1 + i * 4;
  559. p->indexList[i * 6 + 2] = 2 + i * 4;
  560. p->indexList[i * 6 + 3] = 1 + i * 4;
  561. p->indexList[i * 6 + 4] = 3 + i * 4;
  562. p->indexList[i * 6 + 5] = 2 + i * 4;
  563. }
  564. data->addPolygon(p);
  565. //data->calculateNormals();
  566. data->release();
  567. }
  568. void createFluidCube(Bildschirm* zScreen)
  569. {
  570. Model3DData* data = zScreen->zGraphicsApi()->createModel("fluid");
  571. data->setAmbientFactor(0.f);
  572. data->setDiffusFactor(1.f);
  573. data->setSpecularFactor(0.f);
  574. float size = 1;
  575. float left, right, top, bottom;
  576. // Calculate the screen coordinates of the left side of the bitmap.
  577. right = (float)((-size / 2.0));
  578. // Calculate the screen coordinates of the right side of the bitmap.
  579. left = right + (float)size;
  580. // Calculate the screen coordinates of the top of the bitmap.
  581. top = (float)(size / 2.0);
  582. // Calculate the screen coordinates of the bottom of the bitmap.
  583. bottom = top - (float)size;
  584. float front = -size / 2;
  585. float back = front + size;
  586. Vertex3D* vertecies = new Vertex3D[24];
  587. for (int i = 0; i < 24; i++)
  588. vertecies[i].knochenId = 0;
  589. // front side
  590. vertecies[0].pos = Vec3<float>(left, front, top);
  591. vertecies[0].tPos = Vec2<float>(0.f, 0.f);
  592. vertecies[1].pos = Vec3<float>(right, front, top);
  593. vertecies[1].tPos = Vec2<float>(1.f, 0.f);
  594. vertecies[2].pos = Vec3<float>(left, front, bottom);
  595. vertecies[2].tPos = Vec2<float>(0.f, 1.f);
  596. vertecies[3].pos = Vec3<float>(right, front, bottom);
  597. vertecies[3].tPos = Vec2<float>(1.f, 1.f);
  598. // back side
  599. vertecies[4].pos = Vec3<float>(right, back, top);
  600. vertecies[4].tPos = Vec2<float>(0.0f, 0.0f);
  601. vertecies[5].pos = Vec3<float>(left, back, top);
  602. vertecies[5].tPos = Vec2<float>(1.0f, 0.0f);
  603. vertecies[6].pos = Vec3<float>(right, back, bottom);
  604. vertecies[6].tPos = Vec2<float>(0.0f, 1.0f);
  605. vertecies[7].pos = Vec3<float>(left, back, bottom);
  606. vertecies[7].tPos = Vec2<float>(1.0f, 1.0f);
  607. // left side
  608. vertecies[8].pos = Vec3<float>(left, back, top);
  609. vertecies[8].tPos = Vec2<float>(0.f, 0.f);
  610. vertecies[9].pos = Vec3<float>(left, front, top);
  611. vertecies[9].tPos = Vec2<float>(1.f, 0.f);
  612. vertecies[10].pos = Vec3<float>(left, back, bottom);
  613. vertecies[10].tPos = Vec2<float>(0.f, 1.f);
  614. vertecies[11].pos = Vec3<float>(left, front, bottom);
  615. vertecies[11].tPos = Vec2<float>(1.f, 1.f);
  616. // right side
  617. vertecies[12].pos = Vec3<float>(right, front, top);
  618. vertecies[12].tPos = Vec2<float>(0.0f, 0.0f);
  619. vertecies[13].pos = Vec3<float>(right, back, top);
  620. vertecies[13].tPos = Vec2<float>(1.0f, 0.0f);
  621. vertecies[14].pos = Vec3<float>(right, front, bottom);
  622. vertecies[14].tPos = Vec2<float>(0.0f, 1.0f);
  623. vertecies[15].pos = Vec3<float>(right, back, bottom);
  624. vertecies[15].tPos = Vec2<float>(1.0f, 1.0f);
  625. // top side
  626. vertecies[16].pos = Vec3<float>(left, back, top);
  627. vertecies[16].tPos = Vec2<float>(0.f, 0.f);
  628. vertecies[17].pos = Vec3<float>(right, back, top);
  629. vertecies[17].tPos = Vec2<float>(1.f, 0.f);
  630. vertecies[18].pos = Vec3<float>(left, front, top);
  631. vertecies[18].tPos = Vec2<float>(0.f, 1.f);
  632. vertecies[19].pos = Vec3<float>(right, front, top);
  633. vertecies[19].tPos = Vec2<float>(1.f, 1.f);
  634. // botom side
  635. vertecies[20].pos = Vec3<float>(left, front, bottom);
  636. vertecies[20].tPos = Vec2<float>(0.0f, 0.0f);
  637. vertecies[21].pos = Vec3<float>(right, front, bottom);
  638. vertecies[21].tPos = Vec2<float>(1.0f, 0.0f);
  639. vertecies[22].pos = Vec3<float>(left, back, bottom);
  640. vertecies[22].tPos = Vec2<float>(0.0f, 1.0f);
  641. vertecies[23].pos = Vec3<float>(right, back, bottom);
  642. vertecies[23].tPos = Vec2<float>(1.0f, 1.0f);
  643. data->setVertecies(vertecies, 24);
  644. // the order of the polygons has to be NORTH (front), EAST (left), SOUTH
  645. // (back), WEST (right), TOP, BOTTOM according to the Area definition front
  646. // side
  647. Polygon3D* p
  648. = new Polygon3D(); // looking from (0,0,0) to (1,0,0) to see this side
  649. p->indexAnz = 6;
  650. p->indexList = new int[p->indexAnz];
  651. p->indexList[0] = 0;
  652. p->indexList[1] = 1;
  653. p->indexList[2] = 2;
  654. p->indexList[3] = 1;
  655. p->indexList[4] = 3;
  656. p->indexList[5] = 2;
  657. data->addPolygon(p);
  658. // left side
  659. p = new Polygon3D(); // looking from (0,0,0) to (0,1,0) to see this side
  660. p->indexAnz = 6;
  661. p->indexList = new int[p->indexAnz];
  662. p->indexList[0] = 0 + 8;
  663. p->indexList[1] = 1 + 8;
  664. p->indexList[2] = 2 + 8;
  665. p->indexList[3] = 1 + 8;
  666. p->indexList[4] = 3 + 8;
  667. p->indexList[5] = 2 + 8;
  668. data->addPolygon(p);
  669. // back side
  670. p = new Polygon3D(); // looking from (0,0,0) to (-1,0,0) to see this side
  671. p->indexAnz = 6;
  672. p->indexList = new int[p->indexAnz];
  673. p->indexList[0] = 0 + 4;
  674. p->indexList[1] = 1 + 4;
  675. p->indexList[2] = 2 + 4;
  676. p->indexList[3] = 1 + 4;
  677. p->indexList[4] = 3 + 4;
  678. p->indexList[5] = 2 + 4;
  679. data->addPolygon(p);
  680. // right side
  681. p = new Polygon3D(); // looking from (0,0,0) to (0,-1,0) to see this side
  682. p->indexAnz = 6;
  683. p->indexList = new int[p->indexAnz];
  684. p->indexList[0] = 0 + 12;
  685. p->indexList[1] = 1 + 12;
  686. p->indexList[2] = 2 + 12;
  687. p->indexList[3] = 1 + 12;
  688. p->indexList[4] = 3 + 12;
  689. p->indexList[5] = 2 + 12;
  690. data->addPolygon(p);
  691. // top side
  692. p = new Polygon3D(); // looking from (0,0,0) to (0,0,-1) to see this side
  693. p->indexAnz = 6;
  694. p->indexList = new int[p->indexAnz];
  695. p->indexList[0] = 0 + 16;
  696. p->indexList[1] = 1 + 16;
  697. p->indexList[2] = 2 + 16;
  698. p->indexList[3] = 1 + 16;
  699. p->indexList[4] = 3 + 16;
  700. p->indexList[5] = 2 + 16;
  701. data->addPolygon(p);
  702. // botom side
  703. p = new Polygon3D(); // looking from (0,0,0) to (0,0,1) to see this side
  704. p->indexAnz = 6;
  705. p->indexList = new int[p->indexAnz];
  706. p->indexList[0] = 0 + 20;
  707. p->indexList[1] = 1 + 20;
  708. p->indexList[2] = 2 + 20;
  709. p->indexList[3] = 1 + 20;
  710. p->indexList[4] = 3 + 20;
  711. p->indexList[5] = 2 + 20;
  712. data->addPolygon(p);
  713. data->calculateNormals();
  714. data->release();
  715. }
  716. void createModels(Bildschirm* zScreen)
  717. {
  718. createDefaultCube(zScreen);
  719. createCubeItem(zScreen);
  720. createPlayer(zScreen);
  721. createGrass(zScreen);
  722. createFluidCube(zScreen);
  723. }
  724. LoadMenu::LoadMenu(Bildschirm* zScreen)
  725. : Menu(zScreen)
  726. {
  727. Punkt center = zScreen->getBackBufferSize() / 2;
  728. step = initFBalken(
  729. center.x - 100, center.y + 25, 200, 30, FBalken::Style::normal);
  730. stage = initFBalken(
  731. center.x - 100, center.y - 15, 200, 30, FBalken::Style::normal);
  732. all = initFBalken(
  733. center.x - 100, center.y - 55, 200, 30, FBalken::Style::normal);
  734. elements.add(step);
  735. elements.add(stage);
  736. elements.add(all);
  737. new AsynchronCall("Load Menu", [this, zScreen]() {
  738. Sleep(1000);
  739. all->setAktionAnzahl(2);
  740. all->reset();
  741. // loading textures
  742. Datei texturF;
  743. texturF.setDatei("data/textures");
  744. RCArray<Text>* files = texturF.getDateiListe();
  745. if (files)
  746. {
  747. int count = 0;
  748. for (Text* fileName : *files)
  749. {
  750. LTDBDatei dat;
  751. dat.setDatei(new Text(Text("data/textures/") + *fileName));
  752. dat.leseDaten(0);
  753. count += dat.getBildAnzahl();
  754. }
  755. stage->setAktionAnzahl(count);
  756. stage->reset();
  757. for (Text* fileName : *files)
  758. {
  759. LTDBDatei dat;
  760. dat.setDatei(new Text(Text("data/textures/") + *fileName));
  761. dat.leseDaten(0);
  762. for (Text* name : *dat.zBildListe())
  763. {
  764. step->reset();
  765. Bild* b = dat.laden(step, new Text(*name));
  766. zScreen->zGraphicsApi()
  767. ->createOrGetTextur(*fileName + "/" + *name, b)
  768. ->release();
  769. stage->aktionPlus();
  770. }
  771. }
  772. files->release();
  773. }
  774. all->aktionPlus();
  775. // loading models
  776. stage->setAktionAnzahl(1);
  777. Datei modelF;
  778. modelF.setDatei("data/models");
  779. files = modelF.getDateiListe();
  780. if (files)
  781. {
  782. int count = 0;
  783. for (Text* fileName : *files)
  784. {
  785. M3Datei dat(Text("data/models/") + *fileName);
  786. dat.leseDaten();
  787. count += dat.getModelAnzahl();
  788. }
  789. stage->setAktionAnzahl(count + 1);
  790. stage->reset();
  791. for (Text* fileName : *files)
  792. {
  793. M3Datei dat(Text("data/models/") + *fileName);
  794. dat.leseDaten();
  795. for (int i = 0; i < dat.getModelAnzahl(); i++)
  796. {
  797. step->reset();
  798. Model3DData* d = dat.ladeModel(dat.zModelName(i)->getText(),
  799. zScreen->zGraphicsApi(),
  800. *fileName + "/" + *dat.zModelName(i));
  801. d->release();
  802. stage->aktionPlus();
  803. }
  804. }
  805. files->release();
  806. }
  807. createModels(zScreen);
  808. stage->aktionPlus();
  809. all->aktionPlus();
  810. stage->reset();
  811. zScreen->lock();
  812. hide();
  813. menuRegister->get("serverSelection")->show();
  814. zScreen->unlock();
  815. });
  816. }
  817. Bild* loadImage(Framework::Text path)
  818. {
  819. LTDBDatei file;
  820. file.setDatei(path.getTeilText(0, path.positionVon("/", path.anzahlVon("/") - 1)));
  821. file.leseDaten(0);
  822. return file.laden(0, path.getTeilText(path.positionVon("/", path.anzahlVon("/") - 1) + 1));
  823. }