0

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.

Hellboy
  • 1,199
  • 2
  • 15
  • 33

1 Answers1

0

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.

ClayMontgomery
  • 2,786
  • 1
  • 15
  • 14
  • Where should the translations be from, the center of the box and rectangles to the origin ? – Hellboy Jun 25 '13 at 19:06
  • Yes, exactly. This makes it easy to scale or rotate your whole scene, for example, by multiplying all of your model matrices by a single scale or rotate matrix, or both. – ClayMontgomery Jun 25 '13 at 19:52
  • So, I'll do something like this. PVRTMat4 ViewMatrix = PVRTMat4::LookAtRH(vFrom, vTo, vUp); PVRTMat4 ProjectionMatrix =PVRTMat4::PerspectiveFovRH(DEG2RAD(fFOV), AspectRatio, CameraNear, CameraFar, PVRTMat4::OGL, rotate); for(i=0;i – Hellboy Jun 26 '13 at 04:58
  • Yes, that's the way many of the examples in the PowerVR SDK do it. There are a lot of good examples there. But, it can be better to move more of the matrix multiplication to the vertex shader. – ClayMontgomery Jun 26 '13 at 23:33