本文整理汇总了C#中Vec3.Cross方法的典型用法代码示例。如果您正苦于以下问题:C# Vec3.Cross方法的具体用法?C# Vec3.Cross怎么用?C# Vec3.Cross使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vec3
的用法示例。
在下文中一共展示了Vec3.Cross方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
DateTime startTime = DateTime.Now;
const int width = 640;
const int height = 480;
//camera setting
var camera = new Ray(new Vec3(50.0, 52.0, 295.6), new Vec3(0.0, -0.042612, -1.0).Norm());
//x,y vector of screen
Vec3 cx = new Vec3(width * .5135 / height);
Vec3 cy = cx.Cross(camera.dir).Norm() * .5135 ;
//image buffer
Vec3[] image = new Vec3[width * height];
for (int y = 0; y < height;++y)
{
Console.Write("\rRendering {0:F2}%", 100.0 * y / (height - 1));
for (int x = 0 ; x < width; ++x)
{
int index = (height - y - 1) * width + x;
// 2x2 subpixel sampling
for (int sy = 0; sy < 2; ++sy)
{
for (int sx = 0; sx < 2; ++sx)
{
double dx = sx / 2.0;
double dy = sy / 2.0;
Vec3 dir = cx * (((sx + 0.5 + dx) / 2.0 + x) / width - 0.5) +
cy * (((sy + 0.5 + dy) / 2.0 + y) / height - 0.5) + camera.dir;
image[index] = image[index] + Radiance(new Ray(camera.org + dir * 130.0, dir.Norm()), 0);
}
}
}
}
Console.WriteLine("\n{0} sec", (DateTime.Now - startTime).TotalSeconds);
using (StreamWriter sw = new StreamWriter("image.ppm"))
{
sw.Write("P3\r\n{0} {1}\r\n{2}\r\n", width, height, 255);
for (int i = 0; i < width * height; i++)
sw.Write("{0} {1} {2}\r\n", ToInt(image[i].x), ToInt(image[i].y), ToInt(image[i].z));
sw.Close();
}
}