本文整理汇总了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;
}