Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

HanSoL0

Object size on screen based on distance

This topic is 5271 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was wondering if anybody knows the equation that satisfies this problem: Say you have an cube in the middle of the screen and you''re looking straight on to one of its faces. When the cube is 1 unit away from the camera, say width of the face of the cube is 100 pixels. When the camera is x units away from the camera, the width of the face of the cube is now y pixels. Does anybody know the equation that solves that problem, assuming it''s a 45-degree field-of-view? Ryan Buhr Reactor Interactive, LLC. rbuhr@reactorinteractive.net

Share this post


Link to post
Share on other sites
Advertisement
I was going to answer this question but then my homework detector went off. I''ve still got my post pasted into notepad if it isn''t homework...

Share this post


Link to post
Share on other sites
The projected position of vertices is divided by the homogenous w times some constant, which turns out to be the same as the depth in camera space from camera to vertex. This comes out of the basic projection pipeline -- you should read up on it in the API reference.

Call the constant (dependent on the field of view) C. Thus, assuming the cube is planar, assuming the object-space width of the cube is OW, we know that OW*C/1 == 100, and we now want to find Y where OW*C/X == Y. X is the new depth of the cube.

Share this post


Link to post
Share on other sites
that''s a darn schnazzy webpage there. If you did that yourself, kudos to you! (and if not, *ptooi*)

Share this post


Link to post
Share on other sites
Dude, not only is the site snazzy, I checked out the game trailer and holy crap is that awesome! The camera looked like it might be a little jerky, but that''s likely just the video quality. Either way, great work! When is there going to be a demo?

-Auron

Share this post


Link to post
Share on other sites
OK, looks like I was beaten to the punch here, but this is what I was gonna write:
quote:
me:
cubeSize1 / cubeDist1 = cubeSize2 / cubeDist2

It''s just equivalent triangles (is that what you call them? triangles that are scaled versions of other triangles? It''s been a long time since highschool geometry... )

I just thought I''d be careful since last time I (accidentally) answered a homework question I got frowned at.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!