VideoKamera.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #include "VideoKamera.h"
  2. #include "..\Karte\VideoKarte.h"
  3. #include <Punkt.h>
  4. #include <Rahmen.h>
  5. // Inhalt der VideoKamera Klasse aus VideoKamera.h
  6. // Konstruktor
  7. VideoKamera::VideoKamera()
  8. {
  9. pos = Punkt( 0, 0 );
  10. gr = Punkt( 0, 0 );
  11. runde = 0;
  12. rundePos = new Array< Punkt >();
  13. rundeGr = new Array< Punkt >();
  14. rGr = Punkt( 0, 0 );
  15. rahmen = new LRahmen();
  16. rahmen->setFarbe( 0xFF505050 );
  17. rahmen->setRamenBreite( 1 );
  18. ref = 1;
  19. }
  20. // Destruktor
  21. VideoKamera::~VideoKamera()
  22. {
  23. rundePos->release();
  24. rundeGr->release();
  25. rahmen->release();
  26. }
  27. // nicht constant
  28. void VideoKamera::setPosition( int x, int y )
  29. {
  30. pos.x = x;
  31. pos.y = y;
  32. }
  33. void VideoKamera::addPosition( int x, int y, VideoKarte *zMap )
  34. {
  35. pos.x += x;
  36. pos.y += y;
  37. if( pos.x < 0 )
  38. pos.x = 0;
  39. if( pos.y < 0 )
  40. pos.y = 0;
  41. if( pos.x > zMap->getBreite() )
  42. pos.x = zMap->getBreite();
  43. if( pos.y > zMap->getHeight() )
  44. pos.y = zMap->getHeight();
  45. }
  46. void VideoKamera::setSize( int br, int hö )
  47. {
  48. gr.x = br;
  49. gr.y = hö;
  50. }
  51. void VideoKamera::render( Bild &zRObj )
  52. {
  53. rGr = zRObj.getSize();
  54. rahmen->setPosition( getRX( getLinks() ), getRY( getOben() ) );
  55. rahmen->setSize( gr );
  56. rahmen->render( zRObj );
  57. }
  58. void VideoKamera::nextRunde( bool vorwärts )
  59. {
  60. if( vorwärts )
  61. {
  62. rundePos->set( pos, runde );
  63. rundeGr->set( gr, runde );
  64. runde++;
  65. }
  66. else
  67. {
  68. runde--;
  69. pos = rundePos->hat( runde ) ? rundePos->get( runde ) : Punkt( 0, 0 );
  70. gr = rundeGr->hat( runde ) ? rundeGr->get( runde ) : Punkt( 0, 0 );
  71. }
  72. }
  73. // constant
  74. int VideoKamera::getLinks() const
  75. {
  76. return pos.x - (int)( gr.x / 2.0 + 0.5 );
  77. }
  78. int VideoKamera::getOben() const
  79. {
  80. return pos.y - gr.y / 2;
  81. }
  82. int VideoKamera::getRechts() const
  83. {
  84. return pos.x + gr.x / 2;
  85. }
  86. int VideoKamera::getUnten() const
  87. {
  88. return pos.y + gr.y / 2;
  89. }
  90. bool VideoKamera::istSichtbar( int x, int y ) const
  91. {
  92. return ( x >= getLinks() && x < getRechts() && y >= getOben() && y < getUnten() );
  93. }
  94. bool VideoKamera::istMausIn( int x, int y ) const
  95. {
  96. return ( x >= ( rGr.x / 2 - gr.x / 2 ) && x < ( rGr.x / 2 + gr.x / 2 ) && y >= ( rGr.y / 2 - gr.y / 2 ) && y < ( rGr.y / 2 + gr.y / 2 ) );
  97. }
  98. int VideoKamera::getRX( int mapX ) const
  99. {
  100. return rGr.x / 2 - ( pos.x - mapX );
  101. }
  102. int VideoKamera::getRY( int mapY ) const
  103. {
  104. return rGr.y / 2 - ( pos.y - mapY );
  105. }
  106. int VideoKamera::getX() const
  107. {
  108. return pos.x;
  109. }
  110. int VideoKamera::getY() const
  111. {
  112. return pos.y;
  113. }
  114. // Reference Counting
  115. VideoKamera *VideoKamera::getThis()
  116. {
  117. ref++;
  118. return this;
  119. }
  120. VideoKamera *VideoKamera::release()
  121. {
  122. ref--;
  123. if( !ref )
  124. delete this;
  125. return 0;
  126. }