00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "CameraComponent.h"
00018 #include "../../core/GameManager.h"
00019
00020
00021
00022
00023 CameraComponent::CameraComponent(Entity *parent, const vector3df &lookat)
00024 : SceneComponent(parent, true)
00025 {
00026 if(pParent != NULL)
00027 {
00028
00029 ISceneManager *pSceneMgr = GameManager::Instance()->getSceneManager();
00030
00031
00032 mCameraSN = pSceneMgr->addCameraSceneNode(0, parent->getAbsolutePosition(), lookat,
00033 parent->getID());
00034 mSceneNode = mCameraSN;
00035
00036 mCameraAnimator = NULL;
00037
00038
00039 mTriSelector = NULL;
00040 mMetaSelector = pSceneMgr->createMetaTriangleSelector();
00041 }
00042 }
00043
00044
00045 CameraComponent::~CameraComponent()
00046 {
00047 if(pParent != NULL)
00048 {
00049 mCameraSN->remove();
00050 mSceneNode = NULL;
00051 }
00052 }
00053
00054
00055 ICameraSceneNode* CameraComponent::getCameraSceneNode()
00056 {
00057 return mCameraSN;
00058 }
00059
00060
00061 void CameraComponent::bindTargetAndRotation(bool bound)
00062 {
00063 mCameraSN->bindTargetAndRotation(bound);
00064 }
00065
00066
00067 bool CameraComponent::getTargetAndRotationBinding() const
00068 {
00069 return mCameraSN->getTargetAndRotationBinding();
00070 }
00071
00072
00073 f32 CameraComponent::getAspectRatio() const
00074 {
00075 return mCameraSN->getAspectRatio();
00076 }
00077
00078
00079 f32 CameraComponent::getFarValue() const
00080 {
00081 return mCameraSN->getFarValue();
00082 }
00083
00084
00085 f32 CameraComponent::getFOV() const
00086 {
00087 return mCameraSN->getFOV();
00088 }
00089
00090
00091 f32 CameraComponent::getNearValue() const
00092 {
00093 return mCameraSN->getNearValue();
00094 }
00095
00096
00097 const matrix4& CameraComponent::getProjectionMatrix() const
00098 {
00099 return mCameraSN->getProjectionMatrix();
00100 }
00101
00102
00103 const vector3df& CameraComponent::getTarget() const
00104 {
00105 return mCameraSN->getTarget();
00106 }
00107
00108
00109 const vector3df& CameraComponent::getUpVector() const
00110 {
00111 return mCameraSN->getUpVector();
00112 }
00113
00114
00115 const matrix4& CameraComponent::getViewMatrix() const
00116 {
00117 return mCameraSN->getViewMatrix();
00118 }
00119
00120
00121 bool CameraComponent::getIsOrthogonal() const
00122 {
00123 return mCameraSN->isOrthogonal();
00124 }
00125
00126
00127 void CameraComponent::setAsMainCamera()
00128 {
00129 GameManager::Instance()->getSceneManager()->setActiveCamera(mCameraSN);
00130 }
00131
00132
00133 void CameraComponent::setAspectRatio(f32 aspect)
00134 {
00135 mCameraSN->setAspectRatio(aspect);
00136 }
00137
00138
00139 void CameraComponent::setFarValue(f32 value)
00140 {
00141 mCameraSN->setFarValue(value);
00142 }
00143
00144
00145 void CameraComponent::setFOV(f32 value)
00146 {
00147 mCameraSN->setFOV(value);
00148 }
00149
00150
00151 void CameraComponent::setNearValue(f32 value)
00152 {
00153 mCameraSN->setNearValue(value);
00154 }
00155
00156
00157 void CameraComponent::setProjectionMatrix(const matrix4 &projection, bool isOrthogonal)
00158 {
00159 mCameraSN->setProjectionMatrix(projection, isOrthogonal);
00160 }
00161
00162
00163 void CameraComponent::setRotation(const vector3df &rotation)
00164 {
00165 mCameraSN->setRotation(pParent->getAbsoluteRotation() + rotation);
00166 }
00167
00168
00169 void CameraComponent::setTarget(const vector3df &position)
00170 {
00171 mCameraSN->setTarget(position);
00172 }
00173
00174
00175 void CameraComponent::setUpVector(const vector3df &position)
00176 {
00177 mCameraSN->setUpVector(position);
00178 }
00179
00180
00181 void CameraComponent::setNormalMode()
00182 {
00183 if(mCameraAnimator)
00184 mCameraSN->removeAnimator(mCameraAnimator);
00185 }
00186
00187
00188 void CameraComponent::setFPSMode(f32 rotateSpeed, f32 moveSpeed, bool verticalMovement,
00189 f32 jumpSpeed)
00190 {
00191
00192 if(mCameraAnimator)
00193 mCameraSN->removeAnimator(mCameraAnimator);
00194
00195
00196 ISceneNodeAnimatorCameraFPS *animFPS = (ISceneNodeAnimatorCameraFPS*)GameManager::Instance()->
00197 getSceneManager()->getDefaultSceneNodeAnimatorFactory()->
00198 createSceneNodeAnimator("cameraFPS", mCameraSN);
00199
00200 animFPS->setRotateSpeed(rotateSpeed);
00201 animFPS->setMoveSpeed(moveSpeed);
00202 animFPS->setVerticalMovement(verticalMovement);
00203 animFPS->drop();
00204
00205 mCameraAnimator = animFPS;
00206 }
00207
00208
00209 void CameraComponent::setMayaMode(f32 rotateSpeed, f32 zoomSpeed, f32 translationSpeed)
00210 {
00211
00212 if(mCameraAnimator)
00213 mCameraSN->removeAnimator(mCameraAnimator);
00214
00215
00216 ISceneNodeAnimatorCameraMaya *animMaya = (ISceneNodeAnimatorCameraMaya*)GameManager::Instance()->
00217 getSceneManager()->getDefaultSceneNodeAnimatorFactory()->
00218 createSceneNodeAnimator("cameraMaya", mCameraSN);
00219
00220 animMaya->setRotateSpeed(rotateSpeed);
00221 animMaya->setMoveSpeed(translationSpeed);
00222 animMaya->setZoomSpeed(zoomSpeed);
00223 animMaya->drop();
00224
00225 mCameraAnimator = animMaya;
00226 }
00227
00228
00229 bool CameraComponent::parseXML(IXMLReader *file, Entity *entity)
00230 {
00231
00232 CameraComponent *component = NULL;
00233
00234
00235 if(file->getNodeType() == io::EXN_ELEMENT)
00236 {
00237 if(stringw("CameraComponent") == file->getNodeName())
00238 {
00239
00240 component = new CameraComponent(entity);
00241 }
00242 }
00243
00244 if(component == NULL)
00245 return false;
00246
00247
00248 while(file->read())
00249 {
00250 switch(file->getNodeType())
00251 {
00252 case io::EXN_ELEMENT:
00253
00254
00255 if(stringw("asMainCamera") == file->getNodeName())
00256 component->setAsMainCamera();
00257
00258
00259 else if(stringw("aspectRatio") == file->getNodeName())
00260 component->setAspectRatio(file->getAttributeValueAsFloat(L"value"));
00261
00262
00263 else if(stringw("farValue") == file->getNodeName())
00264 component->setFarValue(file->getAttributeValueAsFloat(L"value"));
00265
00266
00267 else if(stringw("FOV") == file->getNodeName())
00268 component->setFOV(file->getAttributeValueAsFloat(L"value"));
00269
00270
00271 else if(stringw("nearValue") == file->getNodeName())
00272 component->setNearValue(file->getAttributeValueAsFloat(L"value"));
00273
00274
00275 else if(stringw("target") == file->getNodeName())
00276 {
00277 component->setTarget( vector3df(file->getAttributeValueAsFloat(L"x"),
00278 file->getAttributeValueAsFloat(L"y"),
00279 file->getAttributeValueAsFloat(L"z") ) );
00280 }
00281
00282
00283 else if(stringw("upVector") == file->getNodeName())
00284 {
00285 component->setUpVector( vector3df(file->getAttributeValueAsFloat(L"x"),
00286 file->getAttributeValueAsFloat(L"y"),
00287 file->getAttributeValueAsFloat(L"z") ) );
00288 }
00289
00290
00291 else if(stringw("FPSMode") == file->getNodeName())
00292 {
00293 component->setFPSMode( file->getAttributeValueAsFloat(L"rotateSpeed"),
00294 file->getAttributeValueAsFloat(L"moveSpeed"),
00295 ( stringc(file->getAttributeValue(L"verticalMovement")) == "true" )
00296 ? true : false,
00297 file->getAttributeValueAsFloat(L"jumpSpeed"));
00298 }
00299
00300
00301 else if(stringw("MayaMode") == file->getNodeName())
00302 {
00303 component->setMayaMode( file->getAttributeValueAsFloat(L"rotateSpeed"),
00304 file->getAttributeValueAsFloat(L"zoomSpeed"),
00305 file->getAttributeValueAsFloat(L"translationSpeed") );
00306 }
00307
00308
00309 else SceneComponent::parseBaseXML(file, component);
00310
00311 break;
00312
00313 case io::EXN_ELEMENT_END:
00314
00315
00316 if(stringw("CameraComponent") == file->getNodeName())
00317 return true;
00318
00319 break;
00320
00321 default:
00322
00323 break;
00324 }
00325
00326 }
00327
00328
00329 return false;
00330 }
00331
00332