OpenGL and Perspective Matrix

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

OpenGL and Perspective Matrix

Postby Benjamin100 on Thu Jan 28, 2016 8:25 pm

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?
Benjamin100
ES Beta Backer
ES Beta Backer
 
Posts: 255
Joined: Tue Jul 19, 2011 10:37 pm

Re: OpenGL and Perspective Matrix

Postby dandymcgee on Fri Jan 29, 2016 12:22 am

Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
 
Posts: 4911
Joined: Tue Apr 29, 2008 4:24 pm
Location: New Hampshire

Re: OpenGL and Perspective Matrix

Postby Benjamin100 on Fri Jan 29, 2016 3:36 am

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?
Benjamin100
ES Beta Backer
ES Beta Backer
 
Posts: 255
Joined: Tue Jul 19, 2011 10:37 pm

Re: OpenGL and Perspective Matrix

Postby Benjamin100 on Fri Jan 29, 2016 3:38 am

Interesting article.
Benjamin100
ES Beta Backer
ES Beta Backer
 
Posts: 255
Joined: Tue Jul 19, 2011 10:37 pm

Re: OpenGL and Perspective Matrix

Postby Falco Girgis on Tue Feb 09, 2016 2:27 pm

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.
"So what happens if the Elysian Shadows Kickstarter fails?"
Image
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
 
Posts: 10693
Joined: Thu May 20, 2004 3:04 pm
Location: Studio Vorbis, AL


Return to Programming Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron