OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ShapeDrawable.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version. The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * OpenSceneGraph Public License for more details.
12 */
13 
14 #ifndef OSG_SHAPEDRAWABLE
15 #define OSG_SHAPEDRAWABLE 1
16 
17 #include <osg/Drawable>
18 #include <osg/Vec2>
19 #include <osg/Vec3>
20 #include <osg/Vec4>
21 #include <osg/Array>
22 #include <osg/PrimitiveSet>
23 
24 namespace osg {
25 
29 class TessellationHints : public Object
30 {
31  public:
32 
35  _detailRatio(1.0f),
36  _targetNumFaces(100),
37  _createFrontFace(true),
38  _createBackFace(false),
39  _createNormals(true),
40  _createTextureCoords(false),
41  _createTop(true),
42  _createBody(true),
43  _createBottom(true) {}
44 
45 
47  Object(tess,copyop),
55  _createTop(tess._createTop),
58 
60 
61 
63  {
66  };
67 
70 
71  inline void setDetailRatio(float ratio) { _detailRatio = ratio; }
72  inline float getDetailRatio() const { return _detailRatio; }
73 
74  inline void setTargetNumFaces(unsigned int target) { _targetNumFaces=target; }
75  inline unsigned int getTargetNumFaces() const { return _targetNumFaces; }
76 
77  inline void setCreateFrontFace(bool on) { _createFrontFace=on; }
78  inline bool getCreateFrontFace() const { return _createFrontFace; }
79 
80  inline void setCreateBackFace(bool on) { _createBackFace=on; }
81  inline bool getCreateBackFace() const { return _createBackFace; }
82 
83  inline void setCreateNormals(bool on) { _createNormals=on; }
84  inline bool getCreateNormals() const { return _createNormals; }
85 
86  inline void setCreateTextureCoords(bool on) { _createTextureCoords=on; }
87  inline bool getCreateTextureCoords() const { return _createTextureCoords; }
88 
89  inline void setCreateTop(bool on) { _createTop=on; }
90  inline bool getCreateTop() const { return _createTop; }
91 
92  inline void setCreateBody(bool on) { _createBody=on; }
93  inline bool getCreateBody() const { return _createBody; }
94 
95  inline void setCreateBottom(bool on) { _createBottom=on; }
96  inline bool getCreateBottom() const { return _createBottom; }
97 
98  protected:
99 
101 
102 
104 
106  unsigned int _targetNumFaces;
107 
112 
116 
117 };
118 
119 
128 {
129  public:
130 
131  ShapeDrawable();
132 
133  ShapeDrawable(Shape* shape, TessellationHints* hints=0);
134 
136  ShapeDrawable(const ShapeDrawable& pg,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
137 
138  virtual Object* cloneType() const { return new ShapeDrawable(); }
139  virtual Object* clone(const CopyOp& copyop) const { return new ShapeDrawable(*this,copyop); }
140  virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const ShapeDrawable*>(obj)!=NULL; }
141  virtual const char* libraryName() const { return "osg"; }
142  virtual const char* className() const { return "ShapeDrawable"; }
143 
145  void setColor(const Vec4& color);
146 
148  const Vec4& getColor() const { return _color; }
149 
150  void setTessellationHints(TessellationHints* hints);
151 
152  TessellationHints* getTessellationHints() { return _tessellationHints.get(); }
153  const TessellationHints* getTessellationHints() const { return _tessellationHints.get(); }
154 
155 
156 
162  virtual void drawImplementation(RenderInfo& renderInfo) const;
163 
164  /* Not all virtual overloads of these methods are overridden in this class, so
165  bring the base class implementation in to avoid hiding the non-used ones. */
166  using Drawable::supports;
167  using Drawable::accept;
168 
170  virtual bool supports(const AttributeFunctor&) const { return false; }
171 
173  virtual bool supports(const Drawable::ConstAttributeFunctor&) const { return true; }
174 
176  virtual void accept(Drawable::ConstAttributeFunctor& af) const;
177 
179  virtual bool supports(const PrimitiveFunctor&) const { return true; }
180 
182  virtual void accept(PrimitiveFunctor& pf) const;
183 
184  virtual BoundingBox computeBoundingBox() const;
185 
186  protected:
187 
188  ShapeDrawable& operator = (const ShapeDrawable&) { return *this;}
189 
190  virtual ~ShapeDrawable();
191 
193 
195 
196 };
197 
198 
199 }
200 
201 #endif
#define OSG_EXPORT
Definition: Export.h:43
bool getCreateBody() const
Definition: ShapeDrawable.h:93
void setDetailRatio(float ratio)
Definition: ShapeDrawable.h:71
const TessellationHints * getTessellationHints() const
TessellationHints(const TessellationHints &tess, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
Definition: ShapeDrawable.h:46
#define NULL
Definition: Export.h:59
void setCreateNormals(bool on)
Definition: ShapeDrawable.h:83
bool getCreateFrontFace() const
Definition: ShapeDrawable.h:78
bool getCreateTextureCoords() const
Definition: ShapeDrawable.h:87
void setCreateTop(bool on)
Definition: ShapeDrawable.h:89
virtual Object * clone(const CopyOp &copyop) const
virtual Object * cloneType() const
void setTessellationMode(TessellationMode mode)
Definition: ShapeDrawable.h:68
void setCreateFrontFace(bool on)
Definition: ShapeDrawable.h:77
float getDetailRatio() const
Definition: ShapeDrawable.h:72
void setCreateBody(bool on)
Definition: ShapeDrawable.h:92
TessellationMode _TessellationMode
const Vec4 & getColor() const
void setCreateBackFace(bool on)
Definition: ShapeDrawable.h:80
void setTargetNumFaces(unsigned int target)
Definition: ShapeDrawable.h:74
virtual bool isSameKindAs(const Object *obj) const
virtual bool supports(const PrimitiveFunctor &) const
TessellationMode getTessellationMode() const
Definition: ShapeDrawable.h:69
bool getCreateNormals() const
Definition: ShapeDrawable.h:84
unsigned int _targetNumFaces
bool getCreateBackFace() const
Definition: ShapeDrawable.h:81
virtual void accept(AttributeFunctor &)
Definition: Drawable.h:441
void setCreateBottom(bool on)
Definition: ShapeDrawable.h:95
META_Object(osg, TessellationHints)
ref_ptr< TessellationHints > _tessellationHints
unsigned int getTargetNumFaces() const
Definition: ShapeDrawable.h:75
void setCreateTextureCoords(bool on)
Definition: ShapeDrawable.h:86
virtual const char * className() const
Definition: AlphaFunc.h:19
virtual bool supports(const Drawable::ConstAttributeFunctor &) const
bool getCreateTop() const
Definition: ShapeDrawable.h:90
virtual bool supports(const AttributeFunctor &) const
bool getCreateBottom() const
Definition: ShapeDrawable.h:96
TessellationHints * getTessellationHints()
virtual bool supports(const AttributeFunctor &) const
Definition: Drawable.h:436
virtual const char * libraryName() const