00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef OST_SCENE_HH
00020 #define OST_SCENE_HH
00021
00022
00023
00024
00025
00026 #include <map>
00027 #include <stack>
00028 #include <vector>
00029
00030 #include <boost/shared_array.hpp>
00031
00032 #include <ost/gfx/module_config.hh>
00033 #include <ost/mol/transform.hh>
00034
00035 #include "color.hh"
00036 #include "gfx_object_fw.hh"
00037 #include "gfx_node_fw.hh"
00038 #include "gfx_node_visitor.hh"
00039 #include "selection.hh"
00040 #include "glwin_base.hh"
00041 #include "scene_observer.hh"
00042 #include "gfx_prim.hh"
00043 #include "gl_include.hh"
00044 #include "povray_fw.hh"
00045
00046 namespace ost { namespace gfx {
00047
00048 class InputEvent;
00049
00050 typedef std::vector<SceneObserver*> SceneObserverList;
00051
00052 struct Viewport {
00053 int bottom;
00054 int left;
00055 int width;
00056 int height;
00057 };
00058
00075 class DLLEXPORT_OST_GFX Scene {
00076 private:
00077
00078
00079
00080
00081 struct SceneViewStackEntry {
00082 mol::Transform transform;
00083 float fov;
00084 float znear,zfar;
00085 };
00086
00087 typedef std::stack<SceneViewStackEntry> SceneViewStack;
00088
00089 public:
00090 static Scene& Instance();
00091
00093 void SetFog(bool f);
00094
00096 void SetFogColor(const Color& c);
00097
00099 void SetShadow(bool f);
00100
00102 bool GetShadow();
00103
00105 void SetShadowQuality(int q);
00106
00108
00109
00110 float GetNear() const;
00111
00113 void SetNear(float n);
00114
00116 float GetFar() const;
00117
00119 void SetFar(float f);
00120
00122 void SetNearFar(float n, float f);
00123
00125 void SetFOV(float f);
00126
00127
00128 float GetFOV() const;
00129
00131 void SetFogNearOffset(float o);
00132
00134 float GetFogNearOffset() const;
00135
00137 void SetFogFarOffset(float o);
00138
00140 float GetFogFarOffset() const;
00141
00143 void SetFogOffsets(float no, float fo);
00144
00146 void Autoslab(bool fast=false, bool redraw=true);
00147
00148
00149 void AutoslabMax();
00150
00152 void AutoAutoslab(bool f);
00154
00156
00157
00158
00159
00160
00161
00162 void Stereo(unsigned int);
00163
00165 void SetStereoInverted(bool f);
00166
00168 void SetStereoEye(unsigned int);
00169
00171 void SetLightDir(const geom::Vec3& dir);
00173 void SetLightProp(const Color& amb, const Color& diff, const Color& spec);
00175 void SetLightProp(float amb, float diff, float spec);
00176
00178
00179
00180
00181 void SetSelectionMode(uint m);
00182 uint GetSelectionMode() const;
00183
00185
00186
00187 void Export(const String& fname, unsigned int w,
00188 unsigned int h, bool transparent=true);
00189
00191 void Export(const String& fname, bool transparent=true);
00192
00194 void ExportPov(const std::string& fname, const std::string& wdir=".");
00196
00197 void OnInput(const InputEvent& e);
00198
00200 void InitGL();
00201
00203 void Resize(int w, int h);
00204
00206 void Pick(int mx, int my, int mask);
00207
00208 float GetDefaultTextSize();
00209
00211 std::pair<GfxObjP, mol::AtomHandle> PickAtom(int mx, int my);
00212
00214 void RenderGL();
00215
00217 void RequestRedraw();
00218
00220 void StatusMessage(const String& s);
00221
00223 void SetViewport(int w, int h);
00224
00226 void SetBackground(const Color& c);
00227
00229 void SetCenter(const geom::Vec3& cen);
00230
00232 geom::Vec3 GetCenter() const;
00233
00235 void CenterOn(const String& s);
00236
00238 void CenterOn(const GfxObjP& s);
00239
00241 geom::Vec3 Project(const geom::Vec3& v, bool ignore_vp=false) const;
00242
00244 geom::Vec3 UnProject(const geom::Vec3& v, bool ignore_vp=false) const;
00245
00247 geom::AlignedCuboid GetBoundingBox(const mol::Transform& tf) const;
00248
00250 mol::Transform GetTransform() const;
00251
00253 void SetTransform(const mol::Transform& t);
00254
00256 geom::Mat4 GetRTC() const;
00257
00259 void SetRTC(const geom::Mat4& rtc);
00260
00262 void PushView();
00263
00265 void PopView();
00266
00268 void ResetProjection();
00269
00271 void Register(GLWinBase* win);
00273 void Unregister(GLWinBase* win);
00274
00276
00277
00278 void Add(const GfxNodeP& go, bool redraw=true);
00281 void Remove(const GfxNodeP& go);
00283 void Remove(const String& name);
00286 bool Rename(const String& old_name, const String& new_name);
00287
00289 GfxObjP operator[](const String& name);
00290
00292 void Apply(const InputEvent& ie, bool request_redraw=true);
00293
00295 void Apply(GfxNodeVisitor& v) const;
00296
00301 size_t GetNodeCount() const;
00302
00304 GfxNodeP GetRootNode() const;
00306
00308 void AttachObserver(SceneObserver* o);
00310 void DetachObserver(SceneObserver* o);
00311
00312 bool InOffscreenMode() const;
00313
00315 static void SetOffscreenMode();
00316
00318 void SetTestMode(bool t);
00319
00320 float ElapsedTime() const;
00321
00322 Viewport GetViewport() const;
00323
00324
00325 void ActivateShader(const String& name);
00326
00327 void SetBlur(uint n);
00328 void BlurSnapshot();
00329
00330 void RenderText(const TextPrim& t);
00331
00332 protected:
00333 friend class GfxObj;
00334 friend class GfxNode;
00335
00336
00337 friend class Entity;
00338
00339 void ObjectChanged(const String& name);
00340 void SelectionChanged(const String& name, const mol::EntityView& sel);
00341 void NodeTransformed(const GfxObjP& object);
00342 void NodeAdded(const GfxNodeP& node);
00343 void RenderModeChanged(const String& name);
00344
00345 private:
00346 template <typename ACTION>
00347 void NotifyObservers(const ACTION& action);
00348 Scene();
00349 Scene(const Scene&) {}
00350 Scene& operator=(const Scene&) {return *this;}
00351
00352 GLWinBase* win_;
00353
00354 mutable GfxNodeP root_node_;
00355 SceneObserverList observers_;
00356
00357 mol::Transform transform_;
00358
00359 float fov_;
00360 float znear_,zfar_;
00361 float fnear_,ffar_;
00362
00363 unsigned int vp_width_,vp_height_;
00364
00365 SceneViewStack scene_view_stack_;
00366
00367 float aspect_ratio_;
00368
00369 Color background_;
00370
00371 geom::Vec3 light_dir_;
00372 geom::Mat3 light_rot_;
00373 Color light_amb_;
00374 Color light_diff_;
00375 Color light_spec_;
00376
00377 bool axis_flag_;
00378 bool fog_flag_;
00379 Color fog_color_;
00380 bool shadow_flag_;
00381 int shadow_quality_;
00382 GLuint texture_id_;
00383 bool auto_autoslab_;
00384
00385 bool offscreen_flag_;
00386
00387 uint selection_mode_;
00388
00389 bool test_flag_;
00390 std::vector<unsigned char> tmp_tex_;
00391
00392 GLuint glyph_tex_id_;
00393 std::vector<geom::Vec2> glyph_map_;
00394 float def_text_size_;
00395
00396 uint blur_count_;
00397 std::vector<boost::shared_array<unsigned char> > blur_buffer_;
00398 GLuint glow_tex_;
00399 unsigned int stereo_;
00400 bool stereo_inverted_;
00401 unsigned int stereo_eye_;
00402 float stereo_eye_dist_,stereo_eye_offset_;
00403
00404 void set_near(float n);
00405 void set_far(float f);
00406 void update_fog();
00407 void prep_shadow_map();
00408 void flag_all_dirty();
00409 void prep_glyphs();
00410 void prep_blur();
00411 void stereo_projection(unsigned int view);
00412 void render_interlaced_stereo();
00413 void render_quad_buffered_stereo();
00414 void render_scene_with_glow();
00415 bool IsNameAvailable(String name);
00416 };
00417
00418 }}
00419
00420 #endif