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