00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef CAMERA_H_
00026 #define CAMERA_H_
00027
00028 #include <Graphics/Scene/SceneObject.h>
00029 #include <Graphics/Renderer/Clipping.h>
00030
00031 namespace Lamp{
00032
00033
00034
00035
00036
00037 class Camera : public SceneObject{
00038 friend class SceneObjectManagerTemplate<Camera>;
00039 friend class CameraManager;
00040 public:
00041
00042
00043
00044
00045 virtual int getReferenceCount() const{ return 0; }
00046
00047
00048
00049
00050
00051 virtual Camera* copy() const;
00052
00053
00054
00055
00056
00057
00058
00059
00060 virtual const Matrix44& getProjectionMatrix(){ return projectionMatrix_; }
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 virtual void setPerspectiveOffCenter(
00073 float left, float right, float bottom, float top,
00074 float nearClip, float farClip){
00075 left_ = left;
00076 right_ = right;
00077 bottom_ = bottom;
00078 top_ = top;
00079 nearClip_ = nearClip;
00080 farClip_ = farClip;
00081 isPerspective_ = true;
00082 buildPerspectiveMatrix();
00083 }
00084
00085
00086
00087
00088
00089
00090
00091
00092 virtual void setPerspective(
00093 float width, float height, float nearClip, float farClip){
00094 left_ = -width * 0.5f;
00095 right_ = -left_;
00096 bottom_ = -height * 0.5f;
00097 top_ = -bottom_;
00098 nearClip_ = nearClip;
00099 farClip_ = farClip;
00100 isPerspective_ = true;
00101 buildPerspectiveMatrix();
00102 }
00103
00104
00105
00106
00107
00108
00109
00110
00111 virtual void setPerspectiveFovY(
00112 float fovY, float aspect, float nearClip, float farClip){
00113 bottom_ = -nearClip / (1.f / Math::tan(fovY * 0.5f));
00114 top_ = -bottom_;
00115 left_ = bottom_ * aspect;
00116 right_ = -left_;
00117 nearClip_ = nearClip;
00118 farClip_ = farClip;
00119 isPerspective_ = true;
00120 buildPerspectiveMatrix();
00121 }
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 virtual void setOrthoOffCenter(
00133 float left, float right, float bottom, float top,
00134 float nearClip, float farClip){
00135 left_ = left;
00136 right_ = right;
00137 bottom_ = bottom;
00138 top_ = top;
00139 nearClip_ = nearClip;
00140 farClip_ = farClip;
00141 isPerspective_ = false;
00142 buildPerspectiveMatrix();
00143 }
00144
00145
00146
00147
00148
00149
00150
00151
00152 virtual void setOrtho(
00153 float width, float height, float nearClip, float farClip){
00154 left_ = -width * 0.5f;
00155 right_ = -left_;
00156 bottom_ = -height * 0.5f;
00157 top_ = -bottom_;
00158 nearClip_ = nearClip;
00159 farClip_ = farClip;
00160 isPerspective_ = false;
00161 buildPerspectiveMatrix();
00162 }
00163
00164
00165
00166
00167
00168
00169 virtual float getLeft(){ return left_; }
00170
00171
00172
00173
00174
00175 virtual float getRight(){ return right_; }
00176
00177
00178
00179
00180
00181 virtual float getBottom(){ return bottom_; }
00182
00183
00184
00185
00186
00187 virtual float getTop(){ return top_; }
00188
00189
00190
00191
00192
00193
00194 virtual float getNearClip(){ return nearClip_; }
00195
00196
00197
00198
00199
00200 virtual void setNearClip(float nearClip){
00201 if(isPerspective_){
00202 setPerspectiveOffCenter(getLeft(), getRight(),
00203 getBottom(), getTop(), nearClip, getFarClip());
00204 }else{
00205 setOrthoOffCenter(getLeft(), getRight(),
00206 getBottom(), getTop(), nearClip, getFarClip());
00207 }
00208 }
00209
00210
00211
00212
00213
00214
00215 virtual float getFarClip(){ return farClip_; }
00216
00217
00218
00219
00220
00221 virtual void setFarClip(float farClip){
00222 if(isPerspective_){
00223 setPerspectiveOffCenter(getLeft(), getRight(),
00224 getBottom(), getTop(), getNearClip(), farClip);
00225 }else{
00226 setOrthoOffCenter(getLeft(), getRight(),
00227 getBottom(), getTop(), getNearClip(), farClip);
00228 }
00229 }
00230
00231
00232
00233
00234
00235
00236 virtual bool isPerspective(){ return isPerspective_; }
00237
00238
00239
00240
00241
00242
00243 virtual float getWidth(){ return right_ - left_; }
00244
00245
00246
00247
00248
00249 virtual float getHeight(){ return top_ - bottom_; }
00250
00251
00252
00253
00254
00255
00256 virtual float getFovY(){
00257 if(!isPerspective_){ return 0.f; }
00258 return 2.f * Math::atan(1.f / (2.f * nearClip_ / (top_ - bottom_)));
00259 }
00260
00261
00262
00263
00264
00265 virtual void setFovY(float fovY){
00266
00267 Assert(isPerspective_);
00268 setPerspectiveFovY(fovY, getAspect(), getNearClip(), getFarClip());
00269 }
00270
00271
00272
00273
00274
00275
00276 virtual float getAspect(){ return (right_ - left_) / (top_ - bottom_); }
00277
00278
00279
00280
00281
00282 virtual void setAspect(float aspect){
00283
00284 Assert(isPerspective_);
00285 setPerspectiveFovY(getFovY(), aspect, getNearClip(), getFarClip());
00286 }
00287
00288
00289
00290
00291
00292
00293
00294
00295 virtual const Matrix44& getViewMatrix(){ return viewMatrix_; }
00296
00297
00298
00299
00300
00301 virtual const Vector3& getPosition(){ return position_; }
00302
00303
00304
00305
00306
00307 virtual const Vector3& getRotation(){ return rotation_; }
00308
00309
00310
00311
00312
00313
00314 virtual void setViewMatrix(const Matrix44& viewMatrix);
00315
00316
00317
00318
00319
00320
00321 virtual void setTransformation(
00322 const Vector3& rotationXYZ, const Vector3& position);
00323
00324
00325
00326
00327
00328
00329 virtual void setTransformation(
00330 const Quaternion& rotation, const Vector3& position);
00331
00332
00333
00334
00335
00336
00337
00338 virtual void setLookAt(
00339 const Vector3& position, const Vector3& target, const Vector3& up);
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349 virtual Clipping::State clipping(const Sphere& boundingSphere);
00350
00351
00352
00353
00354
00355
00356 virtual Clipping::State clipping(const AxisAlignedBox& boundingBox);
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377 virtual const Vector3& getCorner(int index){
00378 Assert(index >= 0);
00379 Assert(index < 8);
00380 return corner_[index];
00381 }
00382
00383
00384
00385
00386
00387 virtual const Sphere& getBoundingSphere(){ return boundingSphere_; }
00388
00389
00390
00391
00392
00393
00394
00395
00396 virtual bool isCamera() const{ return true; }
00397
00398
00399 protected:
00400
00401
00402
00403
00404
00405 Camera(const String& name, Scene* scene);
00406
00407
00408
00409
00410 virtual ~Camera();
00411
00412
00413
00414
00415
00416 virtual void buildPerspectiveMatrix();
00417
00418
00419
00420
00421 virtual void clippingSetup();
00422
00423
00424 private:
00425
00426 Matrix44 projectionMatrix_;
00427
00428 Matrix44 viewMatrix_;
00429
00430 Plane clipPlane_[6];
00431
00432 Sphere boundingSphere_;
00433
00434 Vector3 corner_[8];
00435
00436 Vector3 position_;
00437
00438 Vector3 rotation_;
00439
00440
00441 float left_;
00442
00443 float right_;
00444
00445 float bottom_;
00446
00447 float top_;
00448
00449 float nearClip_;
00450
00451 float farClip_;
00452
00453 bool isPerspective_;
00454 };
00455
00456
00457 }
00458 #endif // End of CAMERA_H_
00459