Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Camera Class Reference

#include <camera.h>

Public Types

enum  ProjectionType { PARALLEL, PERSPECTIVE }
 

Public Member Functions

void setCockpitOffset (float c)
 
float getCockpitOffset ()
 
 Camera (ProjectionType proj=PERSPECTIVE)
 for GetUnit (); More...
 
void LookDirection (const Vector &forevec, const Vector &up)
 
void SetNebula (Nebula *neb)
 
NebulaGetNebula ()
 
void UpdateCameraSounds ()
 This function updates the sound if sound is not updated on a per frame basis. More...
 
void GetView (Matrix &)
 
const VectorGetR ()
 
void GetPQR (Vector &p1, Vector &q1, Vector &r1)
 
void UpdateGFX (GFXBOOL clip, GFXBOOL updateFrustum, GFXBOOL centerCamera, GFXBOOL overrideZFrustum, float overrideZNear, float overrideZFar)
 
void UpdateGFX (GFXBOOL clip=GFXTRUE, GFXBOOL updateFrustum=GFXTRUE, GFXBOOL centerCamera=GFXFALSE)
 
void UpdateGFXFrustum (GFXBOOL overrideZFrustum, float overrideZNear, float overrideZFar)
 
void UpdateGFXAgain ()
 
void UpdatePlanetGFX ()
 
MatrixGetPlanetGFX ()
 
void UpdateGLCenter ()
 
void SetPosition (const QVector &origin, const Vector &velocity, const Vector &angular_velocity, const Vector &acceleration)
 
void GetPosition (QVector &vect)
 
Vector GetAngularVelocity () const
 
Vector GetVelocity () const
 
Vector GetAcceleration () const
 
void GetOrientation (Vector &p, Vector &q, Vector &r)
 
const QVectorGetPosition () const
 
float GetZDist (const Vector &v) const
 
void SetOrientation (const Vector &p, const Vector &q, const Vector &r)
 
void SetSubwindow (float x, float y, float xsize, float ysize)
 
void SetProjectionType (ProjectionType t)
 
void SetZoom (float z)
 
float GetZoom () const
 
void SetFov (float f)
 
float GetFov () const
 
void Yaw (float rad)
 
void Pitch (float rad)
 
void Roll (float rad)
 
void XSlide (float factor)
 
void YSlide (float factor)
 
void ZSlide (float factor)
 
void RestoreViewPort (float xoffset, float yoffset)
 

Public Attributes

Vector P
 
Vector Q
 
Vector R
 
PhysicsSystem myPhysics
 

Detailed Description

Definition at line 32 of file camera.h.

Member Enumeration Documentation

Enumerator
PARALLEL 
PERSPECTIVE 

Definition at line 56 of file camera.h.

57  {
58  PARALLEL,
60  };

Constructor & Destructor Documentation

Camera::Camera ( ProjectionType  proj = PERSPECTIVE)
explicit

for GetUnit ();

Definition at line 36 of file camera.cpp.

References game_data_t::fov, g_game, GFXFALSE, GFXTRUE, P, PI, Q, R, ResetVectors(), Vector, and Yaw().

36  : projectionType( proj )
37  , myPhysics( 0.1, 0.075, &Coord, &P, &Q, &R )
38 {
39  ResetVectors( P, Q, R );
40  R = -R;
41  Coord.i = 0;
42  Coord.j = 0;
43  Coord.k = -1;
44  velocity = angular_velocity = Vector( 0, 0, 0 );
45  lastpos.Set( 0, 0, 0 );
46  cockpit_offset = 0;
48  changed = GFXTRUE;
49  //SetPosition();
50  //SetOrientation();
51  Yaw( PI );
52  x = y = 0;
53  xsize = ysize = 1.0;
54  zoom = 1.0;
55  fov = g_game.fov;
56 
57  lastGFXUpdate.clip = GFXTRUE;
58  lastGFXUpdate.updateFrustum = GFXTRUE;
59  lastGFXUpdate.centerCamera = GFXFALSE;
60  lastGFXUpdate.overrideZFrustum = GFXFALSE;
61  lastGFXUpdate.overrideZNear = 0;
62  lastGFXUpdate.overrideZFar = 1000000;
63 }

Member Function Documentation

Vector Camera::GetAcceleration ( ) const
inline

Definition at line 147 of file camera.h.

Referenced by GameCockpit::Draw().

148  {
149  return accel;
150  }
Vector Camera::GetAngularVelocity ( ) const
inline

Definition at line 139 of file camera.h.

Referenced by Background::Draw(), and Stars::Draw().

140  {
141  return angular_velocity;
142  }
float Camera::getCockpitOffset ( )
inline

Definition at line 52 of file camera.h.

Referenced by BaseInterface::Room::BaseShip::Draw().

53  {
54  return cockpit_offset;
55  }
float Camera::GetFov ( ) const

Definition at line 295 of file camera.cpp.

Referenced by GameCockpit::Draw(), BaseInterface::Room::BaseShip::Draw(), and GameCockpit::DrawNavSystem().

296 {
297  return fov;
298 }
Nebula * Camera::GetNebula ( )

Definition at line 173 of file camera.cpp.

References UnitContainer::GetUnit().

Referenced by ContinuousTerrain::Draw(), GameStarSystem::Draw(), VDU::Draw(), GameUnit< UnitType >::Draw(), GameUnit< UnitType >::DrawNow(), Mesh::DrawNow(), NebulaUpdate(), and SetupFogState().

174 {
175  return reinterpret_cast<Nebula*>( nebula.GetUnit() ); //changed by chuck from (Nebula*) cast
176 }
void Camera::GetOrientation ( Vector p,
Vector q,
Vector r 
)
inline

Definition at line 151 of file camera.h.

References P, Q, and R.

Referenced by Bolt::Draw(), BaseInterface::Room::BaseShip::Draw(), NavigationSystem::Draw(), GameCockpit::SetupViewPort(), and ShoveCamBelowUnit().

152  {
153  p = P;
154  q = Q;
155  r = R;
156  }
Matrix * Camera::GetPlanetGFX ( )

GetView (Matrix x) returns the view matrix (inverse matrix based on camera pqr)

Definition at line 241 of file camera.cpp.

Referenced by GamePlanet::DrawTerrain().

242 {
243  return &planetview;
244  //CopyMatrix (x,view);
245 }
const QVector& Camera::GetPosition ( ) const
inline

Definition at line 157 of file camera.h.

158  {
159  return Coord;
160  }
void Camera::GetPQR ( Vector p1,
Vector q1,
Vector r1 
)

Definition at line 65 of file camera.cpp.

References P, Q, and R.

Referenced by CalculateOrientation(), GameCockpit::Draw(), ParticleTrail::DrawAndUpdate(), ClickList::queryShip(), GameUnit< UnitType >::querySphereClickList(), StarVlist::StarVlist(), StarVlist::UpdateGraphics(), and CoordinateSelect::UpdateMouse().

66 {
67  p1.i = P.i;
68  p1.j = P.j;
69  p1.k = P.k;
70  q1.i = Q.i;
71  q1.j = Q.j;
72  q1.k = Q.k;
73  r1.i = R.i;
74  r1.j = R.j;
75  r1.k = R.k;
76 }
const Vector& Camera::GetR ( )
inline

Definition at line 93 of file camera.h.

References R.

Referenced by Animation::Draw(), Stars::Draw(), Unit::reactToCollision(), GameCockpit::SetupViewPort(), and ShoveCamBehindUnit().

94  {
95  return R;
96  }
Vector Camera::GetVelocity ( ) const
inline

Definition at line 143 of file camera.h.

Referenced by Background::Draw(), Stars::Draw(), GameUnit< UnitType >::Draw(), UnitUtil::getPhysicsPriority(), and UpdateCameraSounds().

144  {
145  return velocity;
146  }
void Camera::GetView ( Matrix vw)

Definition at line 163 of file camera.cpp.

References GFXGetMatrixView().

Referenced by GameUnit< UnitType >::querySphereClickList(), and ClickList::requestIterator().

164 {
165  GFXGetMatrixView( vw );
166 }
float Camera::GetZDist ( const Vector v) const
inline

Definition at line 161 of file camera.h.

References DotProduct(), QVector, and R.

162  {
163  return ::DotProduct( QVector( v )-Coord, QVector( R ) );
164  }
float Camera::GetZoom ( ) const

Definition at line 285 of file camera.cpp.

286 {
287  return zoom;
288 }
void Camera::LookDirection ( const Vector forevec,
const Vector up 
)

Definition at line 247 of file camera.cpp.

References GFXTRUE, P, Q, R, and up.

248 {
249  P = (myR);
250  P.Normalize();
251  Q = up;
252  Q.Normalize();
253  CrossProduct( P, Q, R );
254  changed = GFXTRUE;
255 }
void Camera::Pitch ( float  rad)

Definition at line 306 of file camera.cpp.

References GFXTRUE, P, Q, and R.

307 {
308  ::Pitch( rad, P, Q, R );
309  changed = GFXTRUE;
310 }
void Camera::RestoreViewPort ( float  xoffset,
float  yoffset 
)

Definition at line 183 of file camera.cpp.

References GFXSubwindow().

Referenced by GameCockpit::RestoreViewPort(), GameCockpit::SetupViewPort(), and UpdateGLCenter().

184 {
185  GFXSubwindow( x+xoffset, y+yoffset, xsize, ysize );
186 }
void Camera::Roll ( float  rad)

Definition at line 312 of file camera.cpp.

References GFXTRUE, P, Q, and R.

313 {
314  ::Roll( rad, P, Q, R );
315  changed = GFXTRUE;
316 }
void Camera::setCockpitOffset ( float  c)
inline

Definition at line 47 of file camera.h.

References c, and GFXTRUE.

Referenced by BaseInterface::Room::BaseShip::Draw(), GameCockpit::DrawNavSystem(), and GameCockpit::SetupViewPort().

48  {
49  cockpit_offset = c;
50  changed = GFXTRUE;
51  }
void Camera::SetFov ( float  f)

Definition at line 290 of file camera.cpp.

Referenced by GameCockpit::Draw(), BaseInterface::Room::BaseShip::Draw(), GameCockpit::DrawNavSystem(), and GameCockpit::SetupViewPort().

291 {
292  fov = f;
293 }
void Camera::SetNebula ( Nebula neb)

Definition at line 168 of file camera.cpp.

References UnitContainer::SetUnit().

Referenced by NebulaUpdate(), and GameNebula::PutInsideCam().

169 {
170  nebula.SetUnit( (Unit*) neb );
171 }
void Camera::SetOrientation ( const Vector p,
const Vector q,
const Vector r 
)
void Camera::SetPosition ( const QVector origin,
const Vector velocity,
const Vector angular_velocity,
const Vector acceleration 
)

Definition at line 225 of file camera.cpp.

References FINITE, GFXTRUE, and VSFileSystem::vs_fprintf().

Referenced by GameCockpit::Autopilot(), Briefing::Briefing(), Briefing::Render(), BriefingUtil::setCamPosition(), ShoveCamBehindUnit(), ShoveCamBelowUnit(), and GameUnit< UnitType >::UpdateHudMatrix().

226 {
227  if ( FINITE( origin.i ) && FINITE( origin.j ) && FINITE( origin.k ) ) {
228  velocity = vel;
229  angular_velocity = angvel;
230  accel = acceleration;
231  Coord = origin;
232  changed = GFXTRUE;
233  } else {
234  VSFileSystem::vs_fprintf( stderr, "fatal error in camera" );
235  }
236 }
void Camera::SetProjectionType ( ProjectionType  t)

Definition at line 275 of file camera.cpp.

276 {
277  projectionType = t;
278 }
void Camera::SetSubwindow ( float  x,
float  y,
float  xsize,
float  ysize 
)

Definition at line 266 of file camera.cpp.

References GFXTRUE.

Referenced by GameUniverse::StartDraw().

267 {
268  this->x = x;
269  this->y = y;
270  this->xsize = xsize;
271  this->ysize = ysize;
272  changed = GFXTRUE;
273 }
void Camera::SetZoom ( float  z)

Definition at line 280 of file camera.cpp.

281 {
282  zoom = z;
283 }
void Camera::UpdateCameraSounds ( )

This function updates the sound if sound is not updated on a per frame basis.

Definition at line 135 of file camera.cpp.

References AUDListener(), AUDListenerOrientation(), GetVelocity(), P, Q, and R.

Referenced by UpdateCameraSnds().

136 {
137 #ifndef PERFRAMESOUND
138  AUDListener( Coord, GetVelocity() );
140 #endif
141 }
void Camera::UpdateGFX ( GFXBOOL  clip,
GFXBOOL  updateFrustum,
GFXBOOL  centerCamera,
GFXBOOL  overrideZFrustum,
float  overrideZNear,
float  overrideZFar 
)

Definition at line 78 of file camera.cpp.

References game_data_t::aspect, AUDListener(), AUDListenerOrientation(), g_game, GetElapsedTime(), GFXCalculateFrustum(), GFXLoadIdentity(), GFXLookAt(), GFXParallel(), GFXPerspective(), GFXSubwindow(), myPhysics, P, PARALLEL, PERSPECTIVE, PI, PROJECTION, Q, QVector, R, PhysicsSystem::Update(), Vector, GFXMatrices::view, game_data_t::zfar, and game_data_t::znear.

Referenced by GameStarSystem::Draw(), Stars::Draw(), GameCockpit::Draw(), BaseInterface::Room::BaseShip::Draw(), NavigationSystem::Draw(), GameCockpit::DrawNavSystem(), Briefing::Render(), GameCockpit::SetupViewPort(), GameUniverse::StartDraw(), UpdateGFX(), UpdateGFXAgain(), and UpdateGFXFrustum().

84 {
85  lastGFXUpdate.clip = clip;
86  lastGFXUpdate.updateFrustum = updateFrustum;
87  lastGFXUpdate.centerCamera = centerCamera;
88  lastGFXUpdate.overrideZFrustum = overrideZFrustum;
89  lastGFXUpdate.overrideZNear = overrideZNear;
90  lastGFXUpdate.overrideZFar = overrideZFar;
91 
92  const float ZFARCONST = 1000000;
93  float xmin, xmax, ymin, ymax, znear, zfar;
94  if (1 || changed) {
95  myPhysics.Update();
97  //FIXMEGFXLoadIdentity(VIEW);
98  switch (projectionType)
99  {
100  case Camera::PERSPECTIVE:
101  znear = (overrideZFrustum ? overrideZNear : g_game.znear);
102  zfar = ( overrideZFrustum ? overrideZFar : g_game.zfar*(clip ? 1 : ZFARCONST) );
103 
104  GFXPerspective( zoom*fov, g_game.aspect, znear, zfar, cockpit_offset ); //set perspective to 78 degree FOV
105  break;
106  case Camera::PARALLEL:
107  ymax = g_game.znear*tanf( zoom*fov*PI/( (float) 360.0 ) );
108 
109  ymin = -ymax; //-4.7046
110 
111  xmin = ymin*g_game.aspect; //-6.2571
112  xmax = ymax*g_game.aspect; //6.2571
113 
114  znear = ( overrideZFrustum ? overrideZNear : -g_game.zfar*(clip ? 1 : ZFARCONST) );
115  zfar = ( overrideZFrustum ? overrideZFar : g_game.zfar*(clip ? 1 : ZFARCONST) );
116 
117  //GFXParallel(xmin,xmax,ymin,ymax,-znear,zfar);
118  GFXParallel( g_game.aspect* -zoom, g_game.aspect*zoom, -zoom, zoom, znear, zfar );
119  break;
120  }
121  GFXLookAt( -R, centerCamera ? QVector( 0, 0, 0 ) : Coord, Q );
122  if (updateFrustum) GFXCalculateFrustum();
123 #ifdef PERFRAMESOUND
124  Vector lastpos( view[12], view[13], view[14] );
125  AUDListener( Coord, (Coord-lastpos)/GetElapsedTime() ); //this pos-last pos / elapsed time
126 #endif
127  //GFXGetMatrix(VIEW,view);
128  GFXSubwindow( x, y, xsize, ysize );
129 #ifdef PERFRAMESOUND
131 #endif
132  }
133 }
void Camera::UpdateGFX ( GFXBOOL  clip = GFXTRUE,
GFXBOOL  updateFrustum = GFXTRUE,
GFXBOOL  centerCamera = GFXFALSE 
)
inline

Definition at line 104 of file camera.h.

References UpdateGFX().

105  {
106  UpdateGFX( clip,
107  updateFrustum,
108  centerCamera,
109  lastGFXUpdate.overrideZFrustum,
110  lastGFXUpdate.overrideZNear,
111  lastGFXUpdate.overrideZFar );
112  }
void Camera::UpdateGFXAgain ( )
inline

Definition at line 122 of file camera.h.

References UpdateGFX().

Referenced by GameCockpit::Draw().

123  {
124  UpdateGFX( lastGFXUpdate.clip,
125  lastGFXUpdate.updateFrustum,
126  lastGFXUpdate.centerCamera,
127  lastGFXUpdate.overrideZFrustum,
128  lastGFXUpdate.overrideZNear,
129  lastGFXUpdate.overrideZFar );
130  }
void Camera::UpdateGFXFrustum ( GFXBOOL  overrideZFrustum,
float  overrideZNear,
float  overrideZFar 
)
inline

Definition at line 113 of file camera.h.

References UpdateGFX().

Referenced by Mesh::ProcessUndrawnMeshes(), and Mesh::ProcessZFarMeshes().

114  {
115  UpdateGFX( lastGFXUpdate.clip,
116  lastGFXUpdate.updateFrustum,
117  lastGFXUpdate.centerCamera,
118  overrideZFrustum,
119  overrideZNear,
120  overrideZFar );
121  }
void Camera::UpdateGLCenter ( )

Definition at line 188 of file camera.cpp.

References game_data_t::aspect, g_game, GFXLoadIdentity(), GFXLookAt(), GFXParallel(), GFXPerspective(), ITISDEPRECATED, PARALLEL, PERSPECTIVE, PI, PROJECTION, Q, QVector, R, RestoreViewPort(), VIEW, game_data_t::zfar, and game_data_t::znear.

189 {
190 #define ITISDEPRECATED 0
191  assert( ITISDEPRECATED );
192 #undef ITISDEPRECATED
193 //static float rotfactor = 0;
194  //glMatrixMode(GL_PROJECTION);
195  float xmin, xmax, ymin, ymax;
196  if (changed) {
199  //updating the center should always use a perspective
200  switch (Camera::PERSPECTIVE)
201  {
202  case Camera::PERSPECTIVE:
203  GFXPerspective( zoom*fov, g_game.aspect, g_game.znear, g_game.zfar, cockpit_offset ); //set perspective to 78 degree FOV
204  break;
205  case Camera::PARALLEL:
206  ymax = g_game.znear*tanf( zoom*fov*PI/( (float) 360.0 ) ); //78.0 --> 4.7046
207 
208  ymin = -ymax; //-4.7046
209 
210  xmin = ymin*g_game.aspect; //-6.2571
211  xmax = ymax*g_game.aspect; //6.2571
212 
213  //GFXParallel(xmin,xmax,ymin,ymax,-znear,zfar);
214  GFXParallel( g_game.aspect* -zoom, g_game.aspect*zoom, -zoom, zoom, -g_game.znear, g_game.zfar );
215  break;
216  }
217  RestoreViewPort( 0, 0 );
218 
219  GFXLookAt( -R, QVector( 0, 0, 0 ), Q );
220  //changed = GFXFALSE;
221  }
222  //glMultMatrixf(view);
223 }
void Camera::UpdatePlanetGFX ( )

Definition at line 178 of file camera.cpp.

References Identity().

Referenced by GamePlanet::DrawTerrain().

179 {
180  Identity( planetview );
181 }
void Camera::XSlide ( float  factor)

Definition at line 318 of file camera.cpp.

References GFXTRUE, and P.

319 {
320  Coord += (P*factor).Cast();
321  changed = GFXTRUE;
322 }
void Camera::Yaw ( float  rad)

Definition at line 300 of file camera.cpp.

References GFXTRUE, P, Q, and R.

Referenced by Camera().

301 {
302  ::Yaw( rad, P, Q, R );
303  changed = GFXTRUE;
304 }
void Camera::YSlide ( float  factor)

Definition at line 324 of file camera.cpp.

References GFXTRUE, and Q.

325 {
326  Coord += (Q*factor).Cast();
327  changed = GFXTRUE;
328 }
void Camera::ZSlide ( float  factor)

Definition at line 330 of file camera.cpp.

References GFXTRUE, and R.

331 {
332  Coord += (R*factor).Cast();
333  changed = GFXTRUE;
334 }

Member Data Documentation


The documentation for this class was generated from the following files: