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


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

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


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

示例1: marchSecondary

float RayMarcher::marchSecondary( const Ray &ray )
{
	const float RAY_EPSILON = 0.50f;
	float boxTimes[2];
	if( mBoundingBox.intersect( ray, boxTimes ) != 2 )
		return 0;
		
	Vec3f pointOfDeparture;
	if( boxTimes[0] >= 0 )
		pointOfDeparture = ray.calcPosition( boxTimes[0] );
	else
		pointOfDeparture = ray.calcPosition( boxTimes[1] );
	float span = ray.getOrigin().distance( pointOfDeparture );
	int numSteps = (int)( span / RAY_EPSILON );
	if( numSteps <= 0 ) 
		return 0;

	Vec3f step( ray.getDirection() );
	step *= RAY_EPSILON;

	Vec3f rayPos = ray.getOrigin(); 

	float result = 0;
	for( int i = 0; i < numSteps; ++i ) {
		float D = sampleDensity( rayPos ) * RAY_EPSILON;
		result += D * ( 1.0f - result );
		
		rayPos += step; 
	}

	return result;
}
开发者ID:AKS2346,项目名称:Cinder,代码行数:32,代码来源:RayMarcher.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: rayTrace

	glm::vec3 rayTrace(Ray &ray, const float& t, const glm::vec3& normal, RayTracerState& state) {
		std::vector<std::shared_ptr<LightObject>>::iterator iter;
		glm::vec3 color;

		glm::vec3 p = ray.getOrigin() + t*ray.getDirection();

		for(iter = state.getLights().begin(); iter != state.getLights().end(); iter++){
			float shadow_value;
			shadow_value = (*iter)->PointInShadow(p, state);
			//skipping contribution from this light if the object is fully shadowed by it
			if(shadow_value <=0.00001f)
				continue;

			glm::vec3 pos = (*iter)->position;

			glm::vec3 diff = (*iter)->diff;
			glm::vec3 spec = (*iter)->spec;

			glm::vec3 v = glm::normalize(ray.getOrigin() - p);
			glm::vec3 l = glm::normalize(pos - p);
			glm::vec3 h = glm::normalize(v+l);
			glm::vec3 n = glm::normalize(normal);

			float diffuse = glm::max(0.0f, glm::dot(n, l));
			float specular = glm::pow( glm::max(0.0f, glm::dot(n, h)), 50.0f);

			glm::vec3 new_color = glm::vec3( (diff*diffuse)+(spec*specular) ) * shadow_value ;
			color += new_color;
		}
		color/=state.getLights().size();
		//glm::vec3 absnormal = glm::vec3(abs(normal.x),abs(normal.y),abs(normal.z)); 
		return color;//*shadefactor;
	}
开发者ID:skakri09,项目名称:PG612-innlevering-3,代码行数:33,代码来源:SceneObjectEffect.hpp

示例4: projectRay

Point UIManagerSpherical::projectRay(const Ray& ray) const
	{
	/* Check if the line defined by the ray intersects the sphere: */
	Scalar d2=Geometry::sqr(ray.getDirection());
	Vector oc=ray.getOrigin()-sphere.getCenter();
	Scalar ph=oc*ray.getDirection();
	Scalar det=Math::sqr(ph)-(Geometry::sqr(oc)-Math::sqr(sphere.getRadius()))*d2;
	if(det>=Scalar(0))
		{
		/* Calculate the point where the line exits the sphere: */
		det=Math::sqrt(det);
		return ray((-ph+det)/d2);
		}
	else
		{
		/* Return the projection of the ray's origin onto the sphere: */
		Vector d=ray.getOrigin()-sphere.getCenter();
		Scalar dLen=d.mag();
		if(dLen==Scalar(0))
			{
			d=getForwardDirection();
			dLen=d.mag();
			}
		return sphere.getCenter()+d*(sphere.getRadius()/dLen);
		}
	}
开发者ID:KeckCAVES,项目名称:Vrui,代码行数:26,代码来源:UIManagerSpherical.cpp

示例5: shade

Vertex Rendering::shade(Ray intersect, Scene scene, Vertex viewerDirection) {
	// intersect is a ray with origin at the point of intersect,
	// and direction of the normal of the intersected polygon
	Vertex shade (0,0,0);
	
	vector<Vertex> lights = scene.getDirectionalLights();
	for (int a=0; a<lights.size(); a++) {
		// see if that light is blocked, if so, it's shadow
		Vertex light = Vertex(lights[a].get(0), lights[a].get(1), lights[a].get(2));
		Vertex color = Vertex(lights[a].get(3), lights[a].get(4), lights[a].get(5));
		light = light.scale(-1);
		if (!isShadowed(intersect.getOrigin(), light, scene, false)) {
			light = light.normalize();
			float gradient = max(0.0f, light.dot(intersect.getDirection()));
			float specular = intersect.getDirection().reflect(light.scale(-1)).dot(viewerDirection.scale(-1).normalize());
			specular = pow(max(0.0f, specular),specularConst);
			shade = shade.add(color.scale(gradient+specular));
		}
	}
	
	vector<Vertex> plights = scene.getPointLights();
	for (int a=0; a<plights.size(); a++) {
		Vertex light = Vertex(plights[a].get(0), plights[a].get(1), plights[a].get(2));
		Vertex color = Vertex(plights[a].get(3), plights[a].get(4), plights[a].get(5));
		light = light.sub(intersect.getOrigin());
		if (!isShadowed(intersect.getOrigin(), light, scene, true)) {
			light = light.normalize();
			float gradient = max(0.0f, light.dot(intersect.getDirection()));
			float specular = intersect.getDirection().reflect(light.scale(-1)).dot(viewerDirection.scale(-1).normalize());
			specular = pow(max(0.0f, specular),10);
			shade = shade.add(color.scale(gradient+specular));
		}
	}
	return shade;
}
开发者ID:,项目名称:,代码行数:35,代码来源:

示例6: shadowHit

bool Rect::shadowHit(const Ray& ray, float& tmin) const
{
	if(!castsShadows)
		return false;

	float t = glm::dot((corner - ray.getOrigin()),normal) / glm::dot(ray.getDirection(),normal);

	if(t<=KEpsilon)
		return false;

	glm::vec3 point = ray.getOrigin() + t * ray.getDirection();
	glm::vec3 d = point - v0;

	float dDota = glm::dot(d, v0);
	if(dDota<0.0 || dDota > aLenSquared)
		return false;

	float dDotb = glm::dot(d, v1);
	if(dDotb<0.0f || dDotb > bLenSquared)
		return false;

	tmin = t;

	return true;
}
开发者ID:RyanAdamsGD,项目名称:RayTracer,代码行数:25,代码来源:Rect.cpp

示例7: shaded_color

Color Ray::shaded_color(const LightConstPtr& light, const Vector& lightPoint, const Ray& reflectedray, const Vector& normal, ObjektConstPtr& obj, const Color& textureColor)
{
	Color diffuse, specular;
	
	const Vector lightDir = light->getDirection(reflectedray.getOrigin(), lightPoint);
	const double lightIntensity = light->getItensity(reflectedray.getOrigin(), lightPoint);

	// Diffuse light
	double ldot = lightDir.dot(normal);
	if (1.0 + ldot > 1.0) {
		Color lambert = light->getColor().scmpy(ldot);
		diffuse = lambert.outprodc(obj->getProperty().getReflectance());
	}

	// Specular light
	double spec = reflectedray.getDirection().dot(lightDir);
	if (1.0 + spec > 1.0) {
		spec = pow(spec, obj->getProperty().getShininess());
		spec *= obj->getProperty().getSpecular();
		specular =  light->getColor().scmpy(spec);
	}

	Color reflected_color = diffuse.addcolor(specular);

	if (!textureColor.isNull())	{
		reflected_color = reflected_color.outprodc(textureColor);
	}
	
	return reflected_color.scmpy(lightIntensity);
} /* shaded_color() */
开发者ID:MBulli,项目名称:FHWS-raytracer,代码行数:30,代码来源:Ray.cpp

示例8: collide

pair<Vec3, SceneObject*> collide(Ray &ray, vector<SceneObject*>& sceneObjects){
	// init the best impact point to the ray position
	Vec3 best_impact_point = ray.getOrigin();
	// get the origin of the ray
	Vec3 ray_origin = ray.getOrigin();
	// declare the best scene object;
	SceneObject* best_sceneObject = nullptr;
	// declare the best distance
	float best_dist = numeric_limits<float>::infinity();
	// declare the current distance
	float dist = 0.0;
	// declare the pair for the intersect function
	pair<bool, Vec3> pair_intersect;
	// declare impact point
	Vec3 impact_point;
	//for each object of the scene
	for (vector<SceneObject*>::iterator it = sceneObjects.begin(); it != sceneObjects.end(); it++){
		// determine if the ray intersect the object
		pair_intersect = (*it)->intersect(ray);
		if (pair_intersect.first){
			// compute the distance between the ray and the impact point
			impact_point = pair_intersect.second - ray_origin;
			dist = impact_point.length();
			// if it's the best
			if (best_dist > dist){
				best_dist = dist;
				best_sceneObject = *it;
				best_impact_point = pair_intersect.second;
			}
		}
	}
	return pair<Vec3, SceneObject*>(best_impact_point, best_sceneObject);
}
开发者ID:th0nyXX,项目名称:raycpp,代码行数:33,代码来源:collision.cpp

示例9: intersectRay

bool OsgSceneObject::intersectRay(const Ray& ray, Vector3f* hitPoint)
{
	Vector3f rstart = ray.getOrigin();
	
	// Compute reasonable ray length based on distance between ray origin and
	// owner scene node center.
	Vector3f center = getOwner()->getBoundCenter();
	float dir = (ray.getOrigin() - center).norm();
	Vector3f rend = ray.getPoint(dir * 2);

	osg::Vec3d orig(rstart[0], rstart[1], rstart[2]);
	osg::Vec3d end(rend[0], rend[1], rend[2]);


	Ref<osgUtil::LineSegmentIntersector> lsi = new osgUtil::LineSegmentIntersector(orig, end);
	osgUtil::IntersectionVisitor iv(lsi);

	myTransform->accept(iv);

	if(!lsi->containsIntersections()) return false;

	osgUtil::LineSegmentIntersector::Intersection i = lsi->getFirstIntersection();
	
	osg::Vec3d intersect = i.getWorldIntersectPoint();

	hitPoint->x() = intersect[0];
	hitPoint->y() = intersect[1];
	hitPoint->z() = intersect[2];
	return true;
}
开发者ID:caishanli,项目名称:omegaOsg,代码行数:30,代码来源:OsgSceneObject.cpp

示例10: maxCoordinates

pair<bool, Vec3> Planar::intersect(Ray &ray){
	// declare the impact point
	Vec3 impact_point = ray.getOrigin();

	// normalize the vector (n is already normalized)
	Vec3 l0 = ray.getOrigin();
	Vec3 l = ray.getDirection();

	// calcul the denominator
	float denom = l * n;
	// if the ray and the normal vector of the planar isn't parallel
	if (denom > 1e-6) {
		// calcul t for determinate if the ray intersect the planar
		float t = ((position - l0) * n) / denom;
		// calcul the impact point
		impact_point = l0 + l * t;
		// verif if the impact point is in the square
		if (impact_point.getX() < maxCoordinates().getX() && impact_point.getX() > minCoordinates().getX()
			&& impact_point.getY() < maxCoordinates().getY() && impact_point.getY() > minCoordinates().getY() 
			/*&& impact_point.getZ() <= maxCoordinates().getZ() && impact_point.getZ() >= minCoordinates().getZ()*/){
				return pair<bool, Vec3>(t >= 0, impact_point);
		}
		else{
			return pair<bool, Vec3>(false, impact_point);
		}
	}
	return pair<bool, Vec3>(false, impact_point);
}
开发者ID:th0nyXX,项目名称:raycpp,代码行数:28,代码来源:Planar.cpp

示例11: intersect

bool Plane::intersect( Ray& ray, hpvec3& intersectionPoint ) {
	if( glm::abs(glm::dot(ray.getDirection(), m_normal)) < HP_EPSILON ) {
		return false;
	}
	hpreal t = -(glm::dot(ray.getOrigin(), m_normal) + glm::dot(m_origin, m_normal)) / glm::dot(ray.getDirection(), m_normal);
	intersectionPoint = ray.getOrigin() + t*ray.getDirection();
	return true;
}
开发者ID:jenseh,项目名称:happah,代码行数:8,代码来源:Plane.cpp

示例12: 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;
} 
开发者ID:espinm2,项目名称:adv_gfx_repo,代码行数:57,代码来源:sphere.cpp

示例13: Vector

bool
CollisionManager::isIntersecting(const Ray& ray, Entity* entity, Real& distance)
{
  // get a pointer to the collision model 
  ColDet::CollisionModel3D* mColModel = modelMap[entity->getMesh()->getName()];
  if(mColModel == NULL) return false;
      
  // set the world transform for the entity    
  {
    Matrix4 world; 
    entity->getParentSceneNode()->getWorldTransforms(&world);  
    
    float fMatrix[16];
    fMatrix[0] = world[0][0];
    fMatrix[1] = world[1][0];
    fMatrix[2] = world[2][0];
    fMatrix[3] = world[3][0];
    fMatrix[4] = world[0][1];
    fMatrix[5] = world[1][1];
    fMatrix[6] = world[2][1];
    fMatrix[7] = world[3][1];
    fMatrix[8] = world[0][2];
    fMatrix[9] = world[1][2];
    fMatrix[10] = world[2][2];
    fMatrix[11] = world[3][2];
    fMatrix[12] = world[0][3];
    fMatrix[13] = world[1][3];
    fMatrix[14] = world[2][3];
    fMatrix[15] = world[3][3];

    mColModel->setTransform(fMatrix); 
  }
  
  // convert the ray  
  float Origin[3], Direction[3]; 
  
  Origin[0] = ray.getOrigin().x; 
  Origin[1] = ray.getOrigin().y; 
  Origin[2] = ray.getOrigin().z; 

  Direction[0] = ray.getDirection().x; 
  Direction[1] = ray.getDirection().y; 
  Direction[2] = ray.getDirection().z;  

  // check for a collision 
  bool col = mColModel->rayCollision(Origin, Direction);      

  // for testing purposes 
//   mColModel->getCollidingTriangles(t1, t2, false); 
//   mColModel->getCollisionPoint(colPoint, false); 
  float collisionPoint[3];
  mColModel->getCollisionPoint(collisionPoint, false);
  Vector displacement = ray.getOrigin() - Vector(collisionPoint[0], collisionPoint[1], collisionPoint[2]);
  distance = displacement.length();

  return col; 
}
开发者ID:MrPhil,项目名称:ShortHike,代码行数:57,代码来源:CollisionManager.cpp

示例14: hit

bool TrianglePatch::hit(const Ray &r,double tmax,double time,HitRecord &record)const{
	Vector3 p0=animation[0](vertex[0],time);
	Vector3 p1=animation[1](vertex[1],time);
	Vector3 p2=animation[2](vertex[2],time);

	Vector3 n0=animation[0](vertex[0]+normal[0],time)-p0;
	Vector3 n1=animation[1](vertex[1]+normal[1],time)-p1;
	Vector3 n2=animation[2](vertex[2]+normal[2],time)-p2;

	double A=p0.getX()-p1.getX();
	double B=p0.getY()-p1.getY();
	double C=p0.getZ()-p1.getZ();

	double D=p0.getX()-p2.getX();
	double E=p0.getY()-p2.getY();
	double F=p0.getZ()-p2.getZ();

	double G=r.getDirection().getX();
	double H=r.getDirection().getY();
	double I=r.getDirection().getZ();

	double J=p0.getX()-r.getOrigin().getX();
	double K=p0.getY()-r.getOrigin().getY();
	double L=p0.getZ()-r.getOrigin().getZ();

	double EIHF=E*I-H*F;
	double GFDI=G*F-D*I;
	double DHEG=D*H-E*G;

	double denom=(A*EIHF+B*GFDI+C*DHEG);

	double beta=(J*EIHF+K*GFDI+L*DHEG)/denom;
	if((beta<=0.0f)||(beta>=1.0f))
		return false;

	double AKJB=A*K-J*B;
	double JCAL=J*C-A*L;
	double BLKC=B*L-K*C;

	double gamma=(I*AKJB+H*JCAL+G*BLKC)/denom;
	if((gamma<=0.0f)||(gamma>=1.0f))
		return false;

	double t=-(F*AKJB+E*JCAL+D*BLKC)/denom;
	if((t>=0.0f)&&(t<=tmax)){
		record.t=t;
		record.material=std::make_shared<Material>(material);
		record.hitpoint=r.pointAt(t);
		record.normal=normalize(n0+n1+n2);
		record.UVcoord=(1.0f-beta-gamma)*texCoord[0]+beta*texCoord[1]+gamma*texCoord[2];
		return true;
	}

	return false;
}
开发者ID:gnaggnoyil,项目名称:selfmaderaytracer,代码行数:55,代码来源:TrianglePatch.cpp

示例15: from

    std::vector < std::pair <float, std::string> > PhysicsSystem::getFacedObjects ()
    {
        //get a ray pointing to the center of the viewport
        Ray centerRay = mRender.getCamera()->getCameraToViewportRay(
        mRender.getViewport()->getWidth()/2,
        mRender.getViewport()->getHeight()/2);
        btVector3 from(centerRay.getOrigin().x,-centerRay.getOrigin().z,centerRay.getOrigin().y);
        btVector3 to(centerRay.getPoint(500).x,-centerRay.getPoint(500).z,centerRay.getPoint(500).y);

        return mEngine->rayTest2(from,to);
    }
开发者ID:DeejStar,项目名称:openmw,代码行数:11,代码来源:physicssystem.cpp


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