Skip to main content
GameDev.net gamedev.net
🔒 Locked

Perspective projection :P

Started by Trillian Jan 6, 2007 at 3:57 PM 1 replies 900+ views
Original Post
Trillian
Trillian
Hello! So I have my own Matrix4 class and I've implemented a function to setup a projection matrix. Because I will only have this level of math clases in two years, I copied the formula to set up the matrix from MSDN, from the function D3DXMatrixProjectionRH (RH because opengl is right-handed, right?). The thing is, it doesn't work. However, I tryed to copy the D3DXMatrixOrthoRH and this one works.
Quote:
Original post by MSDN! This function uses the following formula to compute the returned matrix. 2*zn/w 0 0 0 0 2*zn/h 0 0 0 0 zf/(zn-zf) -1 0 0 zn*zf/(zn-zf) 0
Why doesn't my perspercive projection code works? How does glPerspective or such function work? Thanks!
Trillian
Trillian
Okay I think I've found something, the formula used by gluPerspective :

Quote:

Given f defined as follows:

f = cotangent(fovy/2)

The generated matrix is
f
------- 0 0 0
aspect


0 f 0 0

zFar+zNear 2*zFar*zNear
0 0 -------- ------------
zNear-zFar zNear-zFar

0 0 -1 0


This is a bit different from what I have, I'll try it.
Zakwayda
Zakwayda
Two quick notes:

1. The DX projection matrices use a z clipping range of [0,1], whereas OpenGL uses [-1,1]. As a result, some of the corresponding matrix elements differ between the two APIs.

2. The examples in the DX docs use row-vector notation. You may already have accounted for this, but I just thought I'd mention it.

Topic Locked

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

Sign in to reply to this topic.