Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I am currently programming something, and I'm stuck on how to take a 3D vector, then project it on a screen. Say $X_s$ = the screen width and $Y_s$ = the screen height, Pa = pitch and $Y_a$ = yaw, $X_p$ and $Y_p$ are the positions, how would I achieve this effect?

For instance, say I want to draw a name directly above a 3D object.And the only function I have is to draw text on a screen. That means the only thing I need to know is how to calculate the $X$ and $Y$ positions.

Thanks in advance! :)

share|improve this question
1  
There are multiple sites on the net describing this. Try this, this or this. –  dtldarek Mar 14 '12 at 16:02
    
Let's suppose that $x$ is horizontal distance, $y$ is vertical distance and $z$ is the depth distance of your object from your eye (I am considering points not vectors !). Then, in the case of a text in a fixed $z=z_0$ plane, you'll have to 'divide by $z$' (supposing the origine at the center of the screen) to get the 'projected' coordinates : $x_p=a\, Y_s \frac xz,\ y_p=a\, Y_s \frac yz,$ the job of the $a\times Y_s$ product is to convert a $\frac{\pi}4$ angle (with $\tan(\frac{\pi}4)=1$) in something proportional to (for example) the height of your screen. –  Raymond Manzoni Nov 25 '12 at 10:11
    
(concerning $a$ set it to $1$ first it is a overall 'zoom factor'). –  Raymond Manzoni Nov 25 '12 at 10:12

1 Answer 1

Are you using OpenGL? If that's the case, you may get the current projection matrix from opengl and multiply a position with the matrix

share|improve this answer
    
Nope, D3D. And even if it did, I probably wouldn't be able to access that, since I am programming this within a game. (I guess you could call it programming a plugin or tool.) –  JeremyG Jun 18 '11 at 14:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.