Hi,

I have a rectangle rendered. I want to move the camera along the line cutting the rectangle into half, say 0.1 units per frame. I went through the IntroducingPOD sample program. The problem is that the program uses **CPVRTModelPOD** class and hence has functions to get the world matrices etc. I have all the vertex data and index data stored in 2D arrays. I don’t know how to start the navigation of camera. Can someone help ?

# Using Camera

**hellboy**#1

**dgu**#2

Hi

everything is in the sample about camera ,did you change the value of **vFrom** over the time ? (maybe a nice as a plus Lerp function will make it )

regards

david

**hellboy**#5

The function for navigation is not a problem for me. The problem is that I have prepared the “View” and the “Projection” matrices as :

PVRTMat4 ViewMatrix = PVRTMat4::LookAtRH(vFrom, vTo, vUp);

PVRTMat4 ProjectionMatrix = PVRTMat4::PerspectiveFovRH(DEG2RAD(fFOV), AspectRatio, CameraNear, CameraFar, PVRTMat4::OGL, rotate);

PVRTMat4 ViewProjectionMatrix = ProjectionMatrix * ViewMatrix;

But I don’t know what the “Model” matrix means and how should it be prepared.

Additionally, I have passed the matrix as :

int i32Location = glGetUniformLocation(m_uiProgramObject, “myPMVMatrix”);

glUniformMatrix4fv(i32Location, 1, GL_FALSE, ViewProjectionMatrix.ptr());

Is this correct ?

**JoeDavis**#6

Hi,

View & Projection matrices describe the camera position & how it sees the scene. The Model matrix (a.k.a. World matrix) describes your objects position in the scene, for example if it should be translated from it’s default position (0,0,0).

**hellboy**#7

So, the matrix which is passed through glUniformMatrix4fv() is (P*M*V) or (P*V) ? Where should the model matrix be translated to from its default position ?

**dgu**#8

Hello

```
mTrans = PVRTMat4::Translation (x,y,z) for instance and<br />
mMVP = m_mProjection * mTrans * m_mView;
```<br />
of course the view is define by<br />
<br />
<code>m_mView = PVRTMat4::LookAtRH(vFrom, vTo, vUp);</code><br />
<br />
the model-view-projection matrix is pass to the shader to transform the vertices<br />
example :<br />
<code>glUniformMatrix4fv(Uniforms[j].nLocation, 1, GL_FALSE, mMVP.f);</code><br />
regards<br />
david
```

**hellboy**#9

Thanks David, but I can’t understand the idea behind translating the model matrix in the first place. Why is it needed ? Sorry for being so noob.

What is the difference between mMVP.f and mMVP.ptr() ?

**dgu**#10

No worry man, from the doc

```
f= Array of float<br />
ptr=pointer to an array of float or element<br />
```<br />
```

**dgu**#12

define your model view matrix as

PVRTMat4 mMVP;

mMVP = m_mProjection * mTrans * m_mView;

The SDK provide a lot of sample about it , i am sure you will find the answer there as well

regards

david

ps

http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/#The_Model_matrix

**hellboy**#13

No, that’s not my question. I asked why is the translation (mTrans = PVRTMat4::Translation (x,y,z)) required ?

**dgu**#14

in the demo your were looking at

you saw

// Pass the model-view-projection matrix (MVP) to the shader to transform the vertices

```
PVRTMat4 mModelView, mMVP;<br />
mModelView = mView * mWorld;<br />
mMVP = mProjection * mModelView;<br />
glUniformMatrix4fv(m_ShaderProgram.uiMVPMatrixLoc, 1, GL_FALSE, mMVP.f);
```<br />
<br />
like is said before as well you could change your view model only by changing the vFrom value depending where you camera should be.<br />
<br />
the translation that i introduce was to make life easier to move the camera as you like but it s not mandatory..a simple matrix calculation here<br />
<br />
```

**hellboy**#15

Some more questions.

- How is mWorld defined ?

- Will there be as many model matrices as there are meshes in the scene ? If yes, what will the model matrix be for a 3D box ?

- Will the values of x,y,z in Translation(x,y,z) be the coordinates of vFrom ?

**dgu**#16

i see , i think this question is more related to the understanding of rendering using gl

http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/#The_Model__View_and_Projection_matrices

regards

david

**hellboy**#17

OK. I think I got the use of model matrix. Its basically used to transform the objects vertices from local space to world space.

But, still I can’t figure out what mWorld for my scene will contain. I have a 3D box with its base centered at origin and four rectangles in x-y plane surrounding the base of the box. We can think it as a building with streets on all its four sides. What will be the mWorld matrix for such a scene?

I want to navigate camera on the streets on all the four sides.

**hellboy**#18

I finally prepared the model matrix for every object and translated it to the origin. Then, in a loop, I prepared the PMV matrix by multiplying all the three matrices together and passed it to the shader for every object. I think, I got the camera working now.

Thanks.