3
votes

I've been having trouble working out the matrix math for my WebGL scene. Nothing I've tried seems to display correctly.

In my 3D world I have a number of models. Each model has an XYZ vector for position, rotation and scale within the world. The camera has a vector for position and rotation.

What is the best (and obviously working) way to convert these vectors to a model-view matrix for each model to pass to the shader?

Thanks in advance! :)

1

1 Answers

1
votes

The full recipe for generating a model-view matrix usually goes like this:

1. Set up view matrix V (inverse of camera) from camera orientation vectors
2. Set up model translation matrix T from model position vector
3. Set up model rotation matrix R from model orientation vectors
4. Set up model scaling matrix S
5. MV = V       // initialize model-view matrix MV with the view matrix V
6. MV = V*T     // apply the model translation matrix T
7. MV = V*T*R   // apply the model rotation matrix R
8. MV = V*T*R*S // apply the model scaling matrix S