Imagination PowerVR SDK Blog

Using Camera



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 ?



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 )




all the beginner samples are superbe :slight_smile: i am still looking at it everyday :slight_smile:


some nice easing function for your camera :


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 ?



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).


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



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 />


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() ?


No worry man, from the doc

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

```<br />


And about the model matrix ?


define your model view matrix as


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





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


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 />


Some more questions.

  1. How is mWorld defined ?

  2. 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 ?

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


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




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.


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.



super cool