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


C++ Intersection::sphere方法代码示例

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


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

示例1: main

int main(int argc, char* argv[]) {
  Vector viewPoint(0, 0, 0);
  Vector viewDirection(0, 0, 1);
  Vector viewUp(0, -1, 0);

  double frontPlaneDist = 2;
  double backPlaneDist = 1000;

  double viewPlaneDist = 90;
  double viewPlaneWidth = 160;
  double viewPlaneHeight = 90;

  int imageWidth = atoi(argv[1]);
  int imageHeight = atoi(argv[2]);

  Vector viewParallel = viewUp^viewDirection;

  viewDirection.normalize();
  viewUp.normalize();
  viewParallel.normalize();

  Image image(imageWidth, imageHeight);

  Color c;

  //Color only
  /*for (int ix = 0; ix < imageWidth; ix++)
  {
	  for (int iy = 0; iy < imageHeight; iy++)
	  {
		  Vector x0 = viewPoint;
		  Vector x1 = viewPoint + viewDirection*viewPlaneDist + viewUp*imageToViewPlane(iy, imageHeight, viewPlaneHeight)s + viewParallel*imageToViewPlane(ix, imageWidth, viewPlaneWidth);
		  Line ray = Line(x0, x1, false);
		  Intersection i = findFirstIntersection(ray, frontPlaneDist, backPlaneDist);
		  if (i.valid())
		  {
			  c = i.geometry().color();
			  image.setPixel(ix, iy, c);
		  }
	  }
  }*/

  Light l = Light(Vector(0,70,150), Color(1,1,1), Color(1, 1, 1), Color(1,1,1), 1);

  for (int ix = 0; ix < imageWidth; ix++)
  {
	  for (int iy = 0; iy < imageHeight; iy++)
	  {
		  Vector x0 = viewPoint;
		  Vector x1 = viewPoint + viewDirection*viewPlaneDist + viewUp*imageToViewPlane(iy, imageHeight, viewPlaneHeight) + viewParallel*imageToViewPlane(ix, imageWidth, viewPlaneWidth);
		  Line ray = Line(x0, x1, false);
		  Intersection i = findFirstIntersection(ray, frontPlaneDist, backPlaneDist);
		  if (i.valid())
		  {
			  Sphere* s = (Sphere*)i.sphere();
			  Material m = i.geometry().material();
			  Vector L = l.position();
			  Vector C = viewPoint;
			  Vector V = i.vec();
			  Vector S = s->center();
			  Vector N = V - S;
			  N.normalize();
			  Vector T = L - V;
			  T.normalize();
			  Vector E = C - V;
			  E.normalize();
			  Vector R = N*(N*T) * 2 - T;
			  R.normalize();
			  //printf("%f %f, %f\n", S.x(), S.y(), S.z());

			  c = m.ambient() * l.ambient();
			  if (N*T > 0)
			  {
				  c += m.diffuse() * l.diffuse() * (N*T);
			  }
			  if (E*R > 0)
			  {
				  c += m.specular() * l.specular() * pow(E*R, m.shininess());
			  }
			  c *= l.intensity();

			  image.setPixel(ix, iy, c);
		  }
	  }
  }

  image.store("scene.ppm");

  for(int i=0; i<geometryCount; i++) {
    delete scene[i];
  }

  return 0;
}
开发者ID:zalcyon,项目名称:raytracer,代码行数:94,代码来源:main.cpp


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