1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#ifndef CAMERA_H
#define CAMERA_H
#ifdef _WIN32
#pragma once
#endif
#include "mathlib/vmatrix.h"
#include "mathlib/vector4d.h"
#define OCTANT_X_POSITIVE 1
#define OCTANT_Y_POSITIVE 2
#define OCTANT_Z_POSITIVE 4
//
// Return values from BoxIsVisible.
//
enum Visibility_t
{
VIS_NONE = 0, // The box is completely outside the view frustum.
VIS_PARTIAL, // The box is partially inside the view frustum.
VIS_TOTAL // The box is completely inside the view frustum.
};
class CCamera
{
public:
CCamera(void);
virtual ~CCamera(void);
void Move(Vector &vDelta);
void Pitch(float fDegrees);
void Roll(float fDegrees);
void Yaw(float fDegrees);
void MoveForward(float fUnits);
void MoveRight(float fUnits);
void MoveUp(float fUnits);
void GetViewPoint(Vector& fViewPoint) const;
void GetViewForward(Vector& ViewForward) const;
void GetViewUp(Vector& ViewUp) const;
void GetViewRight(Vector& ViewRight) const;
void GetViewMatrix(VMatrix& Matrix);
void GetProjMatrix(VMatrix& Matrix);
void GetViewProjMatrix( VMatrix &Matrix );
float GetYaw(void);
float GetPitch(void);
float GetRoll(void);
QAngle GetAngles( );
void SetYaw(float fDegrees);
void SetPitch(float fDegrees);
void SetRoll(float fDegrees);
void SetViewPoint(const Vector &ViewPoint);
void SetViewTarget(const Vector &ViewTarget);
void SetViewPort( int width, int height );
void GetViewPort( int &width, int &height );
bool IsOrthographic();
void SetFarClip(float fFarZ);
void SetNearClip(float fNearZ);
float GetNearClip(void);
float GetFarClip(void);
void SetPerspective(float fFOV, float fNearZ, float fFarZ);
void GetFrustumPlanes( Vector4D Planes[6] );
float GetFOV(void);
void SetOrthographic(float fZoom, float fNearZ, float fFarZ);
void SetZoom(float fScale);
void Zoom(float fScale);
float GetZoom(void);
void WorldToView( const Vector& vWorld, Vector2D &vView);
void ViewToWorld( const Vector2D &vView, Vector& vWorld);
void BuildRay( const Vector2D &vView, Vector& vStart, Vector& vEnd );
protected:
void BuildViewMatrix();
void BuildProjMatrix();
void CameraIdentityMatrix(VMatrix& Matrix);
VMatrix m_ViewMatrix; // Camera view matrix, based on current yaw, pitch, and roll.
Vector m_ViewPoint;
float m_fYaw; // Counterclockwise rotation around the CAMERA_UP axis, in degrees [-359, 359].
float m_fPitch; // Counterclockwise rotation around the CAMERA_RIGHT axis, in degrees [-90, 90].
float m_fRoll; // Counterclockwise rotation around the CAMERA_FORWARD axis, in degrees [-359, 359].
VMatrix m_ProjMatrix; // Camera projection matrix
bool m_bIsOrthographic; // Camera projection mode
float m_fHorizontalFOV; // Horizontal field of view in degrees.
float m_fNearClip; // Distance to near clipping plane.
float m_fFarClip; // Distance to far clipping plane.
float m_fZoom; // Orthographic zoom scale
float m_fScaleHorz;
float m_fScaleVert;
int m_nViewWidth;
int m_nViewHeight;
VMatrix m_ViewProjMatrix; // view and projection matrix
VMatrix m_InvViewProjMatrix; // inverse view and projection matrix
};
#endif // CAMERA_H
|