Load.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  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 front
  91. // side
  92. Polygon3D* p = new Polygon3D(); // looking from (0,0,0) to (1,0,0) to see this side
  93. p->indexAnz = 6;
  94. p->indexList = new int[p->indexAnz];
  95. p->indexList[0] = 0;
  96. p->indexList[1] = 1;
  97. p->indexList[2] = 2;
  98. p->indexList[3] = 1;
  99. p->indexList[4] = 3;
  100. p->indexList[5] = 2;
  101. data->addPolygon(p);
  102. // left side
  103. p = new Polygon3D(); // looking from (0,0,0) to (0,1,0) to see this side
  104. p->indexAnz = 6;
  105. p->indexList = new int[p->indexAnz];
  106. p->indexList[0] = 0 + 8;
  107. p->indexList[1] = 1 + 8;
  108. p->indexList[2] = 2 + 8;
  109. p->indexList[3] = 1 + 8;
  110. p->indexList[4] = 3 + 8;
  111. p->indexList[5] = 2 + 8;
  112. data->addPolygon(p);
  113. // back side
  114. p = new Polygon3D(); // looking from (0,0,0) to (-1,0,0) to see this side
  115. p->indexAnz = 6;
  116. p->indexList = new int[p->indexAnz];
  117. p->indexList[0] = 0 + 4;
  118. p->indexList[1] = 1 + 4;
  119. p->indexList[2] = 2 + 4;
  120. p->indexList[3] = 1 + 4;
  121. p->indexList[4] = 3 + 4;
  122. p->indexList[5] = 2 + 4;
  123. data->addPolygon(p);
  124. // right side
  125. p = new Polygon3D(); // looking from (0,0,0) to (0,-1,0) to see this side
  126. p->indexAnz = 6;
  127. p->indexList = new int[p->indexAnz];
  128. p->indexList[0] = 0 + 12;
  129. p->indexList[1] = 1 + 12;
  130. p->indexList[2] = 2 + 12;
  131. p->indexList[3] = 1 + 12;
  132. p->indexList[4] = 3 + 12;
  133. p->indexList[5] = 2 + 12;
  134. data->addPolygon(p);
  135. // top side
  136. p = new Polygon3D(); // looking from (0,0,0) to (0,0,-1) to see this side
  137. p->indexAnz = 6;
  138. p->indexList = new int[p->indexAnz];
  139. p->indexList[0] = 0 + 16;
  140. p->indexList[1] = 1 + 16;
  141. p->indexList[2] = 2 + 16;
  142. p->indexList[3] = 1 + 16;
  143. p->indexList[4] = 3 + 16;
  144. p->indexList[5] = 2 + 16;
  145. data->addPolygon(p);
  146. // botom side
  147. p = new Polygon3D(); // looking from (0,0,0) to (0,0,1) to see this side
  148. p->indexAnz = 6;
  149. p->indexList = new int[p->indexAnz];
  150. p->indexList[0] = 0 + 20;
  151. p->indexList[1] = 1 + 20;
  152. p->indexList[2] = 2 + 20;
  153. p->indexList[3] = 1 + 20;
  154. p->indexList[4] = 3 + 20;
  155. p->indexList[5] = 2 + 20;
  156. data->addPolygon(p);
  157. data->calculateNormals();
  158. data->release();
  159. }
  160. void createCubeItem(Bildschirm* zScreen)
  161. {
  162. Framework::Model3DData* data
  163. = window->zBildschirm()->zGraphicsApi()->createModel("itemCube");
  164. data->setAmbientFactor(0.8f);
  165. data->setDiffusFactor(0.1f);
  166. data->setSpecularFactor(0.1f);
  167. float size = 0.2f;
  168. float left, right, top, bottom;
  169. // Calculate the screen coordinates of the left side of the bitmap.
  170. left = (float)((-size / 2.0));
  171. // Calculate the screen coordinates of the right side of the bitmap.
  172. right = left + (float)size;
  173. // Calculate the screen coordinates of the top of the bitmap.
  174. top = (float)(size / 2.0);
  175. // Calculate the screen coordinates of the bottom of the bitmap.
  176. bottom = top - (float)size;
  177. float front = -size / 2;
  178. float back = front + size;
  179. Vertex3D* vertecies = new Vertex3D[24];
  180. for (int i = 0; i < 24; i++)
  181. vertecies[i].knochenId = 0;
  182. // front side
  183. vertecies[0].pos = Vec3<float>(left, front, top);
  184. vertecies[0].tPos = Vec2<float>(0.f, 0.f);
  185. vertecies[1].pos = Vec3<float>(right, front, top);
  186. vertecies[1].tPos = Vec2<float>(1.f, 0.f);
  187. vertecies[2].pos = Vec3<float>(left, front, bottom);
  188. vertecies[2].tPos = Vec2<float>(0.f, 1.f);
  189. vertecies[3].pos = Vec3<float>(right, front, bottom);
  190. vertecies[3].tPos = Vec2<float>(1.f, 1.f);
  191. // back side
  192. vertecies[4].pos = Vec3<float>(right, back, top);
  193. vertecies[4].tPos = Vec2<float>(0.0f, 0.0f);
  194. vertecies[5].pos = Vec3<float>(left, back, top);
  195. vertecies[5].tPos = Vec2<float>(1.0f, 0.0f);
  196. vertecies[6].pos = Vec3<float>(right, back, bottom);
  197. vertecies[6].tPos = Vec2<float>(0.0f, 1.0f);
  198. vertecies[7].pos = Vec3<float>(left, back, bottom);
  199. vertecies[7].tPos = Vec2<float>(1.0f, 1.0f);
  200. // left side
  201. vertecies[8].pos = Vec3<float>(left, back, top);
  202. vertecies[8].tPos = Vec2<float>(0.f, 0.f);
  203. vertecies[9].pos = Vec3<float>(left, front, top);
  204. vertecies[9].tPos = Vec2<float>(1.f, 0.f);
  205. vertecies[10].pos = Vec3<float>(left, back, bottom);
  206. vertecies[10].tPos = Vec2<float>(0.f, 1.f);
  207. vertecies[11].pos = Vec3<float>(left, front, bottom);
  208. vertecies[11].tPos = Vec2<float>(1.f, 1.f);
  209. // right side
  210. vertecies[12].pos = Vec3<float>(right, front, top);
  211. vertecies[12].tPos = Vec2<float>(0.0f, 0.0f);
  212. vertecies[13].pos = Vec3<float>(right, back, top);
  213. vertecies[13].tPos = Vec2<float>(1.0f, 0.0f);
  214. vertecies[14].pos = Vec3<float>(right, front, bottom);
  215. vertecies[14].tPos = Vec2<float>(0.0f, 1.0f);
  216. vertecies[15].pos = Vec3<float>(right, back, bottom);
  217. vertecies[15].tPos = Vec2<float>(1.0f, 1.0f);
  218. // top side
  219. vertecies[16].pos = Vec3<float>(left, back, top);
  220. vertecies[16].tPos = Vec2<float>(0.f, 0.f);
  221. vertecies[17].pos = Vec3<float>(right, back, top);
  222. vertecies[17].tPos = Vec2<float>(1.f, 0.f);
  223. vertecies[18].pos = Vec3<float>(left, front, top);
  224. vertecies[18].tPos = Vec2<float>(0.f, 1.f);
  225. vertecies[19].pos = Vec3<float>(right, front, top);
  226. vertecies[19].tPos = Vec2<float>(1.f, 1.f);
  227. // botom side
  228. vertecies[20].pos = Vec3<float>(left, front, bottom);
  229. vertecies[20].tPos = Vec2<float>(0.0f, 0.0f);
  230. vertecies[21].pos = Vec3<float>(right, front, bottom);
  231. vertecies[21].tPos = Vec2<float>(1.0f, 0.0f);
  232. vertecies[22].pos = Vec3<float>(left, back, bottom);
  233. vertecies[22].tPos = Vec2<float>(0.0f, 1.0f);
  234. vertecies[23].pos = Vec3<float>(right, back, bottom);
  235. vertecies[23].tPos = Vec2<float>(1.0f, 1.0f);
  236. data->setVertecies(vertecies, 24);
  237. // the order of the polygons has to be NORTH (front), EAST (left), SOUTH
  238. // (back), WEST (right), TOP, BOTTOM according to the Area definition front
  239. // side
  240. Polygon3D* p = new Polygon3D();
  241. p->indexAnz = 6;
  242. p->indexList = new int[p->indexAnz];
  243. p->indexList[0] = 0;
  244. p->indexList[1] = 2;
  245. p->indexList[2] = 1;
  246. p->indexList[3] = 1;
  247. p->indexList[4] = 2;
  248. p->indexList[5] = 3;
  249. data->addPolygon(p);
  250. // left side
  251. p = new Polygon3D();
  252. p->indexAnz = 6;
  253. p->indexList = new int[p->indexAnz];
  254. p->indexList[0] = 0 + 8;
  255. p->indexList[1] = 2 + 8;
  256. p->indexList[2] = 1 + 8;
  257. p->indexList[3] = 1 + 8;
  258. p->indexList[4] = 2 + 8;
  259. p->indexList[5] = 3 + 8;
  260. data->addPolygon(p);
  261. // back side
  262. p = new Polygon3D();
  263. p->indexAnz = 6;
  264. p->indexList = new int[p->indexAnz];
  265. p->indexList[0] = 0 + 4;
  266. p->indexList[1] = 2 + 4;
  267. p->indexList[2] = 1 + 4;
  268. p->indexList[3] = 1 + 4;
  269. p->indexList[4] = 2 + 4;
  270. p->indexList[5] = 3 + 4;
  271. data->addPolygon(p);
  272. // right side
  273. p = new Polygon3D();
  274. p->indexAnz = 6;
  275. p->indexList = new int[p->indexAnz];
  276. p->indexList[0] = 0 + 12;
  277. p->indexList[1] = 2 + 12;
  278. p->indexList[2] = 1 + 12;
  279. p->indexList[3] = 1 + 12;
  280. p->indexList[4] = 2 + 12;
  281. p->indexList[5] = 3 + 12;
  282. data->addPolygon(p);
  283. // top side
  284. p = new Polygon3D();
  285. p->indexAnz = 6;
  286. p->indexList = new int[p->indexAnz];
  287. p->indexList[0] = 0 + 16;
  288. p->indexList[1] = 2 + 16;
  289. p->indexList[2] = 1 + 16;
  290. p->indexList[3] = 1 + 16;
  291. p->indexList[4] = 2 + 16;
  292. p->indexList[5] = 3 + 16;
  293. data->addPolygon(p);
  294. // botom side
  295. p = new Polygon3D();
  296. p->indexAnz = 6;
  297. p->indexList = new int[p->indexAnz];
  298. p->indexList[0] = 0 + 20;
  299. p->indexList[1] = 2 + 20;
  300. p->indexList[2] = 1 + 20;
  301. p->indexList[3] = 1 + 20;
  302. p->indexList[4] = 2 + 20;
  303. p->indexList[5] = 3 + 20;
  304. data->addPolygon(p);
  305. data->calculateNormals();
  306. data->release();
  307. }
  308. void createPlayer(Bildschirm* zScreen)
  309. {
  310. Framework::Model3DData* data
  311. = window->zBildschirm()->zGraphicsApi()->createModel("player");
  312. data->setAmbientFactor(0.8f);
  313. data->setDiffusFactor(0.1f);
  314. data->setSpecularFactor(0.1f);
  315. float size = 0.8f;
  316. float left, right, top, bottom;
  317. // Calculate the screen coordinates of the left side of the bitmap.
  318. left = (float)((size / 2.0) * -1);
  319. // Calculate the screen coordinates of the right side of the bitmap.
  320. right = left + (float)size;
  321. // Calculate the screen coordinates of the top of the bitmap.
  322. top = (float)(size / 2.0);
  323. // Calculate the screen coordinates of the bottom of the bitmap.
  324. bottom = top - (float)size;
  325. float front = -1.5f / 2;
  326. float back = front + 1.5f;
  327. Vertex3D* vertecies = new Vertex3D[24];
  328. for (int i = 0; i < 24; i++)
  329. vertecies[i].knochenId = 0;
  330. vertecies[0].pos = Vec3<float>(left, top, front);
  331. vertecies[0].tPos = Vec2<float>(0.f, 0.f);
  332. vertecies[1].pos = Vec3<float>(right, top, front);
  333. vertecies[1].tPos = Vec2<float>(1.f, 0.f);
  334. vertecies[2].pos = Vec3<float>(left, bottom, front);
  335. vertecies[2].tPos = Vec2<float>(0.f, 1.f);
  336. vertecies[3].pos = Vec3<float>(right, bottom, front);
  337. vertecies[3].tPos = Vec2<float>(1.f, 1.f);
  338. vertecies[4].pos = Vec3<float>(left, top, back);
  339. vertecies[4].tPos = Vec2<float>(0.0f, 0.0f);
  340. vertecies[5].pos = Vec3<float>(right, top, back);
  341. vertecies[5].tPos = Vec2<float>(1.0f, 0.0f);
  342. vertecies[6].pos = Vec3<float>(left, bottom, back);
  343. vertecies[6].tPos = Vec2<float>(0.0f, 1.0f);
  344. vertecies[7].pos = Vec3<float>(right, bottom, back);
  345. vertecies[7].tPos = Vec2<float>(1.0f, 1.0f);
  346. vertecies[8].pos = Vec3<float>(left, top, front);
  347. vertecies[8].tPos = Vec2<float>(1.f, 0.f);
  348. vertecies[9].pos = Vec3<float>(right, top, front);
  349. vertecies[9].tPos = Vec2<float>(0.f, 0.f);
  350. vertecies[10].pos = Vec3<float>(left, bottom, front);
  351. vertecies[10].tPos = Vec2<float>(1.f, 1.f);
  352. vertecies[11].pos = Vec3<float>(right, bottom, front);
  353. vertecies[11].tPos = Vec2<float>(0.f, 1.f);
  354. vertecies[12].pos = Vec3<float>(left, top, back);
  355. vertecies[12].tPos = Vec2<float>(0.0f, 0.0f);
  356. vertecies[13].pos = Vec3<float>(right, top, back);
  357. vertecies[13].tPos = Vec2<float>(1.0f, 0.0f);
  358. vertecies[14].pos = Vec3<float>(left, bottom, back);
  359. vertecies[14].tPos = Vec2<float>(0.0f, 1.0f);
  360. vertecies[15].pos = Vec3<float>(right, bottom, back);
  361. vertecies[15].tPos = Vec2<float>(1.0f, 1.0f);
  362. vertecies[16].pos = Vec3<float>(left, top, front);
  363. vertecies[16].tPos = Vec2<float>(0.f, 1.f);
  364. vertecies[17].pos = Vec3<float>(right, top, front);
  365. vertecies[17].tPos = Vec2<float>(1.f, 1.f);
  366. vertecies[18].pos = Vec3<float>(left, bottom, front);
  367. vertecies[18].tPos = Vec2<float>(0.f, 0.f);
  368. vertecies[19].pos = Vec3<float>(right, bottom, front);
  369. vertecies[19].tPos = Vec2<float>(1.f, 0.f);
  370. vertecies[20].pos = Vec3<float>(left, top, back);
  371. vertecies[20].tPos = Vec2<float>(0.0f, 0.0f);
  372. vertecies[21].pos = Vec3<float>(right, top, back);
  373. vertecies[21].tPos = Vec2<float>(1.0f, 0.0f);
  374. vertecies[22].pos = Vec3<float>(left, bottom, back);
  375. vertecies[22].tPos = Vec2<float>(0.0f, 1.0f);
  376. vertecies[23].pos = Vec3<float>(right, bottom, back);
  377. vertecies[23].tPos = Vec2<float>(1.0f, 1.0f);
  378. data->setVertecies(vertecies, 24);
  379. // the order of the polygons has to be NORTH, EAST, SOUTH, WEST, TOP, BOTTOM
  380. // according to the Area definition down side
  381. Polygon3D* p = new Polygon3D();
  382. p->indexAnz = 6;
  383. p->indexList = new int[p->indexAnz];
  384. p->indexList[0] = 6 + 16;
  385. p->indexList[1] = 2 + 16;
  386. p->indexList[2] = 3 + 16;
  387. p->indexList[3] = 6 + 16;
  388. p->indexList[4] = 3 + 16;
  389. p->indexList[5] = 7 + 16;
  390. data->addPolygon(p);
  391. // right side
  392. p = new Polygon3D();
  393. p->indexAnz = 6;
  394. p->indexList = new int[p->indexAnz];
  395. p->indexList[0] = 1 + 8;
  396. p->indexList[1] = 7 + 8;
  397. p->indexList[2] = 3 + 8;
  398. p->indexList[3] = 1 + 8;
  399. p->indexList[4] = 5 + 8;
  400. p->indexList[5] = 7 + 8;
  401. data->addPolygon(p);
  402. // top side
  403. p = new Polygon3D();
  404. p->indexAnz = 6;
  405. p->indexList = new int[p->indexAnz];
  406. p->indexList[0] = 4 + 16;
  407. p->indexList[1] = 1 + 16;
  408. p->indexList[2] = 0 + 16;
  409. p->indexList[3] = 4 + 16;
  410. p->indexList[4] = 5 + 16;
  411. p->indexList[5] = 1 + 16;
  412. data->addPolygon(p);
  413. // left side
  414. p = new Polygon3D();
  415. p->indexAnz = 6;
  416. p->indexList = new int[p->indexAnz];
  417. p->indexList[0] = 0 + 8;
  418. p->indexList[1] = 2 + 8;
  419. p->indexList[2] = 6 + 8;
  420. p->indexList[3] = 0 + 8;
  421. p->indexList[4] = 6 + 8;
  422. p->indexList[5] = 4 + 8;
  423. data->addPolygon(p);
  424. // back side
  425. p = new Polygon3D();
  426. p->indexAnz = 6;
  427. p->indexList = new int[p->indexAnz];
  428. p->indexList[0] = 4;
  429. p->indexList[1] = 6;
  430. p->indexList[2] = 7;
  431. p->indexList[3] = 4;
  432. p->indexList[4] = 7;
  433. p->indexList[5] = 5;
  434. data->addPolygon(p);
  435. // front side
  436. p = new Polygon3D();
  437. p->indexAnz = 6;
  438. p->indexList = new int[p->indexAnz];
  439. p->indexList[0] = 0;
  440. p->indexList[1] = 3;
  441. p->indexList[2] = 2;
  442. p->indexList[3] = 0;
  443. p->indexList[4] = 1;
  444. p->indexList[5] = 3;
  445. data->addPolygon(p);
  446. data->calculateNormals();
  447. data->release();
  448. }
  449. void createGrass(Bildschirm* zScreen)
  450. {
  451. Model3DData* data = zScreen->zGraphicsApi()->createModel("grass");
  452. data->setAmbientFactor(1.f);
  453. data->setDiffusFactor(0.f);
  454. data->setSpecularFactor(0.f);
  455. float size = 1;
  456. float left, right, top, bottom;
  457. // Calculate the screen coordinates of the left side of the bitmap.
  458. right = (float)((-size / 2.0));
  459. // Calculate the screen coordinates of the right side of the bitmap.
  460. left = right + (float)size;
  461. // Calculate the screen coordinates of the top of the bitmap.
  462. top = (float)(size / 2.0);
  463. // Calculate the screen coordinates of the bottom of the bitmap.
  464. bottom = top - (float)size;
  465. float front = -size / 2;
  466. float back = front + size;
  467. Vertex3D* vertecies = new Vertex3D[32];
  468. for (int i = 0; i < 32; i++)
  469. vertecies[i].knochenId = 0;
  470. // first y plane
  471. vertecies[0].pos = Vec3<float>(left, front + 0.2f, top);
  472. vertecies[0].tPos = Vec2<float>(0.01f, 0.01f);
  473. vertecies[1].pos = Vec3<float>(right, front + 0.2f, top);
  474. vertecies[1].tPos = Vec2<float>(0.99f, 0.01f);
  475. vertecies[2].pos = Vec3<float>(left, front + 0.2f, bottom);
  476. vertecies[2].tPos = Vec2<float>(0.01f, 0.99f);
  477. vertecies[3].pos = Vec3<float>(right, front + 0.2f, bottom);
  478. vertecies[3].tPos = Vec2<float>(0.99f, 0.99f);
  479. // second y plane
  480. vertecies[4].pos = Vec3<float>(left, front + 0.4f, top);
  481. vertecies[4].tPos = Vec2<float>(0.01f, 0.01f);
  482. vertecies[5].pos = Vec3<float>(right, front + 0.4f, top);
  483. vertecies[5].tPos = Vec2<float>(0.99f, 0.01f);
  484. vertecies[6].pos = Vec3<float>(left, front + 0.4f, bottom);
  485. vertecies[6].tPos = Vec2<float>(0.01f, 0.99f);
  486. vertecies[7].pos = Vec3<float>(right, front + 0.4f, bottom);
  487. vertecies[7].tPos = Vec2<float>(0.99f, 0.99f);
  488. // third y plane
  489. vertecies[8].pos = Vec3<float>(left, front + 0.6f, top);
  490. vertecies[8].tPos = Vec2<float>(0.01f, 0.01f);
  491. vertecies[9].pos = Vec3<float>(right, front + 0.6f, top);
  492. vertecies[9].tPos = Vec2<float>(0.99f, 0.01f);
  493. vertecies[10].pos = Vec3<float>(left, front + 0.6f, bottom);
  494. vertecies[10].tPos = Vec2<float>(0.01f, 0.99f);
  495. vertecies[11].pos = Vec3<float>(right, front + 0.6f, bottom);
  496. vertecies[11].tPos = Vec2<float>(0.99f, 0.99f);
  497. // forth y plane
  498. vertecies[12].pos = Vec3<float>(left, front + 0.8f, top);
  499. vertecies[12].tPos = Vec2<float>(0.01f, 0.01f);
  500. vertecies[13].pos = Vec3<float>(right, front + 0.8f, top);
  501. vertecies[13].tPos = Vec2<float>(0.99f, 0.01f);
  502. vertecies[14].pos = Vec3<float>(left, front + 0.8f, bottom);
  503. vertecies[14].tPos = Vec2<float>(0.01f, 0.99f);
  504. vertecies[15].pos = Vec3<float>(right, front + 0.8f, bottom);
  505. vertecies[15].tPos = Vec2<float>(0.99f, 0.99f);
  506. // first x plane
  507. vertecies[16].pos = Vec3<float>(right + 0.2f, front, top);
  508. vertecies[16].tPos = Vec2<float>(0.01f, 0.01f);
  509. vertecies[17].pos = Vec3<float>(right + 0.2f, back, top);
  510. vertecies[17].tPos = Vec2<float>(0.99f, 0.01f);
  511. vertecies[18].pos = Vec3<float>(right + 0.2f, front, bottom);
  512. vertecies[18].tPos = Vec2<float>(0.01f, 0.99f);
  513. vertecies[19].pos = Vec3<float>(right + 0.2f, back, bottom);
  514. vertecies[19].tPos = Vec2<float>(0.99f, 0.99f);
  515. // second x plane
  516. vertecies[20].pos = Vec3<float>(right + 0.4f, front, top);
  517. vertecies[20].tPos = Vec2<float>(0.01f, 0.01f);
  518. vertecies[21].pos = Vec3<float>(right + 0.4f, back, top);
  519. vertecies[21].tPos = Vec2<float>(0.99f, 0.01f);
  520. vertecies[22].pos = Vec3<float>(right + 0.4f, front, bottom);
  521. vertecies[22].tPos = Vec2<float>(0.01f, 0.99f);
  522. vertecies[23].pos = Vec3<float>(right + 0.4f, back, bottom);
  523. vertecies[23].tPos = Vec2<float>(0.99f, 0.99f);
  524. // third x plane
  525. vertecies[24].pos = Vec3<float>(right + 0.6f, front, top);
  526. vertecies[24].tPos = Vec2<float>(0.01f, 0.01f);
  527. vertecies[25].pos = Vec3<float>(right + 0.6f, back, top);
  528. vertecies[25].tPos = Vec2<float>(0.99f, 0.01f);
  529. vertecies[26].pos = Vec3<float>(right + 0.6f, front, bottom);
  530. vertecies[26].tPos = Vec2<float>(0.01f, 0.99f);
  531. vertecies[27].pos = Vec3<float>(right + 0.6f, back, bottom);
  532. vertecies[27].tPos = Vec2<float>(0.99f, 0.99f);
  533. // forth x plane
  534. vertecies[28].pos = Vec3<float>(right + 0.8f, front, top);
  535. vertecies[28].tPos = Vec2<float>(0.01f, 0.01f);
  536. vertecies[29].pos = Vec3<float>(right + 0.8f, back, top);
  537. vertecies[29].tPos = Vec2<float>(0.99f, 0.01f);
  538. vertecies[30].pos = Vec3<float>(right + 0.8f, front, bottom);
  539. vertecies[30].tPos = Vec2<float>(0.01f, 0.99f);
  540. vertecies[31].pos = Vec3<float>(right + 0.8f, back, bottom);
  541. vertecies[31].tPos = Vec2<float>(0.99f, 0.99f);
  542. data->setVertecies(vertecies, 32);
  543. for (int i = 0; i < 8; i++)
  544. {
  545. Polygon3D* p = new Polygon3D();
  546. p->indexAnz = 6;
  547. p->indexList = new int[p->indexAnz];
  548. p->indexList[0] = 0 + i * 4;
  549. p->indexList[1] = 1 + i * 4;
  550. p->indexList[2] = 2 + i * 4;
  551. p->indexList[3] = 1 + i * 4;
  552. p->indexList[4] = 3 + i * 4;
  553. p->indexList[5] = 2 + i * 4;
  554. data->addPolygon(p);
  555. p = new Polygon3D();
  556. p->indexAnz = 6;
  557. p->indexList = new int[p->indexAnz];
  558. p->indexList[0] = 0 + i * 4;
  559. p->indexList[1] = 2 + i * 4;
  560. p->indexList[2] = 1 + i * 4;
  561. p->indexList[3] = 1 + i * 4;
  562. p->indexList[4] = 2 + i * 4;
  563. p->indexList[5] = 3 + i * 4;
  564. data->addPolygon(p);
  565. }
  566. data->calculateNormals();
  567. data->release();
  568. }
  569. void createModels(Bildschirm* zScreen)
  570. {
  571. createDefaultCube(zScreen);
  572. createCubeItem(zScreen);
  573. createPlayer(zScreen);
  574. createGrass(zScreen);
  575. }
  576. LoadMenu::LoadMenu(Bildschirm* zScreen)
  577. : Menu(zScreen)
  578. {
  579. Punkt center = zScreen->getBackBufferSize() / 2;
  580. step = initFBalken(
  581. center.x - 100, center.y + 25, 200, 30, FBalken::Style::normal);
  582. stage = initFBalken(
  583. center.x - 100, center.y - 15, 200, 30, FBalken::Style::normal);
  584. all = initFBalken(
  585. center.x - 100, center.y - 55, 200, 30, FBalken::Style::normal);
  586. elements.add(step);
  587. elements.add(stage);
  588. elements.add(all);
  589. new AsynchronCall("Load Menu", [this, zScreen]() {
  590. Sleep(1000);
  591. all->setAktionAnzahl(2);
  592. all->reset();
  593. // loading textures
  594. Datei texturF;
  595. texturF.setDatei("data/textures");
  596. RCArray<Text>* files = texturF.getDateiListe();
  597. if (files)
  598. {
  599. int count = 0;
  600. for (Text* fileName : *files)
  601. {
  602. LTDBDatei dat;
  603. dat.setDatei(new Text(Text("data/textures/") + *fileName));
  604. dat.leseDaten(0);
  605. count += dat.getBildAnzahl();
  606. }
  607. stage->setAktionAnzahl(count);
  608. stage->reset();
  609. for (Text* fileName : *files)
  610. {
  611. LTDBDatei dat;
  612. dat.setDatei(new Text(Text("data/textures/") + *fileName));
  613. dat.leseDaten(0);
  614. for (Text* name : *dat.zBildListe())
  615. {
  616. step->reset();
  617. Bild* b = dat.laden(step, new Text(*name));
  618. zScreen->zGraphicsApi()
  619. ->createOrGetTextur(*fileName + "/" + *name, b)
  620. ->release();
  621. stage->aktionPlus();
  622. }
  623. }
  624. files->release();
  625. }
  626. all->aktionPlus();
  627. // loading models
  628. stage->setAktionAnzahl(1);
  629. Datei modelF;
  630. modelF.setDatei("data/models");
  631. files = modelF.getDateiListe();
  632. if (files)
  633. {
  634. int count = 0;
  635. for (Text* fileName : *files)
  636. {
  637. M3Datei dat(Text("data/models/") + *fileName);
  638. dat.leseDaten();
  639. count += dat.getModelAnzahl();
  640. }
  641. stage->setAktionAnzahl(count + 1);
  642. stage->reset();
  643. for (Text* fileName : *files)
  644. {
  645. M3Datei dat(Text("data/models/") + *fileName);
  646. dat.leseDaten();
  647. for (int i = 0; i < dat.getModelAnzahl(); i++)
  648. {
  649. step->reset();
  650. Model3DData* d = dat.ladeModel(dat.zModelName(i)->getText(),
  651. zScreen->zGraphicsApi(),
  652. *fileName + "/" + *dat.zModelName(i));
  653. d->release();
  654. stage->aktionPlus();
  655. }
  656. }
  657. files->release();
  658. }
  659. createModels(zScreen);
  660. stage->aktionPlus();
  661. all->aktionPlus();
  662. stage->reset();
  663. zScreen->lock();
  664. hide();
  665. menuRegister->get("serverSelection")->show();
  666. zScreen->unlock();
  667. });
  668. }