1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
3 | #pragma once |
4 | |
5 | #include "BsCorePrerequisites.h" |
6 | #include "Renderer/BsCamera.h" |
7 | #include "Scene/BsComponent.h" |
8 | |
9 | namespace bs |
10 | { |
11 | /** @addtogroup Components-Core |
12 | * @{ |
13 | */ |
14 | |
15 | /** |
16 | * @copydoc Camera |
17 | * |
18 | * Wraps a Camera as a Component. |
19 | */ |
20 | class BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:Rendering,n:Camera) CCamera : public Component |
21 | { |
22 | public: |
23 | CCamera(const HSceneObject& parent); |
24 | virtual ~CCamera() = default; |
25 | |
26 | /** @copydoc Camera::getViewport */ |
27 | BS_SCRIPT_EXPORT(n:Viewport,pr:getter) |
28 | SPtr<Viewport> getViewport() const { return mInternal->getViewport(); } |
29 | |
30 | /** @copydoc Camera::setHorzFOV */ |
31 | BS_SCRIPT_EXPORT(n:FieldOfView,pr:setter,range:[1,360],slider,order:-1) |
32 | virtual void setHorzFOV(const Radian& fovy) { mInternal->setHorzFOV(fovy); } |
33 | |
34 | /** @copydoc Camera::getHorzFOV */ |
35 | BS_SCRIPT_EXPORT(n:FieldOfView,pr:getter,range:[1,360],slider,order:-1) |
36 | virtual const Radian& getHorzFOV() const { return mInternal->getHorzFOV(); } |
37 | |
38 | /** @copydoc Camera::setNearClipDistance */ |
39 | BS_SCRIPT_EXPORT(n:NearClipPlane,pr:setter) |
40 | virtual void setNearClipDistance(float nearDist) { mInternal->setNearClipDistance(nearDist); } |
41 | |
42 | /** @copydoc Camera::getNearClipDistance */ |
43 | BS_SCRIPT_EXPORT(n:NearClipPlane,pr:getter) |
44 | virtual float getNearClipDistance() const { return mInternal->getNearClipDistance(); } |
45 | |
46 | /** @copydoc Camera::setFarClipDistance */ |
47 | BS_SCRIPT_EXPORT(n:FarClipPlane,pr:setter) |
48 | virtual void setFarClipDistance(float farDist) { mInternal->setFarClipDistance(farDist); } |
49 | |
50 | /** @copydoc Camera::getFarClipDistance */ |
51 | BS_SCRIPT_EXPORT(n:FarClipPlane,pr:getter) |
52 | virtual float getFarClipDistance() const { return mInternal->getFarClipDistance(); } |
53 | |
54 | /** @copydoc Camera::setAspectRatio */ |
55 | BS_SCRIPT_EXPORT(n:AspectRatio,pr:setter) |
56 | virtual void setAspectRatio(float ratio) { mInternal->setAspectRatio(ratio); } |
57 | |
58 | /** @copydoc Camera::getAspectRatio */ |
59 | BS_SCRIPT_EXPORT(n:AspectRatio,pr:getter) |
60 | virtual float getAspectRatio() const { return mInternal->getAspectRatio(); } |
61 | |
62 | /** @copydoc Camera::setFrustumExtents */ |
63 | virtual void setFrustumExtents(float left, float right, float top, float bottom) |
64 | { |
65 | mInternal->setFrustumExtents(left, right, top, bottom); |
66 | } |
67 | |
68 | /** @copydoc Camera::resetFrustumExtents */ |
69 | virtual void resetFrustumExtents() { mInternal->resetFrustumExtents(); } |
70 | |
71 | /** @copydoc Camera::getFrustumExtents */ |
72 | virtual void getFrustumExtents(float& outleft, float& outright, float& outtop, float& outbottom) const |
73 | { |
74 | mInternal->getFrustumExtents(outleft, outright, outtop, outbottom); |
75 | } |
76 | |
77 | /** @copydoc Camera::getProjectionMatrixRS */ |
78 | BS_SCRIPT_EXPORT(n:ProjMatrix,pr:getter) |
79 | virtual const Matrix4& getProjectionMatrixRS() const { return mInternal->getProjectionMatrixRS(); } |
80 | |
81 | /** @copydoc Camera::getProjectionMatrix */ |
82 | virtual const Matrix4& getProjectionMatrix() const { return mInternal->getProjectionMatrix(); } |
83 | |
84 | /** @copydoc Camera::getViewMatrix */ |
85 | BS_SCRIPT_EXPORT(n:ViewMatrix,pr:getter) |
86 | virtual const Matrix4& getViewMatrix() const { updateView(); return mInternal->getViewMatrix(); } |
87 | |
88 | /** @copydoc Camera::setCustomViewMatrix */ |
89 | virtual void setCustomViewMatrix(bool enable, const Matrix4& viewMatrix = Matrix4::IDENTITY) |
90 | { |
91 | mInternal->setCustomViewMatrix(enable, viewMatrix); |
92 | } |
93 | |
94 | /** @copydoc Camera::isCustomViewMatrixEnabled */ |
95 | virtual bool isCustomViewMatrixEnabled() const { return mInternal->isCustomViewMatrixEnabled(); } |
96 | |
97 | /** @copydoc Camera::setCustomProjectionMatrix */ |
98 | virtual void setCustomProjectionMatrix(bool enable, const Matrix4& projectionMatrix = Matrix4::IDENTITY) |
99 | { |
100 | mInternal->setCustomProjectionMatrix(enable, projectionMatrix); |
101 | } |
102 | |
103 | /** @copydoc Camera::isCustomProjectionMatrixEnabled */ |
104 | virtual bool isCustomProjectionMatrixEnabled() const { return mInternal->isCustomProjectionMatrixEnabled(); } |
105 | |
106 | /** @copydoc Camera::getFrustum */ |
107 | virtual const ConvexVolume& getFrustum() const { return mInternal->getFrustum(); } |
108 | |
109 | /** @copydoc Camera::getWorldFrustum */ |
110 | virtual ConvexVolume getWorldFrustum() const; |
111 | |
112 | /** @copydoc Camera::getBoundingBox */ |
113 | const AABox& getBoundingBox() const { return mInternal->getBoundingBox(); } |
114 | |
115 | /** @copydoc Camera::setProjectionType */ |
116 | BS_SCRIPT_EXPORT(n:ProjectionType,pr:setter,order:-2) |
117 | virtual void setProjectionType(ProjectionType pt) { mInternal->setProjectionType(pt); } |
118 | |
119 | /** @copydoc Camera::getProjectionType */ |
120 | BS_SCRIPT_EXPORT(n:ProjectionType,pr:getter,order:-2) |
121 | virtual ProjectionType getProjectionType() const { return mInternal->getProjectionType(); } |
122 | |
123 | /** @copydoc Camera::setOrthoWindow */ |
124 | virtual void setOrthoWindow(float w, float h) { mInternal->setOrthoWindow(w, h); } |
125 | |
126 | /** @copydoc Camera::setOrthoWindowHeight */ |
127 | BS_SCRIPT_EXPORT(n:OrthoHeight,pr:setter,order:-1) |
128 | virtual void setOrthoWindowHeight(float h) { mInternal->setOrthoWindowHeight(h); } |
129 | |
130 | /** @copydoc Camera::getOrthoWindowHeight */ |
131 | BS_SCRIPT_EXPORT(n:OrthoHeight,pr:getter,order:-1) |
132 | virtual float getOrthoWindowHeight() const { return mInternal->getOrthoWindowHeight(); } |
133 | |
134 | /** @copydoc Camera::setOrthoWindowWidth */ |
135 | BS_SCRIPT_EXPORT(n:OrthoWidth,pr:setter,hide) |
136 | virtual void setOrthoWindowWidth(float w) { mInternal->setOrthoWindowWidth(w); } |
137 | |
138 | /** @copydoc Camera::getOrthoWindowWidth */ |
139 | BS_SCRIPT_EXPORT(n:OrthoWidth,pr:getter,hide) |
140 | virtual float getOrthoWindowWidth() const { return mInternal->getOrthoWindowWidth(); } |
141 | |
142 | /** @copydoc Camera::setPriority */ |
143 | BS_SCRIPT_EXPORT(n:Priority,pr:setter) |
144 | void setPriority(INT32 priority) { mInternal->setPriority(priority); } |
145 | |
146 | /** @copydoc Camera::getPriority */ |
147 | BS_SCRIPT_EXPORT(n:Priority,pr:getter) |
148 | INT32 getPriority() const { return mInternal->getPriority(); } |
149 | |
150 | /** @copydoc Camera::setLayers */ |
151 | BS_SCRIPT_EXPORT(n:Layers,pr:setter,layerMask) |
152 | void setLayers(UINT64 layers) { mInternal->setLayers(layers); } |
153 | |
154 | /** @copydoc Camera::getLayers */ |
155 | BS_SCRIPT_EXPORT(n:Layers,pr:getter,layerMask) |
156 | UINT64 getLayers() const { return mInternal->getLayers(); } |
157 | |
158 | /** @copydoc Camera::setMSAACount */ |
159 | BS_SCRIPT_EXPORT(n:SampleCount,pr:setter) |
160 | void setMSAACount(UINT32 count) { mInternal->setMSAACount(count); } |
161 | |
162 | /** @copydoc Camera::getMSAACount */ |
163 | BS_SCRIPT_EXPORT(n:SampleCount,pr:getter) |
164 | UINT32 getMSAACount() const { return mInternal->getMSAACount(); } |
165 | |
166 | /** @copydoc Camera::setRenderSettings() */ |
167 | BS_SCRIPT_EXPORT(n:RenderSettings,pr:setter,applyOnDirty) |
168 | void setRenderSettings(const SPtr<RenderSettings>& settings) { mInternal->setRenderSettings(settings); } |
169 | |
170 | /** @copydoc Camera::getRenderSettings() */ |
171 | BS_SCRIPT_EXPORT(n:RenderSettings,pr:getter,applyOnDirty) |
172 | const SPtr<RenderSettings>& getRenderSettings() const { return mInternal->getRenderSettings(); } |
173 | |
174 | /** @copydoc Camera::worldToScreenPoint */ |
175 | BS_SCRIPT_EXPORT() |
176 | Vector2I worldToScreenPoint(const Vector3& worldPoint) const { updateView(); return mInternal->worldToScreenPoint(worldPoint); } |
177 | |
178 | /** @copydoc Camera::worldToNdcPoint */ |
179 | BS_SCRIPT_EXPORT() |
180 | Vector2 worldToNdcPoint(const Vector3& worldPoint) const { updateView(); return mInternal->worldToNdcPoint(worldPoint); } |
181 | |
182 | /** @copydoc Camera::worldToViewPoint */ |
183 | BS_SCRIPT_EXPORT() |
184 | Vector3 worldToViewPoint(const Vector3& worldPoint) const { updateView(); return mInternal->worldToViewPoint(worldPoint); } |
185 | |
186 | /** @copydoc Camera::screenToWorldPoint */ |
187 | BS_SCRIPT_EXPORT() |
188 | Vector3 screenToWorldPoint(const Vector2I& screenPoint, float depth = 0.5f) const { updateView(); return mInternal->screenToWorldPoint(screenPoint, depth); } |
189 | |
190 | /** @copydoc Camera::screenToViewPoint */ |
191 | BS_SCRIPT_EXPORT() |
192 | Vector3 screenToViewPoint(const Vector2I& screenPoint, float depth = 0.5f) const { return mInternal->screenToViewPoint(screenPoint, depth); } |
193 | |
194 | /** @copydoc Camera::screenToNdcPoint */ |
195 | BS_SCRIPT_EXPORT() |
196 | Vector2 screenToNdcPoint(const Vector2I& screenPoint) const { return mInternal->screenToNdcPoint(screenPoint); } |
197 | |
198 | /** @copydoc Camera::viewToWorldPoint */ |
199 | BS_SCRIPT_EXPORT() |
200 | Vector3 viewToWorldPoint(const Vector3& viewPoint) const { updateView(); return mInternal->viewToWorldPoint(viewPoint); } |
201 | |
202 | /** @copydoc Camera::viewToScreenPoint */ |
203 | BS_SCRIPT_EXPORT() |
204 | Vector2I viewToScreenPoint(const Vector3& viewPoint) const { return mInternal->viewToScreenPoint(viewPoint); } |
205 | |
206 | /** @copydoc Camera::viewToNdcPoint */ |
207 | BS_SCRIPT_EXPORT() |
208 | Vector2 viewToNdcPoint(const Vector3& viewPoint) const { return mInternal->viewToNdcPoint(viewPoint); } |
209 | |
210 | /** @copydoc Camera::ndcToWorldPoint */ |
211 | BS_SCRIPT_EXPORT() |
212 | Vector3 ndcToWorldPoint(const Vector2& ndcPoint, float depth = 0.5f) const { updateView(); return mInternal->ndcToWorldPoint(ndcPoint, depth); } |
213 | |
214 | /** @copydoc Camera::ndcToViewPoint */ |
215 | BS_SCRIPT_EXPORT() |
216 | Vector3 ndcToViewPoint(const Vector2& ndcPoint, float depth = 0.5f) const { return mInternal->ndcToViewPoint(ndcPoint, depth); } |
217 | |
218 | /** @copydoc Camera::ndcToScreenPoint */ |
219 | BS_SCRIPT_EXPORT() |
220 | Vector2I ndcToScreenPoint(const Vector2& ndcPoint) const { return mInternal->ndcToScreenPoint(ndcPoint); } |
221 | |
222 | /** @copydoc Camera::screenPointToRay */ |
223 | BS_SCRIPT_EXPORT() |
224 | Ray screenPointToRay(const Vector2I& screenPoint) const { updateView(); return mInternal->screenPointToRay(screenPoint); } |
225 | |
226 | /** @copydoc Camera::projectPoint */ |
227 | BS_SCRIPT_EXPORT() |
228 | Vector3 projectPoint(const Vector3& point) const { return mInternal->projectPoint(point); } |
229 | |
230 | /** @copydoc Camera::unprojectPoint */ |
231 | BS_SCRIPT_EXPORT() |
232 | Vector3 unprojectPoint(const Vector3& point) const { return mInternal->unprojectPoint(point); } |
233 | |
234 | /** @copydoc Camera::setMain */ |
235 | BS_SCRIPT_EXPORT(n:Main,pr:setter) |
236 | void setMain(bool main); |
237 | |
238 | /** @copydoc Camera::isMain */ |
239 | BS_SCRIPT_EXPORT(n:Main,pr:getter) |
240 | bool isMain() const { return mInternal->isMain(); } |
241 | |
242 | /** @name Internal |
243 | * @{ |
244 | */ |
245 | |
246 | /** Returns the internal camera that is used for majority of operations by this component. */ |
247 | SPtr<Camera> _getCamera() const { updateView(); return mInternal; } |
248 | |
249 | /** @} */ |
250 | |
251 | protected: |
252 | /** Checks if the world transform of the camera changed, and if needed updates the view matrix. */ |
253 | void updateView() const; |
254 | |
255 | mutable SPtr<Camera> mInternal; |
256 | |
257 | /************************************************************************/ |
258 | /* COMPONENT OVERRIDES */ |
259 | /************************************************************************/ |
260 | protected: |
261 | friend class SceneObject; |
262 | |
263 | /** @copydoc Component::_instantiate */ |
264 | void _instantiate() override; |
265 | |
266 | /** @copydoc Component::onInitialized */ |
267 | void onInitialized() override; |
268 | |
269 | /** @copydoc Component::onDestroyed */ |
270 | void onDestroyed() override; |
271 | |
272 | /************************************************************************/ |
273 | /* RTTI */ |
274 | /************************************************************************/ |
275 | public: |
276 | friend class CCameraRTTI; |
277 | static RTTITypeBase* getRTTIStatic(); |
278 | RTTITypeBase* getRTTI() const override; |
279 | |
280 | protected: |
281 | CCamera();// Serialization only |
282 | }; |
283 | |
284 | /** @} */ |
285 | } |