Main Page   Class Hierarchy   Compound List   File List   Compound Members  

rview.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_RVIEW_H__
00020 #define __CS_RVIEW_H__
00021 
00022 #include "csgeom/math3d.h"
00023 #include "csgeom/frustum.h"
00024 #include "csengine/camera.h"
00025 #include "csutil/csvector.h"
00026 #include "iengine/rview.h"
00027 #include "iengine/engine.h"
00028 
00029 class csMatrix3;
00030 class csVector3;
00031 class csRenderView;
00032 struct csFog;
00033 struct iGraphics3D;
00034 struct iGraphics2D;
00035 struct iPolygon3D;
00036 struct iSector;
00037 struct iClipper2D;
00038 
00044 class csRenderView : public iRenderView
00045 {
00046 private:
00053   struct csRenderContextData
00054   {
00056     csRenderContextData* next;
00057 
00059     void* key;
00064     iBase* data;
00065   };
00066 
00068   csRenderContext* ctxt;
00069 
00071   iEngine* iengine;
00073   iGraphics3D* g3d;
00075   iGraphics2D* g2d;
00076 
00078   float leftx, rightx, topy, boty;
00080   csRenderContextFrustum* top_frustum;
00081 
00086   iDrawFuncCallback* callback;
00087 
00091   void DeleteRenderContextData (csRenderContext* rc);
00092 
00096   void UpdateFrustum (iClipper2D* clip, csRenderContextFrustum*
00097         frust);
00098 
00103   static void TestSphereFrustum (csRenderContextFrustum* frust,
00104         const csVector3& center, float radius, bool& inside, bool& outside);
00105 
00106 public:
00108   csRenderView ();
00110   csRenderView (iCamera* c);
00112   csRenderView (iCamera* c, iClipper2D* v, iGraphics3D* ig3d,
00113     iGraphics2D* ig2d);
00114 
00115   virtual ~csRenderView ();
00116 
00118   void SetEngine (iEngine* engine);
00120   void SetCamera (iCamera* camera);
00121 
00123   virtual void SetCallback (iDrawFuncCallback* cb)
00124   {
00125     if (cb) cb->IncRef ();
00126     if (callback) callback->DecRef ();
00127     callback = cb;
00128   }
00130   virtual iDrawFuncCallback* GetCallback ()
00131   {
00132     return callback;
00133   }
00134 
00136   virtual void CallCallback (int type, void* data)
00137   {
00138     callback->DrawFunc (this, type, data);
00139   }
00140 
00141   SCF_DECLARE_IBASE;
00142 
00144   virtual csRenderContext* GetRenderContext () { return ctxt; }
00145 
00153   virtual void CreateRenderContext ();
00154 
00160   virtual void RestoreRenderContext (csRenderContext* original);
00161 
00167   virtual iCamera* CreateNewCamera ();
00168 
00170   virtual iEngine* GetEngine () { return iengine; }
00172   virtual iGraphics2D* GetGraphics2D () { return g2d; }
00174   virtual iGraphics3D* GetGraphics3D () { return g3d; }
00176   virtual void SetFrustum (float lx, float rx, float ty, float by);
00178   virtual void GetFrustum (float& lx, float& rx, float& ty, float& by)
00179   {
00180     lx = leftx;
00181     rx = rightx;
00182     ty = topy;
00183     by = boty;
00184   }
00186   virtual csRenderContextFrustum* GetTopFrustum ()
00187   {
00188     return top_frustum;
00189   }
00190 
00191   //-----------------------------------------------------------------
00192   // The following functions operate on the current render context.
00193   //-----------------------------------------------------------------
00194 
00196   virtual iClipper2D* GetClipper () { return ctxt->iview; }
00198   virtual void SetClipper (iClipper2D* clip);
00199 
00206   virtual bool IsClipperRequired () { return ctxt->do_clip_frustum; }
00213   virtual bool GetClipPlane (csPlane3& pl)
00214   {
00215     pl = ctxt->clip_plane;
00216     return ctxt->do_clip_plane;
00217   }
00219   virtual csPlane3& GetClipPlane ()
00220   {
00221     return ctxt->clip_plane;
00222   }
00224   virtual void SetClipPlane (const csPlane3& p) { ctxt->clip_plane = p; }
00226   virtual void UseClipPlane (bool u) { ctxt->do_clip_plane = u; }
00228   virtual void UseClipFrustum (bool u) { ctxt->do_clip_frustum = u; }
00229 
00230 
00236   virtual csFogInfo* GetFirstFogInfo () { return ctxt->fog_info; }
00240   virtual void SetFirstFogInfo (csFogInfo* fi)
00241   {
00242     ctxt->fog_info = fi;
00243     ctxt->added_fog_info = true;
00244   }
00248   virtual bool AddedFogInfo () { return ctxt->added_fog_info; }
00252   virtual void ResetFogInfo () { ctxt->added_fog_info = false; }
00253 
00257   virtual iCamera* GetCamera () { return ctxt->icamera; }
00261   virtual void CalculateFogPolygon (G3DPolygonDP& poly);
00265   virtual void CalculateFogPolygon (G3DPolygonDPFX& poly);
00272   virtual void CalculateFogMesh (const csTransform& tr_o2c,
00273         G3DTriangleMesh& mesh);
00279   virtual bool TestBSphere (const csReversibleTransform& o2c,
00280         const csSphere& sphere);
00289   virtual bool ClipBSphere (const csReversibleTransform& o2c,
00290         const csSphere& sphere,
00291         int& clip_portal, int& clip_plane, int& clip_z_plane);
00299   virtual bool ClipBBox (const csBox2& sbox, const csBox3& cbox,
00300         int& clip_portal, int& clip_plane, int& clip_z_plane);
00301 
00305   virtual iSector* GetThisSector () { return ctxt->this_sector; }
00306 
00310   virtual void SetThisSector (iSector* s) { ctxt->this_sector = s; }
00311 
00315   virtual iSector* GetPreviousSector () { return ctxt->previous_sector; }
00316 
00320   virtual void SetPreviousSector (iSector* s) { ctxt->previous_sector = s; }
00321 
00323   virtual iPolygon3D* GetPortalPolygon () { return ctxt->portal_polygon; }
00325   virtual void SetPortalPolygon (iPolygon3D* por)
00326   { ctxt->portal_polygon = por; }
00327 
00331   virtual int GetRenderRecursionLevel () { return ctxt->draw_rec_level; }
00335   virtual void SetRenderRecursionLevel (int rec)
00336   {
00337     ctxt->draw_rec_level = rec;
00338   }
00339 
00343   virtual void AttachRenderContextData (void* key, iBase* data);
00347   virtual iBase* FindRenderContextData (void* key);
00352   virtual void DeleteRenderContextData (void* key);
00353 };
00354 
00355 #endif // __CS_RVIEW_H__

Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000