You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ugeentity.cpp 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #include "ugeentity.h"
  2. UGEEntity::UGEEntity(QObject *parent)
  3. : QObject(parent)
  4. , _visible(true)
  5. {
  6. }
  7. UGEEntity::~UGEEntity()
  8. {
  9. }
  10. Vector3D UGEEntity::getPosition() const
  11. {
  12. return _position;
  13. }
  14. void UGEEntity::setPosition(const Vector3D &position)
  15. {
  16. _position = position;
  17. emit positionChanged();
  18. emit positionChanged(_position);
  19. }
  20. void UGEEntity::move(const Vector3D &move)
  21. {
  22. _position += move;
  23. emit positionChanged();
  24. emit positionChanged(_position);
  25. }
  26. //Vector3D UGEEntity::getSpeed() const
  27. //{
  28. // return _speed;
  29. //}
  30. //void UGEEntity::setSpeed(const Vector3D &speed)
  31. //{
  32. // _speed = speed;
  33. //}
  34. //void UGEEntity::accelerate(const Vector3D &speed)
  35. //{
  36. // _speed += speed;
  37. //}
  38. Vector3D UGEEntity::getRotation() const
  39. {
  40. return _rotation;
  41. }
  42. void UGEEntity::setRotation(const Vector3D &rotation)
  43. {
  44. _rotation = rotation;
  45. emit rotationChanged();
  46. emit rotationChanged(rotation);
  47. }
  48. void UGEEntity::rotate(const Vector3D &rotation)
  49. {
  50. _rotation += rotation;
  51. emit rotationChanged();
  52. emit rotationChanged(rotation);
  53. }
  54. Vector3D UGEEntity::getScale() const
  55. {
  56. return _scale;
  57. }
  58. void UGEEntity::setScale(const Vector3D &scale)
  59. {
  60. _scale = scale;
  61. emit scaleChanged();
  62. emit scaleChanged(_scale);
  63. }
  64. void UGEEntity::scale(const Vector3D &scale)
  65. {
  66. _scale += scale;
  67. emit scaleChanged();
  68. emit scaleChanged(_scale);
  69. }
  70. bool UGEEntity::isVisible() const
  71. {
  72. return _visible;
  73. }
  74. void UGEEntity::setVisible(bool visible)
  75. {
  76. _visible = visible;
  77. emit visibilityChanged();
  78. emit visibilityChanged(_visible);
  79. }
  80. void UGEEntity::show()
  81. {
  82. _visible = true;
  83. emit visibilityChanged();
  84. emit visibilityChanged(_visible);
  85. }
  86. void UGEEntity::hide()
  87. {
  88. _visible = false;
  89. emit visibilityChanged();
  90. emit visibilityChanged(_visible);
  91. }
  92. QColor UGEEntity::getColor() const
  93. {
  94. return _color;
  95. }
  96. void UGEEntity::setColor(const QColor &color)
  97. {
  98. _color = color;
  99. emit colorChanged();
  100. emit colorChanged(_color);
  101. }
  102. Vector3D UGEEntity::getRealPoint(const Vector3D &pos)
  103. {
  104. Vector3D p = pos + _position;
  105. return p;
  106. }
  107. ColorVector3D UGEEntity::getRealPoint(const ColorVector3D &pos)
  108. {
  109. return ColorVector3D(pos.getColor(), getRealPoint((Vector3D)pos));
  110. }
  111. TextureVector3D UGEEntity::getRealPoint(const TextureVector3D &pos)
  112. {
  113. return TextureVector3D(pos.getTextureCoord(), getRealPoint((ColorVector3D)pos));
  114. }
  115. void UGEEntity::drawPoint(AbstractRenderDevice *device, const ColorVector3D &point)
  116. {
  117. device->drawPoint(getRealPoint(point));
  118. }
  119. void UGEEntity::drawLine(AbstractRenderDevice *device, const ColorVector3D &begin, const ColorVector3D &end, double width)
  120. {
  121. device->drawLine(getRealPoint(begin), getRealPoint(end), width);
  122. }
  123. void UGEEntity::drawPolygon(AbstractRenderDevice *device, QList<ColorVector3D> points)
  124. {
  125. for (int i = 0; i < points.size(); ++i) {
  126. points[i] = getRealPoint(points[i]);
  127. }
  128. device->drawPolygon(points);
  129. }
  130. void UGEEntity::drawPolygonTexture(AbstractRenderDevice *device, QList<TextureVector3D> points, const QVariant &textureId)
  131. {
  132. for (int i = 0; i < points.size(); ++i) {
  133. points[i] = getRealPoint(points[i]);
  134. }
  135. device->drawPolygonTexture(points, textureId);
  136. }