Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6204013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:00:59+00:00 2026-05-24T05:00:59+00:00

So I’ve decided to rewrite an old ray tracer I had which was written

  • 0

So I’ve decided to rewrite an old ray tracer I had which was written in C++ and to do it in C#, leveraging the XNA framework.

I still have my old book and can follow the notes however I am confused regarding a few ideas and I was wondering whether someone could articulate it nicely.


    for each x pixel do
        for each y pixel do
        //Generate Ray
        //1 - Calculate world coordinates of current pixel
           //1.1 Calculate Normalized Device coordinates for current pixel 1- to -1 (u, v) 
           u = (2*x/ WIDTH) - 1 ;
           v = (2*y/HEIGHT) - 1 ;
           Vector3 rayDirection = -1*focalLength + u'*u + v'*v


In the above code u’ and v’ are the orthnormal basis calculated for the given camera (I know the same names make it confusing)

If I follow the book and do it the way it expresses, it works. However I am trying to leverage XNA and getting confused on how to perform the same actions but using Matrices.

So I’ve tried to replace the following steps with the XNA code


    class Camera
        {
           public Camera(float width, float height)
           {
            AspectRatio = width/height;
            FOV = Math.PI / 2.0f;
            NearPlane = 1.0f;
            FarPlane = 100.0f;
            ViewMatrix = Matrix.CreateLookAt(Position, Direction,this.Up);
            ProjectionMatrix=Matrix.CreatePerspectiveFieldOfView(FOV,
                                              AspectRatio,NearPlane,FarPlane); 
           }
        }

It’s at this point I’m confused in the order of operations I am supposed to apply in order to get the direction vector for any pixel (x, y) ?

In my head I’m thinking:
(u,v) = ProjectionMatrix * ViewMatrix * ModelToWorld * Vertex(in model space)

Therefore it would make sense that

Vertex (in world space) = Inverse(ViewMatrix) * Inverse(ProjectionMatrix) * [u, v, 0]

I also remembered something about how the view Matrix can be Transposed as well as Inverted since it is orthonormal.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:01:03+00:00Added an answer on May 24, 2026 at 5:01 am

    The reason for NDC is to that you can map an image height/width in pixels to an arbitrary sized image (not necessarily 1:1)
    Essentially what I understood was the following:

    1. You want to convert pixel X&Y to a uniform rectangle from -1 to 1 (essentially centering the camera within the viewing frame)
    2. Perform the inverse projection matrix to which uses FOV, aspect ratio and near plane to place the pixel (in NDC coordinates) into world space coordinates
    3. Perform the inverse of camera matrix to put the coordinate relative to the camera in world space
    4. Calculate direction
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a text area in my form which accepts all possible characters from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I used javascript for loading a picture on my website depending on which small
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.