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.
This commit is contained in:
parent
430c8606e9
commit
7a7a26c2ea
15
ChangeLog
15
ChangeLog
@ -1,7 +1,20 @@
|
|||||||
OSG Change log
|
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,
|
o Made spelling corrections in include/osgDB,osgUtil,osgGLUT,osgWX,
|
||||||
spelling mistakes picked up by a script written by Neil Salter.
|
spelling mistakes picked up by a script written by Neil Salter.
|
||||||
o Made osg::Matrix::_mat private, and updated the rest of the osg
|
o Made osg::Matrix::_mat private, and updated the rest of the osg
|
||||||
|
49
include/osg/EarthSky
Normal file
49
include/osg/EarthSky
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#ifndef OSG_EARTHSKY
|
||||||
|
#define OSG_EARTHSKY 1
|
||||||
|
|
||||||
|
#include <osg/Group>
|
||||||
|
#include <osg/Vec4>
|
||||||
|
|
||||||
|
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
|
@ -22,6 +22,18 @@ typedef uchar ubyte;
|
|||||||
#define M_2_SQRTPI 1.12837916709551257390
|
#define M_2_SQRTPI 1.12837916709551257390
|
||||||
#define M_SQRT2 1.41421356237309504880
|
#define M_SQRT2 1.41421356237309504880
|
||||||
#define M_SQRT1_2 0.70710678118654752440
|
#define M_SQRT1_2 0.70710678118654752440
|
||||||
|
#else
|
||||||
|
#include <math.h>
|
||||||
|
#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
|
#endif
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -204,8 +204,8 @@ bool GliderManipulator::calcMovement()
|
|||||||
osg::Vec3 sv = _camera->getSideVector();
|
osg::Vec3 sv = _camera->getSideVector();
|
||||||
osg::Vec3 lv = _camera->getLookVector();
|
osg::Vec3 lv = _camera->getLookVector();
|
||||||
|
|
||||||
float pitch = -dy*0.15f*dt;
|
float pitch = inDegrees(-dy*0.15f*dt);
|
||||||
float roll = -dx*0.1f*dt;
|
float roll = inDegrees(-dx*0.1f*dt);
|
||||||
|
|
||||||
osg::Matrix mat;
|
osg::Matrix mat;
|
||||||
mat.makeTrans(-center);
|
mat.makeTrans(-center);
|
||||||
@ -214,7 +214,7 @@ bool GliderManipulator::calcMovement()
|
|||||||
if (_yawMode==YAW_AUTOMATICALLY_WHEN_BANKED)
|
if (_yawMode==YAW_AUTOMATICALLY_WHEN_BANKED)
|
||||||
{
|
{
|
||||||
float bank = asinf(sv.z());
|
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);
|
mat *= Matrix::rotate(yaw,0.0f,0.0f,1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,8 +336,7 @@ int main( int argc, char **argv )
|
|||||||
osg::Timer_t after_load = timer.tick();
|
osg::Timer_t after_load = timer.tick();
|
||||||
cout << "Time for load = "<<timer.delta_s(before_load,after_load)<<" seconds"<<endl;
|
cout << "Time for load = "<<timer.delta_s(before_load,after_load)<<" seconds"<<endl;
|
||||||
|
|
||||||
osg::ref_ptr<MySceneView> mySceneView = new MySceneView(viewerMode,socketNumber,camera_fov,camera_offset);
|
osg::ref_ptr<MySceneView> mySceneView = new MySceneView(viewerMode,socketNumber,camera_fov,osg::inDegrees(camera_offset));
|
||||||
|
|
||||||
mySceneView->setSceneData(rootnode);
|
mySceneView->setSceneData(rootnode);
|
||||||
|
|
||||||
// initialize the viewer.
|
// initialize the viewer.
|
||||||
|
@ -170,7 +170,7 @@ int main( int argc, char **argv )
|
|||||||
myTransform->addChild( createCube() );
|
myTransform->addChild( createCube() );
|
||||||
|
|
||||||
// move node in a circle at 90 degrees a sec.
|
// 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.
|
// create the viewer and the model to it.
|
||||||
osgGLUT::Viewer viewer;
|
osgGLUT::Viewer viewer;
|
||||||
|
@ -473,7 +473,7 @@ int main( int argc, char **argv )
|
|||||||
osgGLUT::Viewer viewer;
|
osgGLUT::Viewer viewer;
|
||||||
viewer.addViewport( rootNode );
|
viewer.addViewport( rootNode );
|
||||||
|
|
||||||
loadedModelTransform->setAppCallback(new TransformCallback(loadedModelTransform,45.0f));
|
loadedModelTransform->setAppCallback(new TransformCallback(loadedModelTransform,osg::inDegrees(45.0f)));
|
||||||
|
|
||||||
// register trackball, flight and drive.
|
// register trackball, flight and drive.
|
||||||
viewer.registerCameraManipulator(new osgUtil::TrackballManipulator);
|
viewer.registerCameraManipulator(new osgUtil::TrackballManipulator);
|
||||||
|
@ -10,7 +10,6 @@ using namespace osg;
|
|||||||
Billboard::Billboard()
|
Billboard::Billboard()
|
||||||
{
|
{
|
||||||
_mode = AXIAL_ROT;
|
_mode = AXIAL_ROT;
|
||||||
// _mode = POINT_ROT_WORLD;
|
|
||||||
_axis.set(0.0f,0.0f,1.0f);
|
_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();
|
mat.makeIdent();
|
||||||
//float rotation_zrotation_z = atan2f(ev.x(),ev.y());
|
//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 inv = 1.0f/ev_length;
|
||||||
float c = ev.y()*inv;
|
float c = ev.y()*inv;
|
||||||
float s = ev.x()*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;
|
cp /= cp_len;
|
||||||
|
|
||||||
float rotation_cp = acosf(dot);
|
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;
|
break;
|
||||||
|
20
src/osg/EarthSky.cpp
Normal file
20
src/osg/EarthSky.cpp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include "osg/EarthSky"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -14,6 +14,7 @@ using namespace osg;
|
|||||||
#define DEG2RAD(x) ((x)*M_PI/180.0)
|
#define DEG2RAD(x) ((x)*M_PI/180.0)
|
||||||
#define RAD2DEG(x) ((x)*180.0/M_PI)
|
#define RAD2DEG(x) ((x)*180.0/M_PI)
|
||||||
|
|
||||||
|
|
||||||
// temporary #define's for warning that deprecated methods are being
|
// temporary #define's for warning that deprecated methods are being
|
||||||
// used which should be replaced by the new variants.
|
// used which should be replaced by the new variants.
|
||||||
#define WARN_DEPRECATED
|
#define WARN_DEPRECATED
|
||||||
@ -33,8 +34,6 @@ using namespace osg;
|
|||||||
#define DEPRECATED(message)
|
#define DEPRECATED(message)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ANGLES_IN_DEGREES
|
|
||||||
|
|
||||||
|
|
||||||
#define SET_ROW(row, v1, v2, v3, v4 ) \
|
#define SET_ROW(row, v1, v2, v3, v4 ) \
|
||||||
_mat[(row)][0] = (v1); \
|
_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 )
|
double d = from * to; // dot product == cos( angle between from & to )
|
||||||
if( d < 0.9999 ) {
|
if( d < 0.9999 ) {
|
||||||
double angle = acos(d);
|
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
|
Vec3 axis = to ^ from; //we know ((to) x (from)) is perpendicular to both
|
||||||
makeRot( angle, axis );
|
makeRot( inRadians(angle) , axis );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
makeIdent();
|
makeIdent();
|
||||||
@ -188,7 +184,7 @@ void Matrix::makeRot( float angle, float x, float y, float z ) {
|
|||||||
if( d == 0 )
|
if( d == 0 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#ifdef ANGLES_IN_DEGREES
|
#ifdef USE_DEGREES_INTERNALLY
|
||||||
angle = DEG2RAD(angle);
|
angle = DEG2RAD(angle);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -230,7 +226,7 @@ void Matrix::makeRot( const Quat& q ) {
|
|||||||
|
|
||||||
void Matrix::makeRot( float yaw, float pitch, float roll)
|
void Matrix::makeRot( float yaw, float pitch, float roll)
|
||||||
{
|
{
|
||||||
#ifdef ANGLES_IN_DEGREES
|
#ifdef USE_DEGREES_INTERNALLY
|
||||||
yaw = DEG2RAD(yaw);
|
yaw = DEG2RAD(yaw);
|
||||||
pitch = DEG2RAD(pitch);
|
pitch = DEG2RAD(pitch);
|
||||||
roll = DEG2RAD(roll);
|
roll = DEG2RAD(roll);
|
||||||
|
@ -405,7 +405,7 @@ bool DriveManipulator::calcMovement()
|
|||||||
|
|
||||||
float dx = _ga_t0->getX()-mx;
|
float dx = _ga_t0->getX()-mx;
|
||||||
|
|
||||||
float yaw = dx*0.1f*dt;
|
float yaw = inDegrees(dx*0.1f*dt);
|
||||||
|
|
||||||
osg::Matrix mat;
|
osg::Matrix mat;
|
||||||
mat.makeTrans(-center.x(),-center.y(),-center.z());
|
mat.makeTrans(-center.x(),-center.y(),-center.z());
|
||||||
|
@ -201,8 +201,8 @@ bool FlightManipulator::calcMovement()
|
|||||||
osg::Vec3 sv = _camera->getSideVector();
|
osg::Vec3 sv = _camera->getSideVector();
|
||||||
osg::Vec3 lv = _camera->getLookVector();
|
osg::Vec3 lv = _camera->getLookVector();
|
||||||
|
|
||||||
float pitch = -dy*0.15f*dt;
|
float pitch = inDegrees(-dy*0.15f*dt);
|
||||||
float roll = -dx*0.1f*dt;
|
float roll = inDegrees(-dx*0.1f*dt);
|
||||||
|
|
||||||
osg::Matrix mat;
|
osg::Matrix mat;
|
||||||
mat.makeTrans(-center);
|
mat.makeTrans(-center);
|
||||||
@ -211,7 +211,7 @@ bool FlightManipulator::calcMovement()
|
|||||||
if (_yawMode==YAW_AUTOMATICALLY_WHEN_BANKED)
|
if (_yawMode==YAW_AUTOMATICALLY_WHEN_BANKED)
|
||||||
{
|
{
|
||||||
float bank = asinf(sv.z());
|
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);
|
mat *= Matrix::rotate(yaw,0.0f,0.0f,1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
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));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user