1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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.
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.
14#ifndef OSG_SHAPEDRAWABLE
15#define OSG_SHAPEDRAWABLE 1
17#include <osg/Geometry>
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
29class OSG_EXPORT ShapeDrawable : public osg::Geometry
35 ShapeDrawable(Shape* shape, TessellationHints* hints=0);
37 template<class T> ShapeDrawable(const ref_ptr<T>& shape, TessellationHints* hints=0):
38 _tessellationHints(hints) { setShape(shape.get()); }
40 /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
41 ShapeDrawable(const ShapeDrawable& pg,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
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"; }
49 virtual void setShape(Shape* shape);
51 /** Set the color of the shape.*/
52 void setColor(const Vec4& color);
54 /** Get the color of the shape.*/
55 const Vec4& getColor() const { return _color; }
57 void setTessellationHints(TessellationHints* hints);
59 TessellationHints* getTessellationHints() { return _tessellationHints.get(); }
60 const TessellationHints* getTessellationHints() const { return _tessellationHints.get(); }
62 /** method to invoke to rebuild the geometry that renders the shape.*/
67 ShapeDrawable& operator = (const ShapeDrawable&) { return *this;}
69 virtual ~ShapeDrawable();
73 ref_ptr<TessellationHints> _tessellationHints;