예제 #1
0
        public static Matrix4f createViewMatrix(Vector3f AtVec, Vector3f EyeVec, Vector3f UpVec)
        {
            Matrix4f viewMatrix = Matrix4f.identity();

            viewMatrix = lookAt(AtVec, EyeVec, UpVec);
            return(viewMatrix);
        }
예제 #2
0
        /// <summary>
        /// Builds a rotation 4 * 4 matrix created from an axis vector and an angle.
        /// </summary>
        /// <param name="m">The m.</param>
        /// <param name="angle">The angle.</param>
        /// <param name="v">The v.</param>
        /// <returns></returns>
        public static Matrix4f rotate(Matrix4f m, float angle, Vector3f v)
        {
            float c = Trigonometric.Cos(angle);
            float s = Trigonometric.Sin(angle);

            Vector3f axis = Geometric.Normalize(v);
            Vector3f temp = (1.0f - c) * axis;

            Matrix4f rotate = Matrix4f.identity();

            rotate[0, 0] = c + temp[0] * axis[0];
            rotate[0, 1] = 0 + temp[0] * axis[1] + s * axis[2];
            rotate[0, 2] = 0 + temp[0] * axis[2] - s * axis[1];

            rotate[1, 0] = 0 + temp[1] * axis[0] - s * axis[2];
            rotate[1, 1] = c + temp[1] * axis[1];
            rotate[1, 2] = 0 + temp[1] * axis[2] + s * axis[0];

            rotate[2, 0] = 0 + temp[2] * axis[0] + s * axis[1];
            rotate[2, 1] = 0 + temp[2] * axis[1] - s * axis[0];
            rotate[2, 2] = c + temp[2] * axis[2];

            Matrix4f result = Matrix4f.identity();

            result[0] = m[0] * rotate[0][0] + m[1] * rotate[0][1] + m[2] * rotate[0][2];
            result[1] = m[0] * rotate[1][0] + m[1] * rotate[1][1] + m[2] * rotate[1][2];
            result[2] = m[0] * rotate[2][0] + m[1] * rotate[2][1] + m[2] * rotate[2][2];
            result[3] = m[3];
            return(result);
        }
예제 #3
0
        public static Matrix4f createModelMatrix(Vector3f translation, Vector3f rotate, Vector3f scale)
        {
            Matrix4f modelMatrix = Matrix4f.identity();

            modelMatrix = translate(modelMatrix, translation);
            modelMatrix = MatrixMath.rotate(modelMatrix, Trigonometric.toRadians(rotate.x), new Vector3f(1, 0, 0));
            modelMatrix = MatrixMath.rotate(modelMatrix, Trigonometric.toRadians(rotate.y), new Vector3f(0, 1, 0));
            modelMatrix = MatrixMath.rotate(modelMatrix, Trigonometric.toRadians(rotate.z), new Vector3f(0, 0, 1));
            modelMatrix = MatrixMath.scale(modelMatrix, scale);
            return(modelMatrix);
        }
예제 #4
0
 public static Matrix4f rotate(float angle, Vector3f v)
 {
     return(rotate(Matrix4f.identity(), angle, v));
 }