Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

camera.cpp

Go to the documentation of this file.
00001 /*
00002         Dodge This, ClanLib example Game,
00003         Copyright 1999-2000 by the Dodge This Development Team.
00004 
00005         This game is licensed under the GNU PUBLIC LICENSE (GPL), version 2.
00006 */
00007 
00008 #include "API/gl.h"
00009 #include <math.h>
00010 
00011 //#include "API/gl.h"
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,                   // field of view
00042                 ratio,                 // aspect ratio
00043                 nearZ,                 // near clipping plane
00044                 farZ);                 // far clipping plane
00045 
00046         glMatrixMode(GL_MODELVIEW);
00047         glLoadIdentity();                       
00048 
00049         gluLookAt(
00050                 // position
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                 // center
00055                 vp.pos.x,
00056                 vp.pos.y,
00057                 vp.pos.z,
00058                 // up
00059                 vp.up.x,
00060                 vp.up.y,
00061                 vp.up.z);
00062 }

Generated at Wed Apr 4 19:53:59 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001