本文整理汇总了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;
}