00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef ARCHON_RENDER_VIEW_H
00021 #define ARCHON_RENDER_VIEW_H
00022
00023 #include <archon/math/vector.H>
00024
00025 #include <archon/util/ref.H>
00026
00027 namespace Archon
00028 {
00029 namespace Render
00030 {
00031 using namespace std;
00032 using namespace Math;
00033 using namespace Utilities;
00034
00042 struct Renderer: RefObjectBase
00043 {
00053 virtual void initOpenGlContext() = 0;
00054
00061 virtual void render() = 0;
00062 };
00063
00064
00065 struct Viewport;
00066 struct Screen;
00067 struct Eye;
00068 struct Clip;
00069 struct Channel;
00070 struct Pipe;
00071
00072 struct View: RefObjectBase
00073 {
00074 static Ref<View> create(Ref<Renderer> r)
00075 {
00076 return new View(r);
00077 }
00078
00079 private:
00080 View(Ref<Renderer> r): renderer(r) {}
00081
00082 friend struct Viewport;
00083 friend struct Screen;
00084 friend struct Eye;
00085 friend struct Clip;
00086 friend struct Channel;
00087
00088 const Ref<Renderer> renderer;
00089 Mutex viewMutex;
00090 };
00091
00092
00093 struct Viewport: RefObjectBase
00094 {
00099 static Ref<Viewport> create(Ref<View> v) { return new Viewport(v); }
00100
00119 void set(double left, double bottom,
00120 double width, double height)
00121 {
00122 Mutex::Lock l(view->viewMutex);
00123 this->left = left;
00124 this->bottom = bottom;
00125 this->width = width;
00126 this->height = height;
00127 }
00128
00129 private:
00130 Viewport(Ref<View> v):
00131 view(v), left(0), bottom(0), width(1), height(1) {}
00132
00133 friend struct Channel;
00134 friend struct Pipe;
00135
00136 const Ref<View> view;
00137
00138 double left, bottom;
00139 double width, height;
00140 };
00141
00142
00143 struct Screen: RefObjectBase
00144 {
00151 static Ref<Screen> create(Ref<View> v) { return new Screen(v); }
00152
00175 void set(Vector3 center, Vector3 x, Vector3 y,
00176 double halfWidth, double halfHeight)
00177 {
00178 Mutex::Lock l(view->viewMutex);
00179 this->center = center;
00180 this->x = x;
00181 this->y = y;
00182 this->halfWidth = halfWidth;
00183 this->halfHeight = halfHeight;
00184 }
00185
00212 void set(double aspectRatio,
00213 double fieldOfView = M_PI/4,
00214 double distance = 1)
00215 {
00216 double w = distance * tan(fieldOfView/2);
00217 double h = w;
00218 if(aspectRatio > 1) w *= aspectRatio;
00219 else h /= aspectRatio;
00220
00221 set(Vector3(0, 0, -distance),
00222 Vector3(1, 0, 0), Vector3(0, 1, 0), w, h);
00223 }
00224
00225 private:
00226 Screen(Ref<View> v): view(v) { set(1, M_PI/4); }
00227
00228 friend struct Channel;
00229 friend struct Pipe;
00230
00231 const Ref<View> view;
00232
00233 Vector3 center;
00234 Vector3 x, y;
00235 double halfWidth, halfHeight;
00236 };
00237
00238
00239 struct Eye: RefObjectBase
00240 {
00245 static Ref<Eye> create(Ref<View> v) { return new Eye(v); }
00246
00255 void set(Vector3 position)
00256 {
00257 Mutex::Lock l(view->viewMutex);
00258 this->position = position;
00259 }
00260
00261 private:
00262 Eye(Ref<View> v): view(v), position(Vector3(0, 0, 0)) {}
00263
00264 friend struct Channel;
00265 friend struct Pipe;
00266
00267 const Ref<View> view;
00268
00269 Vector3 position;
00270 };
00271
00272
00273 struct Clip: RefObjectBase
00274 {
00279 static Ref<Clip> create(Ref<View> v) { return new Clip(v); }
00280
00292 void set(double near, double far)
00293 {
00294 Mutex::Lock l(view->viewMutex);
00295 this->near = near;
00296 this->far = far;
00297 }
00298
00299 private:
00300 Clip(Ref<View> v): view(v), near(0.2), far(200) {}
00301
00302 friend struct Channel;
00303 friend struct Pipe;
00304
00305 const Ref<View> view;
00306
00307 double near, far;
00308 };
00309 }
00310 }
00311
00312 #endif // ARCHON_RENDER_VIEW_H