Where to put the menu?

rifter1818

Junior Contributor
Joined
Sep 11, 2003
Messages
255
Location
A cold dark place
Im building a 3d rpg with a battle system simular to that of FF tactics, i have built the 3d part of the battle all the terrains are there and the charactors and monsters anyways now comes what should be the easy part, drawing the menus what i need is to put in a 2d square (menu,popup whatever you want to call it) on the screen next to the chrarctor(s), the only problem is where is the charactor? i have the 3d coordinants x,y,z but how do i figure out where these are on the screen (2d) thanks in advance for your help.
 
Not sure this will work since I have never really done something like this myself and it is a few years since my last math course... So follow this guide on your own risk... I give no guarantees that it will work.

I'll assume you got a global 3D coordinate system where you can get the location of stuff like cameras and location of characters in the 3D world...

You should have specified a clip plane somewhere in front of the camera. This should be a 2D surface and any object closer to the camera than this clip plane will not be rendered. This surface should be parallel to the screen surface.

Draw a line from the camera position in the viewing direction of the camera. This line should intersect the clip plane. Call the point of intersection P1. P1 should be the position of the camera translated in the viewing direction a distance equal to the specified clip plane distance. It should also be in the middle of your screen.

If you can get the position of a caracter you should be able to calculate a line or vector from the camera location to this location. When you got this line you should be able to calculate where it intersects the clip plane. Call this point of intersection P2.

Using the distance to the clip plane, and the specified viewing angle of the camera along the X-axis and Y-axis respectivly you should be able to calculate, with simple trigonometry, the maximum distances from P1 that any line drawn from the camera to an object in the 3D world will intersect the clip plane and still show up on the screen. Call these distances DX and DY.

Now, P1 and P2 should be in the same 2D plane parallel to the screen. It should be fairly easy to establish P2's distance from P1. Call this distance dX and dY for the respective directions.

Now, to calculate the position (x,y) for you 2D popup window derive x and y from:
x/[half screen width] = dX/DX
y/[half screen height] = dy/DY


Well, thats it... I just hope it is correct in case you decide to try it out...

/Jesper
 
Another thought just occured to me...

In case you always click on the character to bring up that 2D menu you should be able to get the 2D screen location of the mouse pointer and use those coordinates right away...

Now why did I only think of this AFTER I wrote my first reply :p

/Jesper
 
Thank you

For your support your method makes sence to me, i really should have figured that out myself seeing as i think im a good math student,... actually its more the everyone says im a brilliant math person yet somehow i get bad marks and need to ask people how do to just about everything.... go figure. anyways i think i can get some coding done based off your suggestion unfortunatly the really simple click idea doesnt work as the menu appears on a timer event,... but clicking would be so easy.... Now just my annimation question left for now i guess.....
 
Back
Top