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.h 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #ifndef UGEENTITY_H
  2. #define UGEENTITY_H
  3. #include <QObject>
  4. #include <QPoint>
  5. #include <QSharedPointer>
  6. #include "utils/vector3d.h"
  7. #include "utils/matrix3x3.h"
  8. #include "engine/abstractrenderdevice.h"
  9. #include "engine/ugameengine.h"
  10. class UGameEngine;
  11. class UGEEntity : public QObject
  12. {
  13. Q_OBJECT
  14. public:
  15. explicit UGEEntity(UGameEngine* engine, QObject *parent);
  16. explicit UGEEntity(UGameEngine* engine);
  17. virtual ~UGEEntity();
  18. Vector3D getPosition() const;
  19. void setPosition(const Vector3D& position);
  20. void move(const Vector3D& move);
  21. // Vector3D getSpeed() const;
  22. // void setSpeed(const Vector3D& speed);
  23. // void accelerate(const Vector3D& speed);
  24. Vector3D getRotation() const;
  25. void setRotation(const Vector3D& rotation);
  26. void rotate(const Vector3D& rotation);
  27. Vector3D getScale() const;
  28. void setScale(const Vector3D& scale);
  29. void scale(const Vector3D& scale);
  30. bool isVisible() const;
  31. void setVisible(bool visible);
  32. void show();
  33. void hide();
  34. const QColor &getColor() const;
  35. void setColor(const QColor &color);
  36. Vector3D getRealPoint(const Vector3D& pos);
  37. ColorVector3D getRealPoint(const ColorVector3D& pos);
  38. TextureVector3D getRealPoint(const TextureVector3D& pos);
  39. Matrix3x3 getTransformationMatrix() const;
  40. Matrix3x3 getScaleMatrix() const;
  41. Matrix3x3 getRotationMatrix() const;
  42. void drawPoint(AbstractRenderDevice* device, const ColorVector3D& point);
  43. void drawLine(AbstractRenderDevice* device, const ColorVector3D& begin, const ColorVector3D& end, double width = 1.0);
  44. void drawPolygon(AbstractRenderDevice* device, QList<ColorVector3D> points);
  45. void drawPolygonTexture(AbstractRenderDevice *device, QList<TextureVector3D> points, const QVariant& textureId);
  46. void draw(AbstractRenderDevice* device);
  47. virtual void onDraw(AbstractRenderDevice* device) = 0;
  48. virtual Vector3D getVectorNearestIntesection(const Vector3D &vector, const Vector3D &pos, bool* ok) = 0;
  49. Vector3D getVectorNearestFaceIntersection(const Vector3D & p0, const Vector3D &p1, const Vector3D &p2, const Vector3D &vector, const Vector3D &pos, bool* ok);
  50. bool isZero(double v);
  51. void update();
  52. virtual void onUpdate();
  53. public slots:
  54. void needUpdate();
  55. signals:
  56. void positionChanged();
  57. void positionChanged(const Vector3D& position);
  58. void rotationChanged();
  59. void rotationChanged(const Vector3D& rotation);
  60. void scaleChanged();
  61. void scaleChanged(const Vector3D& scale);
  62. void visibilityChanged();
  63. void visibilityChanged(bool visible);
  64. void colorChanged();
  65. void colorChanged(QColor color);
  66. protected:
  67. UGameEngine* _engine;
  68. Vector3D _position;
  69. // Vector3D _speed;
  70. Vector3D _rotation;
  71. Vector3D _scale;
  72. bool _visible;
  73. QColor _color;
  74. bool _needUpdate;
  75. Matrix3x3 _tranformation;
  76. double _zero;
  77. private:
  78. void init();
  79. };
  80. #endif // UGEENTITY_H