Start.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. #include <main.h>
  2. #include <Fenster.h>
  3. #include <Bildschirm.h>
  4. #include <RenderThread.h>
  5. #include <Welt3D.h>
  6. #include <Cube.h>
  7. #include <Kam3D.h>
  8. #include <Bild.h>
  9. #include <Rahmen.h>
  10. #include <Textur.h>
  11. #include <Model3D.h>
  12. #include <Model3DList.h>
  13. #include <DXBuffer.h>
  14. #include <DateiSystem.h>
  15. #include <M3Datei.h>
  16. using namespace Framework;
  17. class TreppeOben : public Model3D
  18. {
  19. void makeQuader( Vertex3D* vertecies, int startIndex, Vec3< float > ltf, Vec3< float > rtf, Vec3< float > lbf, Vec3< float > rbf, Vec3< float > ltb, Vec3< float > rtb, Vec3< float > lbb, Vec3< float > rbb )
  20. {
  21. vertecies[ startIndex ].pos = ltf;
  22. vertecies[ startIndex ].tPos = Vec2< float >( 0.f, 0.f );
  23. vertecies[ startIndex + 1 ].pos = rtf;
  24. vertecies[ startIndex + 1 ].tPos = Vec2< float >( 1.f, 0.f );
  25. vertecies[ startIndex + 2 ].pos = lbf;
  26. vertecies[ startIndex + 2 ].tPos = Vec2< float >( 0.f, 1.f );
  27. vertecies[ startIndex + 3 ].pos = rbf;
  28. vertecies[ startIndex + 3 ].tPos = Vec2< float >( 1.f, 1.f );
  29. vertecies[ startIndex + 4 ].pos = ltb;
  30. vertecies[ startIndex + 4 ].tPos = Vec2< float >( 0.0f, 0.0f );
  31. vertecies[ startIndex + 5 ].pos = rtb;
  32. vertecies[ startIndex + 5 ].tPos = Vec2< float >( 1.0f, 0.0f );
  33. vertecies[ startIndex + 6 ].pos = lbb;
  34. vertecies[ startIndex + 6 ].tPos = Vec2< float >( 0.0f, 1.0f );
  35. vertecies[ startIndex + 7 ].pos = rbb;
  36. vertecies[ startIndex + 7 ].tPos = Vec2< float >( 1.0f, 1.0f );
  37. vertecies[ startIndex + 8 ].pos = ltf;
  38. vertecies[ startIndex + 8 ].tPos = Vec2< float >( 1.f, 0.f );
  39. vertecies[ startIndex + 9 ].pos = rtf;
  40. vertecies[ startIndex + 9 ].tPos = Vec2< float >( 0.f, 0.f );
  41. vertecies[ startIndex + 10 ].pos = lbf;
  42. vertecies[ startIndex + 10 ].tPos = Vec2< float >( 1.f, 1.f );
  43. vertecies[ startIndex + 11 ].pos = rbf;
  44. vertecies[ startIndex + 11 ].tPos = Vec2< float >( 0.f, 1.f );
  45. vertecies[ startIndex + 12 ].pos = ltb;
  46. vertecies[ startIndex + 12 ].tPos = Vec2< float >( 0.0f, 0.0f );
  47. vertecies[ startIndex + 13 ].pos = rtb;
  48. vertecies[ startIndex + 13 ].tPos = Vec2< float >( 1.0f, 0.0f );
  49. vertecies[ startIndex + 14 ].pos = lbb;
  50. vertecies[ startIndex + 14 ].tPos = Vec2< float >( 0.0f, 1.0f );
  51. vertecies[ startIndex + 15 ].pos = rbb;
  52. vertecies[ startIndex + 15 ].tPos = Vec2< float >( 1.0f, 1.0f );
  53. vertecies[ startIndex + 16 ].pos = ltf;
  54. vertecies[ startIndex + 16 ].tPos = Vec2< float >( 0.f, 1.f );
  55. vertecies[ startIndex + 17 ].pos = rtf;
  56. vertecies[ startIndex + 17 ].tPos = Vec2< float >( 1.f, 1.f );
  57. vertecies[ startIndex + 18 ].pos = lbf;
  58. vertecies[ startIndex + 18 ].tPos = Vec2< float >( 0.f, 0.f );
  59. vertecies[ startIndex + 19 ].pos = rbf;
  60. vertecies[ startIndex + 19 ].tPos = Vec2< float >( 1.f, 0.f );
  61. vertecies[ startIndex + 20 ].pos = ltb;
  62. vertecies[ startIndex + 20 ].tPos = Vec2< float >( 0.0f, 0.0f );
  63. vertecies[ startIndex + 21 ].pos = rtb;
  64. vertecies[ startIndex + 21 ].tPos = Vec2< float >( 1.0f, 0.0f );
  65. vertecies[ startIndex + 22 ].pos = lbb;
  66. vertecies[ startIndex + 22 ].tPos = Vec2< float >( 0.0f, 1.0f );
  67. vertecies[ startIndex + 23 ].pos = rbb;
  68. vertecies[ startIndex + 23 ].tPos = Vec2< float >( 1.0f, 1.0f );
  69. // front side
  70. Polygon3D* p = new Polygon3D();
  71. p->indexAnz = 6;
  72. p->indexList = new int[ p->indexAnz ];
  73. p->indexBuffer->setLength( p->indexAnz * 4 );
  74. p->indexBuffer->setData( p->indexList );
  75. p->indexList[ 0 ] = startIndex + 0;
  76. p->indexList[ 1 ] = startIndex + 2;
  77. p->indexList[ 2 ] = startIndex + 3;
  78. p->indexList[ 3 ] = startIndex + 0;
  79. p->indexList[ 4 ] = startIndex + 3;
  80. p->indexList[ 5 ] = startIndex + 1;
  81. model->addPolygon( p );
  82. // back side
  83. p = new Polygon3D();
  84. p->indexAnz = 6;
  85. p->indexList = new int[ p->indexAnz ];
  86. p->indexBuffer->setLength( p->indexAnz * 4 );
  87. p->indexBuffer->setData( p->indexList );
  88. p->indexList[ 0 ] = startIndex + 4;
  89. p->indexList[ 1 ] = startIndex + 7;
  90. p->indexList[ 2 ] = startIndex + 6;
  91. p->indexList[ 3 ] = startIndex + 4;
  92. p->indexList[ 4 ] = startIndex + 5;
  93. p->indexList[ 5 ] = startIndex + 7;
  94. model->addPolygon( p );
  95. // right side
  96. p = new Polygon3D();
  97. p->indexAnz = 6;
  98. p->indexList = new int[ p->indexAnz ];
  99. p->indexBuffer->setLength( p->indexAnz * 4 );
  100. p->indexBuffer->setData( p->indexList );
  101. p->indexList[ 0 ] = startIndex + 1 + 8;
  102. p->indexList[ 1 ] = startIndex + 3 + 8;
  103. p->indexList[ 2 ] = startIndex + 7 + 8;
  104. p->indexList[ 3 ] = startIndex + 1 + 8;
  105. p->indexList[ 4 ] = startIndex + 7 + 8;
  106. p->indexList[ 5 ] = startIndex + 5 + 8;
  107. model->addPolygon( p );
  108. // left side
  109. p = new Polygon3D();
  110. p->indexAnz = 6;
  111. p->indexList = new int[ p->indexAnz ];
  112. p->indexBuffer->setLength( p->indexAnz * 4 );
  113. p->indexBuffer->setData( p->indexList );
  114. p->indexList[ 0 ] = startIndex + 0 + 8;
  115. p->indexList[ 1 ] = startIndex + 6 + 8;
  116. p->indexList[ 2 ] = startIndex + 2 + 8;
  117. p->indexList[ 3 ] = startIndex + 0 + 8;
  118. p->indexList[ 4 ] = startIndex + 4 + 8;
  119. p->indexList[ 5 ] = startIndex + 6 + 8;
  120. model->addPolygon( p );
  121. // top side
  122. p = new Polygon3D();
  123. p->indexAnz = 6;
  124. p->indexList = new int[ p->indexAnz ];
  125. p->indexBuffer->setLength( p->indexAnz * 4 );
  126. p->indexBuffer->setData( p->indexList );
  127. p->indexList[ 0 ] = startIndex + 4 + 16;
  128. p->indexList[ 1 ] = startIndex + 0 + 16;
  129. p->indexList[ 2 ] = startIndex + 1 + 16;
  130. p->indexList[ 3 ] = startIndex + 4 + 16;
  131. p->indexList[ 4 ] = startIndex + 1 + 16;
  132. p->indexList[ 5 ] = startIndex + 5 + 16;
  133. model->addPolygon( p );
  134. // down side
  135. p = new Polygon3D();
  136. p->indexAnz = 6;
  137. p->indexList = new int[ p->indexAnz ];
  138. p->indexBuffer->setLength( p->indexAnz * 4 );
  139. p->indexBuffer->setData( p->indexList );
  140. p->indexList[ 0 ] = startIndex + 6 + 16;
  141. p->indexList[ 1 ] = startIndex + 3 + 16;
  142. p->indexList[ 2 ] = startIndex + 2 + 16;
  143. p->indexList[ 3 ] = startIndex + 6 + 16;
  144. p->indexList[ 4 ] = startIndex + 7 + 16;
  145. p->indexList[ 5 ] = startIndex + 3 + 16;
  146. model->addPolygon( p );
  147. }
  148. void makeQuader( Vertex3D* vertecies, int startIndex, Vec3< float > pos, Vec3< float > size )
  149. {
  150. float left, right, top, bottom;
  151. // Calculate the screen coordinates of the left side of the bitmap.
  152. left = pos.x;
  153. // Calculate the screen coordinates of the right side of the bitmap.
  154. right = pos.x + size.x;
  155. // Calculate the screen coordinates of the top of the bitmap.
  156. top = pos.y + size.y;
  157. // Calculate the screen coordinates of the bottom of the bitmap.
  158. bottom = pos.y;
  159. float front = pos.z + size.z;
  160. float back = pos.z;
  161. makeQuader( vertecies, startIndex, Vec3< float >( left, top, front ), Vec3< float >( right, top, front ), Vec3< float >( left, bottom, front ), Vec3< float >( right, bottom, front ),
  162. Vec3< float >( left, top, back ), Vec3< float >( right, top, back ), Vec3< float >( left, bottom, back ), Vec3< float >( right, bottom, back ) );
  163. }
  164. public:
  165. // Konstruktor
  166. // size: Die Größe des Würfels
  167. TreppeOben()
  168. {
  169. model = new Model3DData();
  170. float stdSize = 100;
  171. float left, right, top, bottom;
  172. // Calculate the screen coordinates of the left side of the bitmap.
  173. left = (float)( ( stdSize / 2.0 ) * -1 );
  174. // Calculate the screen coordinates of the right side of the bitmap.
  175. right = left + (float)stdSize;
  176. // Calculate the screen coordinates of the top of the bitmap.
  177. top = (float)( stdSize / 2.0 );
  178. // Calculate the screen coordinates of the bottom of the bitmap.
  179. bottom = top - (float)stdSize;
  180. float front = -stdSize / 2;
  181. float back = front + stdSize;
  182. Vertex3D * vertecies = new Vertex3D[ 48 + 11 * 24 ];
  183. for( int i = 0; i < 48 + 11 * 24; i++ )
  184. vertecies[ i ].knochenId = 0;
  185. makeQuader( vertecies, 0, Vec3< float >( -stdSize / 2, -stdSize / 2, -stdSize / 2 ), Vec3< float >( stdSize, 10, stdSize ) );
  186. makeQuader( vertecies, 24, Vec3< float >( -5, -stdSize / 2, -5 ), Vec3< float >( 10, stdSize + 20, 10 ) );
  187. float last = -5;
  188. for( int i = 0; i < 11; i++ )
  189. {
  190. float fullRad = PI;
  191. float curr = ( fullRad / 10 ) * i;
  192. Mat4< float > rotation = Mat4< float >::rotationY( curr );
  193. Mat4< float > rotation2 = Mat4< float >::rotationY( fullRad / 10 );
  194. Vec3< float > test( stdSize / 2, -stdSize / 2 + i * 10 + 10, 0 );
  195. Vec3< float > diff = rotation2 * test;
  196. float length = diff.z;
  197. Vec3< float > rtf( stdSize / 2, -stdSize / 2 + i * 10 + 20, -diff.z / 2 );
  198. Vec3< float > rtb( stdSize / 2, -stdSize / 2 + i * 10 + 20, diff.z / 2 );
  199. Vec3< float > rbf( stdSize / 2, -stdSize / 2 + i * 10 + 10, -diff.z / 2 );
  200. Vec3< float > rbb( stdSize / 2, -stdSize / 2 + i * 10 + 10, diff.z / 2 );
  201. Vec3< float > ltf( 0, -stdSize / 2 + i * 10 + 20, 5 );
  202. Vec3< float > ltb( 0, -stdSize / 2 + i * 10 + 20, -5 );
  203. Vec3< float > lbf( 0, -stdSize / 2 + i * 10 + 10, 5 );
  204. Vec3< float > lbb( 0, -stdSize / 2 + i * 10 + 10, -5 );
  205. rtf = rotation * rtf;
  206. rtb = rotation * rtb;
  207. rbf = rotation * rbf;
  208. rbb = rotation * rbb;
  209. ltf = rotation * ltf;
  210. ltb = rotation * ltb;
  211. lbf = rotation * lbf;
  212. lbb = rotation * lbb;
  213. makeQuader( vertecies, 48 + i * 24, ltf, rtf, lbf, rbf, ltb, rtb, lbb, rbb );
  214. }
  215. model->setVertecies( vertecies, 48 + 11 * 24 );
  216. M3Datei dat;
  217. dat.setPfad( "3d.m3" );
  218. dat.leseDaten();
  219. dat.saveModel( model, "treppe" );
  220. textur = new Model3DTextur();
  221. }
  222. // Setzt die Textur des Würfels, so dass sie an allen Seiten gleich ist
  223. // textur: Die Textur als Bild
  224. void setTextur( Bild * textur )
  225. {
  226. Textur* t = new Textur();
  227. t->setBildZ( textur );
  228. int anz = model->getPolygonAnzahl();
  229. for( int i = 0; i < anz; i++ )
  230. this->textur->setPolygonTextur( i, t->getThis() );
  231. t->release();
  232. rend = 1;
  233. }
  234. };
  235. class TreppeUnten : public Model3D
  236. {
  237. void makeQuader( Vertex3D* vertecies, int startIndex, Vec3< float > ltf, Vec3< float > rtf, Vec3< float > lbf, Vec3< float > rbf, Vec3< float > ltb, Vec3< float > rtb, Vec3< float > lbb, Vec3< float > rbb )
  238. {
  239. vertecies[ startIndex ].pos = ltf;
  240. vertecies[ startIndex ].tPos = Vec2< float >( 0.f, 0.f );
  241. vertecies[ startIndex + 1 ].pos = rtf;
  242. vertecies[ startIndex + 1 ].tPos = Vec2< float >( 1.f, 0.f );
  243. vertecies[ startIndex + 2 ].pos = lbf;
  244. vertecies[ startIndex + 2 ].tPos = Vec2< float >( 0.f, 1.f );
  245. vertecies[ startIndex + 3 ].pos = rbf;
  246. vertecies[ startIndex + 3 ].tPos = Vec2< float >( 1.f, 1.f );
  247. vertecies[ startIndex + 4 ].pos = ltb;
  248. vertecies[ startIndex + 4 ].tPos = Vec2< float >( 0.0f, 0.0f );
  249. vertecies[ startIndex + 5 ].pos = rtb;
  250. vertecies[ startIndex + 5 ].tPos = Vec2< float >( 1.0f, 0.0f );
  251. vertecies[ startIndex + 6 ].pos = lbb;
  252. vertecies[ startIndex + 6 ].tPos = Vec2< float >( 0.0f, 1.0f );
  253. vertecies[ startIndex + 7 ].pos = rbb;
  254. vertecies[ startIndex + 7 ].tPos = Vec2< float >( 1.0f, 1.0f );
  255. vertecies[ startIndex + 8 ].pos = ltf;
  256. vertecies[ startIndex + 8 ].tPos = Vec2< float >( 1.f, 0.f );
  257. vertecies[ startIndex + 9 ].pos = rtf;
  258. vertecies[ startIndex + 9 ].tPos = Vec2< float >( 0.f, 0.f );
  259. vertecies[ startIndex + 10 ].pos = lbf;
  260. vertecies[ startIndex + 10 ].tPos = Vec2< float >( 1.f, 1.f );
  261. vertecies[ startIndex + 11 ].pos = rbf;
  262. vertecies[ startIndex + 11 ].tPos = Vec2< float >( 0.f, 1.f );
  263. vertecies[ startIndex + 12 ].pos = ltb;
  264. vertecies[ startIndex + 12 ].tPos = Vec2< float >( 0.0f, 0.0f );
  265. vertecies[ startIndex + 13 ].pos = rtb;
  266. vertecies[ startIndex + 13 ].tPos = Vec2< float >( 1.0f, 0.0f );
  267. vertecies[ startIndex + 14 ].pos = lbb;
  268. vertecies[ startIndex + 14 ].tPos = Vec2< float >( 0.0f, 1.0f );
  269. vertecies[ startIndex + 15 ].pos = rbb;
  270. vertecies[ startIndex + 15 ].tPos = Vec2< float >( 1.0f, 1.0f );
  271. vertecies[ startIndex + 16 ].pos = ltf;
  272. vertecies[ startIndex + 16 ].tPos = Vec2< float >( 0.f, 1.f );
  273. vertecies[ startIndex + 17 ].pos = rtf;
  274. vertecies[ startIndex + 17 ].tPos = Vec2< float >( 1.f, 1.f );
  275. vertecies[ startIndex + 18 ].pos = lbf;
  276. vertecies[ startIndex + 18 ].tPos = Vec2< float >( 0.f, 0.f );
  277. vertecies[ startIndex + 19 ].pos = rbf;
  278. vertecies[ startIndex + 19 ].tPos = Vec2< float >( 1.f, 0.f );
  279. vertecies[ startIndex + 20 ].pos = ltb;
  280. vertecies[ startIndex + 20 ].tPos = Vec2< float >( 0.0f, 0.0f );
  281. vertecies[ startIndex + 21 ].pos = rtb;
  282. vertecies[ startIndex + 21 ].tPos = Vec2< float >( 1.0f, 0.0f );
  283. vertecies[ startIndex + 22 ].pos = lbb;
  284. vertecies[ startIndex + 22 ].tPos = Vec2< float >( 0.0f, 1.0f );
  285. vertecies[ startIndex + 23 ].pos = rbb;
  286. vertecies[ startIndex + 23 ].tPos = Vec2< float >( 1.0f, 1.0f );
  287. // front side
  288. Polygon3D* p = new Polygon3D();
  289. p->indexAnz = 6;
  290. p->indexList = new int[ p->indexAnz ];
  291. p->indexBuffer->setLength( p->indexAnz * 4 );
  292. p->indexBuffer->setData( p->indexList );
  293. p->indexList[ 0 ] = startIndex + 0;
  294. p->indexList[ 1 ] = startIndex + 2;
  295. p->indexList[ 2 ] = startIndex + 3;
  296. p->indexList[ 3 ] = startIndex + 0;
  297. p->indexList[ 4 ] = startIndex + 3;
  298. p->indexList[ 5 ] = startIndex + 1;
  299. model->addPolygon( p );
  300. // back side
  301. p = new Polygon3D();
  302. p->indexAnz = 6;
  303. p->indexList = new int[ p->indexAnz ];
  304. p->indexBuffer->setLength( p->indexAnz * 4 );
  305. p->indexBuffer->setData( p->indexList );
  306. p->indexList[ 0 ] = startIndex + 4;
  307. p->indexList[ 1 ] = startIndex + 7;
  308. p->indexList[ 2 ] = startIndex + 6;
  309. p->indexList[ 3 ] = startIndex + 4;
  310. p->indexList[ 4 ] = startIndex + 5;
  311. p->indexList[ 5 ] = startIndex + 7;
  312. model->addPolygon( p );
  313. // right side
  314. p = new Polygon3D();
  315. p->indexAnz = 6;
  316. p->indexList = new int[ p->indexAnz ];
  317. p->indexBuffer->setLength( p->indexAnz * 4 );
  318. p->indexBuffer->setData( p->indexList );
  319. p->indexList[ 0 ] = startIndex + 1 + 8;
  320. p->indexList[ 1 ] = startIndex + 3 + 8;
  321. p->indexList[ 2 ] = startIndex + 7 + 8;
  322. p->indexList[ 3 ] = startIndex + 1 + 8;
  323. p->indexList[ 4 ] = startIndex + 7 + 8;
  324. p->indexList[ 5 ] = startIndex + 5 + 8;
  325. model->addPolygon( p );
  326. // left side
  327. p = new Polygon3D();
  328. p->indexAnz = 6;
  329. p->indexList = new int[ p->indexAnz ];
  330. p->indexBuffer->setLength( p->indexAnz * 4 );
  331. p->indexBuffer->setData( p->indexList );
  332. p->indexList[ 0 ] = startIndex + 0 + 8;
  333. p->indexList[ 1 ] = startIndex + 6 + 8;
  334. p->indexList[ 2 ] = startIndex + 2 + 8;
  335. p->indexList[ 3 ] = startIndex + 0 + 8;
  336. p->indexList[ 4 ] = startIndex + 4 + 8;
  337. p->indexList[ 5 ] = startIndex + 6 + 8;
  338. model->addPolygon( p );
  339. // top side
  340. p = new Polygon3D();
  341. p->indexAnz = 6;
  342. p->indexList = new int[ p->indexAnz ];
  343. p->indexBuffer->setLength( p->indexAnz * 4 );
  344. p->indexBuffer->setData( p->indexList );
  345. p->indexList[ 0 ] = startIndex + 4 + 16;
  346. p->indexList[ 1 ] = startIndex + 0 + 16;
  347. p->indexList[ 2 ] = startIndex + 1 + 16;
  348. p->indexList[ 3 ] = startIndex + 4 + 16;
  349. p->indexList[ 4 ] = startIndex + 1 + 16;
  350. p->indexList[ 5 ] = startIndex + 5 + 16;
  351. model->addPolygon( p );
  352. // down side
  353. p = new Polygon3D();
  354. p->indexAnz = 6;
  355. p->indexList = new int[ p->indexAnz ];
  356. p->indexBuffer->setLength( p->indexAnz * 4 );
  357. p->indexBuffer->setData( p->indexList );
  358. p->indexList[ 0 ] = startIndex + 6 + 16;
  359. p->indexList[ 1 ] = startIndex + 3 + 16;
  360. p->indexList[ 2 ] = startIndex + 2 + 16;
  361. p->indexList[ 3 ] = startIndex + 6 + 16;
  362. p->indexList[ 4 ] = startIndex + 7 + 16;
  363. p->indexList[ 5 ] = startIndex + 3 + 16;
  364. model->addPolygon( p );
  365. }
  366. void makeQuader( Vertex3D* vertecies, int startIndex, Vec3< float > pos, Vec3< float > size )
  367. {
  368. float left, right, top, bottom;
  369. // Calculate the screen coordinates of the left side of the bitmap.
  370. left = pos.x;
  371. // Calculate the screen coordinates of the right side of the bitmap.
  372. right = pos.x + size.x;
  373. // Calculate the screen coordinates of the top of the bitmap.
  374. top = pos.y + size.y;
  375. // Calculate the screen coordinates of the bottom of the bitmap.
  376. bottom = pos.y;
  377. float front = pos.z + size.z;
  378. float back = pos.z;
  379. makeQuader( vertecies, startIndex, Vec3< float >( left, top, front ), Vec3< float >( right, top, front ), Vec3< float >( left, bottom, front ), Vec3< float >( right, bottom, front ),
  380. Vec3< float >( left, top, back ), Vec3< float >( right, top, back ), Vec3< float >( left, bottom, back ), Vec3< float >( right, bottom, back ) );
  381. }
  382. public:
  383. // Konstruktor
  384. // size: Die Größe des Würfels
  385. TreppeUnten()
  386. {
  387. model = new Model3DData();
  388. float stdSize = 100;
  389. float left, right, top, bottom;
  390. // Calculate the screen coordinates of the left side of the bitmap.
  391. left = (float)( ( stdSize / 2.0 ) * -1 );
  392. // Calculate the screen coordinates of the right side of the bitmap.
  393. right = left + (float)stdSize;
  394. // Calculate the screen coordinates of the top of the bitmap.
  395. top = (float)( stdSize / 2.0 );
  396. // Calculate the screen coordinates of the bottom of the bitmap.
  397. bottom = top - (float)stdSize;
  398. float front = -stdSize / 2;
  399. float back = front + stdSize;
  400. Vertex3D * vertecies = new Vertex3D[ 48 + 11 * 24 ];
  401. for( int i = 0; i < 48 + 11 * 24; i++ )
  402. vertecies[ i ].knochenId = 0;
  403. makeQuader( vertecies, 0, Vec3< float >( -stdSize / 2, stdSize / 2 + 10, 0 ), Vec3< float >( stdSize, 10, stdSize / 2 ) );
  404. makeQuader( vertecies, 24, Vec3< float >( -5, -stdSize / 2, -5 ), Vec3< float >( 10, stdSize + 20, 10 ) );
  405. float last = -5;
  406. for( int i = 0; i < 11; i++ )
  407. {
  408. float fullRad = PI;
  409. float curr = ( fullRad / 10 ) * i;
  410. Mat4< float > rotation = Mat4< float >::rotationY( curr );
  411. Mat4< float > rotation2 = Mat4< float >::rotationY( fullRad / 10 );
  412. Vec3< float > test( stdSize / 2, -stdSize / 2 + i * 10 + 10, 0 );
  413. Vec3< float > diff = rotation2 * test;
  414. float length = diff.z;
  415. Vec3< float > rtf( stdSize / 2, -stdSize / 2 + i * 10 + 20, -diff.z / 2 );
  416. Vec3< float > rtb( stdSize / 2, -stdSize / 2 + i * 10 + 20, diff.z / 2 );
  417. Vec3< float > rbf( stdSize / 2, -stdSize / 2 + i * 10 + 10, -diff.z / 2 );
  418. Vec3< float > rbb( stdSize / 2, -stdSize / 2 + i * 10 + 10, diff.z / 2 );
  419. Vec3< float > ltf( 0, -stdSize / 2 + i * 10 + 20, 5 );
  420. Vec3< float > ltb( 0, -stdSize / 2 + i * 10 + 20, -5 );
  421. Vec3< float > lbf( 0, -stdSize / 2 + i * 10 + 10, 5 );
  422. Vec3< float > lbb( 0, -stdSize / 2 + i * 10 + 10, -5 );
  423. rtf = rotation * rtf;
  424. rtb = rotation * rtb;
  425. rbf = rotation * rbf;
  426. rbb = rotation * rbb;
  427. ltf = rotation * ltf;
  428. ltb = rotation * ltb;
  429. lbf = rotation * lbf;
  430. lbb = rotation * lbb;
  431. makeQuader( vertecies, 48 + i * 24, ltf, rtf, lbf, rbf, ltb, rtb, lbb, rbb );
  432. }
  433. model->setVertecies( vertecies, 48 + 11 * 24 );
  434. M3Datei dat;
  435. dat.setPfad( "3d.m3" );
  436. dat.leseDaten();
  437. dat.saveModel( model, "treppe" );
  438. textur = new Model3DTextur();
  439. }
  440. // Setzt die Textur des Würfels, so dass sie an allen Seiten gleich ist
  441. // textur: Die Textur als Bild
  442. void setTextur( Bild * textur )
  443. {
  444. Textur* t = new Textur();
  445. t->setBildZ( textur );
  446. int anz = model->getPolygonAnzahl();
  447. for( int i = 0; i < anz; i++ )
  448. this->textur->setPolygonTextur( i, t->getThis() );
  449. t->release();
  450. rend = 1;
  451. }
  452. };
  453. // Aktion beim schließen des Fensters
  454. void schließen( void* p, void* f )
  455. {
  456. // Stoppe Nachrichten Loop
  457. StopNachrichtenSchleife( ( (WFenster*)f )->getFensterHandle() );
  458. }
  459. int __stdcall Framework::Start( Startparam p )
  460. {
  461. // Fenster erstellen
  462. WNDCLASS wc = F_Normal( p.hinst );
  463. wc.lpszClassName = "3D Creator";
  464. WFenster* f = new WFenster();
  465. f->erstellen( WS_OVERLAPPEDWINDOW, wc );
  466. f->setVSchließAktion( schließen );
  467. f->setAnzeigeModus( SW_SHOWNORMAL );
  468. f->setSize( 1300, 820 );
  469. f->setPosition( Punkt( 100, 100 ) );
  470. // 3D Umgebung erstellen
  471. Bildschirm3D* b = new Bildschirm3D( f->getThis() );
  472. f->setBildschirm( b->getThis() );
  473. b->setFillFarbe( 0 );
  474. b->setTestRend( 0 );
  475. Welt3D* welt = new Welt3D();
  476. TreppeUnten* test = new TreppeUnten();
  477. TreppeOben* test2 = new TreppeOben();
  478. LTDBDatei* assets = new LTDBDatei();
  479. assets->setDatei( new Text( "assets.ltdb" ) );
  480. assets->leseDaten( 0 );
  481. Bild* b1 = assets->laden( 0, new Text( "ground.png" ) );
  482. assets->release();
  483. test->setTextur( b1->getThis() );
  484. test->setPosition( 0, 0, 0 );
  485. welt->addZeichnung( test );
  486. test2->setTextur( b1 );
  487. test2->setPosition( 150, 0, 0 );
  488. welt->addZeichnung( test2 );
  489. Kam3D* kamA = new Kam3D();
  490. kamA->setBildschirmPosition( 10, 10 );
  491. kamA->setBildschirmSize( 385, 385 );
  492. kamA->setPosition( Vec3<float>( -1000, 0, 0 ) );
  493. kamA->setAusrichtung( Vec3<float>( 0, 0, 0 ) );
  494. kamA->setWelt( welt->getThis() );
  495. b->addKamera( kamA );
  496. Kam3D* kamB = new Kam3D();
  497. kamB->setBildschirmPosition( 10, 405 );
  498. kamB->setBildschirmSize( 385, 385 );
  499. kamB->setPosition( Vec3<float>( 0, -1000, 0 ) );
  500. kamB->setAusrichtung( Vec3<float>( 0, 0, 0 ) );
  501. kamB->setWelt( welt->getThis() );
  502. b->addKamera( kamB );
  503. Kam3D* kamC = new Kam3D();
  504. kamC->setBildschirmPosition( 405, 10 );
  505. kamC->setBildschirmSize( 385, 385 );
  506. kamC->setPosition( Vec3<float>( 0, 0, -1000 ) );
  507. kamC->setAusrichtung( Vec3<float>( 0, 0, 0 ) );
  508. kamC->setWelt( welt->getThis() );
  509. b->addKamera( kamC );
  510. Kam3D * kamD = new Kam3D();
  511. kamD->setStyle( Kam3D::Style::Movable | Kam3D::Style::Rotatable | Kam3D::Style::Tick );
  512. kamD->setBildschirmPosition( 405, 405 );
  513. kamD->setBildschirmSize( 385, 385 );
  514. kamD->setPosition( Vec3<float>( 0, 0, -1000 ) );
  515. kamD->setAusrichtung( Vec3<float>( 0, 0, 0 ) );
  516. kamD->setWelt( welt->getThis() );
  517. b->addKamera( kamD );
  518. LRahmen * kamAR = new LRahmen();
  519. kamAR->setPosition( 10, 10 );
  520. kamAR->setFarbe( 0xFFFFFFFF );
  521. kamAR->setRamenBreite( 1 );
  522. kamAR->setSize( 385, 385 );
  523. b->addMember( kamAR );
  524. LRahmen * kamBR = new LRahmen();
  525. kamBR->setPosition( 404, 10 );
  526. kamBR->setFarbe( 0xFFFFFFFF );
  527. kamBR->setRamenBreite( 1 );
  528. kamBR->setSize( 385, 385 );
  529. b->addMember( kamBR );
  530. LRahmen * kamCR = new LRahmen();
  531. kamCR->setPosition( 10, 405 );
  532. kamCR->setFarbe( 0xFFFFFFFF );
  533. kamCR->setRamenBreite( 1 );
  534. kamCR->setSize( 385, 385 );
  535. b->addMember( kamCR );
  536. LRahmen * kamDR = new LRahmen();
  537. kamDR->setPosition( 405, 405 );
  538. kamDR->setFarbe( 0xFFFFFFFF );
  539. kamDR->setRamenBreite( 1 );
  540. kamDR->setSize( 385, 385 );
  541. b->addMember( kamDR );
  542. // Render Loop starten
  543. RenderTh * r = new RenderTh();
  544. r->setBildschirm( b->getThis() );
  545. r->setTickFunktion( [ test, b, kamD ]( void*, void*, double t )
  546. {
  547. //test->setDrehung( test->getDrehung() + Vec3<double>( t, t, t ) );
  548. if( Framework::getTastenStand( T_Enter ) )
  549. {
  550. kamD->setAusrichtung( Vec3<float>( 0, 0, 0 ) );
  551. }
  552. } );
  553. r->beginn();
  554. // Nachrichten Loop starten und warten
  555. StartNachrichtenSchleife();
  556. // Speicher Freigeben
  557. r->beenden();
  558. r->release();
  559. b->release();
  560. f->setBildschirm( 0 );
  561. f->zerstören();
  562. f->release();
  563. welt->release();
  564. return 0;
  565. }