zoukankan      html  css  js  c++  java
  • [原][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;
        }
  • 相关阅读:
    把旧系统迁移到.Net Core 2.0 日记 (18) --JWT 认证(Json Web Token)
    把旧系统迁移到.Net Core 2.0 日记 (17) --多租户和SoftDelete
    swagger访问api, TypeError: Failed to fetch
    nop 4.1 Widget 探究- 视图组件
    Nop 4.1版本已经迁移到.net core2.1版本
    link标签和css引入方式
    script标签
    MIME 类型
    bae64编码
    chrome调试技巧和插件介绍
  • 原文地址:https://www.cnblogs.com/lyggqm/p/8548322.html
Copyright © 2011-2022 走看看