ShapeDrawable 2.8 KB

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