<p>Your math looks correct to me. Your terminology is a little off - technically what you are creating here is just the 'view' matrix rather than the 'modelView'. If you're just drawing a single sphere at the origin then it doesn't make a difference, but normally the modelView is unique for each object in a scene - it's the object's model-to-world transform matrix multiplied by the view matrix you describe above.</p>

CC BY-SA 4.0
2018-06-17T07:58:13.407Z
There are early  2 spheres centered at the origin. Then  the MVmatrix is different for the 2 objects namely I draw a sphere with a translate value and another sphere with another translation value thus in the same rendering cycle I modify the MVmatrix. Isn't this correct? Actually I would realize that a sphere, the Earth, goes around another sphere the Sun but I have some difficult for this rason I want know if my math was mistakes less.
Nick
CC BY-SA 4.0
2018-06-17T13:16:46.943Z
Normally you have a 'transform' - rotation scale and translation - for each object in the world. You can calculate a separate 'model' matrix for each object from these that places it correctly in the world. Then you calculate a single 'view' matrix for the camera, which is the inverse of its transform like you describe above. To then get a single object's position relative to the camera, you multiply view*model to get the modelView for that object.
russ
CC BY-SA 4.0
2018-06-17T15:01:29.637Z
Yes, you are right in general. But in my case is a little more complicated because in the meantime I have to rotate the Earth around the sun. However, assured that my way of generating an orbiting camera is correct I will open a more specific topic. Thanks!
Nick
CC BY-SA 4.0
2018-06-16T07:53:21.813Z
2018-06-16T07:53:21.813Z
russ
<p>I have to create a orbiting camera. I created the model of sun (a sphere) around (0,0,0) , triangulated and Phong shaded it. I would have a camera that goes around the sun thus an orbiting camera and I would know if my way to proceed is right or not:
In WebGl there isn't a phisical camera. Nevertheless I imagine to place my camera at the center (0,0,0) and I have first to translate it of [0 0 100] ([0 0 100] is the point where early is located the camera) and later I rotate the camera around y ([0 1 0]) of some angle (Actually the angle is animated, i.e. the angle increases over time).</p>

<p>Thus cameraMatrix = R(angle,[0 1 0])T([0 0 100])
(First translation and later rotation)</p>

<p>But in WebGl there isn't camera, then I have to move the world with inverse transformation namely:</p>

<p>ModelViewMatrix = inverse(cameraMatrix);</p>

<p>Thus
ModelViewMatrix =  inverse{R(angle,[0 1 0])T([0 0 100])} = inverse(T([0 0 100]))<em>inverse(R(angle,[0 1 0])= T([0 0 -100])</em> R(-angle,[0 1 0])</p>

<p>(In the last first rotation and later translation)</p>

<p>So far is it all right?
Finally in drawScene namely the function of rendering cycle the order of call is inverted namely: </p>

<pre><code>mat4.translate(mvMatrix , [0,0,-100.0]);
mat4.rotate(mvMatrix , degToRad(-angle) , [0,1,0]); 
</code></pre>

<p>in this order does a rototranslation, namely it occurs first the rotation and later the translation (inverted respect the order of call functions).</p>

<p>I would confirm if this is right because I'm a neophyte of Computer Graphics and I'm not sure.
(I know that I can use lookAt() or define the values of cameraMatrix by hand but I'm not interested in it).
Thanks in advance </p>

<rendering><transformations><webgl><matrix><camera>
Correctness or otherwise of the procedure for generating an orbiting camera in WebGl
Nick
# Correctness or otherwise of the procedure for generating an orbiting camera in WebGl

(Asked by: username_0 on 2018-06-14)

I have to create a orbiting camera. I created the model of sun (a sphere) around (0,0,0) , triangulated and Phong shaded it. I would have a camera that goes around the sun thus an orbiting camera and I would know if my way to proceed is right or not:
In WebGl there isn't a phisical camera. Nevertheless I imagine to place my camera at the center (0,0,0) and I have first to translate it of [0 0 100] ([0 0 100] is the point where early is located the camera) and later I rotate the camera around y ([0 1 0]) of some angle (Actually the angle is animated, i.e. the angle increases over time).

Thus cameraMatrix = R(angle,[0 1 0])T([0 0 100])
(First translation and later rotation)

But in WebGl there isn't camera, then I have to move the world with inverse transformation namely:

ModelViewMatrix = inverse(cameraMatrix);

Thus
ModelViewMatrix = inverse{R(angle,[0 1 0])T([0 0 100])} = inverse(T([0 0 100]))*inverse(R(angle,[0 1 0])= T([0 0 -100])* R(-angle,[0 1 0])

(In the last first rotation and later translation)

So far is it all right?
Finally in drawScene namely the function of rendering cycle the order of call is inverted namely:

```
mat4.translate(mvMatrix , [0,0,-100.0]);
mat4.rotate(mvMatrix , degToRad(-angle) , [0,1,0]); 

```

in this order does a rototranslation, namely it occurs first the rotation and later the translation (inverted respect the order of call functions).

I would confirm if this is right because I'm a neophyte of Computer Graphics and I'm not sure.
(I know that I can use lookAt() or define the values of cameraMatrix by hand but I'm not interested in it).
Thanks in advance

**Tags:** rendering, transformations, webgl, matrix, camera


---

## 1 answers

### Answer by username_1 on 2018-06-16. Score: 2 | Accepted answer

Your math looks correct to me. Your terminology is a little off - technically what you are creating here is just the 'view' matrix rather than the 'modelView'. If you're just drawing a single sphere at the origin then it doesn't make a difference, but normally the modelView is unique for each object in a scene - it's the object's model-to-world transform matrix multiplied by the view matrix you describe above.

> **Comments:**
> **username_0**: There are early  2 spheres centered at the origin. Then  the MVmatrix is different for the 2 objects namely I draw a sphere with a translate value and another sphere with another translation value thus in the same rendering cycle I modify the MVmatrix. Isn't this correct? Actually I would realize that a sphere, the Earth, goes around another sphere the Sun but I have some difficult for this rason I want know if my math was mistakes less.  
> **username_1**: Normally you have a 'transform' - rotation scale and translation - for each object in the world. You can calculate a separate 'model' matrix for each object from these that places it correctly in the world. Then you calculate a single 'view' matrix for the camera, which is the inverse of its transform like you describe above. To then get a single object's position relative to the camera, you multiply view*model to get the modelView for that object.  
> **username_0**: Yes, you are right in general. But in my case is a little more complicated because in the meantime I have to rotate the Earth around the sun. However, assured that my way of generating an orbiting camera is correct I will open a more specific topic. Thanks!  

---

