SO3Engine
SO3Camera.cpp
Go to the documentation of this file.
1
12#include "SO3Renderer/SO3Root.h"
13
14namespace SO3
15{
16
17SCamera::SCamera() : SNode(0, "", SNode::CAMERA_TYPE_ID)
18{
19 // Forbiden (private).
20}
21
22SCamera::SCamera(SScene* parent, const std::string& cameraName) : SNode(parent, cameraName, SNode::CAMERA_TYPE_ID)
23{
24 // Create a new camera
25 O3Camera = currentScene->GetOgreScenePointer()->createCamera(cameraName);
26 O3Camera->setNearClipDistance(0.1f);
27 O3Camera->setFarClipDistance(1000.0f);
28
29 ogreMovableObject = O3Camera;
30 O3Camera->setAutoAspectRatio(true);
31 O3SceneNode->attachObject(O3Camera);
32 O3Camera->_notifyManager(currentScene->GetOgreScenePointer());
33 currentViewport = 0;
34
35 O3Camera->setUseMinPixelSize(true);
36}
37
39{
42
43 if (currentViewport != 0)
44 currentViewport->SetCamera(0);
45
46 currentScene->GetOgreScenePointer()->destroyCamera(O3Camera);
48}
49
51{
52 return O3Camera;
53}
54
56{
57 return currentViewport;
58}
59
61{
62 currentViewport = mViewPort;
63 if (mViewPort != 0)
64 {
65 O3Camera->_notifyViewport(mViewPort->GetOgreViewPortPointer());
66 SRoot::getSingletonPtr()->SetProgramCameraParameter(O3Camera->getFOVy().valueRadians(), O3Camera->getNearClipDistance(), O3Camera->getFarClipDistance(), O3Camera->getFocalLength());
67 }
68 else
69 O3Camera->_notifyViewport(0);
70}
71
72void SCamera::SetAspectRatio(const float& ratio)
73{
74 //$BB add autoAspectRatio on Scamera, disable it if we want a special aspectRatio
75 O3Camera->setAutoAspectRatio(false);
76 O3Camera->setAspectRatio(ratio);
77 if (O3Camera->getViewport())
78 O3Camera->getViewport()->_updateDimensions();
79
80 if (currentViewport != 0 && currentViewport->IsStereoViewportRegistered())
81 currentViewport->UpdateStereoCamera(O3Camera);
82}
83
85{
86 return O3Camera->getAspectRatio();
87}
88
90{
91 O3Camera->setAutoAspectRatio(state);
92 if (O3Camera->getViewport())
93 O3Camera->getViewport()->_updateDimensions();
94
95 if (currentViewport != 0 && currentViewport->IsStereoViewportRegistered())
96 currentViewport->UpdateStereoCamera(O3Camera);
97}
98
99void SCamera::SetFrustumOffset(const float& x, const float& y)
100{
101 O3Camera->setFrustumOffset(x, y);
102}
103
105{
106 return O3Camera->getFrustumOffset();
107}
108
109void SCamera::SetCustomProjectionMatrix(bool state, Ogre::Matrix4 projmat)
110{
111 O3Camera->setCustomProjectionMatrix(state, projmat);
112 if (currentViewport != 0 && currentViewport->IsStereoViewportRegistered())
113 currentViewport->UpdateStereoCameraMatrix(O3Camera);
114}
115
116bool SCamera::IsFacingPoint(const Ogre::Vector3& point)
117{
118 Ogre::Plane cameraPlane = Ogre::Plane(Ogre::Vector3(O3Camera->getDerivedOrientation().zAxis()), O3Camera->getDerivedPosition());
119 return (cameraPlane.getSide(point) != Ogre::Plane::NEGATIVE_SIDE);
120}
121
122Ogre::Vector3 SCamera::ToScreenSpace(const Ogre::Vector3& point)
123{
124 return O3Camera->getProjectionMatrix() * (O3Camera->getViewMatrix() * point);
125}
126
127void SCamera::SetRenderingDistance(const float& distance)
128{
129 return O3Camera->setRenderingDistance(distance);
130}
131
133{
134 return O3Camera->getRenderingDistance();
135}
136
137Ogre::Vector3 SCamera::GetBoundingBoxSize(const bool& childs)
138{
139 if (childs)
140 return GetSonsBoundingBox();
141
142 return O3Camera->getBoundingBox().getSize();
143}
144
145Ogre::Vector3 SCamera::GetBoundingBoxCenter(const bool& childs)
146{
147 return O3Camera->getBoundingBox().getCenter();
148}
149
150Ogre::Vector3 SCamera::GetWorldBoundingBoxSize(const bool& childs)
151{
152 if (childs)
153 return GetSonsBoundingBox();
154
155 return O3Camera->getWorldBoundingBox(true).getSize();
156}
157
158Ogre::Vector3 SCamera::GetWorldBoundingBoxCenter(const bool& childs)
159{
160 return O3Camera->getWorldBoundingBox(true).getCenter();
161}
162
163void SCamera::SetNearClipDistance(const float& distance)
164{
165 O3Camera->setNearClipDistance(std::max(0.001f, distance));
166
167 if (currentViewport != 0)
168 SRoot::getSingletonPtr()->SetProgramCameraParameter(O3Camera->getFOVy().valueRadians(), O3Camera->getNearClipDistance(), O3Camera->getFarClipDistance(), O3Camera->getFocalLength());
169
170 if (currentViewport != 0 && currentViewport->IsStereoViewportRegistered())
171 currentViewport->UpdateStereoCamera(O3Camera);
172}
173
175{
176 return O3Camera->getNearClipDistance();
177}
178
179void SCamera::SetFarClipDistance(const float& distance)
180{
181 if (distance <= 0.0f)
182 O3Camera->setFarClipDistance(10000.0f);
183 else
184 O3Camera->setFarClipDistance(std::max(0.002f, std::min(10000000.0f, distance)));
185
186 if (currentViewport != 0)
187 SRoot::getSingletonPtr()->SetProgramCameraParameter(O3Camera->getFOVy().valueRadians(), O3Camera->getNearClipDistance(), O3Camera->getFarClipDistance(), O3Camera->getFocalLength());
188
189 if (currentViewport != 0 && currentViewport->IsStereoViewportRegistered())
190 currentViewport->UpdateStereoCamera(O3Camera);
191}
192
194{
195 return O3Camera->getFarClipDistance();
196}
197
198const Ogre::Matrix4& SCamera::GetProjectionMatrix()
199{
200 return O3Camera->getProjectionMatrix();
201}
202
203const Ogre::Affine3& SCamera::GetViewMatrix()
204//const Ogre::Matrix4& SCamera::GetViewMatrix()
205{
206 return O3Camera->getViewMatrix();
207}
208
209const Ogre::Real SCamera::GetFocalLength()
210{
211 return O3Camera->getFocalLength();
212}
213
214void SCamera::SetFocalLength(const Ogre::Real& focalLength)
215{
216 if (focalLength > 0.0f)
217 {
218 O3Camera->setFocalLength(focalLength);
219
220 if (currentViewport != 0)
221 SRoot::getSingletonPtr()->SetProgramCameraParameter(O3Camera->getFOVy().valueRadians(), O3Camera->getNearClipDistance(), O3Camera->getFarClipDistance(), focalLength);
222 }
223
224 if (currentViewport != 0 && currentViewport->IsStereoViewportRegistered())
225 currentViewport->UpdateStereoCamera(O3Camera);
226}
227
229{
230 return O3Camera->getFOVy().valueRadians();
231}
232
233void SCamera::SetFOVy(const float& newFovY)
234{
235 Ogre::Radian fov(newFovY);
236 if (fov.valueDegrees() >= 180.0f)
237 fov = Ogre::Degree(179.0f);
238
239 O3Camera->setFOVy(fov);
240
241 if (currentViewport != 0)
242 SRoot::getSingletonPtr()->SetProgramCameraParameter(O3Camera->getFOVy().valueRadians(), O3Camera->getNearClipDistance(), O3Camera->getFarClipDistance(), O3Camera->getFocalLength());
243
244 if (currentViewport != 0 && currentViewport->IsStereoViewportRegistered())
245 currentViewport->UpdateStereoCamera(O3Camera);
246}
247
249{
250 return O3Camera->getLodBias();
251}
252
253void SCamera::SetLODbias(const float& bias)
254{
255 if (bias <= 0.0f)
256 return;
257
258 O3Camera->setLodBias(bias);
259 if (currentViewport != 0 && currentViewport->IsStereoViewportRegistered())
260 currentViewport->UpdateStereoCamera(O3Camera);
261}
262
263void SCamera::SetProjectionType(const Ogre::ProjectionType& type)
264{
265 O3Camera->setProjectionType(type);
266 if (currentViewport != 0 && currentViewport->IsStereoViewportRegistered())
267 currentViewport->UpdateStereoCamera(O3Camera);
268}
269
270Ogre::ProjectionType SCamera::GetProjectionType()
271{
272 return O3Camera->getProjectionType();
273}
274
276{
277 O3Camera->setOrthoWindowWidth(size.x);
278 O3Camera->setOrthoWindowHeight(size.y);
279}
280
282{
283 SPoint<float> size;
284 size.x = O3Camera->getOrthoWindowWidth();
285 size.y = O3Camera->getOrthoWindowHeight();
286
287 return size;
288}
289
291{
292 if (O3Camera)
293 return O3Camera->_getNumRenderedFaces();
294 else
295 return 0;
296}
297
299{
300 if (O3Camera)
301 return O3Camera->_getNumRenderedBatches();
302 else
303 return 0;
304}
305
306}
void SetCurrentViewPort(SViewPort *mViewPort)
Definition SO3Camera.cpp:60
float GetFOVy()
virtual float GetRenderingDistance()
Ogre::Vector2 GetFrustumOffset()
void SetAutoAspectRatio(bool state)
Definition SO3Camera.cpp:89
unsigned int GetNumRenderedBatches()
void SetFOVy(const float &newFovY)
void SetFocalLength(const Ogre::Real &focalLength)
float GetAspectRatio()
Definition SO3Camera.cpp:84
virtual Ogre::Vector3 GetWorldBoundingBoxSize(const bool &childs=false)
Ogre::Camera * GetOgreCameraPointer()
Definition SO3Camera.cpp:50
Ogre::ProjectionType GetProjectionType()
void SetNearClipDistance(const float &distance)
virtual Ogre::Vector3 GetBoundingBoxSize(const bool &childs=false)
float GetNearClipDistance()
void SetCustomProjectionMatrix(bool state, Ogre::Matrix4 projmat=Ogre::Matrix4::IDENTITY)
bool IsFacingPoint(const Ogre::Vector3 &point)
float GetLODbias()
void SetProjectionType(const Ogre::ProjectionType &type)
void SetAspectRatio(const float &ratio)
Definition SO3Camera.cpp:72
virtual void SetRenderingDistance(const float &distance)
unsigned int GetNumRenderedFaces()
virtual Ogre::Vector3 GetBoundingBoxCenter(const bool &childs=false)
Ogre::Vector3 ToScreenSpace(const Ogre::Vector3 &point)
SViewPort * getCurrentViewPort()
Definition SO3Camera.cpp:55
const Ogre::Matrix4 & GetProjectionMatrix()
SPoint< float > GetOrthoWindow()
void SetLODbias(const float &bias)
void SetOrthoWindow(const SPoint< float > &size)
virtual Ogre::Vector3 GetWorldBoundingBoxCenter(const bool &childs=false)
float GetFarClipDistance()
void SetFarClipDistance(const float &distance)
const Ogre::Real GetFocalLength()
void SetFrustumOffset(const float &x, const float &y)
Definition SO3Camera.cpp:99
const Ogre::Affine3 & GetViewMatrix()
void UnregisterCamera(Ogre::Camera *cam)
SScene * currentScene
Definition SO3NodeScol.h:68
Ogre::SceneNode * O3SceneNode
Definition SO3NodeScol.h:69
Ogre::MovableObject * ogreMovableObject
Definition SO3NodeScol.h:70
Ogre::Vector3 GetSonsBoundingBox()
NUMERIC_TYPE y
Definition SO3Point.h:40
NUMERIC_TYPE x
Definition SO3Point.h:39
void SetProgramCameraParameter(float fov, float znear, float zfar, float focalLength)
Definition SO3Root.cpp:2810
static SRoot * getSingletonPtr()
Definition SO3Root.cpp:111
SEnvironment * GetEnvironment() const
Ogre::SceneManager * GetOgreScenePointer()
Definition SO3Scene.cpp:449
bool IsStereoViewportRegistered()
void UpdateStereoCamera(Ogre::Camera *camera)
Ogre::Viewport * GetOgreViewPortPointer()
void UpdateStereoCameraMatrix(Ogre::Camera *camera)
void SetCamera(SCamera *camera)