I've been getting back into graphics programming, which I tried before but never really took seriously.
Regarding perspective, I don't understand what I'm doing with the "w" variable in the matrix. What IS the w variable? What does it represent?
Why do I use it for perspective? What is it doing?
OpenGL and Perspective Matrix
Moderator: Coders of Rage
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: OpenGL and Perspective Matrix
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: OpenGL and Perspective Matrix
Ok. This is interesting. I have a couple books on computer graphics, both of which discuss the concept. It is just a little difficult to understand.
I think I understand a bit better. Looking through my books, the issue is that the w isn't really to be thought of as a coordinate in the program. It is just another variable that is placed in the vector to simplify the transformation process. Is that accurate?
I think I understand a bit better. Looking through my books, the issue is that the w isn't really to be thought of as a coordinate in the program. It is just another variable that is placed in the vector to simplify the transformation process. Is that accurate?
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: OpenGL and Perspective Matrix
Interesting article.
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: OpenGL and Perspective Matrix
Basically the 'w' is an extra parameter that when multiplied by the perspective matrix gives a ratio for scaling the X and Y vector components by the Z component (which results in scaling the size of objects based on their distance from the camera). The point of the w and this ratio is so that it can be used in something called "perspective division." Once you've multiplied whatever <x,y,z,w> vector by the perspective matrix and have gotten a new, transformed vector, the <x,y,z> components are all divided by w. This is what produces the effect of distant objects being small and close objects being large in a 3D scene. It's because the X and Y terms are essentially being scaled as a function of the Z term, which is distance from camera when perspective division is applied.
An "orthographic projection" matrix in 2D mode is a matrix whose transform simply results in a 1.0 in the w term. Now when perspective division happens, there is no scaling based on distance, and you're left with a uniform or orthographic perspective. Perspective division was still happening before in 2D, it just wasn't doing anything since you were dividing by 1.0.
An "orthographic projection" matrix in 2D mode is a matrix whose transform simply results in a 1.0 in the w term. Now when perspective division happens, there is no scaling based on distance, and you're left with a uniform or orthographic perspective. Perspective division was still happening before in 2D, it just wasn't doing anything since you were dividing by 1.0.