Changeset 13041 for OpenSceneGraph/trunk/src/osg/ShapeDrawable.cpp
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/src/osg/ShapeDrawable.cpp (modified) (25 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osg/ShapeDrawable.cpp
r12597 r13041 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 */ … … 30 30 { 31 31 public: 32 32 33 33 DrawShapeVisitor(State& state,const TessellationHints* hints): 34 34 _state(state), … … 40 40 OSG_NOTICE<<"Warning: TessellationHints ignored in present osg::ShapeDrawable implementation."<<std::endl; 41 41 } 42 #endif 42 #endif 43 43 } 44 44 45 45 virtual void apply(const Sphere&); 46 46 virtual void apply(const Box&); … … 58 58 State& _state; 59 59 const TessellationHints* _hints; 60 60 61 61 protected: 62 62 … … 64 64 65 65 enum SphereHalf { SphereTopHalf, SphereBottomHalf }; 66 66 67 67 // helpers for apply( Cylinder | Sphere | Capsule ) 68 68 void drawCylinderBody(unsigned int numSegments, float radius, float height); … … 75 75 const float angleDelta = 2.0f*osg::PI/(float)numSegments; 76 76 const float texCoordDelta = 1.0f/(float)numSegments; 77 77 78 78 const float r = radius; 79 79 const float h = height; 80 80 81 81 float basez = -h*0.5f; 82 82 float topz = h*0.5f; 83 83 84 84 float angle = 0.0f; 85 85 float texCoord = 0.0f; 86 86 87 87 bool drawFrontFace = _hints ? _hints->getCreateFrontFace() : true; 88 88 bool drawBackFace = _hints ? _hints->getCreateBackFace() : false; 89 89 90 90 // The only difference between the font & back face loops is that the 91 91 // normals are inverted and the order of the vertex pairs is reversed. 92 // The code is mostly duplicated in order to hoist the back/front face 92 // The code is mostly duplicated in order to hoist the back/front face 93 93 // test out of the loop for efficiency 94 94 … … 105 105 float c = cosf(angle); 106 106 float s = sinf(angle); 107 107 108 108 gl.Normal3f(c,s,0.0f); 109 109 110 110 gl.TexCoord2f(texCoord,1.0f); 111 111 gl.Vertex3f(c*r,s*r,topz); 112 112 113 113 gl.TexCoord2f(texCoord,0.0f); 114 114 gl.Vertex3f(c*r,s*r,basez); 115 115 } 116 116 117 117 // do last point by hand to ensure no round off errors. 118 118 gl.Normal3f(1.0f,0.0f,0.0f); 119 119 120 120 gl.TexCoord2f(1.0f,1.0f); 121 121 gl.Vertex3f(r,0.0f,topz); 122 122 123 123 gl.TexCoord2f(1.0f,0.0f); 124 124 gl.Vertex3f(r,0.0f,basez); 125 125 } 126 126 127 127 if (drawBackFace) { 128 128 for(unsigned int bodyi=0; … … 132 132 float c = cosf(angle); 133 133 float s = sinf(angle); 134 134 135 135 gl.Normal3f(-c,-s,0.0f); 136 136 137 137 gl.TexCoord2f(texCoord,0.0f); 138 138 gl.Vertex3f(c*r,s*r,basez); … … 141 141 gl.Vertex3f(c*r,s*r,topz); 142 142 } 143 143 144 144 // do last point by hand to ensure no round off errors. 145 145 gl.Normal3f(-1.0f,0.0f,0.0f); 146 146 147 147 gl.TexCoord2f(1.0f,0.0f); 148 148 gl.Vertex3f(r,0.0f,basez); 149 149 150 150 gl.TexCoord2f(1.0f,1.0f); 151 151 gl.Vertex3f(r,0.0f,topz); … … 198 198 // The only difference between the font & back face loops is that the 199 199 // normals are inverted and the order of the vertex pairs is reversed. 200 // The code is mostly duplicated in order to hoist the back/front face 200 // The code is mostly duplicated in order to hoist the back/front face 201 201 // test out of the loop for efficiency 202 202 203 203 if (drawFrontFace) { 204 204 for(unsigned int topi=0; topi<numSegments; 205 205 ++topi,angle+=angleDelta,texCoord+=texCoordHorzDelta) 206 206 { 207 207 208 208 float c = cosf(angle); 209 209 float s = sinf(angle); 210 210 211 211 gl.Normal3f(c*nRatioTop,s*nRatioTop,nzTop); 212 212 213 213 gl.TexCoord2f(texCoord,vTop); 214 214 gl.Vertex3f(c*rTop,s*rTop,zTop+zOffset); 215 215 216 216 gl.Normal3f(c*nRatioBase,s*nRatioBase,nzBase); 217 217 218 218 gl.TexCoord2f(texCoord,vBase); 219 219 gl.Vertex3f(c*rBase,s*rBase,zBase+zOffset); 220 220 221 221 } 222 222 223 223 // do last point by hand to ensure no round off errors. 224 224 gl.Normal3f(nRatioTop,0.0f,nzTop); 225 225 226 226 gl.TexCoord2f(1.0f,vTop); 227 227 gl.Vertex3f(rTop,0.0f,zTop+zOffset); 228 228 229 229 gl.Normal3f(nRatioBase,0.0f,nzBase); 230 230 231 231 gl.TexCoord2f(1.0f,vBase); 232 232 gl.Vertex3f(rBase,0.0f,zBase+zOffset); 233 233 } 234 234 235 235 if (drawBackFace) { 236 236 for(unsigned int topi=0; topi<numSegments; 237 237 ++topi,angle+=angleDelta,texCoord+=texCoordHorzDelta) 238 238 { 239 239 240 240 float c = cosf(angle); 241 241 float s = sinf(angle); 242 242 243 243 gl.Normal3f(-c*nRatioBase,-s*nRatioBase,-nzBase); 244 244 245 245 gl.TexCoord2f(texCoord,vBase); 246 246 gl.Vertex3f(c*rBase,s*rBase,zBase+zOffset); 247 247 248 248 gl.Normal3f(-c*nRatioTop,-s*nRatioTop,-nzTop); 249 249 250 250 gl.TexCoord2f(texCoord,vTop); 251 251 gl.Vertex3f(c*rTop,s*rTop,zTop+zOffset); 252 252 } 253 253 254 254 // do last point by hand to ensure no round off errors. 255 255 gl.Normal3f(-nRatioBase,0.0f,-nzBase); 256 256 257 257 gl.TexCoord2f(1.0f,vBase); 258 258 gl.Vertex3f(rBase,0.0f,zBase+zOffset); 259 259 260 260 gl.Normal3f(-nRatioTop,0.0f,-nzTop); 261 261 262 262 gl.TexCoord2f(1.0f,vTop); 263 263 gl.Vertex3f(rTop,0.0f,zTop+zOffset); 264 264 265 265 } 266 266 … … 725 725 726 726 // cylinder body 727 if (createBody) 727 if (createBody) 728 728 drawCylinderBody(numSegments, cylinder.getRadius(), cylinder.getHeight()); 729 729 … … 831 831 832 832 // capsule cylindrical body 833 if (createBody) 833 if (createBody) 834 834 drawCylinderBody(numSegments, capsule.getRadius(), capsule.getHeight()); 835 835 836 836 // capsule top cap 837 if (createTop) 837 if (createTop) 838 838 drawHalfSphere(numSegments, numRows, capsule.getRadius(), SphereTopHalf, capsule.getHeight()/2.0f); 839 839 840 840 // capsule bottom cap 841 if (createBottom) 841 if (createBottom) 842 842 drawHalfSphere(numSegments, numRows, capsule.getRadius(), SphereBottomHalf, -capsule.getHeight()/2.0f); 843 843 … … 856 856 const Vec3Array* vertices = mesh.getVertices(); 857 857 const IndexArray* indices = mesh.getIndices(); 858 858 859 859 if (vertices && indices) 860 860 { … … 1061 1061 { 1062 1062 public: 1063 1063 1064 1064 ComputeBoundShapeVisitor(BoundingBox& bb):_bb(bb) {} 1065 1065 … … 1237 1237 const Vec3Array* vertices = mesh.getVertices(); 1238 1238 const IndexArray* indices = mesh.getIndices(); 1239 1239 1240 1240 if (vertices && indices) 1241 1241 { … … 1328 1328 { 1329 1329 public: 1330 1330 1331 1331 PrimitiveShapeVisitor(PrimitiveFunctor& functor,const TessellationHints* hints): 1332 1332 _functor(functor), … … 1363 1363 { 1364 1364 const float angleDelta = 2.0f*osg::PI/(float)numSegments; 1365 1365 1366 1366 const float r = radius; 1367 1367 const float h = height; 1368 1368 1369 1369 float basez = -h*0.5f; 1370 1370 float topz = h*0.5f; 1371 1371 1372 1372 float angle = 0.0f; 1373 1373 1374 1374 _functor.begin(GL_QUAD_STRIP); 1375 1375 … … 1388 1388 _functor.vertex(osg::Vec3(r,0.0f,topz) * matrix); 1389 1389 _functor.vertex(osg::Vec3(r,0.0f,basez) * matrix); 1390 1390 1391 1391 _functor.end(); 1392 1392 } … … 1434 1434 1435 1435 } 1436 1436 1437 1437 // do last point by hand to ensure no round off errors. 1438 1438 _functor.vertex(osg::Vec3(rTop,0.0f,zTop+zOffset) * matrix); 1439 _functor.vertex(osg::Vec3(rBase,0.0f,zBase+zOffset) * matrix); 1439 _functor.vertex(osg::Vec3(rBase,0.0f,zBase+zOffset) * matrix); 1440 1440 1441 1441 _functor.end(); 1442 1443 1442 1443 1444 1444 lBase=lTop; 1445 1445 rBase=rTop; … … 1447 1447 vBase=vTop; 1448 1448 } 1449 1449 1450 1450 } 1451 1451 … … 1559 1559 Matrix matrix = box.computeRotationMatrix(); 1560 1560 matrix.setTrans(box.getCenter()); 1561 1561 1562 1562 base_1 = base_1*matrix; 1563 1563 base_2 = base_2*matrix; … … 1844 1844 const Vec3Array* vertices = mesh.getVertices(); 1845 1845 const IndexArray* indices = mesh.getIndices(); 1846 1846 1847 1847 if (vertices && indices) 1848 1848 { … … 1870 1870 { 1871 1871 if (field.getNumColumns()==0 || field.getNumRows()==0) return; 1872 1872 1873 1873 Matrix matrix = field.computeRotationMatrix(); 1874 1874 matrix.setTrans(field.getOrigin()); … … 1948 1948 void ShapeDrawable::setTessellationHints(TessellationHints* hints) 1949 1949 { 1950 if (_tessellationHints!=hints) 1951 { 1952 _tessellationHints = hints; 1950 if (_tessellationHints!=hints) 1951 { 1952 _tessellationHints = hints; 1953 1953 dirtyDisplayList(); 1954 1954 } … … 1963 1963 { 1964 1964 gl.Color4fv(_color.ptr()); 1965 1965 1966 1966 DrawShapeVisitor dsv(state,_tessellationHints.get()); 1967 1967 1968 1968 _shape->accept(dsv); 1969 1969 }
