2005-04-15 05:41:28 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
2005-01-27 21:15:21 +08:00
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
2003-01-22 00:45:36 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2005-01-27 21:15:21 +08:00
|
|
|
*
|
2003-01-22 00:45:36 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2005-01-27 21:15:21 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2003-01-22 00:45:36 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2002-10-30 21:27:15 +08:00
|
|
|
|
2002-11-06 18:46:34 +08:00
|
|
|
#ifndef OSG_SHAPEDRAWABLE
|
|
|
|
#define OSG_SHAPEDRAWABLE 1
|
2002-10-30 21:27:15 +08:00
|
|
|
|
|
|
|
#include <osg/Drawable>
|
|
|
|
#include <osg/Vec2>
|
|
|
|
#include <osg/Vec3>
|
|
|
|
#include <osg/Vec4>
|
|
|
|
#include <osg/Array>
|
|
|
|
#include <osg/PrimitiveSet>
|
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
/** Describe several hints that can be passed to a tesselator (like the one used
|
|
|
|
* by \c ShapeDrawable) as a mean to try to influence the way it works.
|
|
|
|
*/
|
2002-10-30 21:27:15 +08:00
|
|
|
class TessellationHints : public Object
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
TessellationHints():
|
|
|
|
_TessellationMode(USE_SHAPE_DEFAULTS),
|
|
|
|
_detailRatio(1.0f),
|
|
|
|
_targetNumFaces(100),
|
|
|
|
_createFrontFace(true),
|
|
|
|
_createBackFace(false),
|
|
|
|
_createNormals(true),
|
|
|
|
_createTextureCoords(false),
|
|
|
|
_createTop(true),
|
|
|
|
_createBody(true),
|
|
|
|
_createBottom(true) {}
|
|
|
|
|
|
|
|
|
|
|
|
TessellationHints(const TessellationHints& tess, const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
|
|
|
Object(tess,copyop),
|
|
|
|
_TessellationMode(tess._TessellationMode),
|
2003-06-25 05:57:13 +08:00
|
|
|
_detailRatio(tess._detailRatio),
|
2005-01-27 21:15:21 +08:00
|
|
|
_targetNumFaces(tess._targetNumFaces),
|
|
|
|
_createFrontFace(tess._createFrontFace),
|
|
|
|
_createBackFace(tess._createBackFace),
|
|
|
|
_createNormals(tess._createNormals),
|
|
|
|
_createTextureCoords(tess._createTextureCoords),
|
|
|
|
_createTop(tess._createTop),
|
|
|
|
_createBody(tess._createBody),
|
|
|
|
_createBottom(tess._createBottom) {}
|
|
|
|
|
|
|
|
META_Object(osg,TessellationHints);
|
|
|
|
|
|
|
|
|
|
|
|
enum TessellationMode
|
|
|
|
{
|
|
|
|
USE_SHAPE_DEFAULTS,
|
2006-01-17 01:03:34 +08:00
|
|
|
USE_TARGET_NUM_FACES
|
2005-01-27 21:15:21 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
inline void setTessellationMode(TessellationMode mode) { _TessellationMode=mode; }
|
|
|
|
inline TessellationMode getTessellationMode() const { return _TessellationMode; }
|
2002-10-30 21:27:15 +08:00
|
|
|
|
2003-06-25 05:57:13 +08:00
|
|
|
inline void setDetailRatio(float ratio) { _detailRatio = ratio; }
|
|
|
|
inline float getDetailRatio() const { return _detailRatio; }
|
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
inline void setTargetNumFaces(unsigned int target) { _targetNumFaces=target; }
|
|
|
|
inline unsigned int getTargetNumFaces() const { return _targetNumFaces; }
|
2002-10-30 21:27:15 +08:00
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
inline void setCreateFrontFace(bool on) { _createFrontFace=on; }
|
|
|
|
inline bool getCreateFrontFace() const { return _createFrontFace; }
|
2002-10-30 21:27:15 +08:00
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
inline void setCreateBackFace(bool on) { _createBackFace=on; }
|
|
|
|
inline bool getCreateBackFace() const { return _createBackFace; }
|
2002-10-30 21:27:15 +08:00
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
inline void setCreateNormals(bool on) { _createNormals=on; }
|
|
|
|
inline bool getCreateNormals() const { return _createNormals; }
|
2002-10-30 21:27:15 +08:00
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
inline void setCreateTextureCoords(bool on) { _createTextureCoords=on; }
|
|
|
|
inline bool getCreateTextureCoords() const { return _createTextureCoords; }
|
2002-10-30 21:27:15 +08:00
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
inline void setCreateTop(bool on) { _createTop=on; }
|
|
|
|
inline bool getCreateTop() const { return _createTop; }
|
2002-10-30 21:27:15 +08:00
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
inline void setCreateBody(bool on) { _createBody=on; }
|
|
|
|
inline bool getCreateBody() const { return _createBody; }
|
2002-10-30 21:27:15 +08:00
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
inline void setCreateBottom(bool on) { _createBottom=on; }
|
|
|
|
inline bool getCreateBottom() const { return _createBottom; }
|
2002-10-30 21:27:15 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
~TessellationHints() {}
|
|
|
|
|
|
|
|
|
|
|
|
TessellationMode _TessellationMode;
|
2003-06-25 05:57:13 +08:00
|
|
|
|
|
|
|
float _detailRatio;
|
2005-01-27 21:15:21 +08:00
|
|
|
unsigned int _targetNumFaces;
|
2002-10-30 21:27:15 +08:00
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
bool _createFrontFace;
|
|
|
|
bool _createBackFace;
|
|
|
|
bool _createNormals;
|
|
|
|
bool _createTextureCoords;
|
2002-10-30 21:27:15 +08:00
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
bool _createTop;
|
|
|
|
bool _createBody;
|
|
|
|
bool _createBottom;
|
2002-10-30 21:27:15 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
|
|
|
|
/** Allow the use of <tt>Shape</tt>s as <tt>Drawable</tt>s, so that they can
|
|
|
|
* be rendered with reduced effort. The implementation of \c ShapeDrawable is
|
|
|
|
* not geared to efficiency; it's better to think of it as a convenience to
|
|
|
|
* render <tt>Shape</tt>s easily (perhaps for test or debugging purposes) than
|
|
|
|
* as the right way to render basic shapes in some efficiency-critical section
|
|
|
|
* of code.
|
|
|
|
* @todo \c ShapeDrawable currently doesn't render <tt>InfinitePlane</tt>s.
|
|
|
|
*/
|
2005-04-12 01:14:17 +08:00
|
|
|
class OSG_EXPORT ShapeDrawable : public Drawable
|
2002-10-30 21:27:15 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2002-11-06 18:46:34 +08:00
|
|
|
ShapeDrawable();
|
2002-10-30 21:27:15 +08:00
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
ShapeDrawable(Shape* shape, TessellationHints* hints=0);
|
2002-10-30 21:27:15 +08:00
|
|
|
|
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
2002-11-06 18:46:34 +08:00
|
|
|
ShapeDrawable(const ShapeDrawable& pg,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
2005-01-27 21:15:21 +08:00
|
|
|
|
2002-12-16 21:40:58 +08:00
|
|
|
virtual Object* cloneType() const { return new ShapeDrawable(); }
|
2005-01-27 21:15:21 +08:00
|
|
|
virtual Object* clone(const CopyOp& copyop) const { return new ShapeDrawable(*this,copyop); }
|
2002-11-06 18:46:34 +08:00
|
|
|
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const ShapeDrawable*>(obj)!=NULL; }
|
2002-10-30 21:27:15 +08:00
|
|
|
virtual const char* libraryName() const { return "osg"; }
|
2002-11-06 18:46:34 +08:00
|
|
|
virtual const char* className() const { return "ShapeDrawable"; }
|
2002-10-30 21:27:15 +08:00
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
/** Set the color of the shape.*/
|
2005-10-02 03:27:52 +08:00
|
|
|
void setColor(const Vec4& color);
|
2005-01-27 21:15:21 +08:00
|
|
|
|
|
|
|
/** Get the color of the shape.*/
|
2003-04-17 04:02:15 +08:00
|
|
|
const Vec4& getColor() const { return _color; }
|
2002-10-30 21:27:15 +08:00
|
|
|
|
2005-10-02 03:27:52 +08:00
|
|
|
void setTessellationHints(TessellationHints* hints);
|
2002-10-30 21:27:15 +08:00
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
TessellationHints* getTessellationHints() { return _tessellationHints.get(); }
|
|
|
|
const TessellationHints* getTessellationHints() const { return _tessellationHints.get(); }
|
2002-10-30 21:27:15 +08:00
|
|
|
|
2003-04-17 04:02:15 +08:00
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
|
|
|
|
/** Draw ShapeDrawable directly ignoring an OpenGL display list which
|
|
|
|
* could be attached. This is the internal draw method which does the
|
|
|
|
* drawing itself, and is the method to override when deriving from
|
|
|
|
* ShapeDrawable for user-drawn objects.
|
|
|
|
*/
|
2002-11-06 23:43:11 +08:00
|
|
|
virtual void drawImplementation(State& state) const;
|
2002-10-30 21:27:15 +08:00
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
/** Return false, osg::ShapeDrawable does not support accept(AttributeFunctor&).*/
|
2005-05-16 19:18:11 +08:00
|
|
|
virtual bool supports(const AttributeFunctor&) const { return false; }
|
2002-11-06 18:24:33 +08:00
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
/** Return true, osg::ShapeDrawable does support accept(ConstAttributeFunctor&).*/
|
2005-05-16 19:18:11 +08:00
|
|
|
virtual bool supports(const ConstAttributeFunctor&) const { return true; }
|
2002-11-06 18:24:33 +08:00
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
/** Accept a ConstAttributeFunctor and call its methods to tell it about the interal attributes that this Drawable has.*/
|
2002-11-06 18:24:33 +08:00
|
|
|
virtual void accept(ConstAttributeFunctor& af) const;
|
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
/** Return true, osg::ShapeDrawable does support accept(PrimitiveFunctor&) .*/
|
2005-05-16 19:18:11 +08:00
|
|
|
virtual bool supports(const PrimitiveFunctor&) const { return true; }
|
2002-10-30 21:27:15 +08:00
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
/** Accept a PrimitiveFunctor and call its methods to tell it about the internal primitives that this Drawable has.*/
|
2002-11-06 18:24:33 +08:00
|
|
|
virtual void accept(PrimitiveFunctor& pf) const;
|
2002-10-30 21:27:15 +08:00
|
|
|
|
2005-05-12 22:03:22 +08:00
|
|
|
virtual BoundingBox computeBound() const;
|
|
|
|
|
2002-10-30 21:27:15 +08:00
|
|
|
protected:
|
|
|
|
|
2002-11-06 18:46:34 +08:00
|
|
|
ShapeDrawable& operator = (const ShapeDrawable&) { return *this;}
|
2002-10-30 21:27:15 +08:00
|
|
|
|
2002-11-06 18:46:34 +08:00
|
|
|
virtual ~ShapeDrawable();
|
2005-01-27 21:15:21 +08:00
|
|
|
|
2003-04-17 04:02:15 +08:00
|
|
|
Vec4 _color;
|
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
ref_ptr<TessellationHints> _tessellationHints;
|
2002-10-30 21:27:15 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|