当前位置: 首页>>代码示例>>C++>>正文


C++ Vec3f::ddot方法代码示例

本文整理汇总了C++中Vec3f::ddot方法的典型用法代码示例。如果您正苦于以下问题:C++ Vec3f::ddot方法的具体用法?C++ Vec3f::ddot怎么用?C++ Vec3f::ddot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vec3f的用法示例。


在下文中一共展示了Vec3f::ddot方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: intersectionRay

bool Sphere::intersectionRay(Vec3f rayFrom, Vec3f rayOrientation, IntersectionEvent* retIntersection)
{
    rayFrom += .0001*rayOrientation;
    Vec3f OC = center - rayFrom;
    //assert(center[0]-rayFrom[0] == OC[0] && center[1]-rayFrom[1] == OC[1] && center[2]-rayFrom[2] == OC[2]);
    
    //double check = norm(OC);
    //assert(fabs(check-sqrt(OC[0]*OC[0]+OC[1]*OC[1]+OC[2]*OC[2]))<.001);
    
    if (norm(OC) >= radius)
    {
        //double d = norm(rayOrientation.cross(rayFrom-center));
        
        double t_ca = rayOrientation.ddot(OC);
        if (t_ca <0)
            return false;
        //else
        //double t_hc_sqr = radius*radius - d*d;
        //or
        double t_hc_sqr2 = radius*radius - pow(norm(OC),2) + t_ca*t_ca;
        //if (fabs(t_hc_sqr-t_hc_sqr2) >.001)
        //{
        //    cout << "diff t_hc_sqr " << t_hc_sqr << ", " << t_hc_sqr2 << endl;
        //    cout << "diff d " << d << ", " << (pow(norm(OC),2)-t_ca*t_ca) << endl;
        //}
        
        if (t_hc_sqr2 < 0)
            return false;
        //else
        double t = t_ca-sqrt(t_hc_sqr2);
        
        if (retIntersection != NULL)
        {
            retIntersection->point = rayFrom + t*rayOrientation;
            retIntersection->normal = (retIntersection->point-center)/radius;
            retIntersection->dist = t;//I think
            //assert( fabs(t - norm(retIntersection->point-rayFrom)) < .001);
            retIntersection->so = this;
            retIntersection->inside = false;
            //cout << "sph intersection at dist: " << t <<endl;
        }
        
        //cout << "d: " << d << endl;
        //cout << "t_ca: " << t_ca << endl;
        //cout << "t_hc_sqr2: " << t_hc_sqr2 << endl;
        
        return true;
    }
    else
    {
        double t_ca = rayOrientation.ddot(OC);
        double t_hc_sqr2 = radius*radius - pow(norm(OC),2) + t_ca*t_ca;
        
        if (t_hc_sqr2 < 0)
            return false;
        //else
        double t = t_ca+sqrt(t_hc_sqr2);
        
        if (retIntersection != NULL)
        {
            retIntersection->point = rayFrom + t*rayOrientation;
            retIntersection->normal = -1*(retIntersection->point-center)/radius;
            retIntersection->dist = t;//I think
            //assert( fabs(t - norm(retIntersection->point-rayFrom)) < .001);
            retIntersection->so = this;
            retIntersection->inside = true;
            //cout << "sph intersection at dist: " << t <<endl;
        }
    }
    return false;
}
开发者ID:herobd,项目名称:cs455,代码行数:71,代码来源:sceneobject.cpp


注:本文中的Vec3f::ddot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。