#### Archived

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

# 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.

## 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 on other sites
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 on other sites
Oh, heh heh, no I''m not a student. This particular problem is related to my targetting system and heads-up-display for a game I''ve been working on for about 2 and a half years. You can check out a video of it here.

Ryan Buhr
Reactor Interactive, LLC.
rbuhr@reactorinteractive.net

##### 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 on other sites
that''s a darn schnazzy webpage there. If you did that yourself, kudos to you! (and if not, *ptooi*)

##### Share on other sites
Thanks, hplus. I''ll give that a try and see what I can come up with. Fractoid, I''d still like to hear your thoughts on it if your homework detector has calmed down. And leiavoia, I did indeed create the site myself. Thanks for the kudos!

Ryan Buhr
Reactor Interactive, LLC.
rbuhr@reactorinteractive.net

##### 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 on other sites
Thanks for the compliments, Auron. Our fully-multiplayer public demo is scheduled to be released at the end of June. We''ll likely be posting something about it on the GameDev homepage as the time draws nearer.

Ryan Buhr
Reactor Interactive, LLC.
rbuhr@reactorinteractive.net

##### 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 on other sites
Thanks very much for all the input guys! You solved my problem. Why can I never figure out the easy stuff for myself?

Ryan Buhr
Reactor Interactive, LLC.
rbuhr@reactorinteractive.net

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 13
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633324
• Total Posts
3011366
• ### Who's Online (See full list)

There are no registered users currently online

×