Pixel.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include "Pixel.h"
  2. #include <Bild.h>
  3. Pixel::Pixel( Vertex pos, Vertex speed, float ep, int id )
  4. : Object2D()
  5. {
  6. setPosition( pos );
  7. setSpeed( speed );
  8. this->ep = ep;
  9. pixelId = id;
  10. collision = false;
  11. save();
  12. }
  13. bool Pixel::tick( const WeltInfo &info, double zeit )
  14. {
  15. ep -= (float)zeit;
  16. return __super::tick( info, zeit ) || 1;
  17. }
  18. void Pixel::render( Mat3< float > &kamMat, Bild &zRObj, const char *kamName )
  19. {
  20. Mat3< float > mat = kamMat * getObjectMatrix();
  21. Vertex p = mat * Vertex( 0, 0 );
  22. Vertex p2 = mat * Vertex( ep / 5, 0 );
  23. zRObj.fillCircle( (int)p.x, (int)p.y, (int)( p2 - p ).getLength() + 1, 0xFFFFFFFF );
  24. }
  25. Rect2< float > Pixel::getBoundingBox() const
  26. {
  27. Rect2< float > r = Rect2< float >();
  28. r.topLeft.x = -(ep / 5 + 1);
  29. r.topLeft.y = -(ep / 5 + 1);
  30. r.bottomRight.x = ep / 5 + 1;
  31. r.bottomRight.y = ep / 5 + 1;
  32. r.topLeft = getWorldPos( r.topLeft );
  33. r.bottomRight = getWorldPos( r.bottomRight );
  34. return r;
  35. }
  36. float Pixel::getEp() const
  37. {
  38. return ep;
  39. }
  40. int Pixel::getId() const
  41. {
  42. return pixelId;
  43. }
  44. void Pixel::save()
  45. {
  46. backup.pos = getPosition();
  47. backup.speed = getSpeed();
  48. backup.rotation = getDrehung();
  49. backup.rSpeed = getDrehungSpeed();
  50. backup.oldEp = ep;
  51. }
  52. void Pixel::load()
  53. {
  54. setPosition( backup.pos );
  55. setSpeed( backup.speed );
  56. setDrehung( backup.rotation );
  57. setDrehungSpeed( backup.rSpeed );
  58. ep = backup.oldEp;
  59. }