Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

Workspace.h

00001 #ifndef WORKSPACE_H
00002 #define WORKSPACE_H
00003 
00004 /* The workspace models the physical obstacles in the world. */
00005 /* This particular workspace is 3D and polygonal. */
00006 
00007 #include <vector>
00008 #include <list>
00009 
00010 #include "prefix.h"
00011 #include "bsp.h"
00012 #include "io.h"
00013 #include "camera.h"
00014 #include "file.h"
00015 #include <stdio.h>
00016 #include "opengl.h"
00017 
00018 
00019 #define DEFAULT_OPACITY 0.6
00020 
00021 
00022 /* instead of including */
00023 class ConStruct;
00024 class Simulation;
00025 
00026 class Workspace
00027 {
00028 public:
00029   /* construction from a configuration structure */
00030   Workspace (const ConStruct &cfg);
00031 
00032   /* destructor */
00033   ~Workspace ();
00034 
00035   /*************** stuff for graphic/IO **************/
00036 
00037   static void render_normal(BSP::Node *n);
00038   static void render_wireframe(BSP::Node *n);
00039   
00040   /* renders the workspace */
00041   void Render (const Simulation *settings);
00042 
00043   //add a point of interest in the workspace
00044   //to be rendered
00045   static void AddDebugPoint(const Vector& pt, const double red, const double green, const double blue);
00046 
00047   //since workspace has several cameras, get active one
00048   const Camera* GetActiveCamera() const;
00049 
00050   /* handles key presses, mouse movement, etc */
00051   void KeyPress (IO_Window *win, const IO_Key &k);
00052   void Update (IO_Window *win, Simulation* sim);
00053 
00054   /****************** intersections ********************/
00055 
00056   /* intersection testing... */
00057   void PillIntersection
00058    (Intersection *ir, LineContext *lc_array, const Vector &p1, const Vector &p2, double radius) const
00059     {
00060       bsp->PillIntersection (ir, lc_array, p1, p2, radius);
00061     }
00062   void SphereIntersection
00063    (Intersection *ir, PointContext *pc_array, const Vector &p, double radius) const
00064     {
00065       bsp->SphereIntersection (ir, pc_array, p, radius);
00066     }
00067   void RayIntersection
00068    (Intersection *ir, const Vector& p, const Vector& direction) const
00069     {
00070       bsp->RayIntersection (ir, p, direction);
00071     }
00072   void InvRayIntersection
00073    (Intersection *ir, const Vector& p, const Vector& direction) const
00074     {
00075       bsp->InvRayIntersection (ir, p, direction);
00076     }
00077   void LineIntersection
00078    (Intersection *ir, const Vector& p1, const Vector& p2) const
00079     {
00080       bsp->LineIntersection (ir, p1, p2);
00081     }
00082   void InvLineIntersection
00083    (Intersection *ir, const Vector& p1, const Vector& p2) const
00084     {
00085       bsp->InvLineIntersection (ir, p1, p2);
00086     }
00087   void PointIntersection
00088    (Intersection *ir, const Vector& p) const
00089     {
00090       bsp->PointIntersection (ir, p);
00091     }
00092   /* builds a list of obstacles that a ray intersects, sorted by distance
00093      (the first element in the list is closest) */
00094   void AllRayIntersections
00095    (std::list<const ObstacleSet::Solid *> *obs, const Vector& p, const Vector& direction) const
00096     {
00097       bsp->AllRayIntersections (obs, p, direction);
00098     }
00099   /* distance testing... */
00100   void PointDistance
00101    (PointContext **pc, PointContext *pc_array, const Vector& p) const
00102     {
00103       bsp->PointDistance (pc, pc_array, p);
00104     }
00105   void LineDistance
00106    (LineContext **lc, LineContext *lc_array, const Vector& p1, 
00107     const Vector& p2) const
00108     {
00109       bsp->LineDistance (lc, lc_array, p1, p2);
00110     }
00111 
00112   /* The following functions access the workspace according to
00113      individual obstacles... */
00114   /* The BSP needs to use this stuff, but you shouldn't... */
00115 
00116   /* Get the number of obstacles in the workspace.  */
00117   inline int NumSolids (void) const { return obset->num_solids(); };
00118 
00119   /* Individual obstacles in the world can be accessed by indices, so
00120      you can use these functions to do distance and intersection
00121      testing against individual obstacles.  */
00122   void ObstaclePillIntersection
00123    (Intersection* ir, const Vector &p1, const Vector& p2, double radius,
00124     LineContext* lc) const;
00125   void ObstacleSphereIntersection
00126    (Intersection* ir, const Vector &p, double radius, PointContext* c) const;
00127 
00128   /* gravity accessor */
00129   const Vector& getGravity() { return gravity; }
00130 
00131   void ToggleVisibility(ObstacleSet::Solid* solid){
00132     solid->toggle_visibility();
00133   }
00134 
00135   /* obstacles */
00136   ObstacleSet* obset;
00137 
00138 private:
00139   /* the file handle for this workspace */
00140   File file;
00141 
00142   /* the direction and magnitude of gravity */
00143   Vector gravity;
00144 
00145   /* Binary Space Partitioning tree */
00146   BSP* bsp;
00147 
00148   /**** camera stuff ****/
00149 
00150   /* write camera presets to file */
00151   void write_cameras (void);
00152 
00153   /* associated camera */
00154   Camera camera;
00155 
00156   /* preset camera positions */
00157   struct preset_camera
00158   {
00159     Vector p, f, u;
00160   };
00161   std::vector<preset_camera> cameras;
00162   int active_camera;
00163 
00164   /**** some extra junk for debugging and graphics ****/
00165 
00166   /* OpenGL texture environment */
00167   std::vector <Texture> textures;
00168 
00169   /* which object is highlighted */
00170   const ObstacleSet::Solid* highlighted;
00171   
00172   struct DebugPoint{
00173     Vector pt;
00174     double color[3];
00175   };
00176     
00177   static std::vector<DebugPoint> debug_pts;
00178 };
00179 #endif

Generated on Fri Jan 12 14:15:02 2007 for Construct by  doxygen 1.4.3-20050530