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


C++ vec_t::dot方法代码示例

本文整理汇总了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);
}
开发者ID:daburch,项目名称:212RayTracer,代码行数:45,代码来源:sphere.cpp


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