00001
00002
00003
00004
00005
00006
00007
00008 #include "API/gl.h"
00009 #include <math.h>
00010
00011
00012
00013 #include "API/GL/camera.h"
00014 #include "API/GL/viewpoint.h"
00015 #include "API/Display/Display/display.h"
00016
00017 CL_Camera::CL_Camera()
00018 {
00019 nearZ = 0;
00020 farZ = 0;
00021 fov = 0;
00022 }
00023
00024 CL_Camera::CL_Camera(
00025 float nearZ,
00026 float farZ,
00027 float fov)
00028 {
00029 this->nearZ = nearZ;
00030 this->farZ = farZ;
00031 this->fov = fov;
00032 }
00033
00034 void CL_Camera::set_viewport(const CL_Viewpoint &vp, float dist) const
00035 {
00036 float ratio = CL_Display::get_width() / (float) CL_Display::get_height();
00037
00038 glMatrixMode(GL_PROJECTION);
00039 glLoadIdentity();
00040 gluPerspective(
00041 fov,
00042 ratio,
00043 nearZ,
00044 farZ);
00045
00046 glMatrixMode(GL_MODELVIEW);
00047 glLoadIdentity();
00048
00049 gluLookAt(
00050
00051 vp.pos.x - dist * vp.dir.x,
00052 vp.pos.y - dist * vp.dir.y,
00053 vp.pos.z - dist * vp.dir.z,
00054
00055 vp.pos.x,
00056 vp.pos.y,
00057 vp.pos.z,
00058
00059 vp.up.x,
00060 vp.up.y,
00061 vp.up.z);
00062 }