# Using Camera

**URL:** <https://forums.imgtec.com/t/using-camera/1818>\
**Category:** PowerVR Insider\
**Created:** [June 25, 2013, 6:34am UTC](https://forums.imgtec.com/t/using-camera/1818 "2013-06-25T06:34:27Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![hellboy](https://avatars.discourse-cdn.com/v4/letter/h/48db29/32.png) [@hellboy](https://forums.imgtec.com/u/hellboy)\
**Post date:** [June 25, 2013, 6:34am UTC](https://forums.imgtec.com/t/using-camera/1818/1 "2013-06-25T06:34:27Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![dgu](https://avatars.discourse-cdn.com/v4/letter/d/94ad74/32.png) [@dgu](https://forums.imgtec.com/u/dgu)\
**Post date:** [June 25, 2013, 7:55am UTC](https://forums.imgtec.com/t/using-camera/1818/2 "2013-06-25T07:55:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dgu](https://avatars.discourse-cdn.com/v4/letter/d/94ad74/32.png) [@dgu](https://forums.imgtec.com/u/dgu)\
**Post date:** [June 25, 2013, 7:56am UTC](https://forums.imgtec.com/t/using-camera/1818/3 "2013-06-25T07:56:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dgu](https://avatars.discourse-cdn.com/v4/letter/d/94ad74/32.png) [@dgu](https://forums.imgtec.com/u/dgu)\
**Post date:** [June 25, 2013, 8:10am UTC](https://forums.imgtec.com/t/using-camera/1818/4 "2013-06-25T08:10:24Z")

</div>

some nice easing function for your camera : [http://gizma.com/easing/](http://gizma.com/easing/)

---

<div class="post-metadata">

**Author:** ![hellboy](https://avatars.discourse-cdn.com/v4/letter/h/48db29/32.png) [@hellboy](https://forums.imgtec.com/u/hellboy)\
**Post date:** [June 25, 2013, 8:45am UTC](https://forums.imgtec.com/t/using-camera/1818/5 "2013-06-25T08:45:58Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![JoeDavis](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.imgtec.com/joedavis/32/71_2.png) [@JoeDavis](https://forums.imgtec.com/u/JoeDavis)\
**Post date:** [June 25, 2013, 8:58am UTC](https://forums.imgtec.com/t/using-camera/1818/6 "2013-06-25T08:58:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hellboy](https://avatars.discourse-cdn.com/v4/letter/h/48db29/32.png) [@hellboy](https://forums.imgtec.com/u/hellboy)\
**Post date:** [June 25, 2013, 9:05am UTC](https://forums.imgtec.com/t/using-camera/1818/7 "2013-06-25T09:05:35Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![dgu](https://avatars.discourse-cdn.com/v4/letter/d/94ad74/32.png) [@dgu](https://forums.imgtec.com/u/dgu)\
**Post date:** [June 25, 2013, 10:01am UTC](https://forums.imgtec.com/t/using-camera/1818/8 "2013-06-25T10:01:21Z")

</div>

Hello

````auto
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
````

---

<div class="post-metadata">

**Author:** ![hellboy](https://avatars.discourse-cdn.com/v4/letter/h/48db29/32.png) [@hellboy](https://forums.imgtec.com/u/hellboy)\
**Post date:** [June 25, 2013, 10:28am UTC](https://forums.imgtec.com/t/using-camera/1818/9 "2013-06-25T10:28:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dgu](https://avatars.discourse-cdn.com/v4/letter/d/94ad74/32.png) [@dgu](https://forums.imgtec.com/u/dgu)\
**Post date:** [June 25, 2013, 10:45am UTC](https://forums.imgtec.com/t/using-camera/1818/10 "2013-06-25T10:45:44Z")

</div>

No worry man, from the doc

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

```<br />
````

---

<div class="post-metadata">

**Author:** ![hellboy](https://avatars.discourse-cdn.com/v4/letter/h/48db29/32.png) [@hellboy](https://forums.imgtec.com/u/hellboy)\
**Post date:** [June 25, 2013, 10:56am UTC](https://forums.imgtec.com/t/using-camera/1818/11 "2013-06-25T10:56:18Z")

</div>

And about the model matrix ?

---

<div class="post-metadata">

**Author:** ![dgu](https://avatars.discourse-cdn.com/v4/letter/d/94ad74/32.png) [@dgu](https://forums.imgtec.com/u/dgu)\
**Post date:** [June 25, 2013, 11:09am UTC](https://forums.imgtec.com/t/using-camera/1818/12 "2013-06-25T11:09:46Z")

</div>

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](http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/#The_Model_matrix)

---

<div class="post-metadata">

**Author:** ![hellboy](https://avatars.discourse-cdn.com/v4/letter/h/48db29/32.png) [@hellboy](https://forums.imgtec.com/u/hellboy)\
**Post date:** [June 25, 2013, 11:11am UTC](https://forums.imgtec.com/t/using-camera/1818/13 "2013-06-25T11:11:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dgu](https://avatars.discourse-cdn.com/v4/letter/d/94ad74/32.png) [@dgu](https://forums.imgtec.com/u/dgu)\
**Post date:** [June 25, 2013, 11:21am UTC](https://forums.imgtec.com/t/using-camera/1818/14 "2013-06-25T11:21:01Z")

</div>

in the demo your were looking at  
  
you saw  
  
// Pass the model-view-projection matrix (MVP) to the shader to transform the vertices

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

---

<div class="post-metadata">

**Author:** ![hellboy](https://avatars.discourse-cdn.com/v4/letter/h/48db29/32.png) [@hellboy](https://forums.imgtec.com/u/hellboy)\
**Post date:** [June 25, 2013, 11:29am UTC](https://forums.imgtec.com/t/using-camera/1818/15 "2013-06-25T11:29:38Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![dgu](https://avatars.discourse-cdn.com/v4/letter/d/94ad74/32.png) [@dgu](https://forums.imgtec.com/u/dgu)\
**Post date:** [June 25, 2013, 11:34am UTC](https://forums.imgtec.com/t/using-camera/1818/16 "2013-06-25T11:34:48Z")

</div>

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](http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/#The_Model__View_and_Projection_matrices)  
  
  
  
regards  
  
david

---

<div class="post-metadata">

**Author:** ![hellboy](https://avatars.discourse-cdn.com/v4/letter/h/48db29/32.png) [@hellboy](https://forums.imgtec.com/u/hellboy)\
**Post date:** [June 25, 2013, 11:54am UTC](https://forums.imgtec.com/t/using-camera/1818/17 "2013-06-25T11:54:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![hellboy](https://avatars.discourse-cdn.com/v4/letter/h/48db29/32.png) [@hellboy](https://forums.imgtec.com/u/hellboy)\
**Post date:** [June 26, 2013, 7:04am UTC](https://forums.imgtec.com/t/using-camera/1818/18 "2013-06-26T07:04:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dgu](https://avatars.discourse-cdn.com/v4/letter/d/94ad74/32.png) [@dgu](https://forums.imgtec.com/u/dgu)\
**Post date:** [June 26, 2013, 7:16am UTC](https://forums.imgtec.com/t/using-camera/1818/19 "2013-06-26T07:16:35Z")

</div>

super cool
