]> git.mxchange.org Git - simgear.git/blob - simgear/scene/sky/clouds3d/camera.hpp
Clouds3D crashes because there is no Light
[simgear.git] / simgear / scene / sky / clouds3d / camera.hpp
1 //------------------------------------------------------------------------------
2 // File : camera.hpp
3 //------------------------------------------------------------------------------
4 // GLVU : Copyright 1997 - 2002 
5 //        The University of North Carolina at Chapel Hill
6 //------------------------------------------------------------------------------
7 // Permission to use, copy, modify, distribute and sell this software and its 
8 // documentation for any purpose is hereby granted without fee, provided that 
9 // the above copyright notice appear in all copies and that both that copyright 
10 // notice and this permission notice appear in supporting documentation. 
11 // Binaries may be compiled with this software without any royalties or 
12 // restrictions. 
13 //
14 // The University of North Carolina at Chapel Hill makes no representations 
15 // about the suitability of this software for any purpose. It is provided 
16 // "as is" without express or implied warranty.
17
18 //============================================================================
19 // camera.hpp : OPENGL-style camera class definition
20 //  Defines and stores a "camera" composed of 3 coord axes, an origin for
21 //  these axes (center-of-projection or eye location), a near and far plane
22 //  as distances from the origin projected along the viewing direction, 
23 //  the viewplane window extents (projection window defined in cam coords 
24 //  on the viewplane - near plane). ViewPlane is defined as the near plane.
25 //  Viewing direction is always defined along the -Z axis with eye at origin.
26 //----------------------------------------------------------------------------
27 // $Id$
28 //============================================================================
29
30 #ifndef CAMERA
31 #define CAMERA
32
33 #include <stdio.h>
34 #include "vec3f.hpp"
35 #include "mat16fv.hpp"
36
37 class Camera
38 {
39  public:
40
41   Vec3f X, Y, Z;            // NORMALIZED CAMERA COORDINATE-AXIS VECTORS
42   Vec3f Orig;               // LOCATION OF ORIGIN OF CAMERA SYSTEM IN WORLD COORDS
43   float wL,wR,wB,wT;        // WINDOW EXTENTS DEFINED AS A RECT ON NearPlane
44   float Near,Far;           // DISTANCES TO NEAR AND FAR PLANES (IN VIEWING DIR)
45
46   Camera();
47   Camera(const Camera &Cam);
48   void Copy(const Camera &Cam);
49
50   void LookAt(const Vec3f& Eye, const Vec3f& ViewRefPt, const Vec3f& ViewUp);
51   void Perspective(float Yfov, float Aspect, float Ndist, float Fdist);
52   void Frustum(float l, float r, float b, float t, float Ndist, float Fdist);
53
54   void TightlyFitToSphere(
55     const Vec3f& Eye, const Vec3f& ViewUp, const Vec3f& Cntr, float Rad);
56
57   void GetLookAtParams(Vec3f *Eye, Vec3f *ViewRefPt, Vec3f *ViewUp) const;
58   void GetPerspectiveParams(float *Yfov, float *Aspect, 
59                             float *Ndist, float *Fdist) const;
60   void GetFrustumParams(float *l, float *r, float *b, float *t, 
61                         float *Ndist, float *Fdist) const;
62   const Vec3f& wCOP() const; // WORLD COORDINATE CENTER-OF-PROJECTION (EYE)
63   Vec3f ViewDir() const;     // VIEWING DIRECTION
64   Vec3f ViewDirOffAxis() const;
65
66   float* GetXform_Screen2Obj(float* M, int WW, int WH) const;
67   float* GetXform_Obj2Screen(float* M, int WW, int WH) const;
68
69   float* GetModelviewMatrix(float* M) const;
70   float* GetProjectionMatrix(float* M) const;
71   float* GetViewportMatrix(float* M, int WW, int WH) const;
72
73   void SetModelviewMatrix(const float* M);
74
75   float* GetInvModelviewMatrix(float* M) const;
76   float* GetInvProjectionMatrix(float* M) const;
77   float* GetInvViewportMatrix(float* M, int WW, int WH) const;
78
79   Vec3f WorldToCam(const Vec3f &wP) const;
80   float WorldToCamZ(const Vec3f &wP) const;
81   Vec3f CamToWorld(const Vec3f &cP) const;
82
83   void LoadIdentityXform();
84   void Xform(const float M[16]);
85
86   void Translate(const Vec3f& trans);
87   void Rotate(const float M[9]);
88
89   void GetPixelRay(float sx, float sy, int ww, int wh, 
90                    Vec3f *Start, Vec3f *Dir) const;
91
92   void WriteToFile(FILE *fp) const;
93   int ReadFromFile(FILE *fp);  // RETURNS "1" IF SUCCESSFUL, "0" IF EOF
94
95   void CalcVerts(Vec3f *V) const;    // CALCS EIGHT CORNERS OF VIEW-FRUSTUM
96   void Print() const;
97   void Display() const;
98   void DisplaySolid() const;
99   void DisplayInGreen() const;
100 };
101
102 #endif