Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: A simple question on matrix in opengl and opencv

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2014
    Posts
    11

    A simple question on matrix in opengl and opencv

    I have some code which has matrix in opencv. Now I would like to use opengl for further modeling. Suppose I have the following matrix:

    double mat[16] = { 1.0, 0.0, -a, 0.0, 0.0, 1.0, -b, 0.0, 0.0, 0.0, -c, 0.0, 0.0, 0.0, 0.0, 1.0};

    I think opengl use column major order as follows:

    1.0 0.0 0.0 0.0
    0.0 1.0 0.0 0.0
    -a -b -c 0.0
    0.0 0.0 0.0 1.0

    whereas opencv use the row major order as follows:

    1.0 0.0 -a 0.0
    0.0 1.0 -b 0.0
    0.0 0.0 -c 0.0
    0.0 0.0 0.0 1.0

    Please let me know if i am not right.

  2. #2
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    495
    OpenGL uses column-major order by default (the "transpose" versions of functions use row-major order). OpenCV uses row-major order by default, but can use column-major order (the stride or step for each dimension can be set explicitly).

    However, if your example matrix was supposed to be a translation, it's transposed (also, the wrong column is used). A matrix for a translation by the vector (x,y,z) looks like:
    Code :
    1 0 0 x
    0 1 0 y
    0 0 1 z
    0 0 0 1

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2014
    Posts
    11
    Actually, the matrix is not a translation matrix, it is a rotation matrix. Apart from row-major and column-major order, is there any other difference due to the coordinate system? Please let me know.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •