码迷,mamicode.com
首页 > 编程语言 > 详细

[原][c++][数学]osg常用图形数学算法小结

时间:2018-03-12 12:03:01      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:nsf   gpo   matrix   ons   turn   log   mic   app   mod   

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;
    }

 

[原][c++][数学]osg常用图形数学算法小结

标签:nsf   gpo   matrix   ons   turn   log   mic   app   mod   

原文地址:https://www.cnblogs.com/lyggqm/p/8548322.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!