# soerensen3

Member

5

6 Neutral

• Rank
Newbie

• Role
Programmer
• Interests
Programming
1. ## OpenGL, Translating a Sphere

It's one or the other. You can use either glm::lookat() to calculate your view matrix or in case you already have a world matrix for your camera object you can obtain a view matrix by inversing the world matrix. @Josheir Have a look at the picture below. It is a visual representation of a world matrix and above you see the mathematical representation. The location is in the 4th column of the matrix. You can see colored axes (X=R, Y=G, Z=B). These can be found in the columns 1 to 3. As stated already by @Zakwayda the world matrix can be used to transform objects from model (a.k.a. object space) to world space. On the right side you see the cube in object space. Please note that the cube isn't rotated and centered at 0,0,0. By calculating the inverse of the above matrix you can convert from world to object space which is exactly what the view matrix does. The view matrix is related to your camera and nothing else so there is no view matrix for your cube. However you can still calculate the inverse matrix only that it is not called view matrix but object matrix.
2. ## OpenGL, Translating a Sphere

Because when you apply the inverse of the model transform of your sphere, it has always the same rotation as your sphere. You can of course also do it the other way around and apply the inverse rotation of your camera to the sphere. I thought the sphere is supposed to be the ball so I thought this makes more sense but it really doesn't matter. However an object that always has the same rotation as your camera will appear to be not rotating from the perspective of your camera. Have a look at the attached screenshots from blender. The cube has the same z rotation as the camera. Please note that in blender the up vector is Z not Y so the rotation is around Z. The X rotation (yaw Pitch) however is different which is why you can see the top of the cube as well. Also the location is different for both objects. The location is in world space. However I forget to mention that all transformation you apply to your camera needs to be inverse, so the yaw and translate part need to be inversed too. So it is better to inverse once after the multiplication. pseudo code: inv_view = mdl_sphere * cam_rotation * cam_translate view = -inv_view Edit: Also the rotation you need is pitch not yaw (X-Axis). Sorry I can never remember the names correctly!
3. ## OpenGL, Translating a Sphere

To me it seems you should first read a bit about matrices and transforms and play with them in a simple application. You have usually three kind of matrices (there can be more but let's keep it simple). World, View and Projection matrix. They each use a different coordinate system with a different origin. This is meant with space. So a vector ( 0, 0, 1 ) in camera space is different from the same vector in world space. You can ignore the projection matrix for now and just keep in mind that it projects the 3D world on your 2D screen and needs to be applied in the end. So my advice is you should get familiar with the other two spaces. There is also object space which you need in this case. Have a look at the link in my first post. What applies to the view matrix in terms of the axes (which is the camera space) applies to any other matrix as well.
4. ## OpenGL, Translating a Sphere

Let's call it a third person camera (orbiting or not). The most simple way to do it I can imagine is taking the sphere model matrix and invert it (let's call it inv_mdl) and take this as a base. Then for rotating your camera all you need is yaw because the camera is automatically rotated with the model already. And you need to go some distance away from the sphere otherwise you'll end up inside it. You can do that before rotating by translating along the negative z-axis. Then you apply the rotation matrix and last the inv_mdl matrix. mat_view = inv_mdl * cam_rot * cam_transl; // This should be your camera matrix