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


C++ Hit::getT方法代码示例

本文整理汇总了C++中Hit::getT方法的典型用法代码示例。如果您正苦于以下问题:C++ Hit::getT方法的具体用法?C++ Hit::getT怎么用?C++ Hit::getT使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Hit的用法示例。


在下文中一共展示了Hit::getT方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: retHit

Hit BVH::BVHNode::trace(const AABB_Ray & aabb_ray, const Ray & ray, Amount minT)
{
   Hit retHit(ray);
   //First check to see if this hit intersects with this node.
   Amount thisT = getBox().intersect(aabb_ray);

   if(thisT > 0 && (thisT < minT || minT < 0))
   {
      if(this->left != nullptr)
      {
         Hit hLeft = this->left->trace(aabb_ray,ray,minT);
         if(hLeft.didHit() && (hLeft.getT() < minT || minT < 0))
         {
            retHit = hLeft;
            minT = hLeft.getT();
         }
      }
      if(this->right != nullptr)
      {
         Hit hRight = this->right->trace(aabb_ray,ray,minT);
         if(hRight.didHit() && (hRight.getT() < minT || minT < 0))
         {
            retHit = hRight;
         }
      }
   }


   return retHit;
}
开发者ID:kyle-piddington,项目名称:PovTracer,代码行数:30,代码来源:BVH.cpp

示例2: plane_intersect

bool Face::plane_intersect(const Ray &r, Hit &h, bool intersect_backfacing, bool* backfacing_hit) {

	// insert the explicit equation for the ray into the implicit equation of the plane

	// equation for a plane
	// ax + by + cz = d;
	// normal . p + direction = 0
	// plug in ray
	// origin + direction * t = p(t)
	// origin . normal + t * direction . normal = d;
	// t = d - origin.normal / direction.normal;

	Vec3f normal = computeNormal();
	double d = normal.Dot3((*this)[0]->get());

	double numer = d - r.getOrigin().Dot3(normal);
	double denom = r.getDirection().Dot3(normal);

	if (denom == 0) return 0;	// parallel to plane

	if (!intersect_backfacing && normal.Dot3(r.getDirection()) >= 0) 
		return 0; // hit the backside

	double t = numer / denom;
	if (t > EPSILON && t < h.getT()) {
		h.set(t,this->getMaterial(),normal,this);
		assert (h.getT() >= EPSILON);
		//hit the backside but that's okay in this case
		if (normal.Dot3(r.getDirection()) >= 0){
			*backfacing_hit = true;
		}
		return 1;
	}
	return 0;
}
开发者ID:pointeplusplus,项目名称:Photon-Mapping,代码行数:35,代码来源:face.cpp

示例3: shadow

Vec3f RayTracer::shadow(const Vec3f &point,
			const Vec3f &pointOnLight,
			const Face *f,
			const Ray &ray,
			const Hit &hit) const
{
        const Vec3f normal(hit.getNormal());
        const Material *m = hit.getMaterial();

	Vec3f dirToLight = pointOnLight - point;
	dirToLight.Normalize();
	/* If dot product < 0, surface is not facing light */
	if (normal.Dot3(dirToLight) > 0) {
		Ray rayToLight(point, dirToLight);
		Hit hLight;
		bool blocked = CastRay(rayToLight, hLight, false);
		while (std::fabs(hLight.getT()) < SURFACE_EPSILON &&
				std::fabs((pointOnLight - point).Length()) > SURFACE_EPSILON) {
			rayToLight = Ray(rayToLight.pointAtParameter(SURFACE_EPSILON),
					dirToLight);
			blocked = CastRay(rayToLight, hLight, false);
		}
		if (hLight.getT() == FLT_MAX || hLight.getMaterial() != f->getMaterial()) {
			return Vec3f(0, 0, 0);
		}

		const Vec3f lightColor = 0.2 * f->getMaterial()->getEmittedColor() * f->getArea();
		return m->Shade(ray,hit,dirToLight,lightColor,args);
	}
	return Vec3f(0, 0, 0);
}
开发者ID:linkinpark342,项目名称:parashader,代码行数:31,代码来源:raytracer.cpp

示例4: intersect

bool Sphere::intersect(const Ray &r, Hit &h, float tmin)
{
	Vec3f v = center - r.getOrigin();
	float tp = v.Dot3(r.getDirection());
	float det = tp*tp - v.Dot3(v) + radius*radius;
	//intersect
	if(det > 0)
	{
		//t'
		det = sqrtf(det); 

		float t1 = tp - det;
		float t2 = tp + det;

		if(t1 > tmin && t1 < h.getT())
		{
			Vec3f normal = (r.pointAtParameter(t1) - center);
			normal /= radius;
			normal.Normalize();
			h.set(t1,material,normal,r);
			return 1;
		}
		else if(t2 > tmin && t2 < h.getT())
		{
			//sphere's normal
			Vec3f normal = (r.pointAtParameter(t2) - center);
			normal /= radius;
			normal.Normalize();
			h.set(t2,material,normal,r);
			return 1;
		}
	}
	return 0;
}
开发者ID:shihongzhi,项目名称:RayTracing,代码行数:34,代码来源:primitives.cpp

示例5: plane_intersect

bool Face::plane_intersect(const Ray &r, Hit &h, bool intersect_backfacing) const {

  // insert the explicit equation for the ray into the implicit equation of the plane

  // equation for a plane
  // ax + by + cz = d;
  // normal . p + direction = 0
  // plug in ray
  // origin + direction * t = p(t)
  // origin . normal + t * direction . normal = d;
  // t = d - origin.normal / direction.normal;

  glm::vec3 normal = computeNormal();
  float d = glm::dot(normal,(*this)[0]->get());

  float numer = d - glm::dot(r.getOrigin(),normal);
  float denom = glm::dot(r.getDirection(),normal);

  if (denom == 0) return 0;  // parallel to plane

  if (!intersect_backfacing && glm::dot(normal,r.getDirection()) >= 0) 
    return 0; // hit the backside

  float t = numer / denom;
  if (t > EPSILON && t < h.getT()) {
    h.set(t,this->getMaterial(),normal);
    assert (h.getT() >= EPSILON);
    return 1;
  }
  return 0;
}
开发者ID:JimmyJimJimJammers,项目名称:ACGFinalProject,代码行数:31,代码来源:face.cpp

示例6: Intersect

bool Transform::Intersect(const Ray &r, Hit &h, float tmin) const
{
  bool result = false;
  
  Matrix m = m_matrix;
  if ( m.Inverse() )
    {
      Vec3f org = r.getOrigin();
      Vec3f dir = r.getDirection();
      m.Transform(org);
      m.TransformDirection(dir);
      Ray r2 (dir, org);
      result = m_pObject->Intersect(r2, h, tmin);
      
      if (result)
	{
	  Matrix m1 = m;
	  m1.Transpose();
	  Vec3f n = h.getNormal();
	  m1.TransformDirection(n);
	  n.Normalize();
	  h.set(h.getT(), h.getMaterial(), n, r);
	}
    }
  return result;
}
开发者ID:netwarm007,项目名称:mit-ocw-6.837,代码行数:26,代码来源:transform.cpp

示例7: intersect

bool Plane::intersect(const Ray & r, Hit & h, float tmin)
{
	assert (tmin >= 0.0f);

	Vec3f org = r.getOrigin();
	Vec3f dir = r.getDirection();

	if (dir.Dot3(normal) < 1.0e-7 && dir.Dot3(normal) > -1.0e-7) {
		return false;
	}					// Appromately parrell to plane

	float tempT = (offset - org.Dot3(normal)) / dir.Dot3(normal);
	if (tempT <= 1e-6) {
		return false;
	}
	else if (tempT >= tmin && tempT < h.getT()) 
	{
		// Update Hit Point
		normal.Normalize();
		h.set(tempT, NULL, normal, color, r);

		return true;
	}
	
	return false;
}
开发者ID:maddy-z,项目名称:Transformation,代码行数:26,代码来源:Plane.cpp

示例8: intersect

/*
The intersect routine will first transform the ray, 
then delegate to the intersect routine of the contained 
object. Make sure to correctly transform the resulting 
normal according to the rule seen in lecture. You may 
choose to normalize the direction of the transformed ray 
or leave it un-normalized. If you decide not to normalize 
the direction, you might need to update some of your intersection code.
*/
bool Transform::intersect(const Ray &r, Hit &h, float tmin)
{
	Vec3f r0 = r.getOrigin();
	Vec3f rd = r.getDirection();
	Matrix inv;
	matrix.Inverse(inv);
	inv.Transform(r0);
	inv.TransformDirection(rd);
	if (object != NULL)
	{
		//这里的h是有问题的,作如下修改:
		bool judge = object->intersect(Ray(r0,rd), h, tmin);
		Vec3f normal = h.getNormal();
		//这里很奇怪,normal的方向没有修正,然而结果却是对的
		//改了之后反而是错的!!
		//这里确定normal没有错,那么就是之后应用normal的
		//问题
		//好吧,就是这里的问题
		//经过把图形摆正,发现求的法向量没有问题,但是没有单位化…………!
		matrix.TransformDirection(normal);
		normal.Normalize();
		//or:
		//Matrix change,res;
		//matrix.Inverse(change);
		//change.Transpose(res);
		//res.TransformDirection(normal);
		h.set(h.getT(), h.getMaterial(), normal, r);
		return judge;
	}
	return false;
}
开发者ID:perfect28,项目名称:MIT-Graphics,代码行数:40,代码来源:transform.cpp

示例9: intersect

bool Sphere::intersect(const Ray &r, Hit &h, float tmin)
{
	//直线方程 P = t*D + R    ①
	//圆方程  ||P||= raduis   ②
	//将①带入②, 由点乘的性质(满足分配率,交换律),求得t^2+2RDt+R^2-r^2=0
	//得t = -RD±sqrt(RD^2-R^2+r^2)
	//选择距离较近的那个点t = -RD-sqrt(RD^2-R^2+r^2)
	Vec3f D = r.getDirection();
	Vec3f R = r.getOrigin()-center;


	float R2 = R.Dot3(R);
	float RD = R.Dot3(D);
	
	float b2_4ac = RD*RD-R2+radius*radius;//R2 RD RDRD这些其实可以存在ray里,但是算法研究以程序清晰为要
	if(b2_4ac<0)return 0;
	float t;
	t = -RD - sqrt(b2_4ac);
	if(t<0){
		t = -RD + sqrt(b2_4ac);
		if(t < 0)return 0;
	}
	if(t<h.getT())
	{
		h.set(t, &color, r);
	}

	return 1;
}
开发者ID:yueyueyueyue,项目名称:6-837-fall-2003,代码行数:29,代码来源:Object3D.cpp

示例10: intersect

bool Sphere::intersect(const Ray &r, Hit &h, float tmin){

	/*Vector equation for sphere
	P*P - r^2 = 0
	((R0-c) + td)*((R0-c) + td) - r^2 = 0
	(td)^2 + 2R0-c)td + (R0-c)^2 - r^2 =0
	Use quadratic equation solve for t
	a = (d^2)
	b = 2(R0-c)d
    c = ((R0-c)^2 - r^2)
	*/

	Vec3f rayOrigin, rayDirection,segment,Q;
	float tpos,tneg,a,b,c,discriminant;

	rayOrigin = r.getOrigin();
	rayDirection = r.getDirection();
	segment = rayOrigin - _center;

	a = rayDirection.Dot3(rayDirection);
	b = 2*segment.Dot3(rayDirection);
	c = segment.Dot3(segment) - _radius*_radius;

	discriminant = sqrt(b*b - 4*a*c); 

	tpos = (-b + discriminant)/(2*a);
	tneg = (-b - discriminant)/(2*a);

	if (tneg > tmin && tneg < h.getT()){
			Q = r.pointAtParameter(tneg);
			Q = Q - _center;
			Q.Normalize();
			h.set(tneg, _material,Q,r);
			return true;
		}
	else if (tpos > tmin && tpos < h.getT()){
			Q = r.pointAtParameter(tpos);
			Q = Q - _center;
			Q.Normalize();
			h.set(tpos,_material,Q,r);
			return true;
		}
	return false;

}
开发者ID:MangoDreams,项目名称:raytracer2.0,代码行数:45,代码来源:sphere.cpp

示例11: TracePhoton

void PhotonMapping::TracePhoton(const Vec3f &position, const Vec3f &direction, 
				const Vec3f &energy, int iter) {
  
  if(iter>args->num_bounces){
    return;
  }

  Hit h = Hit();
  Ray R = Ray(position, direction);
  bool intersect = raytracer->CastRay(R, h, false);
  if(!intersect){
    return;
  }
  Material *m = h.getMaterial();
  Vec3f normal = h.getNormal();
  Vec3f point = R.pointAtParameter(h.getT());
  Vec3f opDirec = direction;
  opDirec.Negate();
  opDirec.Normalize();
  Vec3f diffuse = m->getDiffuseColor(), reflec = m->getReflectiveColor();
  double diffuseAnswer = diffuse.x()+diffuse.y()+diffuse.z();
  double reflecAnswer = reflec.x()+reflec.y()+reflec.z();
  double total = reflecAnswer+diffuseAnswer;
  diffuseAnswer /= total;
  reflecAnswer /= total;
  double seed = GLOBAL_mtrand.rand();
  if(seed <= diffuseAnswer && seed >= 0){
    Vec3f newEnergy = energy * diffuse;
    Vec3f newPosition = point;
    Vec3f newDirection = Vec3f(GLOBAL_mtrand.rand(),GLOBAL_mtrand.rand(),GLOBAL_mtrand.rand());
    newDirection.Normalize();
    Photon answer = Photon(point,opDirec,newEnergy,iter+1);
    kdtree->AddPhoton(answer);
    TracePhoton(newPosition, newDirection, newEnergy, iter+1);
  }
  else if(seed>diffuseAnswer && seed <= 1){
    Vec3f newEnergy = energy * reflec;
    Vec3f newPosition = point;
    Vec3f newDirection = direction - 2 * direction.Dot3(normal) * normal;
    Photon answer = Photon(point,opDirec,newEnergy,iter+1);
    kdtree->AddPhoton(answer);
    TracePhoton(newPosition, newDirection, newEnergy, iter+1);
  }
  // ==============================================
  // ASSIGNMENT: IMPLEMENT RECURSIVE PHOTON TRACING
  // ==============================================

  // Trace the photon through the scene.  At each diffuse or
  // reflective bounce, store the photon in the kd tree.

  // One optimization is to *not* store the first bounce, since that
  // direct light can be efficiently computed using classic ray
  // tracing.



}
开发者ID:kenbellows,项目名称:Advanced-Computer-Graphics-Coursework,代码行数:57,代码来源:photon_mapping.cpp

示例12: shadows

Vec3f RayTracer::shadows(const Ray &ray, const Hit &hit) const
{
	Vec3f answer(0, 0, 0);

	const int num_lights = mesh->getLights().size();
	if (args->num_shadow_samples == 0) {
		for (int i = 0; i < num_lights; ++i) {

			const Face *f = mesh->getLights()[i];
			Vec3f pointOnLight = f->computeCentroid();
			const Vec3f point(ray.pointAtParameter(hit.getT()));
			Vec3f dirToLight = pointOnLight - point;
			dirToLight.Normalize();
			const Vec3f lightColor = 0.2 * f->getMaterial()->getEmittedColor() * f->getArea();
			return hit.getMaterial()->Shade(ray,hit,dirToLight,lightColor,args);
		}
	}

	// ----------------------------------------------
	// add contributions from each light that is not in shadow

	for (int i = 0; i < num_lights; i++) {
		const Face *f = mesh->getLights()[i];
		Vec3f pointOnLight = f->computeCentroid();
		const Vec3f point(ray.pointAtParameter(hit.getT()));

		double answerx = 0, answery = 0, answerz = 0;
		{
			for (int s = 0; s <= args->num_shadow_samples; ++s) {
				const Vec3f sh = shadow(point, pointOnLight, f, ray, hit);
				answerx += sh.x();
				answery += sh.y();
				answerz += sh.z();
				pointOnLight = f->RandomPoint();
			}
		}
		answer += Vec3f(answerx, answery, answerz);
	}
	answer *= static_cast<double>(1) / ((args->num_shadow_samples + 1) * num_lights);
	return answer;
}
开发者ID:linkinpark342,项目名称:parashader,代码行数:41,代码来源:raytracer.cpp

示例13: TracePhoton

void PhotonMapping::TracePhoton(const Vec3f &position, const Vec3f &direction, 
				const Vec3f &energy, int iter) {


  // ==============================================
  // ASSIGNMENT: IMPLEMENT RECURSIVE PHOTON TRACING
  // ==============================================

  // Trace the photon through the scene.  At each diffuse or
  // reflective bounce, store the photon in the kd tree.

  // One optimization is to *not* store the first bounce, since that
  // direct light can be efficiently computed using classic ray
  // tracing.

  //do ray cast
  Ray r(position,direction*(1/direction.Length()));
  Hit h;
  raytracer->CastRay(r,h,true);
  if (h.getT()>1000)
	  return;
  MTRand mtrand;
  Vec3f refl = h.getMaterial()->getReflectiveColor();
  Vec3f diff = h.getMaterial()->getDiffuseColor();
  double ran=mtrand.rand();
  if (iter==0)
	  ran= mtrand.rand(refl.Length()+diff.Length());
  //std::cout<<iter<<" "<<h.getT()<<" "<<refl.Length()+diff.Length()<<std::endl;
  //send reflective photon
  if (iter<args->num_bounces&&ran<=refl.Length())
	  TracePhoton(r.pointAtParameter(h.getT()),r.getDirection()-2*(r.getDirection().Dot3(h.getNormal()))*h.getNormal(),energy,iter+1);
  else if (iter<args->num_bounces&&ran<=refl.Length()+diff.Length())
	  TracePhoton(r.pointAtParameter(h.getT()),RandomDiffuseDirection(h.getNormal()),energy,iter+1);
  else
  {
	  Photon p(position,direction,energy,iter);
	  kdtree->AddPhoton(p);
  }


}
开发者ID:HowOriginal,项目名称:AdvGraphicsProject,代码行数:41,代码来源:photon_mapping.cpp

示例14: reflection

Vec3f RayTracer::reflection(const Ray &start_ray, int bounce_count) const
{
	Ray ray(start_ray);
	Hit h;
	Vec3f answer = TraceRay(ray, h, bounce_count);
	while (h.getT() < SURFACE_EPSILON) {
		ray = Ray(ray.pointAtParameter(SURFACE_EPSILON),
				ray.getDirection());
		answer = TraceRay(ray, h, bounce_count);
	}
	return answer;
}
开发者ID:linkinpark342,项目名称:parashader,代码行数:12,代码来源:raytracer.cpp

示例15: intersect

bool Triangle::intersect( const Ray& r , Hit& h , float tmin){

	Vector3f R_o = r.getOrigin();
	Vector3f R_d = r.getDirection();

	Matrix3f A( this->a.x()-this->b.x() , this->a.x()-this->c.x() , R_d.x() ,
		    this->a.y()-this->b.y() , this->a.y()-this->c.y() , R_d.y() ,
		    this->a.z()-this->b.z() , this->a.z()-this->c.z() , R_d.z()  );

	Matrix3f BetaM( this->a.x()-R_o.x() , this->a.x()-this->c.x() , R_d.x() ,
		        this->a.y()-R_o.y() , this->a.y()-this->c.y() , R_d.y() ,
		        this->a.z()-R_o.z() , this->a.z()-this->c.z() , R_d.z()  );
	
	float beta = BetaM.determinant() / A.determinant();

	Matrix3f GammaM( this->a.x()-this->b.x() , this->a.x()-R_o.x() , R_d.x() ,
		         this->a.y()-this->b.y() , this->a.y()-R_o.y() , R_d.y() ,
		         this->a.z()-this->b.z() , this->a.z()-R_o.z() , R_d.z()  );
	
	float gamma = GammaM.determinant() / A.determinant();

	float alpha = 1.0f - beta - gamma;

	Matrix3f tM( this->a.x()-this->b.x() , this->a.x()-this->c.x() , this->a.x()-R_o.x() ,
		     this->a.y()-this->b.y() , this->a.y()-this->c.y() , this->a.y()-R_o.y() ,
		     this->a.z()-this->b.z() , this->a.z()-this->c.z() , this->a.z()-R_o.z()  );
	
	float t = tM.determinant() / A.determinant();

	if (beta + gamma > 1){
	    return false;
	} 
	if (beta < 0){
	    return false;
	} 
	if (gamma < 0){
	    return false;
	} 

	if (t > tmin && t < h.getT()){

	    Vector3f newNormal = (alpha*this->normals[0] + beta*this->normals[1] + gamma*this->normals[2]).normalized();
	    h.set(t, this->material, newNormal);

	    Vector2f newTexCoord = (alpha*this->texCoords[0] + beta*this->texCoords[1] + gamma*this->texCoords[2]);
	    h.setTexCoord(newTexCoord);

	    return true;	
	} 
	else{
	    return false;
	} 
}
开发者ID:andrewmo2014,项目名称:Ray-Casting,代码行数:53,代码来源:Triangle.cpp


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