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

  • Home
  • SEARCH
  • 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 7618941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:32:04+00:00 2026-05-31T03:32:04+00:00

The math I’m using to compute a 3D vector based on a mouse click

  • 0

The math I’m using to compute a 3D vector based on a mouse click works fine, but the fact that it works is bothering me – specifically, I am scaling the field of view, expressed on the vertical axis by the aspect ratio for the horizontal axis, instead of computing a new ratio based on the field of view for the horizontal axis – the reason this bothers me is that I am linearly scaling the field of view, whereas recomputing the fov tangent for the horizontal axis is not linear – so I wonder if I’ve got a slightly abberant lens in my camera at the end of the day.

Here’s the code, which works fine (note that the FOV is expressed for the horizontal axis and D3D wants it for the vertical axis)

    double mouseX = ((((double) hitPt.x) / (double) vport.cx) - 0.5) * 2.0;
double mouseY = ((1.0 - (((double) hitPt.y) / (double) vport.cy)) - 0.5) * 2.0;
double tfy = tan((fov/aspr) * 0.5);


double tfx = tfy * aspr;

SFMatrix4 CM1;
this->m_renderSurface->GetRawCameraMatrix(CM1);
CM1.Invert();
origin = CM1 * SFVec3f((nearp * tfx) * mouseX,(nearp * tfy) * mouseY,nearp);
dest = CM1 * SFVec3f((farp * tfx) * mouseX,(farp * tfy) * mouseY,farp);

I’ve isolated the line that is offending my sensibilities (tfx = tfy * aspr) – I would rather do
tfx = tan(fov) * 0.5;
but that does not work – there’s an error that increases as it moves away from the center
I know that this is the way that D3D does things and I’m just going to have to live with it – what I’m curious about is which path is actually right (as much as anything can be right in the attempt to shove linear algebra through a discrete mesh), and why

  • 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-31T03:32:05+00:00Added an answer on May 31, 2026 at 3:32 am

    I agree that this is an aspect of projection that is unintuitive at first.

    The field of view of your eyes is essentially projected on a sphere. As a result an object that subtends a certain angle appears to have the same size regardless of whether you are looking straight at it or seeing it in your peripheral vision. The angle difference between two edges of an object is what defines the size, and therefore the angle to an object is a good way to define its position in the field of view.

    When projecting onto a flat surface, the rules are a bit different. Look at this picture:

    enter image description here

    The position of each object on the screen is not determined by the angle to that object. Instead, we use similar triangles:

    (distance from center of screen)     (offset from sight line to object)
    ________________________________  =  ___________________________________________
    (distance from eye to screen)        (distance along sight line to object plane)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I heard of some Math.random() but I'm not sure about using it correctly. Number
Am using Math.round and I am finding that it will not return me any
math.h is not really a documentation. Is there something else that will describe these
I'm not a math guy in the least but I'm interested in learning about
Using assorted matrix math, I've solved a system of equations resulting in coefficients for
Matrix math library that is good to use alongside OpenGL to keep track of
I am implementing some math algorithms based on lists of points, like Distance, Area,
Math has defeated me once again. This is such a simple task, but I
Does decimal math use the FPU? I would think that the answer is yes,
Is the java Math.atan() function known to have any issues? I'm using it in

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.