Skip to main content
gamedev.net
🔒 Locked

On screen coordinates

Started by Blue*Omega Aug 26, 2000 at 1:04 PM 2 replies 350+ views
Original Post
Blue*Omega
Blue*Omega
Heres an interesting question... How can you find out an obejects on screen coordanites? If that didn''t make any sense I''ll give an example. Sy in a 3D rpg you find out a charecters stats by pointing the mouse at them. how would you detect if the mouse was on that object? ----------------------------- Blue*Omega (Insert Witty Quote Here)
SKSlayer
SKSlayer
Use the feedback buffer ...
(you can find me on IRC : #opengl on undernet)
BlackScar
BlackScar
How fast is the feedback buffer? Is there a way to do it mathmatically? Which would be the easiest/fastest way to do it?

Just curious..


~-=-=-=-=-=-=~
~Justin Eslinger~
~.."BlackScar"..~
~-=-=-=-=-=-=~
~-=-=-=-=-=-=~~Justin Eslinger~~.."BlackScar"..~~-=-=-=-=-=-=~
baskuenen
baskuenen
You could project an object''s position from 3D to 2D, and then check the distance. Do this with all objects, and you will know which one is closest.


To go from 3D to 2D: (Projection)

    
double x,y,z; // 3D world coords

double sx,sy; // 2D screen coords


double _sz = FOV / z;
sx = _sz * x;
sy = _sz * y;


This was a simple example, and you probably have to multiply the sx & sy values with the aspect/frustrum sizes...

Hope this helps,
- Bas

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.