public static void TraceRay(Camera camera) { // pixel postion in the normalized sensor space [0;1]^2 Vector2 texCoord = new Vector2(0.0f, 0.0f); // pixel corner in camera space // TODO: offset to pixel center or jitter the pixel area Vector3 pixelPos = new Vector3( (0.5f - texCoord.X) * camera.SensorSize.X, (0.5f - texCoord.Y) * camera.SensorSize.Y, camera.SensorZ); //Vector3 colorSum = Vector3(0.0, 0.0, 0.0); //iVector2 steps = iVector2(3, 3); float apertureRadius = camera.Lens.ApertureRadius; //float apertureRadius = 0.0001f; //Vector2 offsetStep = (2.0 * apertureRadius) * Vector2(1.0 / Vector2(steps - iVector2(1, 1))); //for (int y = 0; y < steps.y; y++) { //for (int x = 0; x < steps.x; x++) { //Vector3 lensOffset = Vector3( //float(x) * offsetStep.x - apertureRadius, //float(y) * offsetStep.y - apertureRadius, 0.0); Vector3 lensOffset = new Vector3(apertureRadius, apertureRadius, 0); //Vector3 lensOffset = Vector3(0, 0, 0); //Vector3 rayDirection = lensOffset - pixelPos; Vector3 rayDirection = ThinLensTransformPoint(pixelPos, camera.Lens.FocalLength) - lensOffset; rayDirection /= rayDirection.Z; // normalize to a unit z step Vector3 startCamera = lensOffset + (-camera.Near) * rayDirection; // convert the start and end points to from [-1;1]^3 to [0;1]^3 Vector3 start = TransformPoint(camera.Perspective, startCamera); start = BigToSmallCube(start); Vector3 endCamera = lensOffset + (-camera.Far) * rayDirection; Vector3 end = TransformPoint(camera.Perspective, endCamera); end = BigToSmallCube(end); //colorSum += intersectHeightField(start, end); //} //} }
public Navigation() { Camera = new Camera(); ResetNavigation(); }
private void ComputeSensorTransform(Camera camera) { sensorTransform = Matrix4.Identity; if (Math.Abs(camera.SensorRotation.X) > 0) { sensorTransform *= Matrix4.CreateRotationX(camera.SensorRotation.X); } if (Math.Abs(camera.SensorRotation.Y) > 0) { sensorTransform *= Matrix4.CreateRotationY(camera.SensorRotation.Y); } sensorTransform3x3 = Matrix4x4To3x3Array(sensorTransform, ref sensorTransform3x3); }
public void ResetCamera() { float aspectRatio = Camera.AspectRatio; Camera = new Camera(); Camera.AspectRatio = aspectRatio; }