|
camera.h00001 /* 00002 Copyright (C) 1998-2001 by Jorrit Tyberghein 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 #ifndef __CS_CAMERA_H__ 00020 #define __CS_CAMERA_H__ 00021 00022 #include "csutil/scf.h" 00023 #include "csgeom/transfrm.h" 00024 #include "iengine/camera.h" 00025 #include "csengine/sector.h" 00026 #include "csengine/polygon.h" 00027 00028 class csSector; 00029 class csPolygon3D; 00030 class Vertex; 00031 class csEngine; 00032 00036 class csCamera : public csOrthoTransform, public iBase 00037 { 00038 private: 00040 csSector* sector; 00042 bool mirror; 00043 00048 bool only_portals; 00049 00051 csPlane3 *fp; 00052 00054 int aspect; 00055 static int default_aspect; 00057 float inv_aspect; 00058 static float default_inv_aspect; 00060 float shift_x; 00061 float shift_y; 00062 00064 float fov_angle; 00065 static float default_fov_angle; 00066 00068 void ComputeAngle (int width); 00069 static void ComputeDefaultAngle (int width); 00070 00077 long cameranr; 00081 static long cur_cameranr; 00082 00083 public: 00085 csCamera (); 00087 csCamera (csCamera* c); 00089 csCamera (const csCamera& c); 00091 virtual ~csCamera (); 00092 00099 long GetCameraNumber () const 00100 { 00101 return cameranr; 00102 } 00103 00108 csPolygon3D* GetHit (csVector3& v); 00109 00111 static void SetDefaultFOV (int fov, int width) 00112 { 00113 default_aspect = fov; 00114 default_inv_aspect = 1.0f / default_aspect; 00115 ComputeDefaultAngle (width); 00116 } 00117 00119 static int GetDefaultFOV () { return default_aspect; } 00121 static float GetDefaultInvFOV () { return default_inv_aspect; } 00123 static float GetDefaultFOVAngle () { return default_fov_angle; } 00124 00126 void SetFOV (int a, int width) 00127 { 00128 aspect = a; 00129 inv_aspect = 1.0f / a; 00130 ComputeAngle (width); 00131 } 00133 int GetFOV () const { return aspect; } 00135 float GetInvFOV () const { return inv_aspect; } 00136 00138 void SetFOVAngle (float a, int width); 00140 float GetFOVAngle () const 00141 { 00142 return fov_angle; 00143 } 00144 00146 float GetShiftX () const { return shift_x; } 00148 float GetShiftY () const { return shift_y; } 00149 00151 void SetFarPlane (const csPlane3* farplane); 00153 csPlane3* GetFarPlane () const { return fp; } 00154 00162 void SetSector (csSector *s) 00163 { 00164 sector = s; 00165 cameranr = cur_cameranr++; 00166 } 00167 00171 csSector* GetSector () const { return sector; } 00172 00178 bool IsMirrored () const { return mirror; } 00179 00186 void SetMirrored (bool m) 00187 { 00188 if (mirror != m) cameranr = cur_cameranr++; 00189 mirror = m; 00190 } 00191 00197 virtual void SetO2T (const csMatrix3& m) 00198 { 00199 csOrthoTransform::SetO2T (m); 00200 cameranr = cur_cameranr++; 00201 } 00202 00208 virtual void SetT2O (const csMatrix3& m) 00209 { 00210 csOrthoTransform::SetT2O (m); 00211 cameranr = cur_cameranr++; 00212 } 00213 00219 virtual void SetO2TTranslation (const csVector3& v) 00220 { 00221 csOrthoTransform::SetO2TTranslation (v); 00222 cameranr = cur_cameranr++; 00223 } 00224 00232 virtual void SetPosition (const csVector3& v) { SetOrigin (v); } 00233 00238 inline void SetW2C (const csMatrix3& m) { SetO2T (m); } 00239 00244 inline void SetC2W (const csMatrix3& m) { SetT2O (m); } 00245 00249 inline csMatrix3 GetW2C () const { return GetO2T (); } 00250 00254 inline csMatrix3 GetC2W () const { return GetT2O (); } 00255 00259 inline csVector3 GetW2CTranslation () const { return GetO2TTranslation (); } 00260 00264 inline csVector3 World2Camera (const csVector3& v) const 00265 { return Other2This (v); } 00266 00270 inline csVector3 Camera2World (const csVector3& v) const 00271 { return This2Other (v); } 00272 00276 inline csVector3 Camera2WorldRelative (const csVector3& v) const 00277 { return This2OtherRelative (v); } 00278 00285 virtual void MoveWorld (const csVector3& v, bool cd = true); 00286 00290 virtual void Move (const csVector3& v, bool cd = true) 00291 { MoveWorld (m_t2o * v, cd); } 00292 00300 virtual void MoveWorldUnrestricted (const csVector3& v) { Translate (v); } 00301 00309 virtual void MoveUnrestricted (const csVector3& v) { Translate (m_t2o * v); } 00310 00315 void Correct (int n); 00316 00318 void SetPerspectiveCenter (float x, float y) { shift_x = x; shift_y = y; } 00319 00321 void Perspective (const csVector3& v, csVector2& p) const 00322 { 00323 float iz = aspect / v.z; 00324 p.x = v.x * iz + shift_x; 00325 p.y = v.y * iz + shift_y; 00326 } 00327 00329 void InvPerspective (const csVector2& p, float z, csVector3& v) const 00330 { 00331 v.z = z; 00332 v.x = (p.x - shift_x) * z * inv_aspect; 00333 v.y = (p.y - shift_y) * z * inv_aspect; 00334 } 00335 00336 SCF_DECLARE_IBASE; 00337 00338 //------------------------ iCamera implementation ------------------------ 00339 struct Camera : public iCamera 00340 { 00341 SCF_DECLARE_EMBEDDED_IBASE (csCamera); 00342 00343 virtual iCamera *Clone () const 00344 { return &(new csCamera (*scfParent))->scfiCamera; } 00345 00346 virtual int GetFOV () const 00347 { return scfParent->GetFOV (); } 00348 virtual float GetInvFOV () const 00349 { return scfParent->GetInvFOV (); } 00350 virtual float GetFOVAngle () const 00351 { return scfParent->GetFOVAngle (); } 00352 virtual void SetFOV (int a, int width) 00353 { scfParent->SetFOV (a, width); } 00354 virtual void SetFOVAngle (float a, int width) 00355 { scfParent->SetFOVAngle (a, width); } 00356 00357 virtual float GetShiftX () const 00358 { return scfParent->GetShiftX (); } 00359 virtual float GetShiftY () const 00360 { return scfParent->GetShiftY (); } 00361 virtual void SetPerspectiveCenter (float x, float y) 00362 { scfParent->SetPerspectiveCenter (x, y); } 00363 00364 virtual csOrthoTransform& GetTransform () 00365 { return *(csOrthoTransform*)scfParent; } 00366 virtual const csOrthoTransform& GetTransform () const 00367 { return *(csOrthoTransform*)scfParent; } 00368 virtual void SetTransform (const csOrthoTransform& tr) 00369 { 00370 *(csOrthoTransform*)scfParent = tr; 00371 scfParent->cameranr = scfParent->cur_cameranr++; 00372 } 00373 virtual void MoveWorld (const csVector3& v, bool cd = true) 00374 { scfParent->MoveWorld (v, cd); } 00375 virtual void Move (const csVector3& v, bool cd = true) 00376 { scfParent->Move (v, cd); } 00377 virtual void MoveWorldUnrestricted (const csVector3& v) 00378 { scfParent->MoveWorldUnrestricted (v); } 00379 virtual void MoveUnrestricted (const csVector3& v) 00380 { scfParent->MoveUnrestricted (v); } 00381 00382 virtual iSector* GetSector () const 00383 { return scfParent->GetSector() ? 00384 &scfParent->GetSector()->scfiSector : NULL; } 00385 virtual void SetSector (iSector *s) 00386 { scfParent->SetSector (s->GetPrivateObject ()); } 00387 00388 virtual iPolygon3D* GetHit (csVector3& v) 00389 { 00390 csPolygon3D* poly = scfParent->GetHit (v); 00391 return poly ? &(poly->scfiPolygon3D) : NULL; 00392 } 00393 virtual void Correct (int n) 00394 { 00395 scfParent->Correct (n); 00396 } 00397 virtual bool IsMirrored () const 00398 { 00399 return scfParent->IsMirrored (); 00400 } 00401 virtual void SetMirrored (bool m) 00402 { 00403 scfParent->SetMirrored (m); 00404 } 00405 virtual csPlane3* GetFarPlane () const 00406 { 00407 return scfParent->GetFarPlane (); 00408 } 00409 virtual void SetFarPlane (csPlane3* fp) 00410 { 00411 scfParent->SetFarPlane (fp); 00412 } 00413 virtual long GetCameraNumber () const 00414 { 00415 return scfParent->GetCameraNumber (); 00416 } 00417 virtual void Perspective (const csVector3& v, csVector2& p) const 00418 { 00419 scfParent->Perspective (v, p); 00420 } 00421 virtual void InvPerspective (const csVector2& p, float z, 00422 csVector3& v) const 00423 { 00424 scfParent->InvPerspective (p, z, v); 00425 } 00426 virtual void OnlyPortals (bool hop) 00427 { 00428 scfParent->only_portals = hop; 00429 } 00430 virtual bool GetOnlyPortals () 00431 { 00432 return scfParent->only_portals; 00433 } 00434 } scfiCamera; 00435 friend struct Camera; 00436 00437 private: 00439 void Correct (int n, float* vals[]); 00440 }; 00441 00442 #endif // __CS_CAMERA_H__ Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000 |