From 7a7a26c2eacb03f6a76aa829e3d1a15fde798376 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 2 Oct 2001 15:59:49 +0000 Subject: [PATCH] Added include/osg/EarthSky and src/osg/EarthSky to cvs. Also move osg across to using radians for angular paramters by default. By defining USE_DEGREES_INTERNALLY you can get the OSG to revert to the old style degrees. This later feature is deprecated and only meant for helping comptability in the interim. --- ChangeLog | 15 ++++++- include/osg/EarthSky | 49 +++++++++++++++++++++++ include/osg/Types | 12 ++++++ src/Demos/hangglide/GliderManipulator.cpp | 6 +-- src/Demos/osgcluster/osgcluster.cpp | 3 +- src/Demos/osgcube/osgcube.cpp | 2 +- src/Demos/osgreflect/osgreflect.cpp | 2 +- src/osg/Billboard.cpp | 5 +-- src/osg/EarthSky.cpp | 20 +++++++++ src/osg/Matrix.cpp | 12 ++---- src/osgUtil/DriveManipulator.cpp | 2 +- src/osgUtil/FlightManipulator.cpp | 6 +-- src/osgUtil/TrackballManipulator.cpp | 2 +- 13 files changed, 112 insertions(+), 24 deletions(-) create mode 100644 include/osg/EarthSky create mode 100644 src/osg/EarthSky.cpp diff --git a/ChangeLog b/ChangeLog index 84708419b..034e14316 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,20 @@ OSG Change log ============== - + o Moved the osg across to using radians for all angular paramters, + previously all angular paramters were degrees as per Performer. + If the osg is compiled with USE_DEGREES_INTERNALLY defined then + the osg will revert to using degrees for anglular paramters, + however, this is only a temporary measure to help users port. + The inline methods inDegrees(float), and inRadians(float) have + been added into osg/Types to make porting easier, these methods + covert the specified anglular quantity into the current internal + angular units. + o Added osg::EarthSky node to support users defined clearing of the + color and depth buffers. + o Added support for removal of duplicate StateSets using the + osgUtil::OptimizeStateVisitor, previously of removal of duplicate + StateAttributes was supported. o Made spelling corrections in include/osgDB,osgUtil,osgGLUT,osgWX, spelling mistakes picked up by a script written by Neil Salter. o Made osg::Matrix::_mat private, and updated the rest of the osg diff --git a/include/osg/EarthSky b/include/osg/EarthSky new file mode 100644 index 000000000..757ffb10c --- /dev/null +++ b/include/osg/EarthSky @@ -0,0 +1,49 @@ +#ifndef OSG_EARTHSKY +#define OSG_EARTHSKY 1 + +#include +#include + +namespace osg { + +/** EarthSky is a Group node which controls the clearing of the color and depth + * buffers at the start of each frame. + * The earth sky by default is empty and simply holds the clear color of + * the background. However, if the uses wants to add their own clearing of + * the color and depth buffers then the children can be added, and the + * background clear turned off. The EarthSky by default has StateSet attached + * to it which sets the default EarthSky bin number to -1, so that all drawables + * below it are placed in a separate bin from the rest of the scene graph, and + * are rendered prior to standard opaque and transparent drawables. +*/ +class SG_EXPORT EarthSky : public Group +{ + public : + + EarthSky(); + + META_Node(EarthSky); + + /** Sets the flag which control whether a glClear is required at the beginning of each frame. */ + inline void setRequiresClear(const bool requiresClear) { _requiresClear = requiresClear; } + + /** Gets the flag which control whether a glClear is required at the beginning of each frame. */ + inline const bool getRequiresClear() const { return _requiresClear; } + + /** Sets the clear color. */ + inline void setClearColor(const Vec4& color) { _clearColor = color; } + + /** Returns the clear color. */ + inline const Vec4& getClearColor() const { return _clearColor; } + + protected : + + virtual ~EarthSky() {} + + bool _requiresClear; + Vec4 _clearColor; +}; + +}; + +#endif diff --git a/include/osg/Types b/include/osg/Types index da034b012..9975e33ec 100644 --- a/include/osg/Types +++ b/include/osg/Types @@ -22,6 +22,18 @@ typedef uchar ubyte; #define M_2_SQRTPI 1.12837916709551257390 #define M_SQRT2 1.41421356237309504880 #define M_SQRT1_2 0.70710678118654752440 +#else +#include +#endif + +#define USE_DEGREES_INTERNALLY + +#ifdef USE_DEGREES_INTERNALLY +inline double inDegrees(float angle) { return angle; } +inline double inRadians(float angle) { return angle*180.0/M_PI; } +#else +inline double inDegrees(float angle) { return angle*M_PI/180.0; } +inline double inRadians(float angle) { return angle; } #endif }; diff --git a/src/Demos/hangglide/GliderManipulator.cpp b/src/Demos/hangglide/GliderManipulator.cpp index c76d4b80d..a435cf4bf 100644 --- a/src/Demos/hangglide/GliderManipulator.cpp +++ b/src/Demos/hangglide/GliderManipulator.cpp @@ -204,8 +204,8 @@ bool GliderManipulator::calcMovement() osg::Vec3 sv = _camera->getSideVector(); osg::Vec3 lv = _camera->getLookVector(); - float pitch = -dy*0.15f*dt; - float roll = -dx*0.1f*dt; + float pitch = inDegrees(-dy*0.15f*dt); + float roll = inDegrees(-dx*0.1f*dt); osg::Matrix mat; mat.makeTrans(-center); @@ -214,7 +214,7 @@ bool GliderManipulator::calcMovement() if (_yawMode==YAW_AUTOMATICALLY_WHEN_BANKED) { float bank = asinf(sv.z()); - float yaw = (-bank*180.0f/M_PI)*dt; + float yaw = inRadians(-bank)*dt; mat *= Matrix::rotate(yaw,0.0f,0.0f,1.0f); } diff --git a/src/Demos/osgcluster/osgcluster.cpp b/src/Demos/osgcluster/osgcluster.cpp index 5df3bf763..f9685ab96 100644 --- a/src/Demos/osgcluster/osgcluster.cpp +++ b/src/Demos/osgcluster/osgcluster.cpp @@ -336,8 +336,7 @@ int main( int argc, char **argv ) osg::Timer_t after_load = timer.tick(); cout << "Time for load = "< mySceneView = new MySceneView(viewerMode,socketNumber,camera_fov,camera_offset); - + osg::ref_ptr mySceneView = new MySceneView(viewerMode,socketNumber,camera_fov,osg::inDegrees(camera_offset)); mySceneView->setSceneData(rootnode); // initialize the viewer. diff --git a/src/Demos/osgcube/osgcube.cpp b/src/Demos/osgcube/osgcube.cpp index 32e302658..f4bac89ec 100644 --- a/src/Demos/osgcube/osgcube.cpp +++ b/src/Demos/osgcube/osgcube.cpp @@ -170,7 +170,7 @@ int main( int argc, char **argv ) myTransform->addChild( createCube() ); // move node in a circle at 90 degrees a sec. - myTransform->setAppCallback(new TransformCallback(myTransform,90.0f)); + myTransform->setAppCallback(new TransformCallback(myTransform,osg::inDegrees(90.0f))); // create the viewer and the model to it. osgGLUT::Viewer viewer; diff --git a/src/Demos/osgreflect/osgreflect.cpp b/src/Demos/osgreflect/osgreflect.cpp index 2a0b68937..cf6d4cc8a 100644 --- a/src/Demos/osgreflect/osgreflect.cpp +++ b/src/Demos/osgreflect/osgreflect.cpp @@ -473,7 +473,7 @@ int main( int argc, char **argv ) osgGLUT::Viewer viewer; viewer.addViewport( rootNode ); - loadedModelTransform->setAppCallback(new TransformCallback(loadedModelTransform,45.0f)); + loadedModelTransform->setAppCallback(new TransformCallback(loadedModelTransform,osg::inDegrees(45.0f))); // register trackball, flight and drive. viewer.registerCameraManipulator(new osgUtil::TrackballManipulator); diff --git a/src/osg/Billboard.cpp b/src/osg/Billboard.cpp index 50840dbe0..29a7429b2 100644 --- a/src/osg/Billboard.cpp +++ b/src/osg/Billboard.cpp @@ -10,7 +10,6 @@ using namespace osg; Billboard::Billboard() { _mode = AXIAL_ROT; - // _mode = POINT_ROT_WORLD; _axis.set(0.0f,0.0f,1.0f); } @@ -85,7 +84,7 @@ void Billboard::calcRotation(const Vec3& eye_local, const Vec3& pos_local,Matrix { mat.makeIdent(); //float rotation_zrotation_z = atan2f(ev.x(),ev.y()); - //mat.makeRot(rotation_z*180.0f/M_PI,0.0f,0.0f,1.0f); + //mat.makeRot(inRadians(rotation_z),0.0f,0.0f,1.0f); float inv = 1.0f/ev_length; float c = ev.y()*inv; float s = ev.x()*inv; @@ -123,7 +122,7 @@ void Billboard::calcRotation(const Vec3& eye_local, const Vec3& pos_local,Matrix cp /= cp_len; float rotation_cp = acosf(dot); - mat.makeRot(rotation_cp*180.0f/M_PI,cp[0],cp[1],cp[2]); + mat.makeRot(inRadians(rotation_cp),cp[0],cp[1],cp[2]); } } break; diff --git a/src/osg/EarthSky.cpp b/src/osg/EarthSky.cpp new file mode 100644 index 000000000..fc8f0a481 --- /dev/null +++ b/src/osg/EarthSky.cpp @@ -0,0 +1,20 @@ +#include "osg/EarthSky" + +#include + +using namespace osg; + +/** + * EarthSky constructor. + */ +EarthSky::EarthSky() +{ + StateSet* stateset = new StateSet; + stateset->setRenderBinDetails(-1,"RenderBin"); + setStateSet(stateset); + + _requiresClear = true; + _clearColor.set(0.0f,0.0f,0.0f,1.0f); + +} + diff --git a/src/osg/Matrix.cpp b/src/osg/Matrix.cpp index 713329f33..ee4ac7192 100644 --- a/src/osg/Matrix.cpp +++ b/src/osg/Matrix.cpp @@ -14,6 +14,7 @@ using namespace osg; #define DEG2RAD(x) ((x)*M_PI/180.0) #define RAD2DEG(x) ((x)*180.0/M_PI) + // temporary #define's for warning that deprecated methods are being // used which should be replaced by the new variants. #define WARN_DEPRECATED @@ -33,8 +34,6 @@ using namespace osg; #define DEPRECATED(message) #endif -#define ANGLES_IN_DEGREES - #define SET_ROW(row, v1, v2, v3, v4 ) \ _mat[(row)][0] = (v1); \ @@ -168,11 +167,8 @@ void Matrix::makeRot( const Vec3& from, const Vec3& to ) double d = from * to; // dot product == cos( angle between from & to ) if( d < 0.9999 ) { double angle = acos(d); -#ifdef ANGLES_IN_DEGREES - angle = RAD2DEG(angle); -#endif Vec3 axis = to ^ from; //we know ((to) x (from)) is perpendicular to both - makeRot( angle, axis ); + makeRot( inRadians(angle) , axis ); } else makeIdent(); @@ -188,7 +184,7 @@ void Matrix::makeRot( float angle, float x, float y, float z ) { if( d == 0 ) return; -#ifdef ANGLES_IN_DEGREES +#ifdef USE_DEGREES_INTERNALLY angle = DEG2RAD(angle); #endif @@ -230,7 +226,7 @@ void Matrix::makeRot( const Quat& q ) { void Matrix::makeRot( float yaw, float pitch, float roll) { -#ifdef ANGLES_IN_DEGREES +#ifdef USE_DEGREES_INTERNALLY yaw = DEG2RAD(yaw); pitch = DEG2RAD(pitch); roll = DEG2RAD(roll); diff --git a/src/osgUtil/DriveManipulator.cpp b/src/osgUtil/DriveManipulator.cpp index 24e8ebbdd..94ee6eedc 100644 --- a/src/osgUtil/DriveManipulator.cpp +++ b/src/osgUtil/DriveManipulator.cpp @@ -405,7 +405,7 @@ bool DriveManipulator::calcMovement() float dx = _ga_t0->getX()-mx; - float yaw = dx*0.1f*dt; + float yaw = inDegrees(dx*0.1f*dt); osg::Matrix mat; mat.makeTrans(-center.x(),-center.y(),-center.z()); diff --git a/src/osgUtil/FlightManipulator.cpp b/src/osgUtil/FlightManipulator.cpp index 8b4cbf97b..0e6eff356 100644 --- a/src/osgUtil/FlightManipulator.cpp +++ b/src/osgUtil/FlightManipulator.cpp @@ -201,8 +201,8 @@ bool FlightManipulator::calcMovement() osg::Vec3 sv = _camera->getSideVector(); osg::Vec3 lv = _camera->getLookVector(); - float pitch = -dy*0.15f*dt; - float roll = -dx*0.1f*dt; + float pitch = inDegrees(-dy*0.15f*dt); + float roll = inDegrees(-dx*0.1f*dt); osg::Matrix mat; mat.makeTrans(-center); @@ -211,7 +211,7 @@ bool FlightManipulator::calcMovement() if (_yawMode==YAW_AUTOMATICALLY_WHEN_BANKED) { float bank = asinf(sv.z()); - float yaw = (-bank*180.0f/M_PI)*dt; + float yaw = inRadians(-bank)*dt; mat *= Matrix::rotate(yaw,0.0f,0.0f,1.0f); } diff --git a/src/osgUtil/TrackballManipulator.cpp b/src/osgUtil/TrackballManipulator.cpp index a153c2b79..e62ed88d2 100644 --- a/src/osgUtil/TrackballManipulator.cpp +++ b/src/osgUtil/TrackballManipulator.cpp @@ -338,7 +338,7 @@ void TrackballManipulator::trackball(osg::Vec3& axis,float& angle, float p1x, fl */ if (t > 1.0) t = 1.0; if (t < -1.0) t = -1.0; - angle = asin(t) * 180.0f/M_PI; + angle = inRadians(asin(t)); }