本文整理汇总了C++中vec_t::dot方法的典型用法代码示例。如果您正苦于以下问题:C++ vec_t::dot方法的具体用法?C++ vec_t::dot怎么用?C++ vec_t::dot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vec_t
的用法示例。
在下文中一共展示了vec_t::dot方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: t
double sphere_t::hits(const vec_t& pos, const vec_t& dir, vec_t& hit, vec_t& N)
{
vec_t pc;
double a = 1.0, b, c;
double d, t(-1.0), t0(-1.0), t1(-1.0);
double precision = 0.000001;
assert(cookie == OBJ_COOKIE);
// get vector from sphere center to ray base (pos - center)
pc = pos - center;
// compute coeffs for quadratic formula, a should be 1.0 if dir normalized
a = dir.dot(dir);
b = 2.0 * pc.dot(dir);
c = pc.dot(pc) - radius * radius;
// determine the discriminant from the quadratic formula
d = b*b - 4.0*a*c;
// if discriminant positive, solve for t
if(d > 0) {
// t is the distance from ray's base to hit on sphere, calculate both
// roots but take the smaller one. Only calculate both if the object is
// transparent.
t0 = (-b - sqrt(d)) / (2.0 * a);
t1 = (-b + sqrt(d)) / (2.0 * a);
if((t0 < t1) && (t0 > 0.00001)) t = t0;
else t = t1;
// since dir is a unit vector, scaling by t creates a vector that reaches
// the hit point on the sphere from the ray's base; adding to the base
// gets us onto the sphere surface
hit = pos + t * dir;
// the final step is to compute the normal at the surface---for a sphere
// the normal is simply a vector pointing from the center to the hit point
//N = (hit - center).norm();
N = 1.0/radius * (hit - center);
}
return(t);
}