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