00001 #ifndef WORKSPACE_H
00002 #define WORKSPACE_H
00003
00004
00005
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
00023 class ConStruct;
00024 class Simulation;
00025
00026 class Workspace
00027 {
00028 public:
00029
00030 Workspace (const ConStruct &cfg);
00031
00032
00033 ~Workspace ();
00034
00035
00036
00037 static void render_normal(BSP::Node *n);
00038 static void render_wireframe(BSP::Node *n);
00039
00040
00041 void Render (const Simulation *settings);
00042
00043
00044
00045 static void AddDebugPoint(const Vector& pt, const double red, const double green, const double blue);
00046
00047
00048 const Camera* GetActiveCamera() const;
00049
00050
00051 void KeyPress (IO_Window *win, const IO_Key &k);
00052 void Update (IO_Window *win, Simulation* sim);
00053
00054
00055
00056
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
00093
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
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
00113
00114
00115
00116
00117 inline int NumSolids (void) const { return obset->num_solids(); };
00118
00119
00120
00121
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
00129 const Vector& getGravity() { return gravity; }
00130
00131 void ToggleVisibility(ObstacleSet::Solid* solid){
00132 solid->toggle_visibility();
00133 }
00134
00135
00136 ObstacleSet* obset;
00137
00138 private:
00139
00140 File file;
00141
00142
00143 Vector gravity;
00144
00145
00146 BSP* bsp;
00147
00148
00149
00150
00151 void write_cameras (void);
00152
00153
00154 Camera camera;
00155
00156
00157 struct preset_camera
00158 {
00159 Vector p, f, u;
00160 };
00161 std::vector<preset_camera> cameras;
00162 int active_camera;
00163
00164
00165
00166
00167 std::vector <Texture> textures;
00168
00169
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