~saiarcot895/ubuntu/trusty/openscenegraph/armhf-support

« back to all changes in this revision

Viewing changes to OpenSceneGraph/include/osgShadow/OccluderGeometry

  • Committer: Package Import Robot
  • Author(s): Dmitrijs Ledkovs
  • Date: 2013-11-12 02:21:14 UTC
  • mfrom: (31.1.3 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20131112022114-qaxfhdnhn88vnh10
Tags: 3.2.0~rc1-1ubuntu1
Fix deprecated url_feof.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 
 
1
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2
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 
 
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
5
 * (at your option) any later version.  The full license is in LICENSE file
6
6
 * included with this distribution, and on the openscenegraph.org website.
7
 
 * 
 
7
 *
8
8
 * This library is distributed in the hope that it will be useful,
9
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
 * OpenSceneGraph Public License for more details.
12
12
*/
13
13
 
29
29
/** OccluderGeometry provides a sepecialised geometry representation of objects in scene that occlude light and therefore cast shadows.
30
30
  * OccluderGeometry supports the computation of silhouette edges and shadow volume geometries, as well as use as geometry that one can rendering
31
31
  * into a shadow map or end caps for the ZP+ algorithm.  OccluderGeometry may be of the same resolution as an underlying geometry that it
32
 
  * represents, or can be of lower resolution and combine manager seperate geometries together into a single shadow casting object. 
 
32
  * represents, or can be of lower resolution and combine manager seperate geometries together into a single shadow casting object.
33
33
  * OccluderGeometry may be attached as UserData to Nodes or to Drawables.  */
34
34
class OSGSHADOW_EXPORT OccluderGeometry : public osg::Drawable
35
35
{
37
37
        OccluderGeometry();
38
38
 
39
39
        OccluderGeometry(const OccluderGeometry& oc, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
40
 
            
 
40
 
41
41
        virtual Object* cloneType() const { return new OccluderGeometry(); }
42
42
        virtual Object* clone(const osg::CopyOp& copyop) const { return new OccluderGeometry(*this,copyop); }
43
43
        virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const OccluderGeometry*>(obj)!=NULL; }
44
44
        virtual const char* libraryName() const { return "osgShadow"; }
45
45
        virtual const char* className() const { return "OccluderGeometry"; }
46
 
        
 
46
 
47
47
        /** Compute an occluder geometry containing all the geometry in specified subgraph.*/
48
48
        void computeOccluderGeometry(osg::Node* subgraph, osg::Matrix* matrix=0, float sampleRatio=1.0f);
49
 
        
 
49
 
50
50
        /** Compute an occluder geometry containing the geometry in specified drawable.*/
51
51
        void computeOccluderGeometry(osg::Drawable* drawable, osg::Matrix* matrix=0, float sampleRatio=1.0f);
52
 
        
 
52
 
53
53
 
54
54
        /** Compute ShadowVolumeGeometry. */
55
55
        void computeShadowVolumeGeometry(const osg::Vec4& lightpos, ShadowVolumeGeometry& svg) const;
56
56
 
57
 
        
 
57
 
58
58
        /** Set the bounding polytope of the OccluderGeometry.*/
59
59
        void setBoundingPolytope(const osg::Polytope& polytope) { _boundingPolytope = polytope; }
60
60
 
67
67
 
68
68
        /** Render the occluder geometry. */
69
69
        virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
70
 
        
 
70
 
71
71
        /** Compute the bounding box around occluder geometry.*/
72
72
        virtual osg::BoundingBox computeBound() const;
73
73
 
81
81
    protected :
82
82
 
83
83
        virtual ~OccluderGeometry() {}
84
 
        
 
84
 
85
85
        struct Edge
86
86
        {
87
87
            Edge():
103
103
                    _p2 = p1;
104
104
                }
105
105
            }
106
 
            
 
106
 
107
107
            inline bool operator < (const Edge& rhs) const
108
108
            {
109
109
                if (_p1 < rhs._p1) return true;
110
110
                if (_p1 > rhs._p1) return false;
111
111
                return (_p2 < rhs._p2);
112
112
            }
113
 
            
 
113
 
114
114
            bool addTriangle(unsigned int tri) const
115
115
            {
116
116
                if (_t1<0)
126
126
                // argg more than two triangles assigned
127
127
                return false;
128
128
            }
129
 
            
 
129
 
130
130
            bool boundaryEdge() const { return _t2<0; }
131
 
        
 
131
 
132
132
            unsigned int    _p1;
133
133
            unsigned int    _p2;
134
 
            
 
134
 
135
135
            mutable int     _t1;
136
136
            mutable int     _t2;
137
 
            
 
137
 
138
138
            mutable osg::Vec3   _normal;
139
139
        };
140
140
 
143
143
        inline bool isLightPointSilhouetteEdge(const osg::Vec3& lightpos, const Edge& edge) const
144
144
        {
145
145
            if (edge.boundaryEdge()) return true;
146
 
            
 
146
 
147
147
            float offset = 0.0f;
148
148
 
149
149
            osg::Vec3 delta(lightpos-_vertices[edge._p1]);
150
150
            delta.normalize();
151
 
            
 
151
 
152
152
            float n1 = delta * _triangleNormals[edge._t1] + offset;
153
153
            float n2 = delta * _triangleNormals[edge._t2] + offset;
154
154
 
158
158
            n2 = cos(acosf(n2) + angle_offset);
159
159
 
160
160
            if (n1==0.0f && n2==0.0f) return false;
161
 
            
162
 
            return n1*n2 <= 0.0f; 
 
161
 
 
162
            return n1*n2 <= 0.0f;
163
163
        }
164
164
 
165
165
        inline bool isLightDirectionSilhouetteEdge(const osg::Vec3& lightdirection, const Edge& edge) const
166
166
        {
167
167
            if (edge.boundaryEdge()) return true;
168
 
            
 
168
 
169
169
            float offset = 0.0f;
170
 
            
 
170
 
171
171
            float n1 = lightdirection * _triangleNormals[edge._t1] + offset;
172
172
            float n2 = lightdirection * _triangleNormals[edge._t2] + offset;
173
173
 
177
177
            n2 = cos(acosf(n2) + angle_offset);
178
178
 
179
179
            if (n1==0.0f && n2==0.0f) return false;
180
 
            
181
 
            return n1*n2 <= 0.0f; 
 
180
 
 
181
            return n1*n2 <= 0.0f;
182
182
        }
183
 
        
 
183
 
184
184
        void setUpInternalStructures();
185
 
        
 
185
 
186
186
        void removeDuplicateVertices();
187
187
        void removeNullTriangles();
188
188
        void computeNormals();
189
189
        void buildEdgeMaps();
190
 
        
 
190
 
191
191
        void computeLightDirectionSilhouetteEdges(const osg::Vec3& lightdirection, UIntList& silhouetteIndices) const;
192
192
        void computeLightPositionSilhouetteEdges(const osg::Vec3& lightpos, UIntList& silhouetteIndices) const;
193
193
 
197
197
        Vec3List _normals;
198
198
        Vec3List _triangleNormals;
199
199
        UIntList _triangleIndices;
200
 
        
 
200
 
201
201
        EdgeList _edges;
202
202
};
203
203
 
207
207
        ShadowVolumeGeometry();
208
208
 
209
209
        ShadowVolumeGeometry(const ShadowVolumeGeometry& oc, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
210
 
            
 
210
 
211
211
        virtual Object* cloneType() const { return new ShadowVolumeGeometry(); }
212
212
        virtual Object* clone(const osg::CopyOp& copyop) const { return new ShadowVolumeGeometry(*this,copyop); }
213
213
        virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const ShadowVolumeGeometry*>(obj)!=NULL; }
220
220
            STENCIL_TWO_PASS,
221
221
            STENCIL_TWO_SIDED
222
222
        };
223
 
        
 
223
 
224
224
        void setDrawMode(DrawMode mode) { _drawMode = mode; }
225
225
        DrawMode getDrawMode() const { return _drawMode; }
226
226
 
227
227
        typedef std::vector<osg::Vec3> Vec3List;
228
228
        typedef std::vector<GLuint> UIntList;
229
 
        
 
229
 
230
230
        void setVertices(const Vec3List& vertices) { _vertices = vertices; }
231
231
        Vec3List& getVertices() { return _vertices; }
232
232
        const Vec3List& getVertices() const { return _vertices; }
233
 
        
 
233
 
234
234
        void setNormals(const Vec3List& normals) { _normals = normals; }
235
235
        Vec3List& getNormals() { return _normals; }
236
236
        const Vec3List& getNormals() const { return _normals; }
237
 
        
 
237
 
238
238
 
239
239
        /** Render the occluder geometry. */
240
240
        virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
241
 
        
 
241
 
242
242
        /** Compute the bounding box around occluder geometry.*/
243
243
        virtual osg::BoundingBox computeBound() const;
244
244