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