00001
00002
00003
00004
00005
00006
00007
00008 #ifndef _Camera_h__
00009 #define _Camera_h__
00010
00011 #include <cmath>
00012 #include "MathHelper.h"
00013 #include "Matrix.h"
00014 #include "View.h"
00015
00016
00017
00018 namespace FemViewer {
00019
00020
00021
00022 template<typename T>
00023 inline T degtorad(const T &angle) { return angle * M_PI / T(180); }
00024
00025 struct Camera {
00026
00027 float near, far;
00028 float fov;
00029 float angle;
00030 fvmath::CVec3f pos, target, up;
00031 Matrix<float> c2w, w2c;
00032
00033 Camera(void) { set(); }
00034
00035 Camera(const View& view) : w2c(view.w2c) {
00036 near = view.getNearClipDistance();
00037 far = view.getFarClipDistance();
00038 fov = view.FOVDegrees;
00039 angle = atan(degtorad(fov * 0.5f));
00040 pos = view.getPosition();
00041 target = view.vCenter;
00042 up = view.vUp;
00043 c2w = w2c.Invers();
00044 }
00045
00046 Camera(const Camera& cam) {
00047 near = cam.near;
00048 far = cam.far;
00049 fov = cam.fov;
00050 angle = cam.angle;
00051 pos = cam.pos;
00052 target = cam.target;
00053 c2w = cam.c2w;
00054 w2c = c2w.Invers();
00055
00056 }
00057
00058 void set(Matrix<float>& cam2world = Matrix<float>::Identity,
00059 const float f = 90,
00060 const float nea = 0.1f,
00061 const float fr = 1000.0f) {
00062 near = nea;
00063 far = fr;
00064 fov = f;
00065 angle = atan(degtorad(fov * 0.5f));
00066 pos = fvmath::CVec3f(1.f,1.f,1.f);
00067 target = View::vDefaultCenter;
00068 up = View::vDefaultUp;
00069 c2w = cam2world;
00070 w2c = c2w.Invers();
00071 }
00072
00073 void set(fvmath::CVec3f eye_,fvmath::CVec3f at_,fvmath::CVec3f up_) {
00074 pos = eye_;
00075 target = at_;
00076 up = up_;
00077
00078 }
00079 };
00080 }
00081 #endif