Start.cpp 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587
  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. class Mauer : public Model3D
  454. {
  455. 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 )
  456. {
  457. vertecies[ startIndex ].pos = ltf;
  458. vertecies[ startIndex ].tPos = Vec2< float >( 0.f, 0.f );
  459. vertecies[ startIndex + 1 ].pos = rtf;
  460. vertecies[ startIndex + 1 ].tPos = Vec2< float >( 1.f, 0.f );
  461. vertecies[ startIndex + 2 ].pos = lbf;
  462. vertecies[ startIndex + 2 ].tPos = Vec2< float >( 0.f, 1.f );
  463. vertecies[ startIndex + 3 ].pos = rbf;
  464. vertecies[ startIndex + 3 ].tPos = Vec2< float >( 1.f, 1.f );
  465. vertecies[ startIndex + 4 ].pos = ltb;
  466. vertecies[ startIndex + 4 ].tPos = Vec2< float >( 0.0f, 0.0f );
  467. vertecies[ startIndex + 5 ].pos = rtb;
  468. vertecies[ startIndex + 5 ].tPos = Vec2< float >( 1.0f, 0.0f );
  469. vertecies[ startIndex + 6 ].pos = lbb;
  470. vertecies[ startIndex + 6 ].tPos = Vec2< float >( 0.0f, 1.0f );
  471. vertecies[ startIndex + 7 ].pos = rbb;
  472. vertecies[ startIndex + 7 ].tPos = Vec2< float >( 1.0f, 1.0f );
  473. vertecies[ startIndex + 8 ].pos = ltf;
  474. vertecies[ startIndex + 8 ].tPos = Vec2< float >( 1.f, 0.f );
  475. vertecies[ startIndex + 9 ].pos = rtf;
  476. vertecies[ startIndex + 9 ].tPos = Vec2< float >( 0.f, 0.f );
  477. vertecies[ startIndex + 10 ].pos = lbf;
  478. vertecies[ startIndex + 10 ].tPos = Vec2< float >( 1.f, 1.f );
  479. vertecies[ startIndex + 11 ].pos = rbf;
  480. vertecies[ startIndex + 11 ].tPos = Vec2< float >( 0.f, 1.f );
  481. vertecies[ startIndex + 12 ].pos = ltb;
  482. vertecies[ startIndex + 12 ].tPos = Vec2< float >( 0.0f, 0.0f );
  483. vertecies[ startIndex + 13 ].pos = rtb;
  484. vertecies[ startIndex + 13 ].tPos = Vec2< float >( 1.0f, 0.0f );
  485. vertecies[ startIndex + 14 ].pos = lbb;
  486. vertecies[ startIndex + 14 ].tPos = Vec2< float >( 0.0f, 1.0f );
  487. vertecies[ startIndex + 15 ].pos = rbb;
  488. vertecies[ startIndex + 15 ].tPos = Vec2< float >( 1.0f, 1.0f );
  489. vertecies[ startIndex + 16 ].pos = ltf;
  490. vertecies[ startIndex + 16 ].tPos = Vec2< float >( 0.f, 1.f );
  491. vertecies[ startIndex + 17 ].pos = rtf;
  492. vertecies[ startIndex + 17 ].tPos = Vec2< float >( 1.f, 1.f );
  493. vertecies[ startIndex + 18 ].pos = lbf;
  494. vertecies[ startIndex + 18 ].tPos = Vec2< float >( 0.f, 0.f );
  495. vertecies[ startIndex + 19 ].pos = rbf;
  496. vertecies[ startIndex + 19 ].tPos = Vec2< float >( 1.f, 0.f );
  497. vertecies[ startIndex + 20 ].pos = ltb;
  498. vertecies[ startIndex + 20 ].tPos = Vec2< float >( 0.0f, 0.0f );
  499. vertecies[ startIndex + 21 ].pos = rtb;
  500. vertecies[ startIndex + 21 ].tPos = Vec2< float >( 1.0f, 0.0f );
  501. vertecies[ startIndex + 22 ].pos = lbb;
  502. vertecies[ startIndex + 22 ].tPos = Vec2< float >( 0.0f, 1.0f );
  503. vertecies[ startIndex + 23 ].pos = rbb;
  504. vertecies[ startIndex + 23 ].tPos = Vec2< float >( 1.0f, 1.0f );
  505. // front side
  506. Polygon3D* p = new Polygon3D();
  507. p->indexAnz = 6;
  508. p->indexList = new int[ p->indexAnz ];
  509. p->indexBuffer->setLength( p->indexAnz * 4 );
  510. p->indexBuffer->setData( p->indexList );
  511. p->indexList[ 0 ] = startIndex + 0;
  512. p->indexList[ 1 ] = startIndex + 2;
  513. p->indexList[ 2 ] = startIndex + 3;
  514. p->indexList[ 3 ] = startIndex + 0;
  515. p->indexList[ 4 ] = startIndex + 3;
  516. p->indexList[ 5 ] = startIndex + 1;
  517. model->addPolygon( p );
  518. // back side
  519. p = new Polygon3D();
  520. p->indexAnz = 6;
  521. p->indexList = new int[ p->indexAnz ];
  522. p->indexBuffer->setLength( p->indexAnz * 4 );
  523. p->indexBuffer->setData( p->indexList );
  524. p->indexList[ 0 ] = startIndex + 4;
  525. p->indexList[ 1 ] = startIndex + 7;
  526. p->indexList[ 2 ] = startIndex + 6;
  527. p->indexList[ 3 ] = startIndex + 4;
  528. p->indexList[ 4 ] = startIndex + 5;
  529. p->indexList[ 5 ] = startIndex + 7;
  530. model->addPolygon( p );
  531. // right side
  532. p = new Polygon3D();
  533. p->indexAnz = 6;
  534. p->indexList = new int[ p->indexAnz ];
  535. p->indexBuffer->setLength( p->indexAnz * 4 );
  536. p->indexBuffer->setData( p->indexList );
  537. p->indexList[ 0 ] = startIndex + 1 + 8;
  538. p->indexList[ 1 ] = startIndex + 3 + 8;
  539. p->indexList[ 2 ] = startIndex + 7 + 8;
  540. p->indexList[ 3 ] = startIndex + 1 + 8;
  541. p->indexList[ 4 ] = startIndex + 7 + 8;
  542. p->indexList[ 5 ] = startIndex + 5 + 8;
  543. model->addPolygon( p );
  544. // left side
  545. p = new Polygon3D();
  546. p->indexAnz = 6;
  547. p->indexList = new int[ p->indexAnz ];
  548. p->indexBuffer->setLength( p->indexAnz * 4 );
  549. p->indexBuffer->setData( p->indexList );
  550. p->indexList[ 0 ] = startIndex + 0 + 8;
  551. p->indexList[ 1 ] = startIndex + 6 + 8;
  552. p->indexList[ 2 ] = startIndex + 2 + 8;
  553. p->indexList[ 3 ] = startIndex + 0 + 8;
  554. p->indexList[ 4 ] = startIndex + 4 + 8;
  555. p->indexList[ 5 ] = startIndex + 6 + 8;
  556. model->addPolygon( p );
  557. // top side
  558. p = new Polygon3D();
  559. p->indexAnz = 6;
  560. p->indexList = new int[ p->indexAnz ];
  561. p->indexBuffer->setLength( p->indexAnz * 4 );
  562. p->indexBuffer->setData( p->indexList );
  563. p->indexList[ 0 ] = startIndex + 4 + 16;
  564. p->indexList[ 1 ] = startIndex + 0 + 16;
  565. p->indexList[ 2 ] = startIndex + 1 + 16;
  566. p->indexList[ 3 ] = startIndex + 4 + 16;
  567. p->indexList[ 4 ] = startIndex + 1 + 16;
  568. p->indexList[ 5 ] = startIndex + 5 + 16;
  569. model->addPolygon( p );
  570. // down side
  571. p = new Polygon3D();
  572. p->indexAnz = 6;
  573. p->indexList = new int[ p->indexAnz ];
  574. p->indexBuffer->setLength( p->indexAnz * 4 );
  575. p->indexBuffer->setData( p->indexList );
  576. p->indexList[ 0 ] = startIndex + 6 + 16;
  577. p->indexList[ 1 ] = startIndex + 3 + 16;
  578. p->indexList[ 2 ] = startIndex + 2 + 16;
  579. p->indexList[ 3 ] = startIndex + 6 + 16;
  580. p->indexList[ 4 ] = startIndex + 7 + 16;
  581. p->indexList[ 5 ] = startIndex + 3 + 16;
  582. model->addPolygon( p );
  583. }
  584. void makeQuader( Vertex3D* vertecies, int startIndex, Vec3< float > pos, Vec3< float > size )
  585. {
  586. float left, right, top, bottom;
  587. // Calculate the screen coordinates of the left side of the bitmap.
  588. left = pos.x;
  589. // Calculate the screen coordinates of the right side of the bitmap.
  590. right = pos.x + size.x;
  591. // Calculate the screen coordinates of the top of the bitmap.
  592. top = pos.y + size.y;
  593. // Calculate the screen coordinates of the bottom of the bitmap.
  594. bottom = pos.y;
  595. float front = pos.z + size.z;
  596. float back = pos.z;
  597. makeQuader( vertecies, startIndex, Vec3< float >( left, top, front ), Vec3< float >( right, top, front ), Vec3< float >( left, bottom, front ), Vec3< float >( right, bottom, front ),
  598. Vec3< float >( left, top, back ), Vec3< float >( right, top, back ), Vec3< float >( left, bottom, back ), Vec3< float >( right, bottom, back ) );
  599. }
  600. public:
  601. // Konstruktor
  602. // size: Die Größe des Würfels
  603. Mauer()
  604. {
  605. model = new Model3DData();
  606. float stdSize = 100;
  607. float left, right, top, bottom;
  608. // Calculate the screen coordinates of the left side of the bitmap.
  609. left = (float)( ( stdSize / 2.0 ) * -1 );
  610. // Calculate the screen coordinates of the right side of the bitmap.
  611. right = left + (float)stdSize;
  612. // Calculate the screen coordinates of the top of the bitmap.
  613. top = (float)( stdSize / 2.0 );
  614. // Calculate the screen coordinates of the bottom of the bitmap.
  615. bottom = top - (float)stdSize;
  616. float front = -stdSize / 2;
  617. float back = front + stdSize;
  618. Vertex3D * vertecies = new Vertex3D[ 48 ];
  619. for( int i = 0; i < 48; i++ )
  620. vertecies[ i ].knochenId = 0;
  621. makeQuader( vertecies, 0, Vec3< float >( -stdSize / 2, -stdSize / 2, -stdSize / 2 ), Vec3< float >( stdSize, 10, stdSize ) );
  622. makeQuader( vertecies, 24, Vec3< float >( -stdSize / 2, -stdSize / 2, -5 ), Vec3< float >( stdSize, stdSize + 10, 10 ) );
  623. model->setVertecies( vertecies, 48 );
  624. textur = new Model3DTextur();
  625. }
  626. // Setzt die Textur des Würfels, so dass sie an allen Seiten gleich ist
  627. // textur: Die Textur als Bild
  628. void setTextur( Bild * textur )
  629. {
  630. Textur* t = new Textur();
  631. t->setBildZ( textur );
  632. int anz = model->getPolygonAnzahl();
  633. for( int i = 0; i < anz; i++ )
  634. this->textur->setPolygonTextur( i, t->getThis() );
  635. t->release();
  636. rend = 1;
  637. }
  638. };
  639. class MauerEcke : public Model3D
  640. {
  641. 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 )
  642. {
  643. vertecies[ startIndex ].pos = ltf;
  644. vertecies[ startIndex ].tPos = Vec2< float >( 0.f, 0.f );
  645. vertecies[ startIndex + 1 ].pos = rtf;
  646. vertecies[ startIndex + 1 ].tPos = Vec2< float >( 1.f, 0.f );
  647. vertecies[ startIndex + 2 ].pos = lbf;
  648. vertecies[ startIndex + 2 ].tPos = Vec2< float >( 0.f, 1.f );
  649. vertecies[ startIndex + 3 ].pos = rbf;
  650. vertecies[ startIndex + 3 ].tPos = Vec2< float >( 1.f, 1.f );
  651. vertecies[ startIndex + 4 ].pos = ltb;
  652. vertecies[ startIndex + 4 ].tPos = Vec2< float >( 0.0f, 0.0f );
  653. vertecies[ startIndex + 5 ].pos = rtb;
  654. vertecies[ startIndex + 5 ].tPos = Vec2< float >( 1.0f, 0.0f );
  655. vertecies[ startIndex + 6 ].pos = lbb;
  656. vertecies[ startIndex + 6 ].tPos = Vec2< float >( 0.0f, 1.0f );
  657. vertecies[ startIndex + 7 ].pos = rbb;
  658. vertecies[ startIndex + 7 ].tPos = Vec2< float >( 1.0f, 1.0f );
  659. vertecies[ startIndex + 8 ].pos = ltf;
  660. vertecies[ startIndex + 8 ].tPos = Vec2< float >( 1.f, 0.f );
  661. vertecies[ startIndex + 9 ].pos = rtf;
  662. vertecies[ startIndex + 9 ].tPos = Vec2< float >( 0.f, 0.f );
  663. vertecies[ startIndex + 10 ].pos = lbf;
  664. vertecies[ startIndex + 10 ].tPos = Vec2< float >( 1.f, 1.f );
  665. vertecies[ startIndex + 11 ].pos = rbf;
  666. vertecies[ startIndex + 11 ].tPos = Vec2< float >( 0.f, 1.f );
  667. vertecies[ startIndex + 12 ].pos = ltb;
  668. vertecies[ startIndex + 12 ].tPos = Vec2< float >( 0.0f, 0.0f );
  669. vertecies[ startIndex + 13 ].pos = rtb;
  670. vertecies[ startIndex + 13 ].tPos = Vec2< float >( 1.0f, 0.0f );
  671. vertecies[ startIndex + 14 ].pos = lbb;
  672. vertecies[ startIndex + 14 ].tPos = Vec2< float >( 0.0f, 1.0f );
  673. vertecies[ startIndex + 15 ].pos = rbb;
  674. vertecies[ startIndex + 15 ].tPos = Vec2< float >( 1.0f, 1.0f );
  675. vertecies[ startIndex + 16 ].pos = ltf;
  676. vertecies[ startIndex + 16 ].tPos = Vec2< float >( 0.f, 1.f );
  677. vertecies[ startIndex + 17 ].pos = rtf;
  678. vertecies[ startIndex + 17 ].tPos = Vec2< float >( 1.f, 1.f );
  679. vertecies[ startIndex + 18 ].pos = lbf;
  680. vertecies[ startIndex + 18 ].tPos = Vec2< float >( 0.f, 0.f );
  681. vertecies[ startIndex + 19 ].pos = rbf;
  682. vertecies[ startIndex + 19 ].tPos = Vec2< float >( 1.f, 0.f );
  683. vertecies[ startIndex + 20 ].pos = ltb;
  684. vertecies[ startIndex + 20 ].tPos = Vec2< float >( 0.0f, 0.0f );
  685. vertecies[ startIndex + 21 ].pos = rtb;
  686. vertecies[ startIndex + 21 ].tPos = Vec2< float >( 1.0f, 0.0f );
  687. vertecies[ startIndex + 22 ].pos = lbb;
  688. vertecies[ startIndex + 22 ].tPos = Vec2< float >( 0.0f, 1.0f );
  689. vertecies[ startIndex + 23 ].pos = rbb;
  690. vertecies[ startIndex + 23 ].tPos = Vec2< float >( 1.0f, 1.0f );
  691. // front side
  692. Polygon3D* p = new Polygon3D();
  693. p->indexAnz = 6;
  694. p->indexList = new int[ p->indexAnz ];
  695. p->indexBuffer->setLength( p->indexAnz * 4 );
  696. p->indexBuffer->setData( p->indexList );
  697. p->indexList[ 0 ] = startIndex + 0;
  698. p->indexList[ 1 ] = startIndex + 2;
  699. p->indexList[ 2 ] = startIndex + 3;
  700. p->indexList[ 3 ] = startIndex + 0;
  701. p->indexList[ 4 ] = startIndex + 3;
  702. p->indexList[ 5 ] = startIndex + 1;
  703. model->addPolygon( p );
  704. // back side
  705. p = new Polygon3D();
  706. p->indexAnz = 6;
  707. p->indexList = new int[ p->indexAnz ];
  708. p->indexBuffer->setLength( p->indexAnz * 4 );
  709. p->indexBuffer->setData( p->indexList );
  710. p->indexList[ 0 ] = startIndex + 4;
  711. p->indexList[ 1 ] = startIndex + 7;
  712. p->indexList[ 2 ] = startIndex + 6;
  713. p->indexList[ 3 ] = startIndex + 4;
  714. p->indexList[ 4 ] = startIndex + 5;
  715. p->indexList[ 5 ] = startIndex + 7;
  716. model->addPolygon( p );
  717. // right side
  718. p = new Polygon3D();
  719. p->indexAnz = 6;
  720. p->indexList = new int[ p->indexAnz ];
  721. p->indexBuffer->setLength( p->indexAnz * 4 );
  722. p->indexBuffer->setData( p->indexList );
  723. p->indexList[ 0 ] = startIndex + 1 + 8;
  724. p->indexList[ 1 ] = startIndex + 3 + 8;
  725. p->indexList[ 2 ] = startIndex + 7 + 8;
  726. p->indexList[ 3 ] = startIndex + 1 + 8;
  727. p->indexList[ 4 ] = startIndex + 7 + 8;
  728. p->indexList[ 5 ] = startIndex + 5 + 8;
  729. model->addPolygon( p );
  730. // left side
  731. p = new Polygon3D();
  732. p->indexAnz = 6;
  733. p->indexList = new int[ p->indexAnz ];
  734. p->indexBuffer->setLength( p->indexAnz * 4 );
  735. p->indexBuffer->setData( p->indexList );
  736. p->indexList[ 0 ] = startIndex + 0 + 8;
  737. p->indexList[ 1 ] = startIndex + 6 + 8;
  738. p->indexList[ 2 ] = startIndex + 2 + 8;
  739. p->indexList[ 3 ] = startIndex + 0 + 8;
  740. p->indexList[ 4 ] = startIndex + 4 + 8;
  741. p->indexList[ 5 ] = startIndex + 6 + 8;
  742. model->addPolygon( p );
  743. // top side
  744. p = new Polygon3D();
  745. p->indexAnz = 6;
  746. p->indexList = new int[ p->indexAnz ];
  747. p->indexBuffer->setLength( p->indexAnz * 4 );
  748. p->indexBuffer->setData( p->indexList );
  749. p->indexList[ 0 ] = startIndex + 4 + 16;
  750. p->indexList[ 1 ] = startIndex + 0 + 16;
  751. p->indexList[ 2 ] = startIndex + 1 + 16;
  752. p->indexList[ 3 ] = startIndex + 4 + 16;
  753. p->indexList[ 4 ] = startIndex + 1 + 16;
  754. p->indexList[ 5 ] = startIndex + 5 + 16;
  755. model->addPolygon( p );
  756. // down side
  757. p = new Polygon3D();
  758. p->indexAnz = 6;
  759. p->indexList = new int[ p->indexAnz ];
  760. p->indexBuffer->setLength( p->indexAnz * 4 );
  761. p->indexBuffer->setData( p->indexList );
  762. p->indexList[ 0 ] = startIndex + 6 + 16;
  763. p->indexList[ 1 ] = startIndex + 3 + 16;
  764. p->indexList[ 2 ] = startIndex + 2 + 16;
  765. p->indexList[ 3 ] = startIndex + 6 + 16;
  766. p->indexList[ 4 ] = startIndex + 7 + 16;
  767. p->indexList[ 5 ] = startIndex + 3 + 16;
  768. model->addPolygon( p );
  769. }
  770. void makeQuader( Vertex3D* vertecies, int startIndex, Vec3< float > pos, Vec3< float > size )
  771. {
  772. float left, right, top, bottom;
  773. // Calculate the screen coordinates of the left side of the bitmap.
  774. left = pos.x;
  775. // Calculate the screen coordinates of the right side of the bitmap.
  776. right = pos.x + size.x;
  777. // Calculate the screen coordinates of the top of the bitmap.
  778. top = pos.y + size.y;
  779. // Calculate the screen coordinates of the bottom of the bitmap.
  780. bottom = pos.y;
  781. float front = pos.z + size.z;
  782. float back = pos.z;
  783. makeQuader( vertecies, startIndex, Vec3< float >( left, top, front ), Vec3< float >( right, top, front ), Vec3< float >( left, bottom, front ), Vec3< float >( right, bottom, front ),
  784. Vec3< float >( left, top, back ), Vec3< float >( right, top, back ), Vec3< float >( left, bottom, back ), Vec3< float >( right, bottom, back ) );
  785. }
  786. public:
  787. // Konstruktor
  788. // size: Die Größe des Würfels
  789. MauerEcke()
  790. {
  791. model = new Model3DData();
  792. float stdSize = 100;
  793. float left, right, top, bottom;
  794. // Calculate the screen coordinates of the left side of the bitmap.
  795. left = (float)( ( stdSize / 2.0 ) * -1 );
  796. // Calculate the screen coordinates of the right side of the bitmap.
  797. right = left + (float)stdSize;
  798. // Calculate the screen coordinates of the top of the bitmap.
  799. top = (float)( stdSize / 2.0 );
  800. // Calculate the screen coordinates of the bottom of the bitmap.
  801. bottom = top - (float)stdSize;
  802. float front = -stdSize / 2;
  803. float back = front + stdSize;
  804. Vertex3D * vertecies = new Vertex3D[ 72 ];
  805. for( int i = 0; i < 72; i++ )
  806. vertecies[ i ].knochenId = 0;
  807. makeQuader( vertecies, 0, Vec3< float >( -stdSize / 2, -stdSize / 2, -stdSize / 2 ), Vec3< float >( stdSize, 10, stdSize ) );
  808. makeQuader( vertecies, 24, Vec3< float >( 0, -stdSize / 2, -5 ), Vec3< float >( stdSize / 2, stdSize + 10, 10 ) );
  809. makeQuader( vertecies, 48, Vec3< float >( -5, -stdSize / 2, 0 ), Vec3< float >( 10, stdSize + 10, stdSize / 2 ) );
  810. model->setVertecies( vertecies, 72 );
  811. textur = new Model3DTextur();
  812. }
  813. // Setzt die Textur des Würfels, so dass sie an allen Seiten gleich ist
  814. // textur: Die Textur als Bild
  815. void setTextur( Bild * textur )
  816. {
  817. Textur* t = new Textur();
  818. t->setBildZ( textur );
  819. int anz = model->getPolygonAnzahl();
  820. for( int i = 0; i < anz; i++ )
  821. this->textur->setPolygonTextur( i, t->getThis() );
  822. t->release();
  823. rend = 1;
  824. }
  825. };
  826. class MauerKreuz : public Model3D
  827. {
  828. 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 )
  829. {
  830. vertecies[ startIndex ].pos = ltf;
  831. vertecies[ startIndex ].tPos = Vec2< float >( 0.f, 0.f );
  832. vertecies[ startIndex + 1 ].pos = rtf;
  833. vertecies[ startIndex + 1 ].tPos = Vec2< float >( 1.f, 0.f );
  834. vertecies[ startIndex + 2 ].pos = lbf;
  835. vertecies[ startIndex + 2 ].tPos = Vec2< float >( 0.f, 1.f );
  836. vertecies[ startIndex + 3 ].pos = rbf;
  837. vertecies[ startIndex + 3 ].tPos = Vec2< float >( 1.f, 1.f );
  838. vertecies[ startIndex + 4 ].pos = ltb;
  839. vertecies[ startIndex + 4 ].tPos = Vec2< float >( 0.0f, 0.0f );
  840. vertecies[ startIndex + 5 ].pos = rtb;
  841. vertecies[ startIndex + 5 ].tPos = Vec2< float >( 1.0f, 0.0f );
  842. vertecies[ startIndex + 6 ].pos = lbb;
  843. vertecies[ startIndex + 6 ].tPos = Vec2< float >( 0.0f, 1.0f );
  844. vertecies[ startIndex + 7 ].pos = rbb;
  845. vertecies[ startIndex + 7 ].tPos = Vec2< float >( 1.0f, 1.0f );
  846. vertecies[ startIndex + 8 ].pos = ltf;
  847. vertecies[ startIndex + 8 ].tPos = Vec2< float >( 1.f, 0.f );
  848. vertecies[ startIndex + 9 ].pos = rtf;
  849. vertecies[ startIndex + 9 ].tPos = Vec2< float >( 0.f, 0.f );
  850. vertecies[ startIndex + 10 ].pos = lbf;
  851. vertecies[ startIndex + 10 ].tPos = Vec2< float >( 1.f, 1.f );
  852. vertecies[ startIndex + 11 ].pos = rbf;
  853. vertecies[ startIndex + 11 ].tPos = Vec2< float >( 0.f, 1.f );
  854. vertecies[ startIndex + 12 ].pos = ltb;
  855. vertecies[ startIndex + 12 ].tPos = Vec2< float >( 0.0f, 0.0f );
  856. vertecies[ startIndex + 13 ].pos = rtb;
  857. vertecies[ startIndex + 13 ].tPos = Vec2< float >( 1.0f, 0.0f );
  858. vertecies[ startIndex + 14 ].pos = lbb;
  859. vertecies[ startIndex + 14 ].tPos = Vec2< float >( 0.0f, 1.0f );
  860. vertecies[ startIndex + 15 ].pos = rbb;
  861. vertecies[ startIndex + 15 ].tPos = Vec2< float >( 1.0f, 1.0f );
  862. vertecies[ startIndex + 16 ].pos = ltf;
  863. vertecies[ startIndex + 16 ].tPos = Vec2< float >( 0.f, 1.f );
  864. vertecies[ startIndex + 17 ].pos = rtf;
  865. vertecies[ startIndex + 17 ].tPos = Vec2< float >( 1.f, 1.f );
  866. vertecies[ startIndex + 18 ].pos = lbf;
  867. vertecies[ startIndex + 18 ].tPos = Vec2< float >( 0.f, 0.f );
  868. vertecies[ startIndex + 19 ].pos = rbf;
  869. vertecies[ startIndex + 19 ].tPos = Vec2< float >( 1.f, 0.f );
  870. vertecies[ startIndex + 20 ].pos = ltb;
  871. vertecies[ startIndex + 20 ].tPos = Vec2< float >( 0.0f, 0.0f );
  872. vertecies[ startIndex + 21 ].pos = rtb;
  873. vertecies[ startIndex + 21 ].tPos = Vec2< float >( 1.0f, 0.0f );
  874. vertecies[ startIndex + 22 ].pos = lbb;
  875. vertecies[ startIndex + 22 ].tPos = Vec2< float >( 0.0f, 1.0f );
  876. vertecies[ startIndex + 23 ].pos = rbb;
  877. vertecies[ startIndex + 23 ].tPos = Vec2< float >( 1.0f, 1.0f );
  878. // front side
  879. Polygon3D* p = new Polygon3D();
  880. p->indexAnz = 6;
  881. p->indexList = new int[ p->indexAnz ];
  882. p->indexBuffer->setLength( p->indexAnz * 4 );
  883. p->indexBuffer->setData( p->indexList );
  884. p->indexList[ 0 ] = startIndex + 0;
  885. p->indexList[ 1 ] = startIndex + 2;
  886. p->indexList[ 2 ] = startIndex + 3;
  887. p->indexList[ 3 ] = startIndex + 0;
  888. p->indexList[ 4 ] = startIndex + 3;
  889. p->indexList[ 5 ] = startIndex + 1;
  890. model->addPolygon( p );
  891. // back side
  892. p = new Polygon3D();
  893. p->indexAnz = 6;
  894. p->indexList = new int[ p->indexAnz ];
  895. p->indexBuffer->setLength( p->indexAnz * 4 );
  896. p->indexBuffer->setData( p->indexList );
  897. p->indexList[ 0 ] = startIndex + 4;
  898. p->indexList[ 1 ] = startIndex + 7;
  899. p->indexList[ 2 ] = startIndex + 6;
  900. p->indexList[ 3 ] = startIndex + 4;
  901. p->indexList[ 4 ] = startIndex + 5;
  902. p->indexList[ 5 ] = startIndex + 7;
  903. model->addPolygon( p );
  904. // right side
  905. p = new Polygon3D();
  906. p->indexAnz = 6;
  907. p->indexList = new int[ p->indexAnz ];
  908. p->indexBuffer->setLength( p->indexAnz * 4 );
  909. p->indexBuffer->setData( p->indexList );
  910. p->indexList[ 0 ] = startIndex + 1 + 8;
  911. p->indexList[ 1 ] = startIndex + 3 + 8;
  912. p->indexList[ 2 ] = startIndex + 7 + 8;
  913. p->indexList[ 3 ] = startIndex + 1 + 8;
  914. p->indexList[ 4 ] = startIndex + 7 + 8;
  915. p->indexList[ 5 ] = startIndex + 5 + 8;
  916. model->addPolygon( p );
  917. // left side
  918. p = new Polygon3D();
  919. p->indexAnz = 6;
  920. p->indexList = new int[ p->indexAnz ];
  921. p->indexBuffer->setLength( p->indexAnz * 4 );
  922. p->indexBuffer->setData( p->indexList );
  923. p->indexList[ 0 ] = startIndex + 0 + 8;
  924. p->indexList[ 1 ] = startIndex + 6 + 8;
  925. p->indexList[ 2 ] = startIndex + 2 + 8;
  926. p->indexList[ 3 ] = startIndex + 0 + 8;
  927. p->indexList[ 4 ] = startIndex + 4 + 8;
  928. p->indexList[ 5 ] = startIndex + 6 + 8;
  929. model->addPolygon( p );
  930. // top side
  931. p = new Polygon3D();
  932. p->indexAnz = 6;
  933. p->indexList = new int[ p->indexAnz ];
  934. p->indexBuffer->setLength( p->indexAnz * 4 );
  935. p->indexBuffer->setData( p->indexList );
  936. p->indexList[ 0 ] = startIndex + 4 + 16;
  937. p->indexList[ 1 ] = startIndex + 0 + 16;
  938. p->indexList[ 2 ] = startIndex + 1 + 16;
  939. p->indexList[ 3 ] = startIndex + 4 + 16;
  940. p->indexList[ 4 ] = startIndex + 1 + 16;
  941. p->indexList[ 5 ] = startIndex + 5 + 16;
  942. model->addPolygon( p );
  943. // down side
  944. p = new Polygon3D();
  945. p->indexAnz = 6;
  946. p->indexList = new int[ p->indexAnz ];
  947. p->indexBuffer->setLength( p->indexAnz * 4 );
  948. p->indexBuffer->setData( p->indexList );
  949. p->indexList[ 0 ] = startIndex + 6 + 16;
  950. p->indexList[ 1 ] = startIndex + 3 + 16;
  951. p->indexList[ 2 ] = startIndex + 2 + 16;
  952. p->indexList[ 3 ] = startIndex + 6 + 16;
  953. p->indexList[ 4 ] = startIndex + 7 + 16;
  954. p->indexList[ 5 ] = startIndex + 3 + 16;
  955. model->addPolygon( p );
  956. }
  957. void makeQuader( Vertex3D* vertecies, int startIndex, Vec3< float > pos, Vec3< float > size )
  958. {
  959. float left, right, top, bottom;
  960. // Calculate the screen coordinates of the left side of the bitmap.
  961. left = pos.x;
  962. // Calculate the screen coordinates of the right side of the bitmap.
  963. right = pos.x + size.x;
  964. // Calculate the screen coordinates of the top of the bitmap.
  965. top = pos.y + size.y;
  966. // Calculate the screen coordinates of the bottom of the bitmap.
  967. bottom = pos.y;
  968. float front = pos.z + size.z;
  969. float back = pos.z;
  970. makeQuader( vertecies, startIndex, Vec3< float >( left, top, front ), Vec3< float >( right, top, front ), Vec3< float >( left, bottom, front ), Vec3< float >( right, bottom, front ),
  971. Vec3< float >( left, top, back ), Vec3< float >( right, top, back ), Vec3< float >( left, bottom, back ), Vec3< float >( right, bottom, back ) );
  972. }
  973. public:
  974. // Konstruktor
  975. // size: Die Größe des Würfels
  976. MauerKreuz()
  977. {
  978. model = new Model3DData();
  979. float stdSize = 100;
  980. float left, right, top, bottom;
  981. // Calculate the screen coordinates of the left side of the bitmap.
  982. left = (float)( ( stdSize / 2.0 ) * -1 );
  983. // Calculate the screen coordinates of the right side of the bitmap.
  984. right = left + (float)stdSize;
  985. // Calculate the screen coordinates of the top of the bitmap.
  986. top = (float)( stdSize / 2.0 );
  987. // Calculate the screen coordinates of the bottom of the bitmap.
  988. bottom = top - (float)stdSize;
  989. float front = -stdSize / 2;
  990. float back = front + stdSize;
  991. Vertex3D * vertecies = new Vertex3D[ 72 ];
  992. for( int i = 0; i < 72; i++ )
  993. vertecies[ i ].knochenId = 0;
  994. makeQuader( vertecies, 0, Vec3< float >( -stdSize / 2, -stdSize / 2, -stdSize / 2 ), Vec3< float >( stdSize, 10, stdSize ) );
  995. makeQuader( vertecies, 24, Vec3< float >( -stdSize / 2, -stdSize / 2, -5 ), Vec3< float >( stdSize, stdSize + 10, 10 ) );
  996. makeQuader( vertecies, 48, Vec3< float >( -5, -stdSize / 2, -stdSize / 2 ), Vec3< float >( 10, stdSize + 10, stdSize ) );
  997. model->setVertecies( vertecies, 72 );
  998. textur = new Model3DTextur();
  999. }
  1000. // Setzt die Textur des Würfels, so dass sie an allen Seiten gleich ist
  1001. // textur: Die Textur als Bild
  1002. void setTextur( Bild * textur )
  1003. {
  1004. Textur* t = new Textur();
  1005. t->setBildZ( textur );
  1006. int anz = model->getPolygonAnzahl();
  1007. for( int i = 0; i < anz; i++ )
  1008. this->textur->setPolygonTextur( i, t->getThis() );
  1009. t->release();
  1010. rend = 1;
  1011. }
  1012. };
  1013. class Boden : public Model3D
  1014. {
  1015. 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 )
  1016. {
  1017. vertecies[ startIndex ].pos = ltf;
  1018. vertecies[ startIndex ].tPos = Vec2< float >( 0.f, 0.f );
  1019. vertecies[ startIndex + 1 ].pos = rtf;
  1020. vertecies[ startIndex + 1 ].tPos = Vec2< float >( 1.f, 0.f );
  1021. vertecies[ startIndex + 2 ].pos = lbf;
  1022. vertecies[ startIndex + 2 ].tPos = Vec2< float >( 0.f, 1.f );
  1023. vertecies[ startIndex + 3 ].pos = rbf;
  1024. vertecies[ startIndex + 3 ].tPos = Vec2< float >( 1.f, 1.f );
  1025. vertecies[ startIndex + 4 ].pos = ltb;
  1026. vertecies[ startIndex + 4 ].tPos = Vec2< float >( 0.0f, 0.0f );
  1027. vertecies[ startIndex + 5 ].pos = rtb;
  1028. vertecies[ startIndex + 5 ].tPos = Vec2< float >( 1.0f, 0.0f );
  1029. vertecies[ startIndex + 6 ].pos = lbb;
  1030. vertecies[ startIndex + 6 ].tPos = Vec2< float >( 0.0f, 1.0f );
  1031. vertecies[ startIndex + 7 ].pos = rbb;
  1032. vertecies[ startIndex + 7 ].tPos = Vec2< float >( 1.0f, 1.0f );
  1033. vertecies[ startIndex + 8 ].pos = ltf;
  1034. vertecies[ startIndex + 8 ].tPos = Vec2< float >( 1.f, 0.f );
  1035. vertecies[ startIndex + 9 ].pos = rtf;
  1036. vertecies[ startIndex + 9 ].tPos = Vec2< float >( 0.f, 0.f );
  1037. vertecies[ startIndex + 10 ].pos = lbf;
  1038. vertecies[ startIndex + 10 ].tPos = Vec2< float >( 1.f, 1.f );
  1039. vertecies[ startIndex + 11 ].pos = rbf;
  1040. vertecies[ startIndex + 11 ].tPos = Vec2< float >( 0.f, 1.f );
  1041. vertecies[ startIndex + 12 ].pos = ltb;
  1042. vertecies[ startIndex + 12 ].tPos = Vec2< float >( 0.0f, 0.0f );
  1043. vertecies[ startIndex + 13 ].pos = rtb;
  1044. vertecies[ startIndex + 13 ].tPos = Vec2< float >( 1.0f, 0.0f );
  1045. vertecies[ startIndex + 14 ].pos = lbb;
  1046. vertecies[ startIndex + 14 ].tPos = Vec2< float >( 0.0f, 1.0f );
  1047. vertecies[ startIndex + 15 ].pos = rbb;
  1048. vertecies[ startIndex + 15 ].tPos = Vec2< float >( 1.0f, 1.0f );
  1049. vertecies[ startIndex + 16 ].pos = ltf;
  1050. vertecies[ startIndex + 16 ].tPos = Vec2< float >( 0.f, 1.f );
  1051. vertecies[ startIndex + 17 ].pos = rtf;
  1052. vertecies[ startIndex + 17 ].tPos = Vec2< float >( 1.f, 1.f );
  1053. vertecies[ startIndex + 18 ].pos = lbf;
  1054. vertecies[ startIndex + 18 ].tPos = Vec2< float >( 0.f, 0.f );
  1055. vertecies[ startIndex + 19 ].pos = rbf;
  1056. vertecies[ startIndex + 19 ].tPos = Vec2< float >( 1.f, 0.f );
  1057. vertecies[ startIndex + 20 ].pos = ltb;
  1058. vertecies[ startIndex + 20 ].tPos = Vec2< float >( 0.0f, 0.0f );
  1059. vertecies[ startIndex + 21 ].pos = rtb;
  1060. vertecies[ startIndex + 21 ].tPos = Vec2< float >( 1.0f, 0.0f );
  1061. vertecies[ startIndex + 22 ].pos = lbb;
  1062. vertecies[ startIndex + 22 ].tPos = Vec2< float >( 0.0f, 1.0f );
  1063. vertecies[ startIndex + 23 ].pos = rbb;
  1064. vertecies[ startIndex + 23 ].tPos = Vec2< float >( 1.0f, 1.0f );
  1065. // front side
  1066. Polygon3D* p = new Polygon3D();
  1067. p->indexAnz = 6;
  1068. p->indexList = new int[ p->indexAnz ];
  1069. p->indexBuffer->setLength( p->indexAnz * 4 );
  1070. p->indexBuffer->setData( p->indexList );
  1071. p->indexList[ 0 ] = startIndex + 0;
  1072. p->indexList[ 1 ] = startIndex + 2;
  1073. p->indexList[ 2 ] = startIndex + 3;
  1074. p->indexList[ 3 ] = startIndex + 0;
  1075. p->indexList[ 4 ] = startIndex + 3;
  1076. p->indexList[ 5 ] = startIndex + 1;
  1077. model->addPolygon( p );
  1078. // back side
  1079. p = new Polygon3D();
  1080. p->indexAnz = 6;
  1081. p->indexList = new int[ p->indexAnz ];
  1082. p->indexBuffer->setLength( p->indexAnz * 4 );
  1083. p->indexBuffer->setData( p->indexList );
  1084. p->indexList[ 0 ] = startIndex + 4;
  1085. p->indexList[ 1 ] = startIndex + 7;
  1086. p->indexList[ 2 ] = startIndex + 6;
  1087. p->indexList[ 3 ] = startIndex + 4;
  1088. p->indexList[ 4 ] = startIndex + 5;
  1089. p->indexList[ 5 ] = startIndex + 7;
  1090. model->addPolygon( p );
  1091. // right side
  1092. p = new Polygon3D();
  1093. p->indexAnz = 6;
  1094. p->indexList = new int[ p->indexAnz ];
  1095. p->indexBuffer->setLength( p->indexAnz * 4 );
  1096. p->indexBuffer->setData( p->indexList );
  1097. p->indexList[ 0 ] = startIndex + 1 + 8;
  1098. p->indexList[ 1 ] = startIndex + 3 + 8;
  1099. p->indexList[ 2 ] = startIndex + 7 + 8;
  1100. p->indexList[ 3 ] = startIndex + 1 + 8;
  1101. p->indexList[ 4 ] = startIndex + 7 + 8;
  1102. p->indexList[ 5 ] = startIndex + 5 + 8;
  1103. model->addPolygon( p );
  1104. // left side
  1105. p = new Polygon3D();
  1106. p->indexAnz = 6;
  1107. p->indexList = new int[ p->indexAnz ];
  1108. p->indexBuffer->setLength( p->indexAnz * 4 );
  1109. p->indexBuffer->setData( p->indexList );
  1110. p->indexList[ 0 ] = startIndex + 0 + 8;
  1111. p->indexList[ 1 ] = startIndex + 6 + 8;
  1112. p->indexList[ 2 ] = startIndex + 2 + 8;
  1113. p->indexList[ 3 ] = startIndex + 0 + 8;
  1114. p->indexList[ 4 ] = startIndex + 4 + 8;
  1115. p->indexList[ 5 ] = startIndex + 6 + 8;
  1116. model->addPolygon( p );
  1117. // top side
  1118. p = new Polygon3D();
  1119. p->indexAnz = 6;
  1120. p->indexList = new int[ p->indexAnz ];
  1121. p->indexBuffer->setLength( p->indexAnz * 4 );
  1122. p->indexBuffer->setData( p->indexList );
  1123. p->indexList[ 0 ] = startIndex + 4 + 16;
  1124. p->indexList[ 1 ] = startIndex + 0 + 16;
  1125. p->indexList[ 2 ] = startIndex + 1 + 16;
  1126. p->indexList[ 3 ] = startIndex + 4 + 16;
  1127. p->indexList[ 4 ] = startIndex + 1 + 16;
  1128. p->indexList[ 5 ] = startIndex + 5 + 16;
  1129. model->addPolygon( p );
  1130. // down side
  1131. p = new Polygon3D();
  1132. p->indexAnz = 6;
  1133. p->indexList = new int[ p->indexAnz ];
  1134. p->indexBuffer->setLength( p->indexAnz * 4 );
  1135. p->indexBuffer->setData( p->indexList );
  1136. p->indexList[ 0 ] = startIndex + 6 + 16;
  1137. p->indexList[ 1 ] = startIndex + 3 + 16;
  1138. p->indexList[ 2 ] = startIndex + 2 + 16;
  1139. p->indexList[ 3 ] = startIndex + 6 + 16;
  1140. p->indexList[ 4 ] = startIndex + 7 + 16;
  1141. p->indexList[ 5 ] = startIndex + 3 + 16;
  1142. model->addPolygon( p );
  1143. }
  1144. void makeQuader( Vertex3D* vertecies, int startIndex, Vec3< float > pos, Vec3< float > size )
  1145. {
  1146. float left, right, top, bottom;
  1147. // Calculate the screen coordinates of the left side of the bitmap.
  1148. left = pos.x;
  1149. // Calculate the screen coordinates of the right side of the bitmap.
  1150. right = pos.x + size.x;
  1151. // Calculate the screen coordinates of the top of the bitmap.
  1152. top = pos.y + size.y;
  1153. // Calculate the screen coordinates of the bottom of the bitmap.
  1154. bottom = pos.y;
  1155. float front = pos.z + size.z;
  1156. float back = pos.z;
  1157. makeQuader( vertecies, startIndex, Vec3< float >( left, top, front ), Vec3< float >( right, top, front ), Vec3< float >( left, bottom, front ), Vec3< float >( right, bottom, front ),
  1158. Vec3< float >( left, top, back ), Vec3< float >( right, top, back ), Vec3< float >( left, bottom, back ), Vec3< float >( right, bottom, back ) );
  1159. }
  1160. public:
  1161. // Konstruktor
  1162. // size: Die Größe des Würfels
  1163. Boden()
  1164. {
  1165. model = new Model3DData();
  1166. float stdSize = 100;
  1167. float left, right, top, bottom;
  1168. // Calculate the screen coordinates of the left side of the bitmap.
  1169. left = (float)( ( stdSize / 2.0 ) * -1 );
  1170. // Calculate the screen coordinates of the right side of the bitmap.
  1171. right = left + (float)stdSize;
  1172. // Calculate the screen coordinates of the top of the bitmap.
  1173. top = (float)( stdSize / 2.0 );
  1174. // Calculate the screen coordinates of the bottom of the bitmap.
  1175. bottom = top - (float)stdSize;
  1176. float front = -stdSize / 2;
  1177. float back = front + stdSize;
  1178. Vertex3D * vertecies = new Vertex3D[ 24 ];
  1179. for( int i = 0; i < 24; i++ )
  1180. vertecies[ i ].knochenId = 0;
  1181. makeQuader( vertecies, 0, Vec3< float >( -stdSize / 2, -stdSize / 2, -stdSize / 2 ), Vec3< float >( stdSize, 10, stdSize ) );
  1182. model->setVertecies( vertecies, 24 );
  1183. textur = new Model3DTextur();
  1184. }
  1185. // Setzt die Textur des Würfels, so dass sie an allen Seiten gleich ist
  1186. // textur: Die Textur als Bild
  1187. void setTextur( Bild * textur )
  1188. {
  1189. Textur* t = new Textur();
  1190. t->setBildZ( textur );
  1191. int anz = model->getPolygonAnzahl();
  1192. for( int i = 0; i < anz; i++ )
  1193. this->textur->setPolygonTextur( i, t->getThis() );
  1194. t->release();
  1195. rend = 1;
  1196. }
  1197. };
  1198. class Held : public Model3D
  1199. {
  1200. 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 )
  1201. {
  1202. vertecies[ startIndex ].pos = ltf;
  1203. vertecies[ startIndex ].tPos = Vec2< float >( 0.f, 0.f );
  1204. vertecies[ startIndex + 1 ].pos = rtf;
  1205. vertecies[ startIndex + 1 ].tPos = Vec2< float >( 1.f, 0.f );
  1206. vertecies[ startIndex + 2 ].pos = lbf;
  1207. vertecies[ startIndex + 2 ].tPos = Vec2< float >( 0.f, 1.f );
  1208. vertecies[ startIndex + 3 ].pos = rbf;
  1209. vertecies[ startIndex + 3 ].tPos = Vec2< float >( 1.f, 1.f );
  1210. vertecies[ startIndex + 4 ].pos = ltb;
  1211. vertecies[ startIndex + 4 ].tPos = Vec2< float >( 0.0f, 0.0f );
  1212. vertecies[ startIndex + 5 ].pos = rtb;
  1213. vertecies[ startIndex + 5 ].tPos = Vec2< float >( 1.0f, 0.0f );
  1214. vertecies[ startIndex + 6 ].pos = lbb;
  1215. vertecies[ startIndex + 6 ].tPos = Vec2< float >( 0.0f, 1.0f );
  1216. vertecies[ startIndex + 7 ].pos = rbb;
  1217. vertecies[ startIndex + 7 ].tPos = Vec2< float >( 1.0f, 1.0f );
  1218. vertecies[ startIndex + 8 ].pos = ltf;
  1219. vertecies[ startIndex + 8 ].tPos = Vec2< float >( 1.f, 0.f );
  1220. vertecies[ startIndex + 9 ].pos = rtf;
  1221. vertecies[ startIndex + 9 ].tPos = Vec2< float >( 0.f, 0.f );
  1222. vertecies[ startIndex + 10 ].pos = lbf;
  1223. vertecies[ startIndex + 10 ].tPos = Vec2< float >( 1.f, 1.f );
  1224. vertecies[ startIndex + 11 ].pos = rbf;
  1225. vertecies[ startIndex + 11 ].tPos = Vec2< float >( 0.f, 1.f );
  1226. vertecies[ startIndex + 12 ].pos = ltb;
  1227. vertecies[ startIndex + 12 ].tPos = Vec2< float >( 0.0f, 0.0f );
  1228. vertecies[ startIndex + 13 ].pos = rtb;
  1229. vertecies[ startIndex + 13 ].tPos = Vec2< float >( 1.0f, 0.0f );
  1230. vertecies[ startIndex + 14 ].pos = lbb;
  1231. vertecies[ startIndex + 14 ].tPos = Vec2< float >( 0.0f, 1.0f );
  1232. vertecies[ startIndex + 15 ].pos = rbb;
  1233. vertecies[ startIndex + 15 ].tPos = Vec2< float >( 1.0f, 1.0f );
  1234. vertecies[ startIndex + 16 ].pos = ltf;
  1235. vertecies[ startIndex + 16 ].tPos = Vec2< float >( 0.f, 1.f );
  1236. vertecies[ startIndex + 17 ].pos = rtf;
  1237. vertecies[ startIndex + 17 ].tPos = Vec2< float >( 1.f, 1.f );
  1238. vertecies[ startIndex + 18 ].pos = lbf;
  1239. vertecies[ startIndex + 18 ].tPos = Vec2< float >( 0.f, 0.f );
  1240. vertecies[ startIndex + 19 ].pos = rbf;
  1241. vertecies[ startIndex + 19 ].tPos = Vec2< float >( 1.f, 0.f );
  1242. vertecies[ startIndex + 20 ].pos = ltb;
  1243. vertecies[ startIndex + 20 ].tPos = Vec2< float >( 0.0f, 0.0f );
  1244. vertecies[ startIndex + 21 ].pos = rtb;
  1245. vertecies[ startIndex + 21 ].tPos = Vec2< float >( 1.0f, 0.0f );
  1246. vertecies[ startIndex + 22 ].pos = lbb;
  1247. vertecies[ startIndex + 22 ].tPos = Vec2< float >( 0.0f, 1.0f );
  1248. vertecies[ startIndex + 23 ].pos = rbb;
  1249. vertecies[ startIndex + 23 ].tPos = Vec2< float >( 1.0f, 1.0f );
  1250. // front side
  1251. Polygon3D* p = new Polygon3D();
  1252. p->indexAnz = 6;
  1253. p->indexList = new int[ p->indexAnz ];
  1254. p->indexBuffer->setLength( p->indexAnz * 4 );
  1255. p->indexBuffer->setData( p->indexList );
  1256. p->indexList[ 0 ] = startIndex + 0;
  1257. p->indexList[ 1 ] = startIndex + 2;
  1258. p->indexList[ 2 ] = startIndex + 3;
  1259. p->indexList[ 3 ] = startIndex + 0;
  1260. p->indexList[ 4 ] = startIndex + 3;
  1261. p->indexList[ 5 ] = startIndex + 1;
  1262. model->addPolygon( p );
  1263. // back side
  1264. p = new Polygon3D();
  1265. p->indexAnz = 6;
  1266. p->indexList = new int[ p->indexAnz ];
  1267. p->indexBuffer->setLength( p->indexAnz * 4 );
  1268. p->indexBuffer->setData( p->indexList );
  1269. p->indexList[ 0 ] = startIndex + 4;
  1270. p->indexList[ 1 ] = startIndex + 7;
  1271. p->indexList[ 2 ] = startIndex + 6;
  1272. p->indexList[ 3 ] = startIndex + 4;
  1273. p->indexList[ 4 ] = startIndex + 5;
  1274. p->indexList[ 5 ] = startIndex + 7;
  1275. model->addPolygon( p );
  1276. // right side
  1277. p = new Polygon3D();
  1278. p->indexAnz = 6;
  1279. p->indexList = new int[ p->indexAnz ];
  1280. p->indexBuffer->setLength( p->indexAnz * 4 );
  1281. p->indexBuffer->setData( p->indexList );
  1282. p->indexList[ 0 ] = startIndex + 1 + 8;
  1283. p->indexList[ 1 ] = startIndex + 3 + 8;
  1284. p->indexList[ 2 ] = startIndex + 7 + 8;
  1285. p->indexList[ 3 ] = startIndex + 1 + 8;
  1286. p->indexList[ 4 ] = startIndex + 7 + 8;
  1287. p->indexList[ 5 ] = startIndex + 5 + 8;
  1288. model->addPolygon( p );
  1289. // left side
  1290. p = new Polygon3D();
  1291. p->indexAnz = 6;
  1292. p->indexList = new int[ p->indexAnz ];
  1293. p->indexBuffer->setLength( p->indexAnz * 4 );
  1294. p->indexBuffer->setData( p->indexList );
  1295. p->indexList[ 0 ] = startIndex + 0 + 8;
  1296. p->indexList[ 1 ] = startIndex + 6 + 8;
  1297. p->indexList[ 2 ] = startIndex + 2 + 8;
  1298. p->indexList[ 3 ] = startIndex + 0 + 8;
  1299. p->indexList[ 4 ] = startIndex + 4 + 8;
  1300. p->indexList[ 5 ] = startIndex + 6 + 8;
  1301. model->addPolygon( p );
  1302. // top side
  1303. p = new Polygon3D();
  1304. p->indexAnz = 6;
  1305. p->indexList = new int[ p->indexAnz ];
  1306. p->indexBuffer->setLength( p->indexAnz * 4 );
  1307. p->indexBuffer->setData( p->indexList );
  1308. p->indexList[ 0 ] = startIndex + 4 + 16;
  1309. p->indexList[ 1 ] = startIndex + 0 + 16;
  1310. p->indexList[ 2 ] = startIndex + 1 + 16;
  1311. p->indexList[ 3 ] = startIndex + 4 + 16;
  1312. p->indexList[ 4 ] = startIndex + 1 + 16;
  1313. p->indexList[ 5 ] = startIndex + 5 + 16;
  1314. model->addPolygon( p );
  1315. // down side
  1316. p = new Polygon3D();
  1317. p->indexAnz = 6;
  1318. p->indexList = new int[ p->indexAnz ];
  1319. p->indexBuffer->setLength( p->indexAnz * 4 );
  1320. p->indexBuffer->setData( p->indexList );
  1321. p->indexList[ 0 ] = startIndex + 6 + 16;
  1322. p->indexList[ 1 ] = startIndex + 3 + 16;
  1323. p->indexList[ 2 ] = startIndex + 2 + 16;
  1324. p->indexList[ 3 ] = startIndex + 6 + 16;
  1325. p->indexList[ 4 ] = startIndex + 7 + 16;
  1326. p->indexList[ 5 ] = startIndex + 3 + 16;
  1327. model->addPolygon( p );
  1328. }
  1329. void makeQuader( Vertex3D* vertecies, int startIndex, Vec3< float > pos, Vec3< float > size )
  1330. {
  1331. float left, right, top, bottom;
  1332. // Calculate the screen coordinates of the left side of the bitmap.
  1333. left = pos.x;
  1334. // Calculate the screen coordinates of the right side of the bitmap.
  1335. right = pos.x + size.x;
  1336. // Calculate the screen coordinates of the top of the bitmap.
  1337. top = pos.y + size.y;
  1338. // Calculate the screen coordinates of the bottom of the bitmap.
  1339. bottom = pos.y;
  1340. float front = pos.z + size.z;
  1341. float back = pos.z;
  1342. makeQuader( vertecies, startIndex, Vec3< float >( left, top, front ), Vec3< float >( right, top, front ), Vec3< float >( left, bottom, front ), Vec3< float >( right, bottom, front ),
  1343. Vec3< float >( left, top, back ), Vec3< float >( right, top, back ), Vec3< float >( left, bottom, back ), Vec3< float >( right, bottom, back ) );
  1344. }
  1345. public:
  1346. // Konstruktor
  1347. // size: Die Größe des Würfels
  1348. Held()
  1349. {
  1350. model = new Model3DData();
  1351. float stdSize = 100;
  1352. float left, right, top, bottom;
  1353. // Calculate the screen coordinates of the left side of the bitmap.
  1354. left = (float)( ( stdSize / 2.0 ) * -1 );
  1355. // Calculate the screen coordinates of the right side of the bitmap.
  1356. right = left + (float)stdSize;
  1357. // Calculate the screen coordinates of the top of the bitmap.
  1358. top = (float)( stdSize / 2.0 );
  1359. // Calculate the screen coordinates of the bottom of the bitmap.
  1360. bottom = top - (float)stdSize;
  1361. float front = -stdSize / 2;
  1362. float back = front + stdSize;
  1363. Vertex3D * vertecies = new Vertex3D[ 24 ];
  1364. for( int i = 0; i < 24; i++ )
  1365. vertecies[ i ].knochenId = 0;
  1366. makeQuader( vertecies, 0, Vec3< float >( -stdSize / 2, -stdSize / 2, -stdSize / 2 ), Vec3< float >( stdSize, 10, stdSize ) );
  1367. model->setVertecies( vertecies, 24 );
  1368. textur = new Model3DTextur();
  1369. }
  1370. // Setzt die Textur des Würfels, so dass sie an allen Seiten gleich ist
  1371. // textur: Die Textur als Bild
  1372. void setTextur( Bild * textur )
  1373. {
  1374. Textur* t = new Textur();
  1375. t->setBildZ( textur );
  1376. int anz = model->getPolygonAnzahl();
  1377. for( int i = 0; i < anz; i++ )
  1378. this->textur->setPolygonTextur( i, t->getThis() );
  1379. t->release();
  1380. rend = 1;
  1381. }
  1382. };
  1383. // Aktion beim schließen des Fensters
  1384. void schließen( void* p, void* f )
  1385. {
  1386. // Stoppe Nachrichten Loop
  1387. StopNachrichtenSchleife( ( (WFenster*)f )->getFensterHandle() );
  1388. }
  1389. int __stdcall Framework::Start( Startparam p )
  1390. {
  1391. // Fenster erstellen
  1392. WNDCLASS wc = F_Normal( p.hinst );
  1393. wc.lpszClassName = "3D Creator";
  1394. WFenster* f = new WFenster();
  1395. f->erstellen( WS_OVERLAPPEDWINDOW, wc );
  1396. f->setVSchließAktion( schließen );
  1397. f->setAnzeigeModus( SW_SHOWNORMAL );
  1398. f->setSize( 1300, 820 );
  1399. f->setPosition( Punkt( 100, 100 ) );
  1400. // 3D Umgebung erstellen
  1401. Bildschirm3D* b = new Bildschirm3D( f->getThis() );
  1402. f->setBildschirm( b->getThis() );
  1403. b->setFillFarbe( 0 );
  1404. b->setTestRend( 0 );
  1405. Welt3D* welt = new Welt3D();
  1406. TreppeUnten* test = new TreppeUnten();
  1407. LTDBDatei* assets = new LTDBDatei();
  1408. assets->setDatei( new Text( "assets.ltdb" ) );
  1409. assets->leseDaten( 0 );
  1410. Bild* b1 = assets->laden( 0, new Text( "ground.png" ) );
  1411. assets->release();
  1412. test->setTextur( b1->getThis() );
  1413. test->setPosition( 0, 0, 0 );
  1414. welt->addZeichnung( test );
  1415. TreppeOben* test2 = new TreppeOben();
  1416. test2->setTextur( b1->getThis() );
  1417. test2->setPosition( 150, 0, 0 );
  1418. welt->addZeichnung( test2 );
  1419. Mauer* test3 = new Mauer();
  1420. test3->setTextur( b1->getThis() );
  1421. test3->setPosition( 150, 0, 150 );
  1422. welt->addZeichnung( test3 );
  1423. MauerEcke* test4 = new MauerEcke();
  1424. test4->setTextur( b1->getThis() );
  1425. test4->setPosition( -150, 0, 0 );
  1426. welt->addZeichnung( test4 );
  1427. MauerKreuz* test5 = new MauerKreuz();
  1428. test5->setTextur( b1->getThis() );
  1429. test5->setPosition( 0, 0, 150 );
  1430. welt->addZeichnung( test5 );
  1431. Boden* test6 = new Boden();
  1432. test6->setTextur( b1->getThis() );
  1433. test6->setPosition( -150, 0, 150 );
  1434. welt->addZeichnung( test6 );
  1435. b1->release();
  1436. Kam3D* kamA = new Kam3D();
  1437. kamA->setBildschirmPosition( 10, 10 );
  1438. kamA->setBildschirmSize( 385, 385 );
  1439. kamA->setPosition( Vec3<float>( -1000, 0, 0 ) );
  1440. kamA->setAusrichtung( Vec3<float>( 0, 0, 0 ) );
  1441. kamA->setWelt( welt->getThis() );
  1442. b->addKamera( kamA );
  1443. Kam3D* kamB = new Kam3D();
  1444. kamB->setBildschirmPosition( 10, 405 );
  1445. kamB->setBildschirmSize( 385, 385 );
  1446. kamB->setPosition( Vec3<float>( 0, -1000, 0 ) );
  1447. kamB->setAusrichtung( Vec3<float>( 0, 0, 0 ) );
  1448. kamB->setWelt( welt->getThis() );
  1449. b->addKamera( kamB );
  1450. Kam3D* kamC = new Kam3D();
  1451. kamC->setBildschirmPosition( 405, 10 );
  1452. kamC->setBildschirmSize( 385, 385 );
  1453. kamC->setPosition( Vec3<float>( 0, 0, -1000 ) );
  1454. kamC->setAusrichtung( Vec3<float>( 0, 0, 0 ) );
  1455. kamC->setWelt( welt->getThis() );
  1456. b->addKamera( kamC );
  1457. Kam3D * kamD = new Kam3D();
  1458. kamD->setStyle( Kam3D::Style::Movable | Kam3D::Style::Rotatable | Kam3D::Style::Tick );
  1459. kamD->setBildschirmPosition( 405, 405 );
  1460. kamD->setBildschirmSize( 385, 385 );
  1461. kamD->setPosition( Vec3<float>( 0, 0, -1000 ) );
  1462. kamD->setAusrichtung( Vec3<float>( 0, 0, 0 ) );
  1463. kamD->setWelt( welt->getThis() );
  1464. b->addKamera( kamD );
  1465. LRahmen * kamAR = new LRahmen();
  1466. kamAR->setPosition( 10, 10 );
  1467. kamAR->setFarbe( 0xFFFFFFFF );
  1468. kamAR->setRamenBreite( 1 );
  1469. kamAR->setSize( 385, 385 );
  1470. b->addMember( kamAR );
  1471. LRahmen * kamBR = new LRahmen();
  1472. kamBR->setPosition( 404, 10 );
  1473. kamBR->setFarbe( 0xFFFFFFFF );
  1474. kamBR->setRamenBreite( 1 );
  1475. kamBR->setSize( 385, 385 );
  1476. b->addMember( kamBR );
  1477. LRahmen * kamCR = new LRahmen();
  1478. kamCR->setPosition( 10, 405 );
  1479. kamCR->setFarbe( 0xFFFFFFFF );
  1480. kamCR->setRamenBreite( 1 );
  1481. kamCR->setSize( 385, 385 );
  1482. b->addMember( kamCR );
  1483. LRahmen * kamDR = new LRahmen();
  1484. kamDR->setPosition( 405, 405 );
  1485. kamDR->setFarbe( 0xFFFFFFFF );
  1486. kamDR->setRamenBreite( 1 );
  1487. kamDR->setSize( 385, 385 );
  1488. b->addMember( kamDR );
  1489. // Render Loop starten
  1490. RenderTh * r = new RenderTh();
  1491. r->setBildschirm( b->getThis() );
  1492. r->setTickFunktion( [ test, b, kamD ]( void*, void*, double t )
  1493. {
  1494. //test->setDrehung( test->getDrehung() + Vec3<double>( t, t, t ) );
  1495. if( Framework::getTastenStand( T_Enter ) )
  1496. {
  1497. kamD->setAusrichtung( Vec3<float>( 0, 0, 0 ) );
  1498. }
  1499. } );
  1500. r->beginn();
  1501. // Nachrichten Loop starten und warten
  1502. StartNachrichtenSchleife();
  1503. // Speicher Freigeben
  1504. r->beenden();
  1505. r->release();
  1506. b->release();
  1507. f->setBildschirm( 0 );
  1508. f->zerstören();
  1509. f->release();
  1510. welt->release();
  1511. return 0;
  1512. }