NCBI C++ ToolKit
glcamera.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef GUI_OPENGL___GL_CAMPERA__HPP
2 #define GUI_OPENGL___GL_CAMPERA__HPP
3 
4 /* $Id: glcamera.hpp 14810 2007-08-13 12:27:15Z dicuccio $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Mike DiCuccio
30  *
31  * File Description:
32  *
33  */
34 
35 #include <corelib/ncbiobj.hpp>
36 #include <gui/opengl.h>
37 #include <gui/gui.hpp>
38 
39 /** @addtogroup GUI_OPENGL
40  *
41  * @{
42  */
43 
45 
46 
47 //
48 // class CGlCamera abstracts the options required for camera set-up.
49 //
50 // This class supports orthographic and perspective view setups, and provides a
51 // variety of means to control the layout. When this class is made current,
52 // the values of the matrices are optionally overwritten rather than saved.
53 //
55 {
56 public:
57  // enum controlling the type of layout we use (orthographic or perspective)
58  // the default is perspective.
59  enum EType {
61  ePerspective
62  };
63 
64  // default ctor
65  CGlCamera();
66 
67  // set up the camera for rendering. the boolean flag passed here indicates
68  // whether the current matrices are to be saved. If they are saved, they
69  // must be restored using ReleaseCurrent(true)
70  void MakeCurrent(bool save_matrices = false);
71 
72  // restore the previously saved projection matrices. The default is for
73  // this to be a null operation; if MakeCurrent(true) was called,
74  // ReleaseCurrent(true) must also be called.
75  void ReleaseCurrent(bool restore_matrices = false);
76 
77  // access the type of layout we use
78  EType GetLayout(void) const;
79  void SetLayout(EType type);
80 
81  //
82  // access the clipping planes
83  // this is specific to the kind of camera set-up we're using
84  //
85 
86  //
87  // Common view setup
88  // The two clipping planes defining the near and far aspects of the frustum
89  // are shared by perspective and orthographic views.
90  GLdouble GetNearPlane (void) const;
91  GLdouble GetFarPlane (void) const;
92  void SetNearPlane (GLdouble);
93  void SetFarPlane (GLdouble);
94 
95  //
96  // Orthographic Setup
97  // An orthographic view is an architectural view that lacks perspective.
98  // Orthographic displays are most commonly used to set up 2D displays that
99  // lack perspective, but they are also valid for 3D scenes in which
100  // perspective hints are not required.
101  //
102  // Orthographic views are defined as a cube, bounded by six planes (near,
103  // far, left, right, top, bottom). The corrdinates used for these are up
104  // to the user to determine; OpenGL makes no assumptions about the
105  // rendering coordinates.
106  GLdouble GetLeftPlane (void) const;
107  GLdouble GetRightPlane (void) const;
108  GLdouble GetTopPlane (void) const;
109  GLdouble GetBottomPlane(void) const;
110 
111  void SetLeftPlane (GLdouble f);
112  void SetRightPlane (GLdouble f);
113  void SetTopPlane (GLdouble f);
114  void SetBottomPlane(GLdouble f);
115 
116  //
117  // Perspective setup
118  // Perspective views are defined by a different set of parameters. The
119  // perspective camera setup creates a frustum (= truncated pyramid) defined
120  // by the following parameters:
121  // - near and far clipping planes (from common set-up)
122  // - field of view (in degrees)
123  // - aspect ratio (width / height)
124  GLdouble GetFieldOfView(void) const;
125  GLdouble GetAspectRatio(void) const;
126 
127  void SetFieldOfView(GLdouble f);
128  void SetAspectRatio(GLdouble f);
129 
130  void Init2dDefault();
131  void Init3dDefault();
132 
133 private:
134 
135  // type of viewing setup we use (default = perspective)
137 
138  // common params
139  GLdouble m_NearPlane;
140  GLdouble m_FarPlane;
141 
142  // ortho params
143  GLdouble m_LeftPlane;
144  GLdouble m_RightPlane;
145  GLdouble m_TopPlane;
146  GLdouble m_BottomPlane;
147 
148  // perspective params
149  GLdouble m_Fov;
150  GLdouble m_Aspect;
151 };
152 
153 
155 
156 /* @} */
157 
158 #endif // GUI_OPENGL___GL_CAMPERA__HPP
CObject –.
Definition: ncbiobj.hpp:180
EType m_Type
Definition: glcamera.hpp:136
GLdouble m_Fov
Definition: glcamera.hpp:149
GLdouble m_LeftPlane
Definition: glcamera.hpp:143
GLdouble m_TopPlane
Definition: glcamera.hpp:145
GLdouble m_BottomPlane
Definition: glcamera.hpp:146
GLdouble m_FarPlane
Definition: glcamera.hpp:140
GLdouble m_NearPlane
Definition: glcamera.hpp:139
GLdouble m_Aspect
Definition: glcamera.hpp:150
GLdouble m_RightPlane
Definition: glcamera.hpp:144
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_GUIOPENGL_EXPORT
Definition: gui_export.h:514
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
double f(double x_, const double &y_)
Definition: njn_root.hpp:188
Standard mechanism to include OpenGL headers for all platforms.
Definition: type.c:6
Modified on Sat May 18 11:36:13 2024 by modify_doxy.py rev. 669887