Results 1 to 3 of 3

Thread: Collada camera

  1. #1
    Junior Member
    Join Date
    May 2018
    Posts
    6

    Collada camera

    Hello everybody,

    How to add collada camera in OpenGL. I have create the look_at matrix by using camera translation data as camera position and look at position as (0,0,0) and up vector as (0,1,0), It renders fine as what i see in collada imported blender. But i dont have any idea about how to add rotate?

    <node id="Camera" name="Camera" type="NODE">
    <translate sid="location">-0.9681758 -0.03152037 20.65355</translate>
    <rotate sid="rotationZ">0 0 1 0</rotate>
    <rotate sid="rotationY">0 1 0 0</rotate>
    <rotate sid="rotationX">1 0 0 0</rotate>
    <scale sid="scale">1 1 0.9999999</scale>
    <instance_camera url="#Camera-camera"/>
    </node>

    For this node, i am using
    glm::lookAt(glm::vec3(-0.9681758,-0.03152037,20.65), glm::vec3(0,0,0), glm::vec3(0,1,0))

    It gives the correct camera view. But how to add rotation??? Anyone have any idea about this?

  2. #2
    I guess you have MVP matrix in shader and you need these matrices

    1. [M] Model transform comes from node element
    2. [V] Camera transform comes from node element. View matrix is inverse of this.
    3. [P] Projection matrix comes from camera element

    But how to add rotation???
    This is same as how to add rotation to model matrix. You can construct a matrix using those individual transforms like this:

    Pseudo Codes:

    mat4 matrix = GLM_MAT4_IDENTITY_INIT; // Node local transform
    while (transform) {
    switch (transform->type) {
    case TRANS_TRANSLATE:
    glm_translate(matrix, ((Translate)transform)->translate);
    }
    case TRANS_ROTATE:
    glm_rotate(matrix, ((Rotate)transform)->rotate, ((Rotate)transform)->angle);
    }
    ...

    transform = transform->next;
    }

    View matrix is inverse of the camera's world transform. After built matrix like above then the VIEW matrix is inverse of that matrix. You don't need to lookat except if it appears in a node instead of other transforms.

    This is local transform (relative to its parent) if you need to world transform (relative to origin) you need to multiply it with parent recursively
    Last edited by recp; 07-24-2018 at 02:12 AM.

  3. #3
    Junior Member
    Join Date
    May 2018
    Posts
    6
    Thanks for your reply recp. It's working.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean