Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Width/Area of Object On Screen

Author
Message
ReiKumar
16
Years of Service
User Offline
Joined: 23rd Sep 2008
Location:
Posted: 13th Oct 2009 05:59
Hi guys.

Is there a function to let me know the width/area of an object (specifically a sphere) on screen?

So if it was close, I would get a larger number and if it was further away, I'd get a smaller number.
Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 13th Oct 2009 06:28
I don't think that there is, but you could try creating a function that takes an object's size, and then computes a formula dependant on the object's position on the Z axis.

Like take an object's ID, use a function to return it's set size, then have that divided by the current Z axis position.

Something like that, I really have a vauge idea.

http://twewy-fan.com/ <-- The first ever fansite for "The World Ends With You"
ReiKumar
16
Years of Service
User Offline
Joined: 23rd Sep 2008
Location:
Posted: 13th Oct 2009 06:44
The problem is that I can't limit it to the Z axis because the user can move around freely in the program.
Jash
14
Years of Service
User Offline
Joined: 12th Oct 2009
Location:
Posted: 13th Oct 2009 08:03
using the distance from the camera to the object and the object's width, you should be able to calculate it's screen size with a little geometry or basic trig. i've done it before in VB.

I make the same kind of games as any Chemisty major would.
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 13th Oct 2009 08:43
To find a sphere's screen radius+area you need to first calculate the inverse secant of your sphere, which is: asec = acos( 1.0f / ( dist / rad ) ); where dist is the distance from the camera to the sphere's centre, and rad is the radius of the sphere. From this you can find the radius of the visible sphere section: sin( asec ) * rad.

To then find the on-screen radius of this use:



ReiKumar
16
Years of Service
User Offline
Joined: 23rd Sep 2008
Location:
Posted: 13th Oct 2009 11:33
Thnx DarkCoder.

So I have a new problem now.

As I've said before I'm making a solar system simulation. Since everything is to scale, when viewed from afar the planets are very small. The reason I asked for this was so that I could determine a number and then have another large sphere show over is screenX and screenY positions and as you zoomed in, they would go away.

However.... it doesn't work.

Help?


Below is the code for my current function which checks the distance every frame. I know thats not efficient but this is just for the testing and building phase, I will be making changes to it later.

dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 13th Oct 2009 12:11
[/quote]However.... it doesn't work.

Help?[quote]

You only implemented half of my post?

ReiKumar
16
Years of Service
User Offline
Joined: 23rd Sep 2008
Location:
Posted: 14th Oct 2009 11:26
What did I miss?
entomophobiac
21
Years of Service
User Offline
Joined: 1st Nov 2002
Location: United States
Posted: 14th Oct 2009 12:17
I think it sounds a little bit redundant to calculate the width of the sphere. Could use only the Pythagoran theorem to calculate the distance between camera and object and not check if the sphere is small on screen -- seems a way around something simple.

Or am I mistaking your intent?
ReiKumar
16
Years of Service
User Offline
Joined: 23rd Sep 2008
Location:
Posted: 14th Oct 2009 22:49
The problem there becomes that there are multiple spheres of different radiuses.

Login to post a reply

Server time is: 2024-10-01 14:41:52
Your offset time is: 2024-10-01 14:41:52