Post by rmill013 on May 30, 2022 20:20:13 GMT
One of the 3 tests for the ray_for_pixel method is failing. Test name is "Constructing a ray when the camera is transformed".
The test expects a Ray with the following:
Origin = Point(0, 2, -5)
Direction = (0.7071, 0.0, -0.707107)
The results I'm getting are:
Origin = Point(0, 2, 5)
Direction = (0.7071, 0.0, -0.707107)
The other two tests for this method are passing, I'm not sure what the issue is because all other tests up to this point have passed. I've spent the last two days trying to debug but have found no obvious culprit. Any help / ideas are appreciated.
Here is my RayForPixel method, it's written in C#
The results I'm getting are:
Origin = Point(0, 2, 5)
Direction = (0.7071, 0.0, -0.707107)
The other two tests for this method are passing, I'm not sure what the issue is because all other tests up to this point have passed. I've spent the last two days trying to debug but have found no obvious culprit. Any help / ideas are appreciated.
Thanks!
The test expects a Ray with the following:
Origin = Point(0, 2, -5)
Direction = (0.7071, 0.0, -0.707107)
The results I'm getting are:
Origin = Point(0, 2, 5)
Direction = (0.7071, 0.0, -0.707107)
The other two tests for this method are passing, I'm not sure what the issue is because all other tests up to this point have passed. I've spent the last two days trying to debug but have found no obvious culprit. Any help / ideas are appreciated.
Here is my RayForPixel method, it's written in C#
public static Ray RayForPixel(in Camera camera, int x, int y)
{
// The offset from the edge of canvas to pixel's center
float xOffset = (x + 0.5f) * camera.PixelSize;
float yOffset = (y + 0.5f) * camera.PixelSize;
// the untransformed coords of the pixel in world space
// (Camera looks toward -z so +x is to th *left*
float worldX = camera.HalfWidth - xOffset;
float worldY = camera.HalfHeight - yOffset;
// using the camera matrix, transform the canvas point and the origin,
// and then compute the ray's direction vector
// (Remember that the canvas is at z = -1
Matrix cameraTransform = camera.Transform;
Matrix inverse = Matrix.Inverse(cameraTransform);
Point pixel = inverse * new Point(worldX, worldY, -1f);
origin = inverse * new Point();
Vector3 direction = Vector3.Normalize(pixel - origin);
return new Ray(origin, direction);
}
The results I'm getting are:
Origin = Point(0, 2, 5)
Direction = (0.7071, 0.0, -0.707107)
The other two tests for this method are passing, I'm not sure what the issue is because all other tests up to this point have passed. I've spent the last two days trying to debug but have found no obvious culprit. Any help / ideas are appreciated.
Thanks!