Add OSG_USE_FLOAT_QUAT build option to use single precision quaternions

This commit is contained in:
Capostrophic 2019-03-13 20:05:12 +03:00 committed by Robert Osfield
parent c548289ac1
commit 12b298130a
9 changed files with 28 additions and 5 deletions

View File

@ -431,6 +431,9 @@ MARK_AS_ADVANCED(OSG_USE_FLOAT_BOUNDINGSPHERE)
OPTION(OSG_USE_FLOAT_BOUNDINGBOX "Set to ON to build OpenSceneGraph with float BoundingBox instead of double." ON) OPTION(OSG_USE_FLOAT_BOUNDINGBOX "Set to ON to build OpenSceneGraph with float BoundingBox instead of double." ON)
MARK_AS_ADVANCED(OSG_USE_FLOAT_BOUNDINGBOX) MARK_AS_ADVANCED(OSG_USE_FLOAT_BOUNDINGBOX)
OPTION(OSG_USE_FLOAT_QUAT "Set to ON to build OpenSceneGraph with float Quat instead of double." OFF)
MARK_AS_ADVANCED(OSG_USE_FLOAT_QUAT)
IF (WIN32) IF (WIN32)
OPTION(OSG_USE_UTF8_FILENAME "Set to ON to use a UTF8 locale for filenames instead of the default locale." OFF) OPTION(OSG_USE_UTF8_FILENAME "Set to ON to use a UTF8 locale for filenames instead of the default locale." OFF)
MARK_AS_ADVANCED(OSG_USE_UTF8_FILENAME) MARK_AS_ADVANCED(OSG_USE_UTF8_FILENAME)

View File

@ -17,6 +17,7 @@
#include <osg/Plane> #include <osg/Plane>
#include <osg/BoundingBox> #include <osg/BoundingBox>
#include <osg/BoundingSphere> #include <osg/BoundingSphere>
#include <osg/Quat>
#ifdef BUILD_CONTRIBUTORS #ifdef BUILD_CONTRIBUTORS
extern void printContributors(const std::string& changeLog, bool printNumEntries); extern void printContributors(const std::string& changeLog, bool printNumEntries);
@ -40,6 +41,7 @@ int main( int argc, char** argv)
arguments.getApplicationUsage()->addCommandLineOption("Plane::value_type", "Print the value of Plane::value_type"); arguments.getApplicationUsage()->addCommandLineOption("Plane::value_type", "Print the value of Plane::value_type");
arguments.getApplicationUsage()->addCommandLineOption("BoundingSphere::value_type", "Print the value of BoundingSphere::value_type"); arguments.getApplicationUsage()->addCommandLineOption("BoundingSphere::value_type", "Print the value of BoundingSphere::value_type");
arguments.getApplicationUsage()->addCommandLineOption("BoundingBox::value_type", "Print the value of BoundingBox::value_type"); arguments.getApplicationUsage()->addCommandLineOption("BoundingBox::value_type", "Print the value of BoundingBox::value_type");
arguments.getApplicationUsage()->addCommandLineOption("Quat::value_type", "Print the value of Quat::value_type");
#ifdef BUILD_CONTRIBUTORS #ifdef BUILD_CONTRIBUTORS
arguments.getApplicationUsage()->addCommandLineOption("-r <file> or --read <file>", "Read the ChangeLog to generate an estimated contributors list."); arguments.getApplicationUsage()->addCommandLineOption("-r <file> or --read <file>", "Read the ChangeLog to generate an estimated contributors list.");
@ -139,6 +141,12 @@ int main( int argc, char** argv)
return 0; return 0;
} }
if (arguments.read("Quat::value_type"))
{
cout << ((sizeof(osg::Quat::value_type) == 4) ? "float" : "double") << endl;
return 0;
}
cout << osgGetLibraryName() << " " << osgGetVersion() << endl << endl; cout << osgGetLibraryName() << " " << osgGetVersion() << endl << endl;
#ifdef BUILD_CONTRIBUTORS #ifdef BUILD_CONTRIBUTORS

View File

@ -32,7 +32,11 @@ class OSG_EXPORT Quat
public: public:
/** Data type of vector components.*/ /** Data type of vector components.*/
#ifdef OSG_USE_FLOAT_QUAT
typedef float value_type;
#else
typedef double value_type; typedef double value_type;
#endif
/** Number of vector components. */ /** Number of vector components. */
enum { num_components = 4 }; enum { num_components = 4 };

View File

@ -28,6 +28,7 @@
#cmakedefine OSG_USE_FLOAT_PLANE #cmakedefine OSG_USE_FLOAT_PLANE
#cmakedefine OSG_USE_FLOAT_BOUNDINGSPHERE #cmakedefine OSG_USE_FLOAT_BOUNDINGSPHERE
#cmakedefine OSG_USE_FLOAT_BOUNDINGBOX #cmakedefine OSG_USE_FLOAT_BOUNDINGBOX
#cmakedefine OSG_USE_FLOAT_QUAT
#cmakedefine OSG_USE_REF_PTR_IMPLICIT_OUTPUT_CONVERSION #cmakedefine OSG_USE_REF_PTR_IMPLICIT_OUTPUT_CONVERSION
#cmakedefine OSG_USE_REF_PTR_SAFE_DEREFERENCE #cmakedefine OSG_USE_REF_PTR_SAFE_DEREFERENCE
#cmakedefine OSG_USE_UTF8_FILENAME #cmakedefine OSG_USE_UTF8_FILENAME

View File

@ -187,7 +187,10 @@ InputStream& InputStream::operator>>( osg::Vec4d& v )
InputStream& InputStream::operator>>( osg::Quat& q ) InputStream& InputStream::operator>>( osg::Quat& q )
{ *this >> q.x() >> q.y() >> q.z() >> q.w(); return *this; } {
double x, y, z, w; *this >> x >> y >> z >> w;
q.set( x, y, z, w ); return *this;
}
InputStream& InputStream::operator>>( osg::Plane& p ) InputStream& InputStream::operator>>( osg::Plane& p )
{ {

View File

@ -172,7 +172,7 @@ OutputStream& OutputStream::operator<<( const osg::Vec4ui& v )
OutputStream& OutputStream::operator<<( const osg::Quat& q ) OutputStream& OutputStream::operator<<( const osg::Quat& q )
{ *this << q.x() << q.y() << q.z() << q.w(); return *this; } { *this << (double)q.x() << (double)q.y() << (double)q.z() << (double)q.w(); return *this; }
OutputStream& OutputStream::operator<<( const osg::Plane& p ) OutputStream& OutputStream::operator<<( const osg::Plane& p )
{ *this << (double)p[0] << (double)p[1] << (double)p[2] << (double)p[3]; return *this; } { *this << (double)p[0] << (double)p[1] << (double)p[2] << (double)p[3]; return *this; }

View File

@ -405,7 +405,7 @@ osg::Quat SpherePlaneProjector::getRotation(const osg::Vec3d& p1, bool p1OnSpher
osg::Quat rotation; osg::Quat rotation;
rotation.makeRotate(p1 - getSphere()->getCenter(), p2 - getSphere()->getCenter()); rotation.makeRotate(p1 - getSphere()->getCenter(), p2 - getSphere()->getCenter());
osg::Vec3d axis; double angle; osg::Vec3d axis; osg::Quat::value_type angle;
rotation.getRotate(angle, axis); rotation.getRotate(angle, axis);
osg::Vec3d realAxis; osg::Vec3d realAxis;

View File

@ -217,7 +217,11 @@ public:
qlhs.makeRotate(osg::DegreesToRadians(lhs[0]),lhs[1],lhs[2],lhs[3]); qlhs.makeRotate(osg::DegreesToRadians(lhs[0]),lhs[1],lhs[2],lhs[3]);
qrhs.makeRotate(osg::DegreesToRadians(rhs[0]),rhs[1],rhs[2],rhs[3]); qrhs.makeRotate(osg::DegreesToRadians(rhs[0]),rhs[1],rhs[2],rhs[3]);
osg::Quat quat = qlhs*qrhs; osg::Quat quat = qlhs*qrhs;
#ifdef OSG_USE_FLOAT_QUAT
osg::Vec4f result;
#else
osg::Vec4d result; osg::Vec4d result;
#endif
quat.getRotate ( result[0], result[1], result[2], result[3]); quat.getRotate ( result[0], result[1], result[2], result[3]);
result[0] = osg::RadiansToDegrees(result[0]); result[0] = osg::RadiansToDegrees(result[0]);
return result; return result;

View File

@ -562,7 +562,7 @@ void ToVRML::apply(osg::MatrixTransform& node) {
osg::Vec3 scale = mat.getScale(); osg::Vec3 scale = mat.getScale();
osg::Quat quat; osg::Quat quat;
mat.get(quat); mat.get(quat);
double angle; osg::Quat::value_type angle;
osg::Vec3 axe; osg::Vec3 axe;
quat.getRotate(angle, axe); quat.getRotate(angle, axe);
@ -597,7 +597,7 @@ void ToVRML::apply(osg::PositionAttitudeTransform& node) {
osg::Vec3 trans = node.getPosition(); osg::Vec3 trans = node.getPosition();
osg::Vec3 scale = node.getScale(); osg::Vec3 scale = node.getScale();
osg::Quat quat = node.getAttitude(); osg::Quat quat = node.getAttitude();
double angle; osg::Quat::value_type angle;
osg::Vec3 axe; osg::Vec3 axe;
quat.getRotate(angle, axe); quat.getRotate(angle, axe);