Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

6 Neutral

About soerensen3

  • Rank

Personal Information

  • Role
  • Interests
  1. soerensen3

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

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

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

    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
  5. soerensen3

    OpenGL, Translating a Sphere

    Some general tips: - First I would move the camera to the sphere instead of the other way around because you probably want it to follow your ball right? Anyway the steps below apply to both cases. - If you want need the camera to be in the same location as the sphere you need the inverse matrix. - Because with a sphere, rotation does not matter it is sufficient to take the sphere position which is in the 4th column of your sphere's matrix or in your camera's view matrix (inverted = *-1). - However if your camera position and your sphere's position are exactly the same you wont see much (at least with backface culling on) because you are inside the sphere, which is probably not what you want. You can move in the direction of you camera by getting it's view dir (3rd column of your view matrix) which can be scaled by the distance you want to keep to your sphere - For more information on what columns in a view matrix represent: http://www.songho.ca/opengl/gl_transform.html#modelview - With that you can do an orbit camera
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!