Created
December 1, 2011 22:14
-
-
Save Darthfett/1420284 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Camera camera = m_Scene.m_Camera; | |
Vector cameraPosition = camera.GetPosition(); | |
// Camera Coordinates directions | |
Vector negZ = (camera.GetTarget() - cameraPosition).Normalize(); | |
Vector posY = camera.GetUp().Normalize(); | |
Vector posX = negZ.Cross(posY).Normalize(); | |
float FOV = camera.GetFOV(); | |
float nearZ = camera.GetNearClip(); | |
float farZ = camera.GetFarClip(); | |
float aspectRatio = ((float) WINDOW_WIDTH / (float) WINDOW_HEIGHT); | |
float halfScreenHeight = nearZ * tan(FOV * PI / 180); | |
float halfScreenWidth = aspectRatio * halfScreenHeight; | |
// Position of pixel -- Screen pixels go from X = [-halfScreenWidth , halfScreenWidth], Y = [-halfScreenHeight, halfScreenHeight] | |
Vector relativePosition = posX * (screenX - halfScreenWidth) + posY * (screenY - halfScreenHeight) + negZ * nearZ; | |
Vector pixelPosition = cameraPosition + relativePosition; | |
Vector rayDirection = (pixelPosition - cameraPosition).Normalize(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment