test3dF.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. #include <Globals.h>
  2. #include <Fenster.h>
  3. #include <MausEreignis.h>
  4. #include <TastaturEreignis.h>
  5. #include <Bildschirm.h>
  6. #include <RenderThread.h>
  7. #include <Zeichnung3D.h>
  8. #include <Model3D.h>
  9. #include <Bild.h>
  10. #include <Zeichnung.h>
  11. #include <Mat4.h>
  12. #include <time.h>
  13. #include <Render3D.h>
  14. #include <Welt3D.h>
  15. #include <Kam3D.h>
  16. #include <iostream>
  17. #include <Mat4.h>
  18. #include <Textur.h>
  19. #include <DXBuffer.h>
  20. #include <Cube.h>
  21. #include <Textur.h>
  22. #include <TexturList.h>
  23. #include <Klient.h>
  24. #include <Animation3D.h>
  25. #include <FrameworkMath.h>
  26. using namespace Framework;
  27. void FClose( void *p, void *zF )
  28. {
  29. StopNachrichtenSchleife( ( (WFenster*)zF )->getFensterHandle() );
  30. }
  31. int kAnz = 10;
  32. Knochen **knochen;
  33. Model3D *createKnochenTestModel()
  34. {
  35. Model3DData *model = new Model3DData();
  36. float stdSize = 50;
  37. float left, right, top, bottom;
  38. // Calculate the screen coordinates of the left side of the bitmap.
  39. left = (float)( ( stdSize / 2.0 ) * -1 );
  40. // Calculate the screen coordinates of the right side of the bitmap.
  41. right = left + (float)stdSize;
  42. // Calculate the screen coordinates of the top of the bitmap.
  43. top = (float)( stdSize / 2.0 );
  44. // Calculate the screen coordinates of the bottom of the bitmap.
  45. bottom = top - (float)stdSize;
  46. float front = -stdSize / 2;
  47. float back = front + stdSize;
  48. Vertex3D *vertecies = new Vertex3D[ kAnz * 4 ];
  49. for( int k = 0; k < kAnz; k++ )
  50. {
  51. for( int i = k * 4; i < 4 + k * 4; i++ )
  52. vertecies[ i ].knochenId = k;
  53. if( k == 0 )
  54. {
  55. vertecies[ 0 + k * 4 ].pos = Vec3<float >( left, top, 0 );
  56. vertecies[ 0 + k * 4 ].tPos = Vec2< float >( 0.f, 0.f );
  57. vertecies[ 1 + k * 4 ].pos = Vec3<float >( right, top, 0 );
  58. vertecies[ 1 + k * 4 ].tPos = Vec2< float >( 1.f, 0.f );
  59. vertecies[ 2 + k * 4 ].pos = Vec3<float >( left, bottom, 0 );
  60. vertecies[ 2 + k * 4 ].tPos = Vec2< float >( 0.f, 1.f );
  61. vertecies[ 3 + k * 4 ].pos = Vec3<float >( right, bottom, 0 );
  62. vertecies[ 3 + k * 4 ].tPos = Vec2< float >( 1.f, 1.f );
  63. }
  64. else
  65. {
  66. vertecies[ 0 + k * 4 ].pos = Vec3<float >( left, top, 100 );
  67. vertecies[ 0 + k * 4 ].tPos = Vec2< float >( 0.f, 0.f );
  68. vertecies[ 1 + k * 4 ].pos = Vec3<float >( right, top, 100 );
  69. vertecies[ 1 + k * 4 ].tPos = Vec2< float >( 1.f, 0.f );
  70. vertecies[ 2 + k * 4 ].pos = Vec3<float >( left, bottom, 100 );
  71. vertecies[ 2 + k * 4 ].tPos = Vec2< float >( 0.f, 1.f );
  72. vertecies[ 3 + k * 4 ].pos = Vec3<float >( right, bottom, 100 );
  73. vertecies[ 3 + k * 4 ].tPos = Vec2< float >( 1.f, 1.f );
  74. }
  75. }
  76. model->setVertecies( vertecies, kAnz * 4 );
  77. for( int k = 0; k < kAnz; k++ )
  78. {
  79. if( k == 0 || k == kAnz - 1 )
  80. {
  81. // front side
  82. Polygon3D *p = new Polygon3D();
  83. p->indexAnz = 6;
  84. p->indexList = new int[ p->indexAnz ];
  85. p->indexBuffer->setLength( p->indexAnz * 4 );
  86. p->indexBuffer->setData( p->indexList );
  87. p->indexList[ 0 ] = 0 + k * 4;
  88. p->indexList[ 1 ] = 3 + k * 4;
  89. p->indexList[ 2 ] = 2 + k * 4;
  90. p->indexList[ 3 ] = 0 + k * 4;
  91. p->indexList[ 4 ] = 1 + k * 4;
  92. p->indexList[ 5 ] = 3 + k * 4;
  93. model->addPolygon( p );
  94. }
  95. if( k != kAnz - 1 )
  96. {
  97. // right side
  98. Polygon3D *p = new Polygon3D();
  99. p->indexAnz = 6;
  100. p->indexList = new int[ p->indexAnz ];
  101. p->indexBuffer->setLength( p->indexAnz * 4 );
  102. p->indexBuffer->setData( p->indexList );
  103. p->indexList[ 0 ] = 1 + k * 4;
  104. p->indexList[ 1 ] = 7 + k * 4;
  105. p->indexList[ 2 ] = 3 + k * 4;
  106. p->indexList[ 3 ] = 1 + k * 4;
  107. p->indexList[ 4 ] = 5 + k * 4;
  108. p->indexList[ 5 ] = 7 + k * 4;
  109. model->addPolygon( p );
  110. // left side
  111. p = new Polygon3D();
  112. p->indexAnz = 6;
  113. p->indexList = new int[ p->indexAnz ];
  114. p->indexBuffer->setLength( p->indexAnz * 4 );
  115. p->indexBuffer->setData( p->indexList );
  116. p->indexList[ 0 ] = 0 + k * 4;
  117. p->indexList[ 1 ] = 2 + k * 4;
  118. p->indexList[ 2 ] = 6 + k * 4;
  119. p->indexList[ 3 ] = 0 + k * 4;
  120. p->indexList[ 4 ] = 6 + k * 4;
  121. p->indexList[ 5 ] = 4 + k * 4;
  122. model->addPolygon( p );
  123. // top side
  124. p = new Polygon3D();
  125. p->indexAnz = 6;
  126. p->indexList = new int[ p->indexAnz ];
  127. p->indexBuffer->setLength( p->indexAnz * 4 );
  128. p->indexBuffer->setData( p->indexList );
  129. p->indexList[ 0 ] = 4 + k * 4;
  130. p->indexList[ 1 ] = 1 + k * 4;
  131. p->indexList[ 2 ] = 0 + k * 4;
  132. p->indexList[ 3 ] = 4 + k * 4;
  133. p->indexList[ 4 ] = 5 + k * 4;
  134. p->indexList[ 5 ] = 1 + k * 4;
  135. model->addPolygon( p );
  136. // down side
  137. p = new Polygon3D();
  138. p->indexAnz = 6;
  139. p->indexList = new int[ p->indexAnz ];
  140. p->indexBuffer->setLength( p->indexAnz * 4 );
  141. p->indexBuffer->setData( p->indexList );
  142. p->indexList[ 0 ] = 6 + k * 4;
  143. p->indexList[ 1 ] = 2 + k * 4;
  144. p->indexList[ 2 ] = 3 + k * 4;
  145. p->indexList[ 3 ] = 6 + k * 4;
  146. p->indexList[ 4 ] = 3 + k * 4;
  147. p->indexList[ 5 ] = 7 + k * 4;
  148. model->addPolygon( p );
  149. }
  150. }
  151. Model3DTextur *textur = new Model3DTextur();
  152. for( int k = 0; k < kAnz; k++ )
  153. {
  154. Textur *t = new Textur();
  155. Bild *tb = new Bild();
  156. tb->neuBild( 100, 100, 0xFF000000 | (rand() % 0xFFFFFF) );
  157. t->setBildZ( tb );
  158. textur->setPolygonTextur( k * 4, t->getThis() );
  159. textur->setPolygonTextur( k * 4 + 1, t->getThis() );
  160. textur->setPolygonTextur( k * 4 + 2, t->getThis() );
  161. textur->setPolygonTextur( k * 4 + 3, t );
  162. }
  163. Model3D *m3d = new Model3D();
  164. m3d->setModelDaten( model );
  165. m3d->setModelTextur( textur );
  166. Skelett *s = new Skelett();
  167. knochen = new Knochen*[ kAnz ];
  168. for( int k = 0; k < kAnz; k++ )
  169. {
  170. Knochen *kn = new Knochen( k );
  171. if( k != 0 )
  172. kn->setPosition( Vec3<float>( 0, 0, 100 ) );
  173. s->addKnochen( kn, k - 1 );
  174. knochen[ k ] = kn;
  175. }
  176. m3d->setSkelettZ( s );
  177. Animation3D *animation = new Animation3D();
  178. animation->addKeyFrame( 2, 20, Vec3<float>( 0, 0, 100 ), Vec3<float>( 2 * 3.14, 2 * 3.14, 2 * 3.14 ) );
  179. animation->addKeyFrame( 2, 0, Vec3<float>( 0, 0, 100 ), Vec3<float>( 0, 0, 0 ) );
  180. animation->addKeyFrame( 4, 20, Vec3<float>( 0, 0, 100 ), Vec3<float>( 2 * 3.14, 2 * 3.14, 2 * 3.14 ) );
  181. animation->addKeyFrame( 4, 0, Vec3<float>( 0, 0, 100 ), Vec3<float>( 0, 0, 0 ) );
  182. animation->addKeyFrame( 6, 20, Vec3<float>( 0, 0, 100 ), Vec3<float>( 2 * 3.14, 2 * 3.14, 2 * 3.14 ) );
  183. animation->addKeyFrame( 6, 0, Vec3<float>( 0, 0, 100 ), Vec3<float>( 0, 0, 0 ) );
  184. animation->addKeyFrame( 8, 20, Vec3<float>( 0, 0, 100 ), Vec3<float>( 2 * 3.14, 2 * 3.14, 2 * 3.14 ) );
  185. animation->addKeyFrame( 8, 0, Vec3<float>( 0, 0, 100 ), Vec3<float>( 0, 0, 0 ) );
  186. m3d->addAnimation( animation, 5 );
  187. return m3d;
  188. }
  189. int _select = 0;
  190. int _achse = 0;
  191. bool taste( void *p, void *o, TastaturEreignis t )
  192. {
  193. Vec3<float> r(0, 0, 0);
  194. if( _achse == 0 )
  195. r.x = 0.001;
  196. if( _achse == 1 )
  197. r.y = 0.001;
  198. if( _achse == 2 )
  199. r.z = 0.001;
  200. if( t.id == TE_Press )
  201. {
  202. switch( t.taste )
  203. {
  204. case '0':
  205. _select = 0;
  206. break;
  207. case '1':
  208. _select = 1;
  209. break;
  210. case '2':
  211. _select = 2;
  212. break;
  213. case '3':
  214. _select = 3;
  215. break;
  216. case '4':
  217. _select = 4;
  218. break;
  219. case '5':
  220. _select = 5;
  221. break;
  222. case '6':
  223. _select = 6;
  224. break;
  225. case '7':
  226. _select = 7;
  227. break;
  228. case '8':
  229. _select = 8;
  230. break;
  231. case '9':
  232. _select = 9;
  233. break;
  234. case 'x':
  235. _achse = 0;
  236. break;
  237. case 'y':
  238. _achse = 1;
  239. break;
  240. case 'z':
  241. _achse = 2;
  242. break;
  243. case '+':
  244. knochen[ _select ]->setDrehung( knochen[ _select ]->getDrehung() + r );
  245. break;
  246. case '-':
  247. knochen[ _select ]->setDrehung( knochen[ _select ]->getDrehung() - r );
  248. break;
  249. }
  250. }
  251. return false;
  252. }
  253. int main()
  254. {
  255. initFramework();
  256. Welt3D *welt = new Welt3D();
  257. Kam3D *kamera = new Kam3D();
  258. kamera->setPosition( Vec3< float >( 0, 75, 0 ) );
  259. kamera->setWelt( welt );
  260. kamera->setBildschirmSize( 1600, 900 );
  261. WFenster *f = new WFenster();
  262. WNDCLASS fc = F_Normal( 0 );
  263. fc.lpszClassName = "Test";
  264. f->erstellen( WS_OVERLAPPEDWINDOW, fc );
  265. f->setSize( 1600, 900 );
  266. f->setVSchließAktion( FClose );
  267. f->setMausAktion( _ret1ME );
  268. f->setTastaturAktion( taste );
  269. f->setAnzeigeModus( 1 );
  270. Bildschirm3D *bs = new Bildschirm3D( f->getThis() );
  271. f->setBildschirm( bs->getThis() );
  272. bs->setFill( 1 );
  273. bs->setFillFarbe( 0 );
  274. //bs->setTestRend( 0 );
  275. bs->addKamera( kamera );
  276. Model3D *sat = createKnochenTestModel();
  277. welt->addZeichnung( sat );
  278. /*
  279. int anzX = 100;
  280. int anzZ = 100;
  281. for( int i = 0; i < 100; i++ )
  282. {
  283. Bild *b = new Bild();
  284. b->neuBild( 100, 100, 0xFF000000 | ( ( rand() % 0xFF ) << 16 ) | ( ( rand() % 0xFF ) << 8 ) | ( rand() % 0xFF ) );
  285. b->fillCircle( 50, 50, 15, 0 );
  286. Textur *t = new Textur();
  287. t->setBildZ( b );
  288. zTexturRegister()->addTextur( t, Text( i ) );
  289. }
  290. Cube **test = new Cube*[ anzX * anzZ ];
  291. for( int i = 0; i < anzX; i++ )
  292. {
  293. for( int j = 0; j < anzZ; j++ )
  294. {
  295. test[ i + j * anzZ ] = new Cube( 100 );
  296. test[ i + j * anzZ ]->setPosition( i * 100.f - 100 * ( anzX / 2 ), 0, j * 100.f - 100 * ( anzZ / 2 ) );
  297. test[ i + j * anzZ ]->setTextur( rand() % 100 );
  298. test[ i + j * anzZ ]->setAlpha( 1 );
  299. test[ i + j * anzZ ]->setDrehung( Vec3< float >( ( rand() % 10 ) / 10.f * 6.28f, ( rand() % 10 ) / 10.f * 6.28f, ( rand() % 10 ) / 10.f * 6.28f ) );
  300. welt->addZeichnung( test[ i + j * anzZ ] );
  301. }
  302. }*/
  303. ZeichnungHintergrund *zh = new ZeichnungHintergrund();
  304. zh->setStyle( ZeichnungHintergrund::Style::Sichtbar | ZeichnungHintergrund::Style::Hintergrund | ZeichnungHintergrund::Style::Buffered );
  305. zh->setHintergrundFarbe( 0 );
  306. zh->setAlphaFeldFarbe( 0xA0FF0000 );
  307. zh->setAlphaFeldStrength( 5 );
  308. zh->setSize( 1580, 860 );
  309. zh->setPosition( 10, 10 );
  310. bs->addMember( zh );
  311. RenderTh *r = new RenderTh();
  312. r->setBildschirm( bs->getThis() );
  313. r->setMaxFps( 60 );
  314. r->beginn();
  315. StartNachrichtenSchleife();
  316. r->beenden();
  317. r->release();
  318. /*
  319. for( int i = 0; i < anzX * anzZ; i++ )
  320. test[ i ]->release();
  321. delete[] test;*/
  322. delete zh;
  323. f->setBildschirm( 0 );
  324. bs->release();
  325. f->release();
  326. welt->release();
  327. kamera->release();
  328. releaseFramework();
  329. return 0;
  330. }