Pole-cam implementation problem

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Pole-cam implementation problem

      To implement pole-camera I use GCC4 code example, but instead of DirectX I try to use OpenGL API and GLM library for math. I was faced with the following problem, that when I apply torque to target (press 'A' or ''D') , it rotates right accordingly, the camera is spinning too, but target does not translate. In the result, target moves out of view after a while. I don't know I explained correctly and clearly. So, I capture this moment.


      How can fix this problem ? Or at least guide in the right path.

      I suppose, target rotates around world origin and does not translated in the previous place, where it was.

      The post was edited 2 times, last by itisscan ().

    • I found where I had mistake.

      When I got projection matrix in order to render scene node.

      Source Code

      1. Mat4x4 CameraNode::GetWorldViewProjection(Scene *pScene)
      2. {
      3. Mat4x4 world = pScene->GetTopMatrix();
      4. Mat4x4 view = VGet()->FromWorld();
      5. Mat4x4 worldView = view * world
      6. Mat4x4 projection = m_Projection * worldView;
      7. return projection;
      8. }

      I just change order of multiplication of worldView matrix. Now it is look like this Mat4x4 worldView = world * view;

      But I still can't understand. In first situation, we translate cube to origin and then we rotate it. But what is happening in the second situation ? I'm really confused.
    • This is likely a case where doing something seems correct, or nearly so, but isn't.

      Changing the world view project matrix isn't the right path - leave that the way it is.
      Instead, change the position and orientation of the camera node as your target object changes position and user input torques the camera around the object.

      I'm assuming that your target object will have a rigid attachment to the camera, so as it turns, the camera will orbit about it to always look in the same direction as positive Z, typically the forward vector. Also, for simplicity sake, I'll assume a constant pitch for your camera so you don't have to modulate that with a separate axis of input (likely an up/down motion of a mouse or joystick). You can always add that later. I'll also assume you want to control this object over flat ground. That is a much easier place to start.

      Each frame, perform the following operations.
      1. Grab input from the keyboard or mouse, and use that to apply orientation and position changes to your target object. Save that rotation matrix, you'll use it again.
      2. Set your camera's position to exactly the target object's new position. Set the orientation of the camera to yaw,pitch,and roll to be zero. If you use Quaternions, set the orientation to the identity.
      3. Construct a new matrix, to rotate around the RIGHT axis, typically X, to the value of your constant camera pitch.
      4. Multiply the rotate matrix you made in Step 1, with the one in step 3, in that order! It's important.
      5. Use that matrix as your new camera orientation.
      6. Call the renderer.

      I hope that helps!
      Author, Programmer, Brewer, Patriot
    • Thank you for response and help. I have followed your instructions and I got the next result. youtu.be/YsPjQ2rL8jo

      Just to make sure that I all made right I want to show my code.

      Source Code

      1. if(m_pTarget){
      2. //1)Get target's world matrix
      3. Mat4x4 targetMatrix = m_pTarget->VGet()->ToWorld();
      4. Vec3 pos = targetMatrix.GetPosition();
      5. //2)Set camera's position to the target object's new position
      6. Mat4x4 camera;
      7. camera.SetPosition(pos);
      8. //3)Construct a new matrix, to rotate around the RIGHT axis.
      9. Mat4x4 pitch;
      10. pitch.BuildYawPitchRoll(DEGREES_TO_RADIANS(0), DEGREES_TO_RADIANS(-10), DEGREES_TO_RADIANS(0));
      11. //4)Multiply target's rotation matrix with PITCH matrix.
      12. Mat4x4 targetRotation = targetMatrix;
      13. targetMatrix.SetPosition(Vec3(0.0f,0.0f,0.0f));
      14. Mat4x4 resultRotation = targetRotation * pitch;
      15. //5)Get resulted matrix
      16. Mat4x4 resultCamera = camera * resultRotation;
      17. //6)Set resulted matrix to camera node''s properties.
      18. VSetTransform(&resultCamera); }
      Display All

      It is much better than I had. But what about offset vector, in order to make something like 3rd person camera.

      For example, If I do

      Source Code

      1. camera.SetPosition(pos + Vec3(m_cameraOffSet)));

      I have the same result, which I described in the first post. youtu.be/SeiQP-7H6Mg

      How can I solve this, that the target was always before the camera ?


      The night brings counsel... :)

      Drawing the situation on the paper, I have realized that offset vector must be multiplied with target rotation matrix and only then I can add it with target position. Now code looks like this

      Source Code

      1. Vec3 directionOffsetVector = targetMatrix.Xform(m_CamOffsetVector);
      2. camera.SetPosition(pos + direction);

      So I get the same result like in Teapot Wars game, as I wanted.

      Now I want to add the mouse control, that camera could rotate around the target. I suppose I have to do next steps:

      1)Take input from the mouse, in order to calculate pitch, yaw and roll values. Build rotation matrix with these values. (Let will be called "Input matrix".)
      2)Multiply "Input matrix" with offset vector, which I calculated earlier.

      The post was edited 18 times, last by itisscan ().