Question

I have a scene as follows :

A 3D box with its base centered at origin and four rectangles surrounding the base of the box. We can think it as a building with streets on all its four sides. I want to get the projection view model matrix. I have prepared the projection and view matrices based on camera settings but am not sure about the model matrices. Will every object in the scene have a different model matrix or only one model matrix for the scene as a whole ?

What will be the model matrix for the cube and the rectangles ?

I wish to move camera on the streets on all the four sides of the building.

Was it helpful?

Solution

It can be done either way, but I recommend having a separate model matrix for each building (cube) which probably consist of just translations. Each will have a different translation from the origin. Then, pass each of these model matrices in turn to the vertex shader before each is drawn with glDrawArrays(). Your camera position should go into the view-projection matrix which is also passed to the Vertex shader, but only updated when the camera actually moves. Your Vertex shader must then multiply the model and view-projection matrices together. This puts must of the work into the shader, where it should be.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top