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


C++ Ray::getDir方法代码示例

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


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

示例1: intersect

bool Tri::intersect(Ray& _ray, float* thit, Intersection* in) {
  Ray ray = _ray.transform(inverseTransform);
  if (!intersectP(ray)) { return false; }
  if (*thit < t) { return false; }

  p = ray.getPos() + ray.getDir() * t;
  w = p - a;
  vCrossW = glm::cross(v, w);
  uCrossW = glm::cross(u, w);

  if (glm::dot(vCrossW, vCrossU) < 0) { return false; }
  if (glm::dot(uCrossW, uCrossV) < 0) { return false; }

  beta = glm::length(vCrossW)/denom;
  gamma = glm::length(uCrossW)/denom;
  alpha = 1 - beta - gamma;

  if (!(beta <= 1 && gamma <= 1 && beta + gamma <= 1)) { return false; }

  *thit = t;
  in->localGeo.pos = mat4TimesVec3(getTransform(),
    (ray.getPos() + t * ray.getDir()), 1.0);
  in->localGeo.normal = getNormal();
  //shift position slightly towards normal (epsilon shift)
  in->localGeo.pos = in->localGeo.pos + in->localGeo.normal * epsilon;
  in->primitive = this;

  return true;
}
开发者ID:mdurn,项目名称:raytracer,代码行数:29,代码来源:Tri.cpp

示例2: intersect

ptc::IntersectDescr Rectangle::intersect( const Ray& ray )
{
	const double dir_dot = normal_.dot( ray.getDir() );
	
	const bool is_grazing = std::abs( dir_dot ) <= 1e-4;
	const bool is_wrong_side = !getIsDoubleSided() && dir_dot >= -1e-4;
	
	if( is_grazing || is_wrong_side )
	{
		return IntersectDescr( this );
	}

	const Vector center_vec = center_ - ray.getOrigin();
	const double distance = -normal_.dot( center_vec );

	const double param = distance / -dir_dot;

	const Vector intersect = ray.getOrigin() + param * ray.getDir();
	const Vector intersect_vec = intersect - center_;

	const bool is_right_vec_ok = std::abs( right_.dot( intersect_vec ) ) <= .5 * width_;
	const bool is_up_vec_ok = std::abs( up_.dot( intersect_vec ) ) <= .5 * height_;

	if( is_right_vec_ok && is_up_vec_ok )
	{
		return IntersectDescr( param, intersect, normal_, ray.getDir(), this );
	}

	return IntersectDescr( this );
}
开发者ID:asplendidday,项目名称:ptchan,代码行数:30,代码来源:Rectangle.cpp

示例3: planeIntersect

/**
 * Intersect a Ray with a plane defined by the 4 coefficients Ax + By + Cz + D = 0.
 * A,B,C are the plane normal
 */
bool planeIntersect(const Ray& r, const float *plane, PointF& intersection) {
    Normal normal(plane[0], plane[1], plane[2]);
    
    const PointF& rp = r.getPos();
    float dotNormalRayDir = Math::dot3(normal, r.getDir());
    
    // Is the ray perpendicular to the plane's normal?
    if (fabs(dotNormalRayDir) < PLANE_INTERSECTION_THRESHOLD) {
        return false;
    }
    
    // Determine which side of the plane the point is on
    float distFromPlane = Math::dot3(normal, rp) + plane[3];
    float t = distFromPlane/dotNormalRayDir;
    
    // > 0 if ray and normal are in the same direction and
    // the ray is on the normal side of the plane or
    // If the ray and normal point in opposite directions and
    // the ray is not on the normal side of the plane
    if (t > 0) {
        return false;
    }
    
    intersection = Math::vec3AXPlusB(r.getDir(), -t, r.getPos());
    return true;
}
开发者ID:bfgorski,项目名称:Renderer,代码行数:30,代码来源:BasicTypesImpl.cpp

示例4: intersect

//(r⃗ ·r⃗)t2 +2r⃗ ·(r⃗o −cen⃗ter)t+(r⃗o −cen⃗ter)·(r⃗o −cen⃗ter)−R2 =0
bool Sphere::intersect(const Ray& r, const float tmin, float &t_max){
	float t0, t1; // solutions for t if the ray intersects

    // analytic solution
	Vector3D L = r.getOrigin() - center;
	// std::cout << "L " << L << std::endl;
	float a = r.getDir().dot(r.getDir());
	// std::cout << "a " << a << std::endl;
	float b = 2 * r.getDir().dot(L);
	// std::cout << "b " << b << std::endl;
	float c = L.dot(L) - (radius * radius ) ;
	// std::cout << "c " << c << std::endl;

	if (!solveQuadratic(a, b, c, t0, t1)) return false;

	if (t0 > t1) std::swap(t0, t1);
	if (t0 < 0) {
	    t0 = t1; // if t0 is negative, let's use t1 instead
	    if (t0 < 0) 
	    	return false; // both t0 and t1 are negative
	}
	t_max = t0;

	return true;

}
开发者ID:Sandarmann,项目名称:Programming,代码行数:27,代码来源:Sphere.cpp

示例5: intersect_search

bool intersect_search(Ray ray, Triangle* trig, int nTriangles, PoI* poi)
{
	float min_hit = 99999;
	int count = 0;
	float t_hit;
	for (count = 0; count < nTriangles; count ++)
	{
		Triangle t = trig[count];
		//t.scale(2, 1, 1); //scale by x-axis by 2
		

		bool hit = t.hit(ray, &t_hit);
		if (hit && t_hit < min_hit)
		{
			min_hit = t_hit;
			poi->setCollision(ray.getDir() * min_hit + ray.getPos());
			poi->setColor(t.kd);
			Vector myNorm = t.getNormal();
			//if normal faces the wrong way, then needs to do soemthing about it
        	//cos(angle) = dot_product / (a.len * b.len)
        	float cosine = myNorm.Vdot(ray.getDir()) / (myNorm.getMag() * ray.getDir().getMag());
        	if (cosine < 0)
        	{
       			myNorm = myNorm * -1;
        	}
			poi->setNormal(t.getNormal());
		}
	}
	if (min_hit != 99999)
	{
		return true;
	}
	return false;
}
开发者ID:Mduchamp,项目名称:CS-184,代码行数:34,代码来源:Scene.cpp

示例6: intersect

Intersect Sphere::intersect(Ray r) {
    Intersect::Intersect ret = *new Intersect::Intersect();
    std::vector<float> d = r.getDir();
    std::vector<float> e = r.getEye();
    std::vector<float> eminusp(3);
    eminusp[0] = e[0] - position[0];
    eminusp[1] = e[1] - position[1];
    eminusp[2] = e[2] - position[2];
    float ddotd = d[0]*d[0]+d[1]*d[1]+d[2]*d[2];
    float empdot = eminusp[0]*eminusp[0] + eminusp[1]*eminusp[1] + eminusp[2]*eminusp[2];
    float ddoteminusp = d[0]*eminusp[0] + d[1]*eminusp[1] + d[2]*eminusp[2];
    float discriminant = sqrt(ddoteminusp * ddoteminusp - ddotd*(empdot - radius*radius));
    if (discriminant >= 0) {
        ret.setHit(true);
        float scalar = -1.0f;
        float * scale = &scalar;
        std::vector<float> scaled(3);
        scaled = vScale(-1, d);
        //scaled[0] = d[0]*(-1);
        //scaled[1] = d[1]*(-1);
        //scaled[2] = d[2]*(-1);
        float sdotemp = scaled[0]*eminusp[0] + scaled[1]*eminusp[1] + scaled[2]*eminusp[2];
        ret.setPoint(r.project((sdotemp+discriminant)/ddotd));
    }
    return ret;
}
开发者ID:WesleyTo,项目名称:as2,代码行数:26,代码来源:RayTrace.cpp

示例7: checkRay

  bool Sphere::checkRay (const Ray& ray, worldUnit& range, Vector& dist) const
  {
    dist = position.diff(ray.getStart());

    worldUnit a = ray.getDir().dotProduct(dist);

    auto squareLength = dist.dotProduct();
    worldUnit D = squareRadius - squareLength + a * a;

    //There is no intersection with sphere if D < 0
    if (D < 0.f)
    {
      return false;
    }

    worldUnit t = SQRT(D);

    if (squareLength >= squareRadius)
    { //We are outside sphere
      a -= t;
    }
    else
    { //We are inside sphere
      a += t;
    }

    if ( (a > 0.0f) && (a < range))
    {
      range = a;
      return true;
    }

    return false;
  }
开发者ID:travnick,项目名称:GKiO-Projekt-GK,代码行数:34,代码来源:Sphere.cpp

示例8: subsurface

RGB SubsurfacePathtracer::subsurface(RayIntersection* p_intersection, Ray *p_ray) {

	int SSS_SAMPLES = 30;
	RGB color;
	float absFactor = 0.01f;

	for(int i = 0; i < SSS_SAMPLES; i++) {
		RGB sampleColor;
		Ray ray = p_intersection->object->getShader()->getSubsurfaceSampledRay(p_intersection->object, p_intersection->point, p_intersection->normal, p_ray->getDir(), p_intersection->uv);
		RayIntersection intersection;
		
		//test any intersection (for inner occulsion)
		if(ray.nearestIntersection(scene->getObjects(), scene->getObjectCount(), &intersection)) {

			if(intersection.normal.dot(ray.getDir()) > 0) {
				sampleColor = p_intersection->object->getShader()->getDiffuseIrradiance(intersection.object, intersection.point, intersection.normal, intersection.uv, ray.getDir(), scene);
				
				float absortion = 1 - (intersection.dist * absFactor);

				if(absortion < 0) {
					absortion = 0;
				}

				//printf("%f\n", sampleColor.r);

				sampleColor = sampleColor * absortion;
				color = color + sampleColor;
			}
		}
	}

	color = color / (float)SSS_SAMPLES;

	return color;
}
开发者ID:joaomontenegro,项目名称:monteray,代码行数:35,代码来源:SubsurfacePathtracer.cpp

示例9: intersect

Intersect Triangle::intersect(Ray r) {
	Intersect::Intersect ret = *new Intersect::Intersect();
	float a = v1.getX() - v2.getX();
	float b = v1.getY() - v2.getY();
	float c = v1.getZ() - v2.getZ();
	float d = v1.getX() - v3.getX();
	float e = v1.getY() - v3.getY();
	float f = v1.getZ() - v3.getZ();
	float g = r.getDir().at(0);
	float h = r.getDir().at(1);
	float i = r.getDir().at(2);
	float j = v1.getX() - r.getEye().at(0);
	float k = v1.getY() - r.getEye().at(1);
	float l = v1.getZ() - r.getEye().at(2);
	float eiminushf = e*i - h*f;
	float gfminusdi = g*f - d*i;
	float dhminuseg = d*h - e*g;
	float akminusjb = a*k - j*b;
	float jcminusal = j*c - a*l;
	float blminuskc = b*l - k*c;
	float m = a*(eiminushf) + b*(gfminusdi) + c*(dhminuseg);
	float beta = (j*(eiminushf) + k*(gfminusdi) + l*(dhminuseg))/m;
	if (beta < 0) {return ret;}
	float gamma = (i*(akminusjb) + h*(jcminusal) + g*(blminuskc))/m;
	if (gamma < 0 || beta+gamma > 1) {return ret;}
	float t = (-1)*(f*(akminusjb) + e*(jcminusal) + d*(blminuskc))/m;
	std::vector<float> p;
	
	std::vector<float> vec1 = v1.toVec();
	std::vector<float> vec2 = v2.toVec();
	std::vector<float> vec3 = v3.toVec();
	std::vector<float> sub1 = vSub(&vec2, &vec1);
	std::vector<float> sub2 = vSub(&vec3, &vec1);
	std::vector<float> scaled1 = vScale(&beta, &sub1);
	std::vector<float> scaled2 = vScale(&gamma, &sub2);
	std::vector<float> added1 = vAdd(&vec1, &scaled1);
	p = vAdd(&added1, &scaled2);
	
	ret.setPoint(p);
	
	return ret;
}
开发者ID:WesleyTo,项目名称:as2,代码行数:42,代码来源:Triangle.cpp

示例10: intersection

HitInfo Sphere::intersection(const Ray & ray){
	double a = Vector(ray.getDir()).dot(Vector(ray.getDir()));
	double b = 2*Vector(ray.getStart()).dot(ray.getDir());
	double c = Vector(ray.getStart()).dot(Vector(ray.getStart()))-1;

	double discr = pow(b,2) - 4*a*c;

	double t1 =(-b-sqrt(discr))/(2*a);
	double t2 =(-b+sqrt(discr))/(2*a);
	double t = t2;

	if (t1<t2){
		if(t1 >= 0){
			t = t1;
		}
	}

	Point intersect = ray.getPoint(t);

	return HitInfo(t, intersect, mtrl, Vector(intersect));
}
开发者ID:Mithos-Yggdrasill,项目名称:3DCG_RenderingFramework,代码行数:21,代码来源:Sphere.cpp

示例11: transmit

/** Cast transmitted ray
 ** @param ray incoming ray
 ** @param pt intersection point
 ** @param normal normal of pt
 ** @param ior2 index of refraction of the object
 ** @return transmitted ray
 **/
Ray transmit(Ray ray, Vec pt, Vec normal, float ior1, float ior2){
  Vec r = ray.getDir();
  float alpha = ior1 / ior2;
  float c1 = normal.dot(r) * -1;
  float c2 = sqrt(1 - pow(alpha,2) * (1 - pow(c1,2)));
  Vec v = r * alpha + normal * (c1 * alpha - c2);
  Ray t(pt, v, 0, 9999, TransmittedRay);
  if (debugMode) {
    printf("transmitted ray origin: "); t.getOrig().print();
    printf("transmitted ray direction: "); t.getDir().print();
  }
  return t;
}
开发者ID:jacyxli,项目名称:ray-tracer,代码行数:20,代码来源:main.cpp

示例12: intersect

bool Sphere::intersect(const Ray& ray, RaySurfIntersection& res)const{
    res.shp = NULL;

    //Transform ray to object space
    const Ray rOb = w2o(ray);

    const Vector o = Vector(rOb.getOrigin().x, rOb.getOrigin().y, rOb.getOrigin().z);
    const Vector d = rOb.getDir();
    const float A = d.dot(d);
    const float B = 2.0f * (d.dot(o));
    const float C = o.dot(o) - (r * r);


    struct MathUtils::QuadraticEqnRes<float> slv =
        MathUtils::solveQuadratic<float>(A, B, C);
    float tHitFinal = 0.0f; //After the below code this will eventually be set to
    //the first hit point in front of the camera
    if(slv.solCount == 0){
        return false;
    }else if(slv.solCount == 1){
        tHitFinal = slv.sol1;
        if(tHitFinal < 0.0f){
            //No solutions in front of camera
            return false;
        }
    }else{ //2 solutions
        //Find smallest t value that is > 0.0f
        if(slv.sol1 < 0.0f && slv.sol2 < 0.0f){
            //No solutions in front of camera
            return false;
        }else{
            //At least one hit in front of camera
            slv.sol1 = slv.sol1 < 0.0f ? Constants::MAX_FLOAT_VAL : slv.sol1;
            slv.sol2 = slv.sol2 < 0.0f ? Constants::MAX_FLOAT_VAL : slv.sol2;
            tHitFinal = std::min<float>(slv.sol1, slv.sol2);
        }
    }

    //Make sure hit is in front of camera
    Assert(tHitFinal >= 0.0f);

    res.tHit = tHitFinal;
    res.locWS = ray(res.tHit);
    Vector normalVecAtHit = res.locWS - o2w(Point(0.0f,0.0f,0.0f));
    res.n = normalVecAtHit.getNormalized();
    res.shp = this;
    return true;
}
开发者ID:caomw,项目名称:renderer,代码行数:48,代码来源:Sphere.cpp

示例13: intersect

CIsect Plane::intersect(const Ray& ray)
{
	float angle = dot(mNormal, ray.getDir());
	if (fabs(angle) < FLOAT_ZERO) 
	{
		return CIsect(false);
	}
	float t = (-(dot(ray.getOrg(), mNormal) + mD) / angle);
	if (t > 0.f)
	{
		CIsect res(true, t, this, getNormal(ray, t));
		res.Dst.push_back(t);
		res.InsideIntervals.push_back(Span(t, t));
		return res;
	}
	return CIsect(false);
}
开发者ID:DimkoChurinov,项目名称:raytracing,代码行数:17,代码来源:plane.cpp

示例14: raySphereCollide

void Collide::raySphereCollide(const Body * ray_, const Body * sphere_)
{
	Ray *ray = (Ray*)ray_;
	Sphere *sphere = (Sphere*)sphere_;
	Vector3 vec = ray->getStart() - sphere->getCenter();
	setCollide(true);
	setDistance(0.0f);
	float fB = vec.Dot(ray->getDir());
	float fC = vec.Dot(vec) - sphere->getRadius()*sphere->getRadius();
	if (fC > 0.0f && fB > 0.0f)
		setCollide(false);
	float fDisc = fB*fB - fC;
	if (fDisc < 0.0f)
		setCollide(false);

	// compute the response vectors
	Vector3 responseObject1 = ray_->getCenter()- sphere_->getCenter();
	Vector3 responseObject2 = sphere_->getCenter() - ray_->getCenter();
	setResponseObject1(responseObject1);
	setResponseObject2(responseObject2);
}
开发者ID:jackhui,项目名称:GE,代码行数:21,代码来源:cdCollide.cpp

示例15: intersectP

bool Tri::intersectP(Ray& ray) {
  t = (glm::dot(a, planeNormal) - glm::dot(ray.getPos(), planeNormal)) /
    glm::dot(ray.getDir(), planeNormal);
  if (t > 0) { return true; }
  else { return false; }
}
开发者ID:mdurn,项目名称:raytracer,代码行数:6,代码来源:Tri.cpp


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