Converting transforms to matrices
Shader programs work well with matrices. They don't have a native representation of a transform structure. You could port the transform code into GLSL, but that's not the best solution. Instead, you could convert a transform into a matrix right before submitting it as a shader uniform.
Since transforms encode data that could be stored in matrices, it's possible to convert a transform into a matrix. To convert a transform into a matrix, the matrix needs to be thought of in terms of vectors.
First, find the basis vectors by multiplying the orientation of the global basis vectors by the transform's rotation. Next, scale the basis vectors by the scale of the transform. This yields the final basis vectors to fill the upper 3x3 sub-matrix. The position goes directly into the last column of the matrix.
Implement the from Transform
method in Transform.cpp
. Don't forget to add the function declaration to Transform.h
:
mat4...