openscenegraph
ShapeDrawable
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/Geometry>
18
19namespace osg {
20
21
22/** Allow the use of <tt>Shape</tt>s as <tt>Drawable</tt>s, so that they can
23 * be rendered with reduced effort. The implementation of \c ShapeDrawable is
24 * not geared to efficiency; it's better to think of it as a convenience to
25 * render <tt>Shape</tt>s easily (perhaps for test or debugging purposes) than
26 * as the right way to render basic shapes in some efficiency-critical section
27 * of code.
28 */
29class OSG_EXPORT ShapeDrawable : public osg::Geometry
30{
31 public:
32
33 ShapeDrawable();
34
35 ShapeDrawable(Shape* shape, TessellationHints* hints=0);
36
37 template<class T> ShapeDrawable(const ref_ptr<T>& shape, TessellationHints* hints=0):
38 _tessellationHints(hints) { setShape(shape.get()); }
39
40 /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
41 ShapeDrawable(const ShapeDrawable& pg,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
42
43 virtual Object* cloneType() const { return new ShapeDrawable(); }
44 virtual Object* clone(const CopyOp& copyop) const { return new ShapeDrawable(*this,copyop); }
45 virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const ShapeDrawable*>(obj)!=NULL; }
46 virtual const char* libraryName() const { return "osg"; }
47 virtual const char* className() const { return "ShapeDrawable"; }
48
49 virtual void setShape(Shape* shape);
50
51 /** Set the color of the shape.*/
52 void setColor(const Vec4& color);
53
54 /** Get the color of the shape.*/
55 const Vec4& getColor() const { return _color; }
56
57 void setTessellationHints(TessellationHints* hints);
58
59 TessellationHints* getTessellationHints() { return _tessellationHints.get(); }
60 const TessellationHints* getTessellationHints() const { return _tessellationHints.get(); }
61
62 /** method to invoke to rebuild the geometry that renders the shape.*/
63 void build();
64
65 protected:
66
67 ShapeDrawable& operator = (const ShapeDrawable&) { return *this;}
68
69 virtual ~ShapeDrawable();
70
71 Vec4 _color;
72
73 ref_ptr<TessellationHints> _tessellationHints;
74
75};
76
77
78}
79
80#endif