Camera3D.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #pragma once
  2. #include "Mat4.h"
  3. #include "Point.h"
  4. #include "Drawing3D.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. float openingAngle;
  40. float minZ;
  41. float maxZ;
  42. Vec3<float> pos;
  43. float rotX;
  44. float rotY;
  45. float rotZ;
  46. ViewPort viewport;
  47. World3D* welt;
  48. __int64 style;
  49. float speed;
  50. //! Updates the view and projection matrices
  51. void updateMatrix();
  52. public:
  53. //! Constructor
  54. DLLEXPORT Cam3D();
  55. //! Destructor
  56. DLLEXPORT ~Cam3D();
  57. //! Sets the position of the camera in the 3D world
  58. DLLEXPORT void setPosition(Vec3<float> pos);
  59. //! Zooms in by moving the camera slightly towards the target
  60. //! \param val The distance the camera should move
  61. DLLEXPORT void scrollIn(float val);
  62. //! Zooms out by moving the camera slightly away from the target
  63. //! \param val The distance the camera should move
  64. DLLEXPORT void scrollOut(float val);
  65. //! Aligns the camera so that it points exactly at a specific point
  66. //! \param ziel The point the camera should point at
  67. DLLEXPORT void setAusrichtung(Vec3<float> ziel);
  68. //! Sets the rotation of the camera around individual axes
  69. //! \param rotation The rotation around individual axes
  70. DLLEXPORT void setRotation(Vec3<float> rotation);
  71. //! Sets the position of the image on the screen
  72. //! \param p A point with x and y coordinates in pixels
  73. DLLEXPORT void setScreenPosition(Punkt p);
  74. //! Sets the position of the image on the screen
  75. //! \param x The x coordinate in pixels
  76. //! \param y The y coordinate in pixels
  77. DLLEXPORT void setScreenPosition(int x, int y);
  78. //! Sets the size of the image on the screen
  79. //! \param p A point with x as width and y as height in pixels
  80. DLLEXPORT void setScreenSize(Punkt p);
  81. //! Sets the size of the image on the screen
  82. //! \param br The width in pixels
  83. //! \param hi The height in pixels
  84. DLLEXPORT void setScreenSize(int br, int hi);
  85. //! Sets the world to be drawn
  86. //! \param w The world
  87. DLLEXPORT void setWorld(World3D* w);
  88. //! Sets the style of the camera
  89. //! \param style The new style consisting of flags from the
  90. //! associated Style class
  91. DLLEXPORT void setStyle(__int64 style);
  92. //! Sets the style of the camera
  93. //! \param style All style flags to be changed
  94. //! add_remove: 1 if the style should be added. 0 if the style
  95. //! should be removed
  96. DLLEXPORT void setStyle(__int64 style, bool add_remove);
  97. //! Adds style flags
  98. //! \param style The style to add
  99. DLLEXPORT void addStyle(__int64 style);
  100. //! Removes style flags
  101. //! \param style The style to remove
  102. DLLEXPORT void removeStyle(__int64 style);
  103. //! Set the movement speed per second if the camera has style Movable
  104. DLLEXPORT void setMovementSpeed(float speed);
  105. //! Processes elapsed time
  106. //! \param tickval The time in seconds since the last call of this
  107. //! function \return true if the image needs to be redrawn, false otherwise.
  108. DLLEXPORT virtual bool tick(double tv);
  109. //! Processes a mouse event
  110. //! \param me The mouse event to process
  111. DLLEXPORT virtual void doMouseEvent(MouseEvent& me);
  112. //! Processes a keyboard event
  113. //! \param te The keyboard event to process
  114. DLLEXPORT virtual void doKeyboardEvent(KeyboardEvent& te);
  115. //! Returns whether specific styles are set
  116. //! \param style The styles to check
  117. //! \return 1 if all styles in style are set
  118. DLLEXPORT bool hatStyle(__int64 style) const;
  119. //! Returns whether specific styles are not set
  120. //! \param style The styles to check
  121. //! \return 1 if all styles in style are not set
  122. DLLEXPORT bool hatStyleNicht(__int64 style) const;
  123. //! Returns a pointer to the viewport
  124. DLLEXPORT const ViewPort* zViewPort() const;
  125. //! Returns the position of the camera in the world
  126. DLLEXPORT const Vec3<float>& getWorldPosition() const;
  127. //! Returns the position in the world
  128. //! \param screen The position on the screen to translate
  129. DLLEXPORT const Vec3<float> getWorldPosition(Punkt screen) const;
  130. //! Returns the direction of the camera in the world
  131. //! \param screen The position on the screen to translate
  132. DLLEXPORT const Vec3<float> getWorldDirection(Punkt screen) const;
  133. //! Returns the projection matrix of the camera
  134. DLLEXPORT const Mat4<float>& getProjectionMatrix() const;
  135. //! Returns the view matrix of the camera
  136. DLLEXPORT const Mat4<float>& getViewMatrix() const;
  137. //! Returns the rotation around individual axes
  138. DLLEXPORT const Vec3<float> getRotation() const;
  139. //! Returns the position of the camera on the screen
  140. DLLEXPORT const Punkt getScreenPos() const;
  141. //! Returns the size of the camera on the screen
  142. DLLEXPORT const Punkt getScreenSize() const;
  143. //! Returns the world
  144. DLLEXPORT World3D* getWorld() const;
  145. //! Returns the world without increased reference counter
  146. DLLEXPORT World3D* zWorld() const;
  147. };
  148. } // namespace Framework