00001 00008 #include "SO3Camera.h" 00009 #include "../SO3SceneGraph/SO3Scene.h" 00010 #include "../SO3Renderer/SO3ViewPort.h" 00011 00012 namespace SO3 00013 { 00014 00015 SCamera::SCamera() : SNode(0, "", SNode::CAMERA_TYPE_ID) 00016 { 00017 // Forbiden (private). 00018 } 00019 00020 SCamera::SCamera(SScene* parent, std::string cameraName) : SNode(parent, cameraName, SNode::CAMERA_TYPE_ID) 00021 { 00022 O3Camera = currentScene->GetOgreScenePointer()->createCamera(cameraName); 00023 ogreMovableObject = O3Camera; 00024 00025 O3Camera->setAutoAspectRatio(true); 00026 00027 O3SceneNode->attachObject(O3Camera); 00028 O3Camera->_notifyManager(currentScene->GetOgreScenePointer()); 00029 currentViewport = 0; 00030 } 00031 00032 SCamera::~SCamera() 00033 { 00034 if (currentViewport != 0) 00035 currentViewport->SetCamera(0); 00036 00037 currentScene->GetOgreScenePointer()->destroyCamera(O3Camera); 00038 ogreMovableObject = 0; 00039 } 00040 00041 Ogre::Camera* SCamera::GetOgreCameraPointer() 00042 { 00043 return O3Camera; 00044 } 00045 00046 SViewPort* SCamera::getCurrentViewPort() 00047 { 00048 return currentViewport; 00049 } 00050 00051 void SCamera::SetCurrentViewPort(SViewPort* mViewPort) 00052 { 00053 currentViewport = mViewPort; 00054 } 00055 00056 void SCamera::SetAspectRatio(float ratio) 00057 { 00058 //$BB add autoAspectRatio on Scamera, disable it if we want a special aspectRatio 00059 O3Camera->setAutoAspectRatio(false); 00060 O3Camera->setAspectRatio(ratio); 00061 O3Camera->getViewport()->_updateDimensions(); 00062 } 00063 00064 bool SCamera::IsFacingPoint(Ogre::Vector3 point) 00065 { 00066 Ogre::Plane cameraPlane = Ogre::Plane(Ogre::Vector3(O3Camera->getDerivedOrientation().zAxis()), O3Camera->getDerivedPosition()); 00067 return (cameraPlane.getSide(point) != Ogre::Plane::NEGATIVE_SIDE); 00068 } 00069 00070 Ogre::Vector3& SCamera::ToScreenSpace(Ogre::Vector3& point) 00071 { 00072 point = O3Camera->getProjectionMatrix() * (O3Camera->getViewMatrix() * point); 00073 return point; 00074 } 00075 00076 void SCamera::SetRenderingDistance(float distance) 00077 { 00078 return O3Camera->setRenderingDistance(distance); 00079 } 00080 00081 float SCamera::GetRenderingDistance() 00082 { 00083 return O3Camera->getRenderingDistance(); 00084 } 00085 00086 Ogre::Vector3 SCamera::GetBoundingBoxSize(bool childs) 00087 { 00088 if (childs) 00089 return GetSonsBoundingBox(); 00090 00091 return O3Camera->getBoundingBox().getSize(); 00092 } 00093 00094 Ogre::Vector3 SCamera::GetBoundingBoxCenter(bool childs) 00095 { 00096 return O3Camera->getBoundingBox().getCenter(); 00097 } 00098 00099 void SCamera::SetNearClipDistance(float distance) 00100 { 00101 O3Camera->setNearClipDistance(distance); 00102 } 00103 00104 float SCamera::GetNearClipDistance() 00105 { 00106 return O3Camera->getNearClipDistance(); 00107 } 00108 00109 void SCamera::SetFarClipDistance(float distance) 00110 { 00111 O3Camera->setFarClipDistance(distance); 00112 } 00113 00114 float SCamera::GetFarClipDistance() 00115 { 00116 return O3Camera->getFarClipDistance(); 00117 } 00118 00119 const Ogre::Matrix4& SCamera::GetProjectionMatrix() 00120 { 00121 return O3Camera->getProjectionMatrix(); 00122 } 00123 00124 const Ogre::Matrix4& SCamera::GetViewMatrix() 00125 { 00126 return O3Camera->getViewMatrix(); 00127 } 00128 00129 }
1.6.3