Object size on screen based on distance

Started by
10 comments, last by HanSoL0 19 years, 10 months ago
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

Ryan Buhr

Technical Lead | Sector 13

Reactor Interactive, LLC

Facebook | Twitter

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

Ryan Buhr

Technical Lead | Sector 13

Reactor Interactive, LLC

Facebook | Twitter

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.

enum Bool { True, False, FileNotFound };
that''s a darn schnazzy webpage there. If you did that yourself, kudos to you! (and if not, *ptooi*)
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

Ryan Buhr

Technical Lead | Sector 13

Reactor Interactive, LLC

Facebook | Twitter

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

Ryan Buhr

Technical Lead | Sector 13

Reactor Interactive, LLC

Facebook | Twitter

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

Ryan Buhr

Technical Lead | Sector 13

Reactor Interactive, LLC

Facebook | Twitter

This topic is closed to new replies.

Advertisement