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.

Newcomers DBPro Corner / 3D world - 2D Mouse

Author
Message
jotomicron
22
Years of Service
User Offline
Joined: 17th Nov 2002
Location: Portugal
Posted: 25th Nov 2002 21:05
Hi!

Does anyone has a code that let me convert 2D coordenates (in the mouse) to 3D coordenates. Some explaining would be greatfull!

Thanx
TGWDNGHN
22
Years of Service
User Offline
Joined: 2nd Oct 2002
Location:
Posted: 27th Nov 2002 19:57
you can use the mousey cordinate to move an object in the z x=y or z, y-x or z, and once you have z you cvan do z-x or y , put all your Qs in one post

If life gives you a lemon, shove it up a water gun and squirt it into someone's eyes!
jotomicron
22
Years of Service
User Offline
Joined: 17th Nov 2002
Location: Portugal
Posted: 27th Nov 2002 20:54
Ok! Some time ago i find this code:



I use it, but I can't figure out why does it work! Could somebody try to explain it to me?

Thanx!
Fluffy Paul
21
Years of Service
User Offline
Joined: 16th Dec 2002
Location: United Kingdom
Posted: 26th Dec 2002 23:47
OK, here we go.
The writer uses the angle the camera is pointing in as the basis for the calculation. This means that if you click in the exact centre of the screen then you'll select whatever the camera is pointing at. The maths is used to work out what happens depending how far away from the centre of the screen you clicked.

The first thing to remember is that the screen represents a field of view in the 3D world. Have you played Commando's by Pyro Studios/Eidos Interactive? Or how about Metal Gear Solid?
In those games the enemy's field of view was shown to the player as part of the game. Imagine you are a human player controlling one of those enemies. Anything in that field of view appears on your screen. Things on the left of your FOV appear on the left of your screen and things in the right of your FOV appear in the right of your screen.

The FOV is described as an angle. 90 degrees is pretty much a standard FOV. Remember that, what ever the FOV, the number of degrees describes everything you see from the left hand side of your screen to the right hand side.

Returning to the code snippet we see that the author has based their calculations on the direction of the camera.
Assuming the FOV in this case is still 90 degrees, this means that something visible on the left of the screen can be up to 45 degrees to the left of the camera. Likewise, something on the rightmost edge of the screen would be 45 degrees to the right of the camera.

What the code author does is say "OK, the field of view is 90 degrees but my screen is 1024 pixels wide. This means that each pixel is 'worth' 90/1024 degrees that's 0.0879 degrees per pixel."

So if someone clicks 100 pixels to the right from the centre of the screen then the program goes off and says "the 3D direction of the click is 100*0.0879 to the right... which is +8.79 degrees to the Y angle of the camera". If that click was the same distance away from the centre of the screen but to the left then the angle would have come out as -8.79 degrees from the camera's Y angle.

The computer then does the same calculation for the mouse's Y position to determine how high or low to pitch the new angle.

So, to summarise, the computer takes the position of the mouse, works out how far from the centre of the screen it is (in both x and y directions), then converts this to degrees remembering to factor in the FOV. The final product is an angle offset which is added to (or subtracted from) the camera's orientation.

Is that OK?

Login to post a reply

Server time is: 2024-11-23 19:38:46
Your offset time is: 2024-11-23 19:38:46