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

Building a projection matrix without api

Started by Malmer Aug 15, 2004 at 4:26 PM 2 replies 7.4k views
Original Post
Malmer
Malmer
How does one really go about building a projection matrix? In Direct3D and OpenGL there are various functions for building them, but how does one do it in software? And what difference will the matrix have if the coordinate system is a right-handed one. Thanks! Malmer
Willbo
Willbo
Are you wondering how the matrix look like?
You could look up the function in the DirectX SDK, to see how it
looks like.
This is ripped directly from the DX SDK 9.0

D3DXMatrixPerspectiveFovRHw       0       0                00       h       0                00       0       zf/(zn-zf)      -10       0       zn*zf/(zn-zf)    0D3DXMatrixPerspectiveFovLHw       0       0               00       h       0               00       0       zf/(zf-zn)      10       0       -zn*zf/(zf-zn)  0


where:
h is the view space height. It is calculated from
h = cot(fovY/2);
w is the view space width. It is calculated from
w = h / Aspect.
fovY is in radians
zf is far view-plane
zn is near view-plane
Aspect is the view space height divided by width

- Patrik Willbo
nts
nts
Quote:
Original post by Malmer
How does one really go about building a projection matrix? In Direct3D and OpenGL there are various functions for building them, but how does one do it in software? And what difference will the matrix have if the coordinate system is a right-handed one.

Thanks!
Malmer


If you are working with OGL then download the Mesa/3D source code and have a look at the glu functions. Such as gluPerspective, gluLookAt, etc its all there.

JohnBolton
JohnBolton
And straight from the docs on glFrustum:
    E  0  A  0    0  F  B  0    0  0  C  D    0  0  -1 0        A = (right+left)/(right-left)    B = (top+bottom)/(top-bottom)    C = -(far+near)/(far-near)    D = -2*far*near/(far-near)    E = 2*near/(right-left)    F = 2*near/(top-bottom)
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!

Topic Locked

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

Sign in to reply to this topic.