c++ - Multiply vec3 with mat4 using glm -


at moment, convert vec3 vec4, multiply matrix, , cast vec3

code:

glm::vec3 transformed = glm::vec3(matrix * glm::vec4(point, 0.0)) 

it works, think not way calculate it. possible apply mat4 on vec3, without casting vec4 , back?

when working opengl wise stick homogeneous coordinates. 3d space these 4d vectors fourth element equals 1. when calculations in 4 dimensional space, no conversions needed anywhere.

also note in example, lose translation may have been recorded in transformation matrix. if want keep you'll need use 1 4th element, not 0.

appendix f of red book describes how , why homogeneous coordinates used within opengl.


Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -