[原][c++][数学]osg常用图形数学算法小结
1.cos趋近
// a reasonable approximation of cosine interpolation double smoothStepInterp( double t ) { return (t*t)*(3.0-2.0*t); }
2.pow趋近
// rough approximation of pow(x,y) double powFast( double x, double y ) { return x/(x+y-y*x); }
3.
// accel/decel curve (a < 0 => decel) double accelerationInterp( double t, double a ) { return a == 0.0? t : a > 0.0? powFast( t, a ) : 1.0 - powFast(1.0-t, -a); }
4.
// normalized linear intep osg::Vec3d nlerp(const osg::Vec3d& a, const osg::Vec3d& b, double t) { double am = a.length(), bm = b.length(); osg::Vec3d c = a*(1.0-t) + b*t; c.normalize(); c *= (1.0-t)*am + t*bm; return c; }
5.
// linear interp osg::Vec3d lerp(const osg::Vec3d& a, const osg::Vec3d& b, double t) { return a*(1.0-t) + b*t; }
6.
osg::Matrix computeLocalToWorld(osg::Node* node) { osg::Matrix m; if ( node ) { osg::NodePathList nodePaths = node->getParentalNodePaths(); if ( nodePaths.size() > 0 ) { m = osg::computeLocalToWorld( nodePaths[0] ); } else { osg::Transform* t = dynamic_cast<osg::Transform*>(node); if ( t ) { t->computeLocalToWorldMatrix( m, 0L ); } } } return m; }
7.
osg::Vec3d computeWorld(osg::Node* node) { return node ? osg::Vec3d(0,0,0) * computeLocalToWorld(node) : osg::Vec3d(0,0,0); }
8.
double normalizeAzimRad( double input ) { if(fabs(input) > 2*osg::PI) input = fmod(input,2*osg::PI); if( input < -osg::PI ) input += osg::PI*2.0; if( input > osg::PI ) input -= osg::PI*2.0; return input; }