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


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

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


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

示例1: RayThruPixel

Ray Renderer::RayThruPixel(int i, int j)
{
	Ray viewRay;

	Camera* camera = m_scene.GetCamera();

	viewRay.SetOrigin(camera->GetlookfromPoint());

	int d = camera->Getfov();
	int l, r, b, t;
	double u, v;

	l = -(m_scene.GetImageWidth() / 2);
	r = m_scene.GetImageWidth() / 2;
	b = -(m_scene.GetImageHeight() / 2);
	t = m_scene.GetImageHeight() / 2;

	u = l + (r - l) * (i + 0.5) / m_scene.GetImageWidth();
	v = b + (t - b) * (j + 0.5) / m_scene.GetImageHeight();

	Vector w(camera->GetlookatPoint().Inverse());
	Vector upVector(camera->GetupVector());
	Vector uVector = w * upVector;

	Vector directionVector;
	
	directionVector = (w * (-d)) + (uVector * u) + (upVector * v);

	viewRay.SetDirection(directionVector);

	return viewRay;
}
开发者ID:DiMasta,项目名称:Raytracing_edX,代码行数:32,代码来源:Rederer.cpp

示例2: TestPixelRay

void
RayTracer::Draw(unsigned char *framebuf, int framewidth, int frameheight)
{
	float screen_x_step = (screen_max.vec[0] - screen_min.vec[0]) / (float)framewidth;
	float screen_y_step = (screen_max.vec[1] - screen_min.vec[1]) / (float)frameheight;

	float fx = screen_min.vec[0];
	float fy = screen_min.vec[1];

	for(int y = 0; y < frameheight; y++) {
		for(int x = 0; x < framewidth; x++) {
			Vector dir;
			dir.Clear();

			dir.vec[0] = fx;
			dir.vec[1] = fy;
			dir.vec[2] = 2.0f;

			Ray ray;
			ray.SetOrigin(Vector(0.0f, 0.0f, 0.0f));
			ray.SetDirection(dir);

			unsigned int p = TestPixelRay(x, y, ray);

			unsigned char r = p >> 24;
			unsigned char g = p >> 16;
			unsigned char b = p >> 8;

			framebuf[framewidth * y * 4 + x * 4 + 0] = r;
			framebuf[framewidth * y * 4 + x * 4 + 1] = g;
			framebuf[framewidth * y * 4 + x * 4 + 2] = b;
			framebuf[framewidth * y * 4 + x * 4 + 3] = 0xff;

			fx += screen_x_step;
		}

		fx = screen_min.vec[0];
		fy += screen_y_step;
	}
}
开发者ID:joshb,项目名称:raytracer,代码行数:40,代码来源:raytracer.cpp

示例3: DivideTriangle

void SoftBodyNode::DivideTriangle(TDVertexContainer& Vertices, 
								TDConnectContainer& Connections, 
								TDConnectContainer::iterator itFace)
{
	TDConnect::iterator itIdx = itFace->begin();
	TDConnect::size_type nIdxA = *itIdx;
	TDConnect::size_type nIdxB = *(itIdx + 1);
	TDConnect::size_type nIdxC = *(itIdx + 2);
	TDConnect::size_type nIdxD = -1;
	TDConnect::size_type nIdxE = -1;
	TDConnect::size_type nIdxF = -1;
	TDVertex A(m_Vertices[nIdxA]);
	TDVertex B(m_Vertices[nIdxB]);
	TDVertex C(m_Vertices[nIdxC]);
	TDVertex AB(B-A);
	TDVertex AC(C-A);
	TDVertex BC(C-B);
	//TDVertex Normal(AB.Cross(AC));

	//normals of the edges - I don't know if this idea makes sense - I've never come
	//across an edge normal before in computer graphics literature. In this program I've defined the normal of
	//an edge to be the sum of the normals of the adjoining vertices. This is not true in general. 
	//It should be the sum of the normals of the adjoining faces, ie the faces that the edge border, 
	//but in this case because the kernel polyhedron is an octahedron, we may be able to get away with it.
	TDVertex NormalAB(*(m_Normals[nIdxA]) + *(m_Normals[nIdxB]));
	TDVertex NormalAC(*(m_Normals[nIdxA]) + *(m_Normals[nIdxC]));
	TDVertex NormalBC(*(m_Normals[nIdxB]) + *(m_Normals[nIdxC]));
		
	NormalAB = 1.0f/bnu::norm_2(NormalAB) * NormalAB;
	NormalAC = 1.0f/bnu::norm_2(NormalAC) * NormalAC;
	NormalBC = 1.0f/bnu::norm_2(NormalBC) * NormalBC;

	TDVertex MidAB(A + 0.5*AB);
	TDVertex MidAC(A + 0.5*AC);
	TDVertex MidBC(B + 0.5*BC);
	
	Sphere BoundSphere;
	bnu::vector<double> Center(3);
	Center[0] = 0.0; Center[1] = 1.0; Center[2] = 0.0;
	BoundSphere.SetCenter(Center);
	BoundSphere.SetRadius(0.5);
	
	Ray Ray;
	Ray.SetOrigin(MidAB);
	Ray.SetDirection(NormalAB);
	TDVertexContainer Points;	
	FindIntersection(Ray, BoundSphere, Points);
	assert(Points.size() == 1);
	TDVertex D(Points[0]);

	Ray.SetOrigin(MidBC);
	Ray.SetDirection(NormalBC);
	FindIntersection(Ray, BoundSphere, Points);
	assert(Points.size()== 1);
	TDVertex E(Points[0]);

	Ray.SetOrigin(MidAC);
	Ray.SetDirection(NormalAC);
	FindIntersection(Ray, BoundSphere, Points);
	assert(Points.size()== 1);
	TDVertex F(Points[0]);

	TDVertexContainer::iterator itVec;
	if ((itVec = find_if(Vertices.begin(), Vertices.end(), bind(Equal<TDVertex>(), _1, D))) == Vertices.end())
	{
		Vertices.push_back(D);
		nIdxD = Vertices.size() - 1;
	}
	else
	{
		nIdxD = Vertices.size() - (Vertices.end() - itVec);
	}
	if ((itVec = find_if(Vertices.begin(), Vertices.end(), bind(Equal<TDVertex>(), _1, E))) == Vertices.end())
	{
		Vertices.push_back(E);
		nIdxE = Vertices.size() - 1;
	}
	else
	{
		nIdxE = Vertices.size() - (Vertices.end() - itVec);
	}
	if ((itVec = find_if(Vertices.begin(), Vertices.end(), bind(Equal<TDVertex>(), _1, F))) == Vertices.end())
	{
		Vertices.push_back(F);
		nIdxF = Vertices.size() - 1;
	}
	else
	{
		nIdxF = Vertices.size() - (Vertices.end() - itVec);
	}
	
	vector<unsigned> vecFace;
	vecFace.push_back(nIdxA);
	vecFace.push_back(nIdxD);
	vecFace.push_back(nIdxF);
	Connections.push_back(vecFace);
	
	vecFace.clear();
	vecFace.push_back(nIdxD);
	vecFace.push_back(nIdxB);
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:edge-svn,代码行数:101,代码来源:SoftBodyNode.cpp


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