私はc#で簡単なレイトレーサー/レイキャスターを書いています。過去にVectorsで有効期限が切れたので、以下のコードでわかるように、Vector3Dというクラスを作成しました。Raysを処理するクラスも作成しました。今のところ、光線がカメラから発生し、画面上のすべてのピクセルにキャストされてから、シーン内のカメラの前にあるオブジェクトにキャストされることを確認する必要があります。出力(Debug.WriteLine)にテキストを書き込むことで期限切れになりましたが、実際に機能しているかどうかを確認するのは困難です。次のコードは適切ですか、それとも私を参照/ガイドする別の方法またはサイトをお勧めしますか?
for (int x = 0; x < sizeofoutput.Width; x++)
{
for (int y = 0; y < sizeofoutput.Height; y++)
{
Vector3D lookat = new Vector3D(sizeofoutput.Width / 2, sizeofoutput.Height / 2, 0);
Vector3D lookatrev = new Vector3D(lookat.X * -1, lookat.Y * -1, 0);
Vector3D tmp2 = lookatrev + new Vector3D(x, y, 0);
Vector3D campos = new Vector3D(0, 2, -6); // camera position.
Vector3D raydir = tmp2 - campos; // ray goes into a pixel.
Vector3D rayorg = campos; // ray starts at camera.
Ray ray = new Ray(rayorg); // create the ray from the data provided.
ray.Direction = raydir;
for (int c = 0; c < sceneobj.Length; c++)
{
// find object and render!
}
}
}