CrystalSpace

Public API Reference

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

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 csSector;
00028 class Vertex;
00029 class csEngine;
00030 struct iPolygon3D;
00031 
00035 class csCamera : public csOrthoTransform, public iBase
00036 {
00037 private:
00039   csSector* sector;
00041   bool mirror;
00042 
00047   bool only_portals;
00048 
00050   csPlane3 *fp;
00051 
00053   int aspect;
00054   static int default_aspect;
00056   float inv_aspect;
00057   static float default_inv_aspect;
00059   float shift_x;
00060   float shift_y;
00061 
00063   float fov_angle;
00064   static float default_fov_angle;
00065 
00067   void ComputeAngle (int width);
00068   static void ComputeDefaultAngle (int width);
00069 
00076   long cameranr;
00080   static long cur_cameranr;
00081 
00082 public:
00084   csCamera ();
00086   csCamera (csCamera* c);
00088   csCamera (const csCamera& c);
00090   virtual ~csCamera ();
00091 
00098   long GetCameraNumber () const
00099   {
00100     return cameranr;
00101   }
00102 
00107   iPolygon3D* GetHit (csVector3& v);
00108 
00110   static void SetDefaultFOV (int fov, int width)
00111   {
00112     default_aspect = fov;
00113     default_inv_aspect = 1.0f / default_aspect;
00114     ComputeDefaultAngle (width);
00115   }
00116 
00118   static int GetDefaultFOV () { return default_aspect; }
00120   static float GetDefaultInvFOV () { return default_inv_aspect; }
00122   static float GetDefaultFOVAngle () { return default_fov_angle; }
00123 
00125   void SetFOV (int a, int width)
00126   {
00127     aspect = a;
00128     inv_aspect = 1.0f / a;
00129     ComputeAngle (width);
00130   }
00132   int GetFOV () const { return aspect; }
00134   float GetInvFOV () const { return inv_aspect; }
00135 
00137   void SetFOVAngle (float a, int width);
00139   float GetFOVAngle () const
00140   {
00141     return fov_angle;
00142   }
00143 
00145   float GetShiftX () const { return shift_x; }
00147   float GetShiftY () const { return shift_y; }
00148 
00150   void SetFarPlane (const csPlane3* farplane);
00152   csPlane3* GetFarPlane () const { return fp; }
00153 
00161   void SetSector (csSector *s)
00162   {
00163     sector = s;
00164     cameranr = cur_cameranr++;
00165   }
00166 
00170   csSector* GetSector () const { return sector; }
00171 
00177   bool IsMirrored () const { return mirror; }
00178 
00185   void SetMirrored (bool m)
00186   {
00187     if (mirror != m) cameranr = cur_cameranr++;
00188     mirror = m;
00189   }
00190 
00196   virtual void SetO2T (const csMatrix3& m)
00197   {
00198     csOrthoTransform::SetO2T (m);
00199     cameranr = cur_cameranr++;
00200   }
00201 
00207   virtual void SetT2O (const csMatrix3& m)
00208   {
00209     csOrthoTransform::SetT2O (m);
00210     cameranr = cur_cameranr++;
00211   }
00212 
00218   virtual void SetO2TTranslation (const csVector3& v)
00219   {
00220     csOrthoTransform::SetO2TTranslation (v);
00221     cameranr = cur_cameranr++;
00222   }
00223 
00231   virtual void SetPosition (const csVector3& v) { SetOrigin (v); }
00232 
00237   inline void SetW2C (const csMatrix3& m) { SetO2T (m); }
00238 
00243   inline void SetC2W (const csMatrix3& m) { SetT2O (m); }
00244 
00248   inline csMatrix3 GetW2C () const { return GetO2T (); }
00249 
00253   inline csMatrix3 GetC2W () const { return GetT2O (); }
00254 
00258   inline csVector3 GetW2CTranslation () const { return GetO2TTranslation (); }
00259 
00263   inline csVector3 World2Camera (const csVector3& v) const
00264   { return Other2This (v); }
00265 
00269   inline csVector3 Camera2World (const csVector3& v) const
00270   { return This2Other (v); }
00271 
00275   inline csVector3 Camera2WorldRelative (const csVector3& v) const
00276   { return This2OtherRelative (v); }
00277 
00284   virtual void MoveWorld (const csVector3& v, bool cd = true);
00285 
00289   virtual void Move (const csVector3& v, bool cd = true)
00290   { MoveWorld (m_t2o * v, cd); }
00291 
00299   virtual void MoveWorldUnrestricted (const csVector3& v) { Translate (v); }
00300 
00308   virtual void MoveUnrestricted (const csVector3& v) { Translate (m_t2o * v); }
00309 
00314   void Correct (int n);
00315 
00317   void SetPerspectiveCenter (float x, float y) { shift_x = x; shift_y = y; }
00318 
00320   void Perspective (const csVector3& v, csVector2& p) const
00321   {
00322     float iz = aspect / v.z;
00323     p.x = v.x * iz + shift_x;
00324     p.y = v.y * iz + shift_y;
00325   }
00326 
00328   void InvPerspective (const csVector2& p, float z, csVector3& v) const
00329   {
00330     v.z = z;
00331     v.x = (p.x - shift_x) * z * inv_aspect;
00332     v.y = (p.y - shift_y) * z * inv_aspect;
00333   }
00334 
00335   SCF_DECLARE_IBASE;
00336 
00337   //------------------------ 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       return scfParent->GetHit (v);
00391     }
00392     virtual void Correct (int n)
00393     {
00394       scfParent->Correct (n);
00395     }
00396     virtual bool IsMirrored () const
00397     {
00398       return scfParent->IsMirrored ();
00399     }
00400     virtual void SetMirrored (bool m)
00401     {
00402       scfParent->SetMirrored (m);
00403     }
00404     virtual csPlane3* GetFarPlane () const
00405     {
00406       return scfParent->GetFarPlane ();
00407     }
00408     virtual void SetFarPlane (csPlane3* fp)
00409     {
00410       scfParent->SetFarPlane (fp);
00411     }
00412     virtual long GetCameraNumber () const
00413     {
00414       return scfParent->GetCameraNumber ();
00415     }
00416     virtual void Perspective (const csVector3& v, csVector2& p) const
00417     {
00418       scfParent->Perspective (v, p);
00419     }
00420     virtual void InvPerspective (const csVector2& p, float z,
00421         csVector3& v) const
00422     {
00423       scfParent->InvPerspective (p, z, v);
00424     }
00425     virtual void OnlyPortals (bool hop)
00426     {
00427       scfParent->only_portals = hop;
00428     }
00429     virtual bool GetOnlyPortals ()
00430     {
00431       return scfParent->only_portals;
00432     }
00433   } scfiCamera;
00434   friend struct Camera;
00435 
00436 private:
00438   void Correct (int n, float* vals[]);
00439 };
00440 
00441 #endif // __CS_CAMERA_H__

Generated for Crystal Space by doxygen 1.2.14