perspective projection matrix question

Started by
1 comment, last by memento_mori 16 years, 6 months ago
Hello, I am currently writing a very (extremely) basic software renderer for a uni project. For now it is only supposed to render vertices as dots on the screen and apply some transformations. Here are the steps I'm following to do that: (please let me know i'm doing anything wrong): a) Get points from cartesian system (x, y and z coordinates), add w component with a value of 1 b) Multiply this vector with transformation matrix (I'm only doing rotation ATM) c) Finally multiply the resulting transformed vector with Projection matrix. d) The result should be a 2D point. Render the point. My question is: How do I compute the Projection matrix, and how can the multiplication of a 4x4 matrix with a 1x4 vector return a 1x2 vector (did i miss something, i suck at linear algebra :P) Please if anyone can point me to a good article on this that would be great. Thanks
Advertisement
Hello,

Your textbook should give the derivation of the perspective projection matrix. If not, you can just copy the one Direct3D or OpengL uses (look on the net).

Quote:
How do I compute the Projection matrix, and how can the multiplication of a 4x4 matrix with a 1x4 vector return a 1x2 vector (did i miss something, i suck at linear algebra :P)


It doesn't return a 1x2 vector. It returns a 1x4 vector, and a point is said to be in homogeneous clip space after the perspective projection matrix. Note that the perspective projection matrix just does the linear part of projection, there is still a nonlinear part that must be done in a second step. This nonlinear part is the homogeneous divide (or divide by w):

(x, y, z, w) // point after perspective projection matrix

(x/w, y/w, z/w, 1) // complete the projection

The point (x/w, y/w) is the 2D point on the projection window. The z/w is used for depth buffering and can be discarded if you do not need to implement that.
-----Quat
Hmm that cleared things alot for me...
thanks for your fast reply. and since my parameters (camera distance, FoV, screen width, height, etc...) are fixed atm, i'll do as you say and let Direct3D create my matrix and steal it :D:D:D :P
just hope it works.
cheers and thanks

This topic is closed to new replies.

Advertisement