Class GLMatrix


  • public class GLMatrix
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int M00  
      static int M01  
      static int M02  
      static int M03  
      static int M10  
      static int M11  
      static int M12  
      static int M13  
      static int M20  
      static int M21  
      static int M22  
      static int M23  
      static int M30  
      static int M31  
      static int M32  
      static int M33  
      float[] tmp  
      float[] val  
    • Constructor Summary

      Constructors 
      Constructor Description
      GLMatrix()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addDepthOffset​(int delta)
      add some offset (similar to glDepthOffset)
      void copy​(GLMatrix m)
      Copy values from mat
      static void frustumM​(float[] m, int offset, float left, float right, float bottom, float top, float near, float far)
      Define a projection matrix in terms of six clip planes
      void get​(float[] m)
      Get the Matrix as float array
      static boolean invertM​(float[] mInv, int mInvOffset, float[] m, int mOffset)
      Inverts a 4 x 4 matrix.
      static void lookAt​(float[] m, int offset, float eyex, float eyey, float eyez, float centerx, float centery, float centerz, float upx, float upy, float upz)  
      void multiplyLhs​(GLMatrix lhs)
      Use this matrix as rhs, multiply it on lhs and store result.
      void multiplyMM​(GLMatrix lhs, GLMatrix rhs)
      Multiply rhs onto lhs and store result in Matrix.
      void multiplyRhs​(GLMatrix rhs)
      Multiply rhs onto Matrix.
      static void orthoM​(float[] m, int offset, float left, float right, float bottom, float top, float near, float far)  
      void prj​(float[] vec3)
      Project Vector with Matrix
      void prj2D​(float[] src, int src_offset, float[] dst, int dst_offset, int length)
      Project Vectors with Matrix
      void prj2D​(float[] vec, int offset, int cnt)  
      void prj3D​(float[] vec, int offset, int cnt)  
      void set​(float[] values)
      Sets the matrix to the given matrix as a float array.
      void setAsUniform​(int location)
      Set Matrix with glUniformMatrix
      void setIdentity()
      Set identity matrix
      void setRotation​(float a, float x, float y, float z)
      Set rotation
      void setScale​(float x, float y, float z)
      Set scale factor
      void setTranslation​(float x, float y, float z)
      Set translation
      void setTransScale​(float tx, float ty, float scale)
      Set translation and x,y scale
      void setValue​(int pos, float value)
      Set single value
      void transposeM​(GLMatrix mat)
      Transpose mat and store result in Matrix
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • GLMatrix

        public GLMatrix()
    • Method Detail

      • set

        public void set​(float[] values)
        Sets the matrix to the given matrix as a float array. The float array must have at least 16 elements; the first 16 will be copied.
        Parameters:
        values - The matrix, in float form, that is to be copied. Remember that this matrix is in column major order.
      • get

        public void get​(float[] m)
        Get the Matrix as float array
        Parameters:
        m - float array to store Matrix
      • copy

        public void copy​(GLMatrix m)
        Copy values from mat
        Parameters:
        mat - Matrix to copy
      • prj

        public void prj​(float[] vec3)
        Project Vector with Matrix
        Parameters:
        vec3 - Vector to project
      • prj3D

        public void prj3D​(float[] vec,
                          int offset,
                          int cnt)
      • prj2D

        public void prj2D​(float[] vec,
                          int offset,
                          int cnt)
      • prj2D

        public void prj2D​(float[] src,
                          int src_offset,
                          float[] dst,
                          int dst_offset,
                          int length)
        Project Vectors with Matrix
        Parameters:
        vec2 - Vector to project
      • multiplyRhs

        public void multiplyRhs​(GLMatrix rhs)
        Multiply rhs onto Matrix.
        Parameters:
        rhs - right hand side
      • multiplyLhs

        public void multiplyLhs​(GLMatrix lhs)
        Use this matrix as rhs, multiply it on lhs and store result.
        Parameters:
        lhs - right hand side
      • multiplyMM

        public void multiplyMM​(GLMatrix lhs,
                               GLMatrix rhs)
        Multiply rhs onto lhs and store result in Matrix.

        This matrix MUST be different from lhs and rhs!

        As you know, when combining matrices for vector projection this has the same effect first as applying rhs then lhs.

        Parameters:
        lhs - left hand side
        rhs - right hand side
      • transposeM

        public void transposeM​(GLMatrix mat)
        Transpose mat and store result in Matrix
        Parameters:
        mat - to transpose
      • setRotation

        public void setRotation​(float a,
                                float x,
                                float y,
                                float z)
        Set rotation
        Parameters:
        a - angle in degree
        x - around x-axis
        y - around y-axis
        z - around z-axis
      • setTranslation

        public void setTranslation​(float x,
                                   float y,
                                   float z)
        Set translation
        Parameters:
        x - along x-axis
        y - along y-axis
        z - along z-axis
      • setScale

        public void setScale​(float x,
                             float y,
                             float z)
        Set scale factor
        Parameters:
        x - axis
        y - axis
        z - axis
      • setTransScale

        public void setTransScale​(float tx,
                                  float ty,
                                  float scale)
        Set translation and x,y scale
        Parameters:
        tx - translate x
        ty - translate y
        scale - factor x,y
      • setAsUniform

        public void setAsUniform​(int location)
        Set Matrix with glUniformMatrix
        Parameters:
        location - GL location id
      • setValue

        public void setValue​(int pos,
                             float value)
        Set single value
        Parameters:
        pos - at position
        value - value to set
      • addDepthOffset

        public void addDepthOffset​(int delta)
        add some offset (similar to glDepthOffset)
        Parameters:
        delta - offset
      • setIdentity

        public void setIdentity()
        Set identity matrix
      • frustumM

        public static void frustumM​(float[] m,
                                    int offset,
                                    float left,
                                    float right,
                                    float bottom,
                                    float top,
                                    float near,
                                    float far)
        Define a projection matrix in terms of six clip planes
        Parameters:
        m - the float array that holds the perspective matrix
        offset - the offset into float array m where the perspective matrix data is written
      • invertM

        public static boolean invertM​(float[] mInv,
                                      int mInvOffset,
                                      float[] m,
                                      int mOffset)
        Inverts a 4 x 4 matrix.
        Parameters:
        mInv - the array that holds the output inverted matrix
        mInvOffset - an offset into mInv where the inverted matrix is stored.
        m - the input array
        mOffset - an offset into m where the matrix is stored.
        Returns:
        true if the matrix could be inverted, false if it could not.
      • lookAt

        public static void lookAt​(float[] m,
                                  int offset,
                                  float eyex,
                                  float eyey,
                                  float eyez,
                                  float centerx,
                                  float centery,
                                  float centerz,
                                  float upx,
                                  float upy,
                                  float upz)
      • orthoM

        public static void orthoM​(float[] m,
                                  int offset,
                                  float left,
                                  float right,
                                  float bottom,
                                  float top,
                                  float near,
                                  float far)