CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

camera.h

00001 /*
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 
00027 class Vertex;
00028 class csEngine;
00029 struct iPolygon3D;
00030 
00034 class csCamera : public csOrthoTransform, public iBase
00035 {
00036 private:
00038   iSector* sector;
00040   bool mirror;
00041 
00046   bool only_portals;
00047 
00049   csPlane3 *fp;
00050 
00052   int aspect;
00053   static int default_aspect;
00055   float inv_aspect;
00056   static float default_inv_aspect;
00058   float shift_x;
00059   float shift_y;
00060 
00062   float fov_angle;
00063   static float default_fov_angle;
00064 
00066   void ComputeAngle (int width);
00067   static void ComputeDefaultAngle (int width);
00068 
00075   long cameranr;
00079   static long cur_cameranr;
00080 
00081 public:
00083   csCamera ();
00085   csCamera (csCamera* c);
00087   csCamera (const csCamera& c);
00089   virtual ~csCamera ();
00090 
00097   long GetCameraNumber () const
00098   {
00099     return cameranr;
00100   }
00101 
00106   iPolygon3D* GetHit (csVector3& v);
00107 
00109   static void SetDefaultFOV (int fov, int width)
00110   {
00111     default_aspect = fov;
00112     default_inv_aspect = 1.0f / default_aspect;
00113     ComputeDefaultAngle (width);
00114   }
00115 
00117   static int GetDefaultFOV () { return default_aspect; }
00119   static float GetDefaultInvFOV () { return default_inv_aspect; }
00121   static float GetDefaultFOVAngle () { return default_fov_angle; }
00122 
00124   void SetFOV (int a, int width)
00125   {
00126     aspect = a;
00127     inv_aspect = 1.0f / a;
00128     ComputeAngle (width);
00129   }
00131   int GetFOV () const { return aspect; }
00133   float GetInvFOV () const { return inv_aspect; }
00134 
00136   void SetFOVAngle (float a, int width);
00138   float GetFOVAngle () const
00139   {
00140     return fov_angle;
00141   }
00142 
00144   float GetShiftX () const { return shift_x; }
00146   float GetShiftY () const { return shift_y; }
00147 
00149   void SetFarPlane (const csPlane3* farplane);
00151   csPlane3* GetFarPlane () const { return fp; }
00152 
00160   void SetSector (iSector *s)
00161   {
00162     sector = s;
00163     cameranr = cur_cameranr++;
00164   }
00165 
00169   iSector* GetSector () const { return sector; }
00170 
00176   bool IsMirrored () const { return mirror; }
00177 
00184   void SetMirrored (bool m)
00185   {
00186     if (mirror != m) cameranr = cur_cameranr++;
00187     mirror = m;
00188   }
00189 
00195   virtual void SetO2T (const csMatrix3& m)
00196   {
00197     csOrthoTransform::SetO2T (m);
00198     cameranr = cur_cameranr++;
00199   }
00200 
00206   virtual void SetT2O (const csMatrix3& m)
00207   {
00208     csOrthoTransform::SetT2O (m);
00209     cameranr = cur_cameranr++;
00210   }
00211 
00217   virtual void SetO2TTranslation (const csVector3& v)
00218   {
00219     csOrthoTransform::SetO2TTranslation (v);
00220     cameranr = cur_cameranr++;
00221   }
00222 
00230   virtual void SetPosition (const csVector3& v) { SetOrigin (v); }
00231 
00236   inline void SetW2C (const csMatrix3& m) { SetO2T (m); }
00237 
00242   inline void SetC2W (const csMatrix3& m) { SetT2O (m); }
00243 
00247   inline csMatrix3 GetW2C () const { return GetO2T (); }
00248 
00252   inline csMatrix3 GetC2W () const { return GetT2O (); }
00253 
00257   inline csVector3 GetW2CTranslation () const { return GetO2TTranslation (); }
00258 
00262   inline csVector3 World2Camera (const csVector3& v) const
00263   { return Other2This (v); }
00264 
00268   inline csVector3 Camera2World (const csVector3& v) const
00269   { return This2Other (v); }
00270 
00274   inline csVector3 Camera2WorldRelative (const csVector3& v) const
00275   { return This2OtherRelative (v); }
00276 
00283   virtual void MoveWorld (const csVector3& v, bool cd = true);
00284 
00288   virtual void Move (const csVector3& v, bool cd = true)
00289   { MoveWorld (m_t2o * v, cd); }
00290 
00298   virtual void MoveWorldUnrestricted (const csVector3& v) { Translate (v); }
00299 
00307   virtual void MoveUnrestricted (const csVector3& v) { Translate (m_t2o * v); }
00308 
00313   void Correct (int n);
00314 
00316   void SetPerspectiveCenter (float x, float y) { shift_x = x; shift_y = y; }
00317 
00319   void Perspective (const csVector3& v, csVector2& p) const
00320   {
00321     float iz = aspect / v.z;
00322     p.x = v.x * iz + shift_x;
00323     p.y = v.y * iz + shift_y;
00324   }
00325 
00327   void InvPerspective (const csVector2& p, float z, csVector3& v) const
00328   {
00329     v.z = z;
00330     v.x = (p.x - shift_x) * z * inv_aspect;
00331     v.y = (p.y - shift_y) * z * inv_aspect;
00332   }
00333 
00334   SCF_DECLARE_IBASE;
00335 
00336   //------------------------ iCamera implementation ------------------------
00338   struct Camera : public iCamera
00339   {
00340     SCF_DECLARE_EMBEDDED_IBASE (csCamera);
00341 
00342     virtual iCamera *Clone () const
00343     { return &(new csCamera (*scfParent))->scfiCamera; }
00344 
00345     virtual int GetFOV () const
00346     { return scfParent->GetFOV (); }
00347     virtual float GetInvFOV () const
00348     { return scfParent->GetInvFOV (); }
00349     virtual float GetFOVAngle () const
00350     { return scfParent->GetFOVAngle (); }
00351     virtual void SetFOV (int a, int width)
00352     { scfParent->SetFOV (a, width); }
00353     virtual void SetFOVAngle (float a, int width)
00354     { scfParent->SetFOVAngle (a, width); }
00355 
00356     virtual float GetShiftX () const
00357     { return scfParent->GetShiftX (); }
00358     virtual float GetShiftY () const
00359     { return scfParent->GetShiftY (); }
00360     virtual void SetPerspectiveCenter (float x, float y)
00361     { scfParent->SetPerspectiveCenter (x, y); }
00362 
00363     virtual csOrthoTransform& GetTransform ()
00364     { return *(csOrthoTransform*)scfParent; }
00365     virtual const csOrthoTransform& GetTransform () const
00366     { return *(csOrthoTransform*)scfParent; }
00367     virtual void SetTransform (const csOrthoTransform& tr)
00368     {
00369       *(csOrthoTransform*)scfParent = tr;
00370       scfParent->cameranr = scfParent->cur_cameranr++;
00371     }
00372     virtual void MoveWorld (const csVector3& v, bool cd = true)
00373     { scfParent->MoveWorld (v, cd); }
00374     virtual void Move (const csVector3& v, bool cd = true)
00375     { scfParent->Move (v, cd); }
00376     virtual void MoveWorldUnrestricted (const csVector3& v)
00377     { scfParent->MoveWorldUnrestricted (v); }
00378     virtual void MoveUnrestricted (const csVector3& v)
00379     { scfParent->MoveUnrestricted (v); }
00380 
00381     virtual iSector* GetSector () const { return scfParent->GetSector(); }
00382     virtual void SetSector (iSector *s) { scfParent->SetSector (s); }
00383 
00384     virtual iPolygon3D* GetHit (csVector3& v)
00385     {
00386       return scfParent->GetHit (v);
00387     }
00388     virtual void Correct (int n)
00389     {
00390       scfParent->Correct (n);
00391     }
00392     virtual bool IsMirrored () const
00393     {
00394       return scfParent->IsMirrored ();
00395     }
00396     virtual void SetMirrored (bool m)
00397     {
00398       scfParent->SetMirrored (m);
00399     }
00400     virtual csPlane3* GetFarPlane () const
00401     {
00402       return scfParent->GetFarPlane ();
00403     }
00404     virtual void SetFarPlane (csPlane3* fp)
00405     {
00406       scfParent->SetFarPlane (fp);
00407     }
00408     virtual long GetCameraNumber () const
00409     {
00410       return scfParent->GetCameraNumber ();
00411     }
00412     virtual void Perspective (const csVector3& v, csVector2& p) const
00413     {
00414       scfParent->Perspective (v, p);
00415     }
00416     virtual void InvPerspective (const csVector2& p, float z,
00417         csVector3& v) const
00418     {
00419       scfParent->InvPerspective (p, z, v);
00420     }
00421     virtual void OnlyPortals (bool hop)
00422     {
00423       scfParent->only_portals = hop;
00424     }
00425     virtual bool GetOnlyPortals ()
00426     {
00427       return scfParent->only_portals;
00428     }
00429   } scfiCamera;
00430   friend struct Camera;
00431 
00432 private:
00434   void Correct (int n, float* vals[]);
00435 };
00436 
00437 #endif // __CS_CAMERA_H__

Generated for Crystal Space by doxygen 1.2.14