Camera3D.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #pragma once
  2. #include "Drawing3D.h"
  3. #include "Mat4.h"
  4. #include "Point.h"
  5. //! DirectX 11 Types
  6. struct D3D11_VIEWPORT;
  7. namespace Framework
  8. {
  9. struct MouseEvent; //! MouseEvent.h
  10. class Render3D; //! Render3D.h
  11. class World3D; //! World3D.h
  12. struct ViewPort
  13. {
  14. float x;
  15. float y;
  16. float width;
  17. float height;
  18. float front;
  19. float back;
  20. };
  21. //! A 3D camera that draws a section of a 3D world into a specific
  22. //! area of the screen
  23. class Cam3D : public virtual Framework::ReferenceCounter
  24. {
  25. public:
  26. class Style
  27. {
  28. public:
  29. static const __int64 Movable = 0x1;
  30. static const __int64 Rotatable = 0x2;
  31. static const __int64 Zoomable = 0x4;
  32. static const __int64 Tick = 0x8;
  33. };
  34. protected:
  35. bool rend;
  36. private:
  37. Mat4<float> view;
  38. Mat4<float> proj;
  39. Mat4<float> inverseView;
  40. Mat4<float> inverseProj;
  41. float openingAngle;
  42. float minZ;
  43. float maxZ;
  44. Vec3<float> pos;
  45. float rotX;
  46. float rotY;
  47. float rotZ;
  48. ViewPort viewport;
  49. World3D* welt;
  50. __int64 style;
  51. float speed;
  52. //! Updates the view and projection matrices
  53. void updateMatrix();
  54. public:
  55. //! Constructor
  56. DLLEXPORT Cam3D();
  57. //! Destructor
  58. DLLEXPORT ~Cam3D();
  59. //! Sets the position of the camera in the 3D world
  60. DLLEXPORT void setPosition(Vec3<float> pos);
  61. //! Zooms in by moving the camera slightly towards the target
  62. //! \param val The distance the camera should move
  63. DLLEXPORT void scrollIn(float val);
  64. //! Zooms out by moving the camera slightly away from the target
  65. //! \param val The distance the camera should move
  66. DLLEXPORT void scrollOut(float val);
  67. //! Aligns the camera so that it points exactly at a specific point
  68. //! \param ziel The point the camera should point at
  69. DLLEXPORT void setViewDirection(Vec3<float> ziel);
  70. //! Sets the rotation of the camera around individual axes
  71. //! \param rotation The rotation around individual axes
  72. DLLEXPORT void setRotation(Vec3<float> rotation);
  73. //! Sets the position of the image on the screen
  74. //! \param p A point with x and y coordinates in pixels
  75. DLLEXPORT void setScreenPosition(Point p);
  76. //! Sets the position of the image on the screen
  77. //! \param x The x coordinate in pixels
  78. //! \param y The y coordinate in pixels
  79. DLLEXPORT void setScreenPosition(int x, int y);
  80. //! Sets the size of the image on the screen
  81. //! \param p A point with x as width and y as height in pixels
  82. DLLEXPORT void setScreenSize(Point p);
  83. //! Sets the size of the image on the screen
  84. //! \param br The width in pixels
  85. //! \param hi The height in pixels
  86. DLLEXPORT void setScreenSize(int br, int hi);
  87. //! Sets the world to be drawn
  88. //! \param w The world
  89. DLLEXPORT void setWorld(World3D* w);
  90. //! Sets the style of the camera
  91. //! \param style The new style consisting of flags from the
  92. //! associated Style class
  93. DLLEXPORT void setStyle(__int64 style);
  94. //! Sets the style of the camera
  95. //! \param style All style flags to be changed
  96. //! add_remove: 1 if the style should be added. 0 if the style
  97. //! should be removed
  98. DLLEXPORT void setStyle(__int64 style, bool add_remove);
  99. //! Adds style flags
  100. //! \param style The style to add
  101. DLLEXPORT void addStyle(__int64 style);
  102. //! Removes style flags
  103. //! \param style The style to remove
  104. DLLEXPORT void removeStyle(__int64 style);
  105. //! Set the movement speed per second if the camera has style Movable
  106. DLLEXPORT void setMovementSpeed(float speed);
  107. //! Processes elapsed time
  108. //! \param tickval The time in seconds since the last call of this
  109. //! function \return true if the image needs to be redrawn, false
  110. //! otherwise.
  111. DLLEXPORT virtual bool tick(double tv);
  112. //! Processes a mouse event
  113. //! \param me The mouse event to process
  114. DLLEXPORT virtual void doMouseEvent(MouseEvent& me);
  115. //! Processes a keyboard event
  116. //! \param te The keyboard event to process
  117. DLLEXPORT virtual void doKeyboardEvent(KeyboardEvent& te);
  118. //! Returns whether specific styles are set
  119. //! \param style The styles to check
  120. //! \return 1 if all styles in style are set
  121. DLLEXPORT bool hasStyle(__int64 style) const;
  122. //! Returns whether specific styles are not set
  123. //! \param style The styles to check
  124. //! \return 1 if all styles in style are not set
  125. DLLEXPORT bool hasStyleNot(__int64 style) const;
  126. //! Returns a pointer to the viewport
  127. DLLEXPORT const ViewPort* zViewPort() const;
  128. //! Returns the position of the camera in the world
  129. DLLEXPORT const Vec3<float>& getWorldPosition() const;
  130. //! Returns the position in the world
  131. //! \param screen The position on the screen to translate
  132. DLLEXPORT const Vec3<float> getWorldPosition(Point screen) const;
  133. //! Returns the direction of the camera in the world
  134. //! \param screen The position on the screen to translate
  135. DLLEXPORT const Vec3<float> getWorldDirection(Point screen) const;
  136. //! Returns the projection matrix of the camera
  137. DLLEXPORT const Mat4<float>& getProjectionMatrix() const;
  138. //! Returns the view matrix of the camera
  139. DLLEXPORT const Mat4<float>& getViewMatrix() const;
  140. //! Returns the inverse view matrix of the camera
  141. DLLEXPORT const Mat4<float>& getInverseViewMatrix() const;
  142. //! Returns the inverse projection matrix of the camera
  143. DLLEXPORT const Mat4<float>& getInverseProjectionMatrix() const;
  144. //! Returns the rotation around individual axes
  145. DLLEXPORT const Vec3<float> getRotation() const;
  146. //! Returns the position of the camera on the screen
  147. DLLEXPORT const Point getScreenPos() const;
  148. //! Returns the size of the camera on the screen
  149. DLLEXPORT const Point getScreenSize() const;
  150. //! Returns the world
  151. DLLEXPORT World3D* getWorld() const;
  152. //! Returns the world without increased reference counter
  153. DLLEXPORT World3D* zWorld() const;
  154. //! Sets the minimum distance of the camera to the target point
  155. DLLEXPORT void setMinDistance(float dist);
  156. //! Returns the minimum distance of the camera to the target point
  157. DLLEXPORT float getMinDistance() const;
  158. //! Sets the maximum distance of the camera to the target point
  159. DLLEXPORT void setMaxDistance(float dist);
  160. //! Returns the maximum distance of the camera to the target point
  161. DLLEXPORT float getMaxDistance() const;
  162. };
  163. } // namespace Framework