Add OSG_USE_FLOAT_QUAT build option to use single precision quaternions
This commit is contained in:
parent
c548289ac1
commit
12b298130a
@ -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)
|
||||
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)
|
||||
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)
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <osg/Plane>
|
||||
#include <osg/BoundingBox>
|
||||
#include <osg/BoundingSphere>
|
||||
#include <osg/Quat>
|
||||
|
||||
#ifdef BUILD_CONTRIBUTORS
|
||||
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("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("Quat::value_type", "Print the value of Quat::value_type");
|
||||
|
||||
#ifdef BUILD_CONTRIBUTORS
|
||||
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;
|
||||
}
|
||||
|
||||
if (arguments.read("Quat::value_type"))
|
||||
{
|
||||
cout << ((sizeof(osg::Quat::value_type) == 4) ? "float" : "double") << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
cout << osgGetLibraryName() << " " << osgGetVersion() << endl << endl;
|
||||
|
||||
#ifdef BUILD_CONTRIBUTORS
|
||||
|
@ -32,7 +32,11 @@ class OSG_EXPORT Quat
|
||||
public:
|
||||
|
||||
/** Data type of vector components.*/
|
||||
#ifdef OSG_USE_FLOAT_QUAT
|
||||
typedef float value_type;
|
||||
#else
|
||||
typedef double value_type;
|
||||
#endif
|
||||
|
||||
/** Number of vector components. */
|
||||
enum { num_components = 4 };
|
||||
|
@ -28,6 +28,7 @@
|
||||
#cmakedefine OSG_USE_FLOAT_PLANE
|
||||
#cmakedefine OSG_USE_FLOAT_BOUNDINGSPHERE
|
||||
#cmakedefine OSG_USE_FLOAT_BOUNDINGBOX
|
||||
#cmakedefine OSG_USE_FLOAT_QUAT
|
||||
#cmakedefine OSG_USE_REF_PTR_IMPLICIT_OUTPUT_CONVERSION
|
||||
#cmakedefine OSG_USE_REF_PTR_SAFE_DEREFERENCE
|
||||
#cmakedefine OSG_USE_UTF8_FILENAME
|
||||
|
@ -187,7 +187,10 @@ InputStream& InputStream::operator>>( osg::Vec4d& v )
|
||||
|
||||
|
||||
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 )
|
||||
{
|
||||
|
@ -172,7 +172,7 @@ OutputStream& OutputStream::operator<<( const osg::Vec4ui& v )
|
||||
|
||||
|
||||
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 )
|
||||
{ *this << (double)p[0] << (double)p[1] << (double)p[2] << (double)p[3]; return *this; }
|
||||
|
@ -405,7 +405,7 @@ osg::Quat SpherePlaneProjector::getRotation(const osg::Vec3d& p1, bool p1OnSpher
|
||||
osg::Quat rotation;
|
||||
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);
|
||||
|
||||
osg::Vec3d realAxis;
|
||||
|
@ -217,7 +217,11 @@ public:
|
||||
qlhs.makeRotate(osg::DegreesToRadians(lhs[0]),lhs[1],lhs[2],lhs[3]);
|
||||
qrhs.makeRotate(osg::DegreesToRadians(rhs[0]),rhs[1],rhs[2],rhs[3]);
|
||||
osg::Quat quat = qlhs*qrhs;
|
||||
#ifdef OSG_USE_FLOAT_QUAT
|
||||
osg::Vec4f result;
|
||||
#else
|
||||
osg::Vec4d result;
|
||||
#endif
|
||||
quat.getRotate ( result[0], result[1], result[2], result[3]);
|
||||
result[0] = osg::RadiansToDegrees(result[0]);
|
||||
return result;
|
||||
|
@ -562,7 +562,7 @@ void ToVRML::apply(osg::MatrixTransform& node) {
|
||||
osg::Vec3 scale = mat.getScale();
|
||||
osg::Quat quat;
|
||||
mat.get(quat);
|
||||
double angle;
|
||||
osg::Quat::value_type angle;
|
||||
osg::Vec3 axe;
|
||||
quat.getRotate(angle, axe);
|
||||
|
||||
@ -597,7 +597,7 @@ void ToVRML::apply(osg::PositionAttitudeTransform& node) {
|
||||
osg::Vec3 trans = node.getPosition();
|
||||
osg::Vec3 scale = node.getScale();
|
||||
osg::Quat quat = node.getAttitude();
|
||||
double angle;
|
||||
osg::Quat::value_type angle;
|
||||
osg::Vec3 axe;
|
||||
quat.getRotate(angle, axe);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user