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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:05:22+00:00 2026-05-17T00:05:22+00:00

I am currently dealing with several thousand boxes that i’d like to project onto

  • 0

I am currently dealing with several thousand boxes that i’d like to project onto the screen to determinate their sizes and distances to the camera.

My current approach is to get a sphere representing the box and project that using view and projection matrices and the viewport values.

// PSEUDOCODE

// project box center from world into viewspace
boxCenterInViewSpace = viewMatrix * boxCenter;

// get two points left and right of center
leftPoint = boxCenter - radius;
right = boxCenter + radius;

// project points from view into eye space
leftPoint = projectionMatrix * leftPoint;
rightPoint = projectionMatrix * rightPoint;

// normalize points
leftPoint /= leftPoint.w;
rightPoint /= rightPoint.w;

// move to 0..1 range
leftPoint = leftPoint * 0.5 + 0.5;
rightPoint = rightPoint * 0.5 + 0.5;

// scale to viewport
leftPoint.x = leftPoint.x * viewPort.right + viewPort.left;
leftPoint.y = leftPoint.y * viewPort.bottom + viewPort.top;

rightPoint.x = rightPoint.x * viewPort.right + viewPort.left;
rightPoint.y = rightPoint.y * viewPort.bottom + viewPort.top;

// at this point i check if the node is visible on screen by comparing the points to the viewport

// calculate size
length(rightPoint - leftPoint)

At another point i calculate the distance of the box to the camera.

The first problem is that i won’t know if the box is just below the viewport as i just calculate horizontal. Is there a way to project a real sphere onto the screen somehow? Some method that looks like:

float getSizeOfSphereProjectedOnScreen(vec3 midpoint, float radius)

The other question is simpler: In with coordinate space is the z coordinate corresponding to the distance to the camera?

To sum it up i want to calculate:

  1. Is the Box in the view frustum?
  2. What is the size of the Box on the screen?
  3. What is the distance from Box to camera?

To simplify calculations i’d like to use a sphere representation for this but i don’t know how to project a sphere.

  • 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-17T00:05:23+00:00Added an answer on May 17, 2026 at 12:05 am

    [Updated]

    What is the distance from Box to camera?

    In
    [which] coordinate space is the z
    coordinate corresponding to the
    distance to the camera?

    The answer is none of the usual spaces. The closest one would be in view space (i.e. after you apply the view matrix but not the projection matrix). In view space, the distance to the camera should be sqrt(x*x + y*y + z*z), because the camera is at the origin. (z would be a reasonable approximation only if |x| and |y| were really small relative to |z|.) This is assuming that knowing the distance from the camera to the center of the box is good enough.

    I think if you really wanted a space in which the z coordinate corresponds to the distance to the camera, you’d need to map a spherical locus of points sqrt(x*x + y*y + z*z) = d to a plane z = d. I don’t know that you can do that with a matrix.

    • Is the Box in the view frustum?
    • What is the size of the Box on the screen?

    I think you’re on the right track with this, but depending on which direction the camera is facing, your left and right points might not determine how wide the box looks or whether the box intersects the view frustum. See my answer to your other question for a long way to do this.

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

Sidebar

Related Questions

I'm currently working on an C#/ASP.NET project that will host several differents e-commerce websites,
I currently have a project where we are dealing with 30million+ keywords for PPC
Currently I am dealing with a large dataset and some queries are executing several
I'm dealing with an issue with my current employer that has seriously made me
Currently we have a project with a standard subversion repository layout of: ./trunk ./branches
i´m currently dealing with a system where i have to track the state for
I believe several of us have already worked on a project where not only
First, the set up: I have a script that executes several tasks after a
I have a web application that stores a lot of user generated files. Currently
We have an architecture where we provide each customer Business Intelligence-like services for their

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.