diff --git a/include/osg/Math b/include/osg/Math index 1ea7c0d51..fb63e8127 100644 --- a/include/osg/Math +++ b/include/osg/Math @@ -33,6 +33,12 @@ const double PI_4 = 0.78539816339744830962; const double LN_2 = 0.69314718055994530942; const double INVLN_2 = 1.0 / LN_2; +const float PIf = 3.14159265358979323846f; +const float PI_2f = 1.57079632679489661923f; +const float PI_4f = 0.78539816339744830962f; +const float LN_2f = 0.69314718055994530942f; +const float INVLN_2f = 1.0f / LN_2f; + template inline T absolute(T v) { return v<(T)0?-v:v; } diff --git a/src/osg/ShapeDrawable.cpp b/src/osg/ShapeDrawable.cpp index 39f5b68c3..9ebf4bd83 100644 --- a/src/osg/ShapeDrawable.cpp +++ b/src/osg/ShapeDrawable.cpp @@ -72,7 +72,7 @@ class DrawShapeVisitor : public ConstShapeVisitor void DrawShapeVisitor::drawCylinderBody(unsigned int numSegments, float radius, float height) { - const float angleDelta = 2.0f*osg::PI/(float)numSegments; + const float angleDelta = 2.0f*osg::PIf/(float)numSegments; const float texCoordDelta = 1.0f/(float)numSegments; const float r = radius; @@ -157,7 +157,7 @@ void DrawShapeVisitor::drawCylinderBody(unsigned int numSegments, float radius, void DrawShapeVisitor::drawHalfSphere(unsigned int numSegments, unsigned int numRows, float radius, SphereHalf which, float zOffset) { - float lDelta = osg::PI/(float)numRows; + float lDelta = osg::PIf/(float)numRows; float vDelta = 1.0f/(float)numRows; bool top = (which==SphereTopHalf); @@ -165,10 +165,10 @@ void DrawShapeVisitor::drawHalfSphere(unsigned int numSegments, unsigned int num bool drawFrontFace = _hints ? _hints->getCreateFrontFace() : true; bool drawBackFace = _hints ? _hints->getCreateBackFace() : false; - float angleDelta = osg::PI*2.0f/(float)numSegments; + float angleDelta = osg::PIf*2.0f/(float)numSegments; float texCoordHorzDelta = 1.0f/(float)numSegments; - float lBase=-osg::PI*0.5f + (top?(lDelta*(numRows/2)):0.0f); + float lBase=-osg::PIf*0.5f + (top?(lDelta*(numRows/2)):0.0f); float rBase=(top?(cosf(lBase)*radius):0.0f); float zBase=(top?(sinf(lBase)*radius):-radius); float vBase=(top?(vDelta*(numRows/2)):0.0f); @@ -300,15 +300,15 @@ void DrawShapeVisitor::apply(const Sphere& sphere) numSegments = MIN_NUM_SEGMENTS; } - float lDelta = osg::PI/(float)numRows; + float lDelta = osg::PIf/(float)numRows; float vDelta = 1.0f/(float)numRows; - float angleDelta = osg::PI*2.0f/(float)numSegments; + float angleDelta = osg::PIf*2.0f/(float)numSegments; float texCoordHorzDelta = 1.0f/(float)numSegments; if (drawBackFace) { - float lBase=-osg::PI*0.5f; + float lBase=-osg::PIf*0.5f; float rBase=0.0f; float zBase=-sphere.getRadius(); float vBase=0.0f; @@ -378,7 +378,7 @@ void DrawShapeVisitor::apply(const Sphere& sphere) if (drawFrontFace) { - float lBase=-osg::PI*0.5f; + float lBase=-osg::PIf*0.5f; float rBase=0.0f; float zBase=-sphere.getRadius(); float vBase=0.0f; @@ -610,7 +610,7 @@ void DrawShapeVisitor::apply(const Cone& cone) float normalRatio = 1.0f/(sqrtf(1.0f+normalz*normalz)); normalz *= normalRatio; - float angleDelta = 2.0f*osg::PI/(float)numSegments; + float angleDelta = 2.0f*osg::PIf/(float)numSegments; float texCoordHorzDelta = 1.0/(float)numSegments; float texCoordRowDelta = 1.0/(float)numRows; float hDelta = cone.getHeight()/(float)numRows; @@ -666,7 +666,7 @@ void DrawShapeVisitor::apply(const Cone& cone) if (createBottom) { gl.Begin(GL_TRIANGLE_FAN); - angle = osg::PI*2.0f; + angle = osg::PIf*2.0f; texCoord = 1.0f; basez = cone.getBaseOffset(); @@ -725,7 +725,7 @@ void DrawShapeVisitor::apply(const Cylinder& cylinder) if (createBody) drawCylinderBody(numSegments, cylinder.getRadius(), cylinder.getHeight()); - float angleDelta = 2.0f*osg::PI/(float)numSegments; + float angleDelta = 2.0f*osg::PIf/(float)numSegments; float texCoordDelta = 1.0f/(float)numSegments; float r = cylinder.getRadius(); @@ -773,7 +773,7 @@ void DrawShapeVisitor::apply(const Cylinder& cylinder) gl.TexCoord2f(0.5f,0.5f); gl.Vertex3f(0.0f,0.0f,basez); - angle = osg::PI*2.0f; + angle = osg::PIf*2.0f; texCoord = 1.0f; for(unsigned int bottomi=0; bottomi