Load.cpp 27 KB

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