2
$\begingroup$

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

$\endgroup$
2
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Umbert Jun 17 '18 at 7:58
  • $\begingroup$ 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. $\endgroup$ – russ Jun 17 '18 at 13:16
  • $\begingroup$ 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! $\endgroup$ – Umbert Jun 17 '18 at 15:01

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.