public static void UniformMatrix4x3(int location, bool transpose, ref Matrix4x3d matrix) { unsafe { fixed(double *matrix_ptr = &matrix.Row0.X) { GL.UniformMatrix4x3(location, 1, transpose, matrix_ptr); } } }
/// <summary> /// I'm using internal ModelView matrix computation. /// </summary> Matrix4 computeModelView() { if (Time < lastTime) { currentKeyFrame = 1; } lastTime = Time; while (Time > keyFrames[currentKeyFrame + 1].Time) { currentKeyFrame++; } double t = (Time - keyFrames[currentKeyFrame].Time) / (keyFrames[currentKeyFrame + 1].Time - keyFrames[currentKeyFrame].Time); if (acceleration) { if (t < 0.5) { t = t * t * 2d; } else { t = -2d * t * t + 4d * t - 1d; } } Vector4d timeVector = new Vector4d(t * t * t, t * t, t, 1); Vector4d baseVector = Multiply(timeVector, catmullRomMatrix); Matrix4x3d positionMatrix = new Matrix4x3d(keyFrames[currentKeyFrame - 1].Position, keyFrames[currentKeyFrame].Position, keyFrames[currentKeyFrame + 1].Position, keyFrames[currentKeyFrame + 2].Position); Vector3 eye; if (keyFrames[currentKeyFrame].Position != keyFrames[currentKeyFrame + 1].Position) { eye = (Vector3)Multiply(baseVector, positionMatrix); } else { eye = (Vector3)keyFrames[currentKeyFrame].Position; } Matrix4x3d lookAtMatrix = new Matrix4x3d(keyFrames[currentKeyFrame - 1].LookAt, keyFrames[currentKeyFrame].LookAt, keyFrames[currentKeyFrame + 1].LookAt, keyFrames[currentKeyFrame + 2].LookAt); Vector3 target; if (keyFrames[currentKeyFrame].LookAt != keyFrames[currentKeyFrame + 1].LookAt) { target = (Vector3)Multiply(baseVector, lookAtMatrix); } else { target = (Vector3)keyFrames[currentKeyFrame].LookAt; } return(Matrix4.LookAt(eye, target, (Vector3)keyFrames[currentKeyFrame].Up)); }
private Vector3d Multiply(Vector4d left, Matrix4x3d right) { Vector3d vector = new Vector3d(); for (int i = 0; i < 3; i++) { double sum = 0d; for (int j = 0; j < 4; j++) { sum += left[j] * right[j, i]; } vector[i] = sum; } return(vector); }
public static void UniformMatrix4x3(int location, bool transpose, ref Matrix4x3d matrix) { unsafe { fixed (double* matrix_ptr = &matrix.Row0.X) { GL.UniformMatrix4x3(location, 1, transpose, matrix_ptr); } } }
public void SetUniform(Matrix4x3d matrix, int id) { GL.UniformMatrix4x3(id, true, ref matrix); }
private static void Set(int location, Matrix4x3d value) => GL.UniformMatrix4x3(location, false, ref value);