View Full Version : Please explain glVertex4fv(...)
08-29-2011, 01:25 AM
I'm trying to understand how works glVertex4fv(...)?
I couldnt find much info about it.
When w is not 1 how does it work?
When is typical case to use glVertex4fv(excepting my icon example few days ago) ?
08-29-2011, 02:03 AM
It is homogenous coordinate. The primary reason for the 4th w component is that it allows translations to be described as matrix multiplications, i.e.
/ 1 0 0 t_x \ / x \ / x+t_x \
| 0 1 0 t_y | | y | | y+t_y |
| 0 0 1 t_z | | z | = | z+t_z |
\ 0 0 0 1 / \ 1 / \ 1 / .
This way all rotations, scalings and translations can be handled using one matrix multiplication.
When w is not one it works like the same but the w component is a scaling to your vector:
(x, y, z, w) is equal to (x/w, y/w, z/w, 1) in projective geometry (see e.g. here (http://ai.stanford.edu/~birch/projective/node4.html)).
99% of the time you will want to set w=1. I did not read your icon example but for example when using shaders you might use the 4th component to encode additional vertex-related data without having to specify an additional vertex attribute (saves memory and code lines).
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.