00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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/planeclp.h"
00026 #include "csengine/sector.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;
00047 bool only_portals;
00048
00050 csPlaneClip *fp;
00051 bool use_farplane;
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 (csPlaneClip* farplane) { fp = farplane; }
00153 csPlaneClip* GetFarPlane () const { return fp; }
00154
00156 bool UseFarPlane () const { return use_farplane; }
00158 void UseFarPlane (bool useit) { use_farplane = fp && useit; }
00159
00167 void SetSector (csSector *s)
00168 {
00169 sector = s;
00170 cameranr = cur_cameranr++;
00171 }
00172
00176 csSector* GetSector () const { return sector; }
00177
00183 bool IsMirrored () const { return mirror; }
00184
00191 void SetMirrored (bool m)
00192 {
00193 if (mirror != m) cameranr = cur_cameranr++;
00194 mirror = m;
00195 }
00196
00202 virtual void SetO2T (const csMatrix3& m)
00203 {
00204 csOrthoTransform::SetO2T (m);
00205 cameranr = cur_cameranr++;
00206 }
00207
00213 virtual void SetT2O (const csMatrix3& m)
00214 {
00215 csOrthoTransform::SetT2O (m);
00216 cameranr = cur_cameranr++;
00217 }
00218
00224 virtual void SetO2TTranslation (const csVector3& v)
00225 {
00226 csOrthoTransform::SetO2TTranslation (v);
00227 cameranr = cur_cameranr++;
00228 }
00229
00237 virtual void SetPosition (const csVector3& v) { SetOrigin (v); }
00238
00243 inline void SetW2C (const csMatrix3& m) { SetO2T (m); }
00244
00249 inline void SetC2W (const csMatrix3& m) { SetT2O (m); }
00250
00254 inline csMatrix3 GetW2C () const { return GetO2T (); }
00255
00259 inline csMatrix3 GetC2W () const { return GetT2O (); }
00260
00264 inline csVector3 GetW2CTranslation () const { return GetO2TTranslation (); }
00265
00269 inline csVector3 World2Camera (const csVector3& v) const
00270 { return Other2This (v); }
00271
00275 inline csVector3 Camera2World (const csVector3& v) const
00276 { return This2Other (v); }
00277
00281 inline csVector3 Camera2WorldRelative (const csVector3& v) const
00282 { return This2OtherRelative (v); }
00283
00290 virtual void MoveWorld (const csVector3& v, bool cd = true);
00291
00295 virtual void Move (const csVector3& v, bool cd = true)
00296 { MoveWorld (m_t2o * v, cd); }
00297
00305 virtual void MoveWorldUnrestricted (const csVector3& v) { Translate (v); }
00306
00314 virtual void MoveUnrestricted (const csVector3& v) { Translate (m_t2o * v); }
00315
00320 void Correct (int n);
00321
00323 void SetPerspectiveCenter (float x, float y) { shift_x = x; shift_y = y; }
00324
00326 void Perspective (const csVector3& v, csVector2& p) const
00327 {
00328 float iz = aspect / v.z;
00329 p.x = v.x * iz + shift_x;
00330 p.y = v.y * iz + shift_y;
00331 }
00332
00334 void InvPerspective (const csVector2& p, float z, csVector3& v) const
00335 {
00336 v.z = z;
00337 v.x = (p.x - shift_x) * z * inv_aspect;
00338 v.y = (p.y - shift_y) * z * inv_aspect;
00339 }
00340
00341 SCF_DECLARE_IBASE;
00342
00343
00344 struct Camera : public iCamera
00345 {
00346 SCF_DECLARE_EMBEDDED_IBASE (csCamera);
00347 virtual csCamera* GetPrivateObject ()
00348 { return scfParent; }
00349
00350 virtual int GetFOV () const
00351 { return scfParent->GetFOV (); }
00352 virtual float GetInvFOV () const
00353 { return scfParent->GetInvFOV (); }
00354 virtual float GetFOVAngle () const
00355 { return scfParent->GetFOVAngle (); }
00356 virtual void SetFOV (int a, int width)
00357 { scfParent->SetFOV (a, width); }
00358 virtual void SetFOVAngle (float a, int width)
00359 { scfParent->SetFOVAngle (a, width); }
00360
00361 virtual float GetShiftX () const
00362 { return scfParent->GetShiftX (); }
00363 virtual float GetShiftY () const
00364 { return scfParent->GetShiftY (); }
00365 virtual void SetPerspectiveCenter (float x, float y)
00366 { scfParent->SetPerspectiveCenter (x, y); }
00367
00368 virtual csOrthoTransform& GetTransform ()
00369 { return *(csOrthoTransform*)scfParent; }
00370 virtual void SetTransform (const csOrthoTransform& tr)
00371 {
00372 *(csOrthoTransform*)scfParent = tr;
00373 scfParent->cameranr = scfParent->cur_cameranr++;
00374 }
00375 virtual void MoveWorld (const csVector3& v, bool cd = true)
00376 { scfParent->MoveWorld (v, cd); }
00377 virtual void Move (const csVector3& v, bool cd = true)
00378 { scfParent->Move (v, cd); }
00379 virtual void MoveWorldUnrestricted (const csVector3& v)
00380 { scfParent->MoveWorldUnrestricted (v); }
00381 virtual void MoveUnrestricted (const csVector3& v)
00382 { scfParent->MoveUnrestricted (v); }
00383
00384 virtual iSector* GetSector () const
00385 { return scfParent->GetSector() ?
00386 &scfParent->GetSector()->scfiSector : 0; }
00387 virtual void SetSector (iSector *s)
00388 { scfParent->SetSector (s->GetPrivateObject ()); }
00389
00390 virtual void Correct (int n)
00391 {
00392 scfParent->Correct (n);
00393 }
00394 virtual bool IsMirrored () const
00395 {
00396 return scfParent->IsMirrored ();
00397 }
00398 virtual void SetMirrored (bool m)
00399 {
00400 scfParent->SetMirrored (m);
00401 }
00402 virtual bool GetFarPlane (csPlane3& pl) const
00403 {
00404 if (scfParent->fp)
00405 {
00406 pl = *scfParent->fp;
00407 return scfParent->use_farplane;
00408 }
00409 else
00410 return false;
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__