TestKamera2D.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #include <Fenster.h>
  2. #include <Bildschirm.h>
  3. #include <RenderThread.h>
  4. #include <Welt2D.h>
  5. #include <M2Datei.h>
  6. #include <Model2D.h>
  7. #include <DateiSystem.h>
  8. #include <Textur2D.h>
  9. #include <Kamera2D.h>
  10. #include <iostream>
  11. #include <Bild.h>
  12. using namespace Framework;
  13. namespace Framework
  14. {
  15. void initFramework();
  16. void releaseFramework();
  17. }
  18. void FClose( void *p, void *zF );
  19. Punkt p1;
  20. Punkt p2;
  21. int kamera2DTest()
  22. {
  23. p1 = Punkt( -1, -1 );
  24. initFramework();
  25. Welt2D w2d;
  26. w2d.setAirResistance( 0.001 );
  27. w2d.setCircular( 1 );
  28. w2d.setSize( 5000, 5000 );
  29. w2d.setSize( 1 );
  30. Welt2D *w2 = &w2d;
  31. Kamera2D kam2d;
  32. Kamera2D *kam2 = &kam2d;
  33. WNDCLASS wndC = Framework::F_Normal( 0 );
  34. wndC.lpszClassName = "Kamera 2D Test";
  35. WFenster f;
  36. f.erstellen( WS_OVERLAPPEDWINDOW, wndC );
  37. f.setPosition( Punkt( 100, 100 ) );
  38. f.setSize( 900, 900 );
  39. f.setVSchließAktion( FClose );
  40. f.setMausAktion( [ w2, kam2 ]( void *p, void *o, MausEreignis me )
  41. {
  42. p2 = Punkt( me.mx, me.my );
  43. if( me.id == ME_RRechts )
  44. {
  45. Vertex wp = kam2->getWorldCoordinates( Punkt( me.mx, me.my ) );
  46. w2->explosion( wp, 100000, 10000 );
  47. }
  48. if( me.id == ME_RLinks )
  49. {
  50. if( p1 == Punkt( -1, -1 ) )
  51. p1 = Punkt( me.mx, me.my );
  52. else
  53. {
  54. w2->impuls( kam2->getWorldCoordinates( p1 ), kam2->getWorldDirection( Vertex( me.mx, me.my ) - (Vertex)p1 ) );
  55. p1 = Punkt( -1, -1 );
  56. }
  57. }
  58. return 1;
  59. } );
  60. f.setTastaturAktion( _ret1TE );
  61. f.setAnzeigeModus( 1 );
  62. Bildschirm2D b( f.getThis() );
  63. b.update();
  64. b.setTestRend( 0 );
  65. b.setFill( 0 );
  66. f.setBildschirm( b.getThis() );
  67. RenderTh rth;
  68. rth.setBildschirm( b.getThis() );
  69. rth.setRenderFunktion( []( void*a, void*rth, Bild*c )
  70. {
  71. c->fillRegion( 0, 0, c->getBreite(), c->getHeight(), 0xFF000000 );
  72. std::cout << "FPS: " << (1 / (( RenderTh*)rth)->getRenderTickZeit()) << " | Zeit pro Tick:" << ( (RenderTh*)rth )->getRenderTickZeit() << "\n";
  73. if( p1 != Punkt( -1, -1 ) )
  74. c->drawLinie( p1, p2, 0xFFFFFFFF );
  75. } );
  76. rth.beginn();
  77. M2Datei d;
  78. d.setPfad( "ship.m2" );
  79. d.leseDaten();
  80. Model2DData *m = d.ladeModel( "ship" );
  81. LTDBDatei td;
  82. td.setDatei( new Text( "ship.ltdb" ) );
  83. td.leseDaten( 0 );
  84. Bild *bt = td.laden( 0, new Text( "a.png" ) );
  85. Textur2D txt;
  86. txt.setTexturZ( bt );
  87. for( int i = 0; i < 100; i++ )
  88. {
  89. Model2DObject *mdl = new Model2DObject();
  90. mdl->setModel( m->getThis() );
  91. mdl->setPosition( (float)(rand() / 16 - RAND_MAX / 32), (float)(rand() / 16 - RAND_MAX / 32) );
  92. mdl->setSpeed( (float)rand() / 128 - (float)rand() / 128, (float)rand() / 128 - (float)rand() / 128 );
  93. mdl->setDrehungSpeed( (float)rand() / ( RAND_MAX / 2 ) - (float)rand() / ( RAND_MAX / 2 ) );
  94. mdl->setTextur( txt.getThis(), "ship" );
  95. w2d.addObject( mdl );
  96. }
  97. kam2d.setStyle( Kamera2D::Style::Sichtbar );
  98. kam2d.setSize( 900, 900 );
  99. kam2d.setWelt( w2d.getThis() );
  100. kam2d.setZoom( 0.3f );
  101. b.addMember( &kam2d );
  102. StartNachrichtenSchleife();
  103. rth.beenden();
  104. return 0;
  105. }