Drawing3D.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #pragma once
  2. #include "Mat4.h"
  3. #include "ReferenceCounter.h"
  4. namespace Framework
  5. {
  6. struct MouseEvent3D;
  7. struct KeyboardEvent;
  8. class Render3D; //! Render3D.h
  9. //! An object that can be drawn by the Screen3D class.
  10. class Drawable3D : public virtual ReferenceCounter
  11. {
  12. protected:
  13. Vec3<float> pos; //! Position of the object
  14. Vec3<float> angle; //! Rotation angles for x, y and z
  15. Mat4<float> welt; //! World translation matrix
  16. float radius; //! The radius of a sphere that encloses the entire object
  17. bool alpha; //! Stores whether the object contains partially or fully
  18. //! transparent areas
  19. bool rend;
  20. bool lastTickReturn;
  21. float size;
  22. public:
  23. //! Constructor
  24. DLLEXPORT Drawable3D();
  25. DLLEXPORT virtual ~Drawable3D();
  26. //! Sets the position of the drawing in the world
  27. //! \param p The position
  28. DLLEXPORT void setPosition(const Vec3<float>& p);
  29. //! Sets the position of the drawing in the world
  30. //! \param x The x position
  31. //! \param y The y position
  32. //! \param z The z position
  33. DLLEXPORT void setPosition(float x, float y, float z);
  34. //! Sets the position of the drawing in the world
  35. //! \param x The x position
  36. DLLEXPORT void setX(float x);
  37. //! Sets the position of the drawing in the world
  38. //! \param y The y position
  39. DLLEXPORT void setY(float y);
  40. //! Sets the position of the drawing in the world
  41. //! \param z The z position
  42. DLLEXPORT void setZ(float z);
  43. //! Sets the rotation of the drawing in the world
  44. //! \param d The rotation around the x, y and z axes
  45. DLLEXPORT void setRotation(const Vec3<float>& d);
  46. //! Sets the rotation of the drawing in the world
  47. //! \param xWinkel The rotation around the x axis
  48. //! \param yWinkel The rotation around the y axis
  49. //! \param zWinkel The rotation around the z axis
  50. DLLEXPORT void setRotation(float xWinkel, float yWinkel, float zWinkel);
  51. //! Sets the rotation of the drawing in the world
  52. //! \param winkel The rotation around the x axis
  53. DLLEXPORT void setRotationX(float winkel);
  54. //! Sets the rotation of the drawing in the world
  55. //! \param winkel The rotation around the y axis
  56. DLLEXPORT void setRotationY(float winkel);
  57. //! Sets the rotation of the drawing in the world
  58. //! \param winkel The rotation around the z axis
  59. DLLEXPORT void setRotationZ(float winkel);
  60. //! Sets whether the object contains partially or fully transparent
  61. //! areas \param a true if partially or fully transparent areas exist
  62. DLLEXPORT void setAlpha(bool a);
  63. //! Sets the scaling
  64. DLLEXPORT void setSize(float size);
  65. //! Returns the scaling
  66. DLLEXPORT float getSize() const;
  67. //! Calculates the matrices of all bones in the drawing's skeleton
  68. //! \param viewProj The multiplied camera matrices
  69. //! \param matBuffer An array of matrices to fill
  70. //! \return The number of matrices the drawing requires
  71. DLLEXPORT virtual int calculateMatrices(
  72. const Mat4<float>& viewProj, Mat4<float>* matBuffer);
  73. //! Processes a mouse event
  74. //! \param me The mouse event to process
  75. DLLEXPORT virtual void doMouseEvent(MouseEvent3D& me);
  76. //! Processes a keyboard event
  77. //! \param te The keyboard event to process
  78. DLLEXPORT virtual void doKeyboardEvent(KeyboardEvent& te);
  79. //! Processes elapsed time
  80. //! \param tickval The time in seconds since the last call of this
  81. //! function \return true if the object changed, false otherwise.
  82. DLLEXPORT virtual bool tick(double tickval);
  83. //! Returns whether the object contains partially or fully transparent
  84. //! areas
  85. DLLEXPORT bool hasAlpha() const;
  86. //! Returns the radius of a sphere that encloses the entire model
  87. DLLEXPORT inline float getRadius() const;
  88. //! Returns a point representing the position of the drawing in the
  89. //! world
  90. DLLEXPORT const Vec3<float>& getPos() const;
  91. //! Returns the X position of the drawing in the world
  92. DLLEXPORT float getX() const;
  93. //! Returns the Y position of the drawing in the world
  94. DLLEXPORT float getY() const;
  95. //! Returns the Z position of the drawing in the world
  96. DLLEXPORT float getZ() const;
  97. //! Returns a vector representing the rotation of the drawing in the
  98. //! world. x is the rotation around the X axis in radians, etc.
  99. DLLEXPORT const Vec3<float>& getRotation() const;
  100. //! Returns the rotation around the X axis in radians
  101. DLLEXPORT float getXRotation() const;
  102. //! Returns the rotation around the Y axis in radians
  103. DLLEXPORT float getYRotation() const;
  104. //! Returns the rotation around the Z axis in radians
  105. DLLEXPORT float getZRotation() const;
  106. //! Returns the matrix that translates the drawing into world space
  107. DLLEXPORT const Mat4<float>& getMatrix() const;
  108. //! Calculates a point in world coordinates from a point in local
  109. //! drawing coordinates by applying rotation, scaling and translation
  110. DLLEXPORT Vec3<float> applyWorldTransformation(
  111. const Vec3<float>& modelPos) const;
  112. //! returns whether the object should be rendered because it was changed
  113. DLLEXPORT bool getLastTickReturn() const;
  114. };
  115. } // namespace Framework