Load.cpp 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864
  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(0.f);
  453. data->setDiffusFactor(1.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 createFluidCube(Bildschirm* zScreen)
  570. {
  571. Model3DData* data = zScreen->zGraphicsApi()->createModel("fluid");
  572. data->setAmbientFactor(0.f);
  573. data->setDiffusFactor(1.f);
  574. data->setSpecularFactor(0.f);
  575. float size = 1;
  576. float left, right, top, bottom;
  577. // Calculate the screen coordinates of the left side of the bitmap.
  578. right = (float)((-size / 2.0));
  579. // Calculate the screen coordinates of the right side of the bitmap.
  580. left = right + (float)size;
  581. // Calculate the screen coordinates of the top of the bitmap.
  582. top = (float)(size / 2.0);
  583. // Calculate the screen coordinates of the bottom of the bitmap.
  584. bottom = top - (float)size;
  585. float front = -size / 2;
  586. float back = front + size;
  587. Vertex3D* vertecies = new Vertex3D[24];
  588. for (int i = 0; i < 24; i++)
  589. vertecies[i].knochenId = 0;
  590. // front side
  591. vertecies[0].pos = Vec3<float>(left, front, top);
  592. vertecies[0].tPos = Vec2<float>(0.f, 0.f);
  593. vertecies[0].knochenId = 1;
  594. vertecies[1].pos = Vec3<float>(right, front, top);
  595. vertecies[1].tPos = Vec2<float>(1.f, 0.f);
  596. vertecies[1].knochenId = 2;
  597. vertecies[2].pos = Vec3<float>(left, front, bottom);
  598. vertecies[2].tPos = Vec2<float>(0.f, 1.f);
  599. vertecies[3].pos = Vec3<float>(right, front, bottom);
  600. vertecies[3].tPos = Vec2<float>(1.f, 1.f);
  601. // back side
  602. vertecies[4].pos = Vec3<float>(right, back, top);
  603. vertecies[4].tPos = Vec2<float>(0.0f, 0.0f);
  604. vertecies[4].knochenId = 3;
  605. vertecies[5].pos = Vec3<float>(left, back, top);
  606. vertecies[5].tPos = Vec2<float>(1.0f, 0.0f);
  607. vertecies[5].knochenId = 4;
  608. vertecies[6].pos = Vec3<float>(right, back, bottom);
  609. vertecies[6].tPos = Vec2<float>(0.0f, 1.0f);
  610. vertecies[7].pos = Vec3<float>(left, back, bottom);
  611. vertecies[7].tPos = Vec2<float>(1.0f, 1.0f);
  612. // left side
  613. vertecies[8].pos = Vec3<float>(left, back, top);
  614. vertecies[8].tPos = Vec2<float>(0.f, 0.f);
  615. vertecies[8].knochenId = 4;
  616. vertecies[9].pos = Vec3<float>(left, front, top);
  617. vertecies[9].tPos = Vec2<float>(1.f, 0.f);
  618. vertecies[9].knochenId = 1;
  619. vertecies[10].pos = Vec3<float>(left, back, bottom);
  620. vertecies[10].tPos = Vec2<float>(0.f, 1.f);
  621. vertecies[11].pos = Vec3<float>(left, front, bottom);
  622. vertecies[11].tPos = Vec2<float>(1.f, 1.f);
  623. // right side
  624. vertecies[12].pos = Vec3<float>(right, front, top);
  625. vertecies[12].tPos = Vec2<float>(0.0f, 0.0f);
  626. vertecies[12].knochenId = 2;
  627. vertecies[13].pos = Vec3<float>(right, back, top);
  628. vertecies[13].tPos = Vec2<float>(1.0f, 0.0f);
  629. vertecies[13].knochenId = 3;
  630. vertecies[14].pos = Vec3<float>(right, front, bottom);
  631. vertecies[14].tPos = Vec2<float>(0.0f, 1.0f);
  632. vertecies[15].pos = Vec3<float>(right, back, bottom);
  633. vertecies[15].tPos = Vec2<float>(1.0f, 1.0f);
  634. // top side
  635. vertecies[16].pos = Vec3<float>(left, back, top);
  636. vertecies[16].tPos = Vec2<float>(0.f, 0.f);
  637. vertecies[16].knochenId = 4;
  638. vertecies[17].pos = Vec3<float>(right, back, top);
  639. vertecies[17].knochenId = 3;
  640. vertecies[17].tPos = Vec2<float>(1.f, 0.f);
  641. vertecies[18].pos = Vec3<float>(left, front, top);
  642. vertecies[18].tPos = Vec2<float>(0.f, 1.f);
  643. vertecies[18].knochenId = 1;
  644. vertecies[19].pos = Vec3<float>(right, front, top);
  645. vertecies[19].tPos = Vec2<float>(1.f, 1.f);
  646. vertecies[19].knochenId = 2;
  647. // botom side
  648. vertecies[20].pos = Vec3<float>(left, front, bottom);
  649. vertecies[20].tPos = Vec2<float>(0.0f, 0.0f);
  650. vertecies[21].pos = Vec3<float>(right, front, bottom);
  651. vertecies[21].tPos = Vec2<float>(1.0f, 0.0f);
  652. vertecies[22].pos = Vec3<float>(left, back, bottom);
  653. vertecies[22].tPos = Vec2<float>(0.0f, 1.0f);
  654. vertecies[23].pos = Vec3<float>(right, back, bottom);
  655. vertecies[23].tPos = Vec2<float>(1.0f, 1.0f);
  656. data->setVertecies(vertecies, 24);
  657. // the order of the polygons has to be NORTH (front), EAST (left), SOUTH
  658. // (back), WEST (right), TOP, BOTTOM according to the Area definition front
  659. // side
  660. Polygon3D* p
  661. = new Polygon3D(); // looking from (0,0,0) to (1,0,0) to see this side
  662. p->indexAnz = 6;
  663. p->indexList = new int[p->indexAnz];
  664. p->indexList[0] = 0;
  665. p->indexList[1] = 1;
  666. p->indexList[2] = 2;
  667. p->indexList[3] = 1;
  668. p->indexList[4] = 3;
  669. p->indexList[5] = 2;
  670. data->addPolygon(p);
  671. // left side
  672. p = new Polygon3D(); // looking from (0,0,0) to (0,1,0) to see this side
  673. p->indexAnz = 6;
  674. p->indexList = new int[p->indexAnz];
  675. p->indexList[0] = 0 + 8;
  676. p->indexList[1] = 1 + 8;
  677. p->indexList[2] = 2 + 8;
  678. p->indexList[3] = 1 + 8;
  679. p->indexList[4] = 3 + 8;
  680. p->indexList[5] = 2 + 8;
  681. data->addPolygon(p);
  682. // back side
  683. p = new Polygon3D(); // looking from (0,0,0) to (-1,0,0) to see this side
  684. p->indexAnz = 6;
  685. p->indexList = new int[p->indexAnz];
  686. p->indexList[0] = 0 + 4;
  687. p->indexList[1] = 1 + 4;
  688. p->indexList[2] = 2 + 4;
  689. p->indexList[3] = 1 + 4;
  690. p->indexList[4] = 3 + 4;
  691. p->indexList[5] = 2 + 4;
  692. data->addPolygon(p);
  693. // right side
  694. p = new Polygon3D(); // looking from (0,0,0) to (0,-1,0) to see this side
  695. p->indexAnz = 6;
  696. p->indexList = new int[p->indexAnz];
  697. p->indexList[0] = 0 + 12;
  698. p->indexList[1] = 1 + 12;
  699. p->indexList[2] = 2 + 12;
  700. p->indexList[3] = 1 + 12;
  701. p->indexList[4] = 3 + 12;
  702. p->indexList[5] = 2 + 12;
  703. data->addPolygon(p);
  704. // top side
  705. p = new Polygon3D(); // looking from (0,0,0) to (0,0,-1) to see this side
  706. p->indexAnz = 6;
  707. p->indexList = new int[p->indexAnz];
  708. p->indexList[0] = 0 + 16;
  709. p->indexList[1] = 1 + 16;
  710. p->indexList[2] = 2 + 16;
  711. p->indexList[3] = 1 + 16;
  712. p->indexList[4] = 3 + 16;
  713. p->indexList[5] = 2 + 16;
  714. data->addPolygon(p);
  715. // botom side
  716. p = new Polygon3D(); // looking from (0,0,0) to (0,0,1) to see this side
  717. p->indexAnz = 6;
  718. p->indexList = new int[p->indexAnz];
  719. p->indexList[0] = 0 + 20;
  720. p->indexList[1] = 1 + 20;
  721. p->indexList[2] = 2 + 20;
  722. p->indexList[3] = 1 + 20;
  723. p->indexList[4] = 3 + 20;
  724. p->indexList[5] = 2 + 20;
  725. data->addPolygon(p);
  726. Skelett* s = new Skelett();
  727. s->addKnochen(new Knochen(0));
  728. s->addKnochen(new Knochen(1), 0);
  729. s->addKnochen(new Knochen(2), 0);
  730. s->addKnochen(new Knochen(3), 0);
  731. s->addKnochen(new Knochen(4), 0);
  732. data->setSkelettZ(s);
  733. data->calculateNormals();
  734. data->release();
  735. }
  736. void createModels(Bildschirm* zScreen)
  737. {
  738. createDefaultCube(zScreen);
  739. createCubeItem(zScreen);
  740. createPlayer(zScreen);
  741. createGrass(zScreen);
  742. createFluidCube(zScreen);
  743. }
  744. LoadMenu::LoadMenu(Bildschirm* zScreen)
  745. : Menu(zScreen)
  746. {
  747. Punkt center = zScreen->getBackBufferSize() / 2;
  748. step = initFBalken(
  749. center.x - 100, center.y + 25, 200, 30, FBalken::Style::normal);
  750. stage = initFBalken(
  751. center.x - 100, center.y - 15, 200, 30, FBalken::Style::normal);
  752. all = initFBalken(
  753. center.x - 100, center.y - 55, 200, 30, FBalken::Style::normal);
  754. elements.add(step);
  755. elements.add(stage);
  756. elements.add(all);
  757. new AsynchronCall("Load Menu", [this, zScreen]() {
  758. Sleep(1000);
  759. all->setAktionAnzahl(2);
  760. all->reset();
  761. // loading textures
  762. Datei texturF;
  763. texturF.setDatei("data/textures");
  764. RCArray<Text>* files = texturF.getDateiListe();
  765. if (files)
  766. {
  767. int count = 0;
  768. for (Text* fileName : *files)
  769. {
  770. LTDBDatei dat;
  771. dat.setDatei(new Text(Text("data/textures/") + *fileName));
  772. dat.leseDaten(0);
  773. count += dat.getBildAnzahl();
  774. }
  775. stage->setAktionAnzahl(count);
  776. stage->reset();
  777. for (Text* fileName : *files)
  778. {
  779. LTDBDatei dat;
  780. dat.setDatei(new Text(Text("data/textures/") + *fileName));
  781. dat.leseDaten(0);
  782. for (Text* name : *dat.zBildListe())
  783. {
  784. step->reset();
  785. Bild* b = dat.laden(step, new Text(*name));
  786. zScreen->zGraphicsApi()
  787. ->createOrGetTextur(*fileName + "/" + *name, b)
  788. ->release();
  789. stage->aktionPlus();
  790. }
  791. }
  792. files->release();
  793. }
  794. all->aktionPlus();
  795. // loading models
  796. stage->setAktionAnzahl(1);
  797. Datei modelF;
  798. modelF.setDatei("data/models");
  799. files = modelF.getDateiListe();
  800. if (files)
  801. {
  802. int count = 0;
  803. for (Text* fileName : *files)
  804. {
  805. M3Datei dat(Text("data/models/") + *fileName);
  806. dat.leseDaten();
  807. count += dat.getModelAnzahl();
  808. }
  809. stage->setAktionAnzahl(count + 1);
  810. stage->reset();
  811. for (Text* fileName : *files)
  812. {
  813. M3Datei dat(Text("data/models/") + *fileName);
  814. dat.leseDaten();
  815. for (int i = 0; i < dat.getModelAnzahl(); i++)
  816. {
  817. step->reset();
  818. Model3DData* d = dat.ladeModel(dat.zModelName(i)->getText(),
  819. zScreen->zGraphicsApi(),
  820. *fileName + "/" + *dat.zModelName(i));
  821. d->release();
  822. stage->aktionPlus();
  823. }
  824. }
  825. files->release();
  826. }
  827. createModels(zScreen);
  828. stage->aktionPlus();
  829. all->aktionPlus();
  830. stage->reset();
  831. zScreen->lock();
  832. hide();
  833. menuRegister->get("serverSelection")->show();
  834. zScreen->unlock();
  835. });
  836. }