本文整理汇总了C++中Vec3f::Distance3f方法的典型用法代码示例。如果您正苦于以下问题:C++ Vec3f::Distance3f方法的具体用法?C++ Vec3f::Distance3f怎么用?C++ Vec3f::Distance3f使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vec3f
的用法示例。
在下文中一共展示了Vec3f::Distance3f方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: intersect
bool Sphere::intersect(const Ray &r, Hit &h) const {
// ==========================================
// ASSIGNMENT: IMPLEMENT SPHERE INTERSECTION
// ==========================================
// a = d (dot) d
double a = r.getDirection().Dot3(r.getDirection());
// b = 2d (dot) (orginPoint - centerPoint)
double b = (2*(r.getDirection())).Dot3(r.getOrigin() - center);
// c = (p_0 - p_c) dot (p_0-p_c) - r^2
double c = (r.getOrigin() - center).Dot3(r.getOrigin() - center) - (radius*radius);
// t = (-b +/- sqrt(b2 - 4 a c)) / (2 a)
// if inside is negative, then it doesn't intersect the sphere
// if zero just a slight glance of sphere
// if two then you interect and leave
double inside = (b*b) - 4*a*c;
if(inside >= 0 ){
//inside
// get the first intersection point
double t = ((-1*b) - sqrt(inside)) / (2*a);
if(t < 0) return false;
// get pt collision
Vec3f pt = r.getOrigin() + t * r.getDirection();
if(pt.Distance3f(r.getOrigin()) < EPSILON) return false;
Vec3f norm((pt.x() - center.x())/radius, (pt.y() - center.y())/radius, (pt.z() - center.z())/radius);
norm.Normalize();
h.set(t,getMaterial(),norm);
return true;
}else{
// Negative and therefore missed
return false;
}
// return true if the sphere was intersected, and update
// the hit data structure to contain the value of t for the ray at
// the intersection point, the material, and the normal
return false;
}