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 4602356
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:58:19+00:00 2026-05-21T23:58:19+00:00

I’m writing a ray tracer (mostly for fun) and whilst I’ve written one in

  • 0

I’m writing a ray tracer (mostly for fun) and whilst I’ve written one in the past, and spent a decent amount of time searching, no tutorials seem to shed light on the way to calculate the eye rays in a perspective projection, without using matrices.

I believe the last time I did it was by (potentially) inefficiently rotating the eye vectors x/y degrees from the camera direction vector using a Quaternion class. This was in C++, and I’m doing this one in C#, though that’s not so important.

Pseudocode (assuming V * Q = transform operation)

yDiv = fovy / height
xDiv = fovx / width

for x = 0 to width
    for y = 0 to height

        xAng = (x / 2 - width) * xDiv
        yAng = (y / 2 - height) * yDiv
        Q1 = up vector, xAng
        Q2 = camera right vector, yAng
        Q3 = mult(Q1, Q2)

        pixelRay = transform(Q3, camera direction)
        raytrace pixelRay

    next
next

I think the actual problem with this is that it’s simulating a spherical screen surface, not a flat screen surface.

Mind you, whilst I know how and why to use cross products, dot products, matrices and such, my actual 3D mathematics problem solving skills aren’t fantastic.

So given:

  • Camera position, direction and up-vector
  • Field of view
  • Screen pixels and/or sub-sampling divisions

What is the actual method to produce an eye ray for x/y pixel coordinates for a raytracer?

To clarify: I exactly what I’m trying to calculate, I’m just not great at coming up with the 3D math to compute it, and no ray tracer code I find seems to have the code I need to compute the eye ray for an individual pixel.

enter image description here

  • 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-21T23:58:19+00:00Added an answer on May 21, 2026 at 11:58 pm

    enter image description here

    INPUT: camera_position_vec, direction_vec, up_vec, screen_distance
    
    right_vec = direction_vec x up_vec
    for y from 0 to 1600:
        for x from 0 to 2560:
            # location of point in 3d space on screen rectangle
            P_3d = camera_position_vec + screen_distance*direction_vec
                   + (y-800)*-up_vec
                   + (x-1280)*right_vec
    
            ray = Ray(camera_position_vec, P_3d)
            yield "the eye-ray for `P_2d` is `ray`"
    

    x means the cross product

    edit:
    The answer assumed that direction_vec is normalized, as it should be. right_vec is in the picture (seemingly where the left should be), but right_vec is not necessary and, if included, should always be in the same direction as -(up_vec x direction_vec). Furthermore the picture implies the x-coord increases as one goes right, and the y-coord increases as one goes down. The signs have been changed slightly to reflect that. A zoom may either be performed by multiplying the x- and y- terms in the equation, or more efficiently, multiplying the vectors and using scaled_up_vec and scaled_right_vec. A zoom is however equivalent (since aperture doesn’t matter; this is a perfect pinhole camera) to changing the field of view (FoV) which is a much better nicer quantity to deal with than arbitrary “zoom”. For information about how to implement FoV, seem my comment below.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am writing an app with both english and french support. The app requests
I have a reasonable size flat file database of text documents mostly saved in
I'm making a simple page using Google Maps API 3. My first. One marker
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.