Camera.cpp

Go to the documentation of this file.
00001 // Copyright (C) 2005 Dave Griffiths
00002 //
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 //
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 
00017 #include "Camera.h"
00018 
00019 using namespace Fluxus;
00020     
00021 Camera::Camera() :
00022 m_Initialised(false),
00023 m_Ortho(false),
00024 m_CameraAttached(NULL),
00025 m_CameraLag(0),
00026 m_Up(-1),
00027 m_Down(1),
00028 m_Left(-0.75),
00029 m_Right(0.75),
00030 m_Front(1),
00031 m_Back(10000),
00032 m_OrthZoom(1.0f),
00033 m_ViewX(0),
00034 m_ViewY(0),
00035 m_ViewWidth(1),
00036 m_ViewHeight(1)
00037 {
00038     // default camera position
00039     m_Transform.translate(0,0,-10);
00040 }
00041 
00042 Camera::~Camera()
00043 {
00044 }
00045 
00046 void Camera::DoProjection()
00047 {
00048     if (m_Ortho) glOrtho(m_Down*m_OrthZoom,m_Up*m_OrthZoom,m_Right*m_OrthZoom,m_Left*m_OrthZoom,m_Front,m_Back);
00049     else glFrustum(m_Up,m_Down,m_Left,m_Right,m_Front,m_Back);
00050 }
00051 
00052 void Camera::DoCamera()
00053 {
00054     glMultMatrixf(m_Transform.arr());
00055 
00056     if (m_CameraAttached)
00057     {
00058         if (m_CameraLag!=0)
00059         {
00060             m_LockedMatrix.blend(m_CameraAttached->GetState()->Transform.inverse(),m_CameraLag);
00061         }
00062         else
00063         {
00064             m_LockedMatrix=m_CameraAttached->GetState()->Transform.inverse();
00065         }
00066 
00067         glMultMatrixf(m_LockedMatrix.arr());        
00068     }
00069 }
00070 
00071 void Camera::LockCamera(Primitive *p)
00072 {
00073      m_CameraAttached=p;
00074 }
00075 
00076 dMatrix Camera::GetProjection()
00077 {
00078     dMatrix Projection;
00079     glGetFloatv(GL_PROJECTION_MATRIX,Projection.arr());
00080     return Projection;
00081 }

Generated on Wed Sep 17 21:16:30 2008 for The Fluxus Renderer (libfluxus) by  doxygen 1.5.1