camera.hpp

Go to the documentation of this file.
00001 /*
00002     RenderStack  Support library for OpenGL 3+
00003     Copyright (C) 2010  Timo Suoranta
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Lesser General Public
00007     License as published by the Free Software Foundation; either
00008     version 2.1 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Lesser General Public License for more details.
00014 
00015     You should have received a copy of the GNU Lesser General Public
00016     License along with this library; if not, write to the Free Software
00017     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018 */
00019 
00027 #ifndef CAMERA_HPP
00028 #define CAMERA_HPP
00029 
00030 #include "renderstack/rs.h"
00031 #include "renderstack/frame.hpp"
00032 #include <exception>
00033 
00034 namespace renderstack {
00035 
00036 class viewport;
00037 
00038 class invalid_camera_projection_exception 
00039 :   public std::exception
00040 {
00041 };
00042 
00043 enum camera_projection
00044 {
00045     camera_projection_perspective_horizontal = 1,
00046     camera_projection_perspective_vertical,
00047     camera_projection_orthogonal_horizontal,
00048     camera_projection_orthogonal_vertical,
00049     camera_projection_orthogonal
00050 };
00051 
00053 class camera
00054 :   public frame
00055 {
00056 public:
00057     camera();
00058 
00059     void update(viewport const &viewport);
00060     void update_frame(frame const &frame);
00061 
00062 public:
00063     bool connect(uniform_bindings &bindings, enum logical_uniform uniform, int slot);
00064 
00065     void set_near_clip       (float                  v ) { m_near_clip = v; }
00066     void set_far_clip        (float                  v ) { m_far_clip = v; }
00067     void set_projection_type (enum camera_projection v ) { m_projection_type = v; }
00068     void set_fov             (float                  angle_radians ) { m_fov = angle_radians; }
00069     void set_ortho_width     (float                  v ) { m_ortho_width = v; }
00070     void set_ortho_height    (float                  v ) { m_ortho_height = v; }
00071 
00072     float                   near_clip      () const { return m_near_clip; }
00073     float                   far_clip       () const { return m_far_clip; }
00074     enum camera_projection  projection_type() const { return m_projection_type; }
00075     float                   fov            () const { return m_fov; }
00076     float                   ortho_width    () const { return m_ortho_width; }
00077     float                   ortho_height   () const { return m_ortho_height; }
00078 
00079     matrix const        &frame_to_clip  () const { return m_frame_to_clip; }
00080     matrix const        &frame_to_camera() const { return m_frame_to_camera; }
00081     matrix const        &world_to_clip  () const { return m_world_to_clip; }
00082     matrix const        &clip_to_world  () const { return m_clip_to_world; }
00083     matrix const        &clip_to_local  () const { return m_clip_to_local; }
00084     matrix const        &local_to_clip  () const { return m_local_to_clip; }
00085 
00086     matrix              &frame_to_clip  () { return m_frame_to_clip; }
00087     matrix              &frame_to_camera() { return m_frame_to_camera; }
00088     matrix              &world_to_clip  () { return m_world_to_clip; }
00089     matrix              &clip_to_world  () { return m_clip_to_world; }
00090     matrix              &clip_to_local  () { return m_clip_to_local; }
00091     matrix              &local_to_clip  () { return m_local_to_clip; }
00092 
00093 private:
00094     float               m_near_clip;
00095     float               m_far_clip;
00096     camera_projection   m_projection_type;
00097     float               m_fov;
00098     float               m_ortho_width;
00099     float               m_ortho_height;
00100 
00101     matrix              m_frame_to_clip;
00102     matrix              m_frame_to_camera;
00103     matrix              m_world_to_clip;
00104     matrix              m_clip_to_world;
00105     matrix              m_clip_to_local;    /*  clip to camera(view), aka. inverse projection  */ 
00106     matrix              m_local_to_clip;    /*  camera(view) to clip, aka. projection  */ 
00107 };
00108 
00109 }
00110 
00111 #endif
00112 
Generated on Sun Apr 11 12:23:08 2010 for RenderStack by  doxygen 1.6.3