ubit
u3d.hpp
1 /************************************************************************
2  *
3  * u3d.cpp: 3D Widgets
4  * Ubit GUI Toolkit - Version 6 - Matthieu Nottale, Eric Lecolinet
5  * (C) 2009 | Eric Lecolinet | TELECOM ParisTech | http://www.enst.fr/~elc/ubit
6  *
7  * ***********************************************************************
8  * COPYRIGHT NOTICE :
9  * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE
10  * IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
11  * YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU
12  * GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION;
13  * EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
14  * SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
15  * ***********************************************************************/
16 
17 #ifndef _u3d_hpp_
18 #define _u3d_hpp_ 1
19 #include <ubit/uattr.hpp>
20 #include <ubit/ubox.hpp>
21 #include <ubit/uctlmenu.hpp>
22 #include <ubit/uview.hpp>
23 namespace ubit {
24 
31  class U3Dcanvas: public UBox {
32  public:
33  UCLASS(U3Dcanvas)
34 
37 
38  virtual ~U3Dcanvas();
39 
40  static UStyle* createStyle();
41 
42  float getFovy() const {return fovy;}
43  float getAspect() const {return aspect;}
44  float getNear() const {return near;}
45  float getFar() const {return far;}
46 
47  void setFovy(float f) {fovy = f;}
48  void setAspect(float a) {aspect = a;}
49  void setNear(float n) {near = n;}
50  void setFar(float f) {far = f;}
51 
52  private:
53  friend class U3DcanvasView;
54  float fovy, aspect, near, far;
55  };
56 
57  inline U3Dcanvas& u3dcanvas(UArgs a = UArgs::none) {return *new U3Dcanvas(a);}
59 
60  /* ==================================================== ==== ======= */
73  class U3Dbox : public UBox {
74  public:
75  UCLASS(U3Dbox)
76 
79 
80  static UStyle* createStyle();
81 
82  U3Dpos& pos() {return *ppos;}
87  U3Dbox& setTrans(float x, float y, float z);
88  U3Dbox& setRot(float x_rot, float y_rot, float z_rot);
89  U3Dbox& translate(float delta_x, float delta_y, float delta_z);
90  U3Dbox& rotate(float delta_x_rot, float delta_y_rot, float delta_z_rot);
91 
92  protected:
93  uptr<U3Dpos> ppos;
94  };
95 
96  inline U3Dbox& u3dbox(UArgs a = UArgs::none) {return *new U3Dbox(a);}
98 
99  /* ==================================================== ==== ======= */
102  class U3Dwin : public U3Dbox {
103  public:
104  UCLASS(U3Dwin)
105 
108 
109  static UStyle* createStyle();
110 
111  protected:
112  virtual UBox& createTitleBar(const UStr& title);
113  };
114 
115  inline U3Dwin& u3dwin(UArgs a = UArgs::none) {return *new U3Dwin(a);}
117 
118  /* ==================================================== ==== ======= */
129  class U3Dpos : public UPos {
130  public:
131  UCLASS(U3Dpos)
132 
133  U3Dpos();
134 
135  U3Dpos(float x, float y, float z);
137 
138  float getZ() const {return z;}
139  float getXRot() const {return x_rot;}
140  float getYRot() const {return y_rot;}
141  float getZRot() const {return z_rot;}
142 
143  U3Dpos& setTrans(float x, float y, float z);
144  U3Dpos& setRot(float x_rot, float y_rot, float z_rot, bool update = true);
145  U3Dpos& translate(float delta_x, float delta_y, float delta_z);
146  U3Dpos& rotate(float delta_x_rot, float delta_y_rot, float delta_z_rot);
147 
148  virtual bool is3Dpos() const {return true;}
150 
151  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
152 
153  virtual void setImpl(float _x, float _y, bool upd);
154  virtual void setImpl(float _x, float _y, float _z, bool upd);
155  virtual void update();
156  virtual void putProp(UUpdateContext*, UElem&);
157 
158  private:
159  friend class UView;
160  friend class U3DcanvasView;
161  float z, x_rot, y_rot, z_rot;
162  };
163 
164  inline U3Dpos& u3dpos(float x, float y, float z) {return *new U3Dpos(x, y, z);}
166 
167  /* ==================================================== ===== ======= */
168  /* [Impl] U3Dcanvas' view.
169  *
170  * Mouse and paint coordinates are transformed by U3DcanvasView when passed
171  * to its children to make geometrical transformations transparent for them.
172  */
173  class U3DcanvasView: public UView {
174  public:
175  static UViewStyle style; // renderer
176  virtual UViewStyle* getViewStyle() {return &style;}
177 
178  U3DcanvasView(UBox* _box, UView* _parview, UHardwinImpl* hw) : UView(_box, _parview, hw) {}
179 
180  static UView* createView(UBox* box, UView* parv, UHardwinImpl* hw) {
181  return new U3DcanvasView(box, parv, hw);
182  }
183 
184  virtual void doUpdate(UUpdateContext&, URect r, URect clip, class UViewUpdate&);
185  virtual UView* findInChildren(UElem*, const UPoint& winpos,
186  const UUpdateContext&, UViewFind&);
187 
188  bool unproject(const U3Dpos* pos3d, const UPoint& winpos, UPoint& convpos);
189  };
190 
191 }
192 #endif
[Instable/OpenGL] 3D canvas: makes it possible to display children in 3D space.
Definition: u3d.hpp:31
Widget position.
Definition: uboxgeom.hpp:91
Definition: uviewImpl.hpp:92
virtual bool is3Dpos() const
returns true if this is a U3Dpos.
Definition: u3d.hpp:148
Box container.
Definition: ubox.hpp:64
2D Point.
Definition: ugeom.hpp:25
void update()
updates object graphics.
Definition: ubox.hpp:96
2D Rectangle.
Definition: ugeom.hpp:165
Definition: uviewImpl.hpp:141
lightweight general purpose container.
Definition: uelem.hpp:44
U3Dcanvas(UArgs a=UArgs::none)
creates a new 3D canvas;
Definition: u3d.cpp:281
[Instable/OpenGL] 3D position.
Definition: u3d.hpp:129
Smart Pointer for UObject instances (.
Definition: uobject.hpp:365
[Instable/OpenGL] 3D box: a box that can be orientated in 3D space.
Definition: u3d.hpp:73
U3Dpos & pos()
returns a reference to the 3D position of this 3D window.
Definition: u3d.hpp:82
Argument list (for passing arguments to constructor or add functions).
Definition: uargs.hpp:43
[Instable/OpenGL] 3D window: framed U3Dbox with a title.
Definition: u3d.hpp:102
Box View.
Definition: uview.hpp:65
Specifies the View Style of an UBox.
Definition: uview.hpp:42
Definition: uupdatecontext.hpp:32
Definition: u3d.hpp:173
Definition: uhardfont.hpp:31
static const UArgs none
the empty arglist.
Definition: uargs.hpp:45
Definition: uwinImpl.hpp:84
Compiled Object Style.
Definition: ustyle.hpp:44
Ubit String.
Definition: ustr.hpp:72