openscenegraph
ClusterCullingCallback
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_CLUSTERCULLINGCALLBACK
15#define OSG_CLUSTERCULLINGCALLBACK 1
16
17#include <osg/Drawable>
18#include <osg/Callback>
19
20namespace osg {
21
22/** @class ClusterCullingCallback
23 @brief Implements cluster culling to cull back facing subgraphs and drawables. Derived from Drawable::CullCallback and osg::NodeCallback.
24
25 This culling callback is intended to be attached to a node using the setCullCallback method. If the
26 node is a drawable cull(osg::NodeVisitor*, osg::Drawable*, osg::State*) otherwise
27 operator()(Node*, NodeVisitor*) will be called during the cull traversal.
28
29 To decide whether the node (in case of a drawable) or its children (in case of any other node type) are
30 to be culled depends on four parameters:
31 - a control point,
32 - a normal specified at the control point,
33 - a deviation value representing the cosinus of an enclosed angle and
34 - a radius describing a sphere around the control point.
35
36 The node is culled if the following two conditions are fulfilled:
37 - the distance between the current eye/view point to the control point is larger or equal to radius,
38 - the cosinus of the enclosed angle between the normal and the vector from the control point to the eye/view point
39 is smaller(!) than the specified deviation value (normally this value is negative meaning that the enclosed angle
40 between the control point and the eye/view point is larger than the angle indirectly specified by the
41 deviation value).
42
43 @remark As the deviation is representing the cosine of an enclosed angle its value should be within the
44 the interval [-1; 1]. A value of one will cull all nodes while a value of -1 will never cull a node.
45 The deviation will normally have negative values because then the enclosed angle between the normal and the
46 eye/view point is larger than 90 degrees (and therefore the eye sees the "back" from the control point).
47*/
48class OSG_EXPORT ClusterCullingCallback : public DrawableCullCallback, public NodeCallback
49{
50 public:
51
52 ClusterCullingCallback();
53 ClusterCullingCallback(const ClusterCullingCallback& ccc,const CopyOp& copyop);
54 ClusterCullingCallback(const osg::Vec3& controlPoint, const osg::Vec3& normal, float deviation, float radius=-1.0f);
55 ClusterCullingCallback(const osg::Drawable* drawable);
56
57 META_Object(osg,ClusterCullingCallback);
58
59 virtual NodeCallback* asNodeCallback() { return osg::NodeCallback::asNodeCallback(); }
60 virtual const NodeCallback* asNodeCallback() const { return osg::NodeCallback::asNodeCallback(); }
61
62 virtual DrawableCullCallback* asDrawableCullCallback() { return osg::DrawableCullCallback::asDrawableCullCallback(); }
63 virtual const DrawableCullCallback* asDrawableCullCallback() const { return osg::DrawableCullCallback::asDrawableCullCallback(); }
64
65 // use the NodeCallbacks implementation of run.
66 virtual bool run(osg::Object* object, osg::Object* data) { return NodeCallback::run(object, data); }
67
68 /** Computes the control point, normal, and deviation from the
69 * given drawable contents. */
70 void computeFrom(const osg::Drawable* drawable);
71
72 /** Transform the ClusterCullingCallback's positional members to a new coordinate frame.*/
73 void transform(const osg::Matrixd& matrix);
74
75 void set(const osg::Vec3& controlPoint, const osg::Vec3& normal, float deviation, float radius);
76
77 void setControlPoint(const osg::Vec3& controlPoint) { _controlPoint = controlPoint; }
78 const osg::Vec3& getControlPoint() const { return _controlPoint; }
79
80 void setNormal(const osg::Vec3& normal) { _normal = normal; }
81 const osg::Vec3& getNormal() const { return _normal; }
82
83 void setRadius(float radius) { _radius = radius; }
84 float getRadius() const { return _radius; }
85
86 void setDeviation(float deviation) { _deviation = deviation; }
87 float getDeviation() const { return _deviation; }
88
89 virtual bool cull(osg::NodeVisitor*, osg::Drawable*, osg::State*) const;
90
91 /** Callback method called by the NodeVisitor when visiting a node.*/
92 virtual void operator()(Node* node, NodeVisitor* nv);
93
94 protected:
95
96 virtual ~ClusterCullingCallback() {}
97
98 osg::Vec3 _controlPoint;
99 osg::Vec3 _normal;
100 float _radius;
101 float _deviation;
102};
103
104
105}
106
107#endif