TestKamera2D.cpp 3.2 KB

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