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


C++ Vector4::Mod方法代码示例

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


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

示例1: FindNearestTIntersectionWithSphere

double FindNearestTIntersectionWithSphere(Ray* ray, int* index, int noCheckID = NONE) {
    
    assert(noCheckID==NONE || (noCheckID>=0 && noCheckID<num_spheres));
    
    double nearestTIntersect = INFINITY;
    *index = NONE;
    
    /* (x_d^2 + y_d^2 + z_d^2)t^2 + 2((x_o-x_c)x_d +(y_o-y_c)y_d + (z_o-z_c)z_d)t
     *  + (x_o-x_c)^2 + (y_o-y_c)^2 + (z_o-z_c)^2 - r^2 = 0
     */
    unsigned int i;
    for (i = 0; i < num_spheres; i++) {
        
        if (i==noCheckID){
            continue;
        }
        
        Vector4* sphereCenter = new Vector4(spheres[i].position);
        
        Vector4* sphereRay = new Vector4(ray->source);
        sphereRay->Subtraction(sphereCenter);
        
        double A = pow(ray->dir->Mod(), 2);
        double B = 2 * (ray->dir->DotProduct(sphereRay));
        double C = pow(sphereRay->Mod(), 2) - pow(spheres[i].radius, 2);
        
        double soln1=0.0,soln2=0.0;
        SolveQuadraticEquation(A,B,C,&soln1,&soln2);       
        
        if (soln1 >= 0 && soln2 >= 0){
//            //For Debugging Purposes
//            printf("(%f,%f)\n",soln1,soln2);
            
            double candidateT = NONE;
            if(soln1<soln2){
                candidateT = soln1;
            }
            else{
                candidateT = soln2;
            }
                
            //assert(candidateT>=soln1 && candidateT>=soln2);
            if(nearestTIntersect > candidateT /*&& candidateT>(cameraZ-screenZ)*/) {
                nearestTIntersect = candidateT;            
                *index = i;           
            }
        }
        
        delete(sphereCenter);
        delete(sphereRay);
    }       
    
    return nearestTIntersect;
}
开发者ID:AshishPrasad,项目名称:Ray-Tracing,代码行数:54,代码来源:assign3.cpp


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