OpenSceneGraph/include/osg/Object
Robert Osfield 6ed233d0d2 Added DataVariance enum and set/get fields to osg::Object to help identify
which objects have values that vary over the lifetime of the object (DYNAMIC)
and ones that do not vary (STATIC).  Removed the equivalent code in
osg::Transform, StateSet and StateAttribute, as these are now encompassed
by the new DataVariance field.

Removed MatrixMode enum from Matrix, and associated fields/parameters from
osg::Transfrom and osg::NodeVisitor, since MatrixMode was not providing
any useful functionality, but made the interface more complex (MatrixMode
was an experimental API)

Added ReferenceFrame field to osg::Transform which allows users to specify
transforms that are relative to their parents (the default, and previous behavior)
or absolute reference frame, which can be used for HUD's, camera relative
light sources etc etc.  Note, the view frustum culling for absolute Transform
are disabled, and all their parents up to the root are also automatically
have view frustum culling disabled.  However, once passed an absolute Transform
node culling will return to its default state of on, so you can still cull
underneath an absolute transform, its only the culling above which is disabled.
2002-04-11 23:20:23 +00:00

96 lines
3.6 KiB
Plaintext

//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
//Distributed under the terms of the GNU Library General Public License (LGPL)
//as published by the Free Software Foundation.
#ifndef OSG_OBJECT
#define OSG_OBJECT 1
#include <osg/Referenced>
#include <osg/CopyOp>
namespace osg {
/** META_Object macro define the standard clone, isSameKindAs and className methods.
* Use when subclassing from Object to make it more convinient to define
* the standard pure virtual clone, isSameKindAs and className methods
* which are required for all Object subclasses.*/
#define META_Object(T) \
virtual osg::Object* cloneType() const { return osgNew T (); } \
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return osgNew T (*this,copyop); } \
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const T *>(obj)!=NULL; } \
virtual const char* className() const { return #T; }
/** Base class/standard interface for objects which require IO support,
cloning and reference counting.
Based on GOF Composite, Prototype and Template Method patterns.
*/
class SG_EXPORT Object : public Referenced
{
public:
/** Construct an object. Note Object is a pure virtual base class
and therefore cannot be constructed on its own, only derived
classes which override the clone and className methods are
concrete classes and can be constructed.*/
inline Object():Referenced(),_dataVariance(DYNAMIC) {}
/** Copy constructor, optional CopyOp object can be used to control
* shallow vs deep copying of dynamic data.*/
Object(const Object&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
/** Clone the type of an object, with Object* return type.
Must be defined by derived classes.*/
virtual Object* cloneType() const = 0;
/** Clone the an object, with Object* return type.
Must be defined by derived classes.*/
virtual Object* clone(const CopyOp&) const = 0;
virtual bool isSameKindAs(const Object*) const { return true; }
/** return the name of the object's class type. Must be defined
by derived classes.*/
virtual const char* className() const = 0;
enum DataVariance
{
DYNAMIC,
STATIC
};
/** Set the data variance of this object.
* Can be set to either STATIC for values that do not change over the lifetime of the object,
* or DYNAMIC for values that vary over the lifetime of the object. The DataVariance value
* can be used be routines such as optimzation codes that wish to share static data.*/
inline void setDataVariance(const DataVariance dv) { _dataVariance = dv; }
/** Get the data variance of this object.*/
inline const DataVariance getDataVariance() const { return _dataVariance; }
protected:
/** Object destructor. Note, is protected so that Objects cannot
be deleted other than by being dereferenced and the reference
count being zero (see osg::Referenced), preventing the deletion
of nodes which are still in use. This also means that
Node's cannot be created on stack i.e Node node will not compile,
forcing all nodes to be created on the heap i.e Node* node
= new Node().*/
virtual ~Object() {}
DataVariance _dataVariance;
private:
/** disallow any copy operator.*/
Object& operator = (const Object&) { return *this; }
};
}
#endif