1c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo// Use of this source code is governed by a BSD-style license that can be
3c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo// found in the LICENSE file.
4c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo
5c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo// Matrix implementation here is col-major, both storage-wise and
6c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo// operation-wise.
7c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo
8c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo#ifndef MATRIXOP_H_INCLUDED
9c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo#define MATRIXOP_H_INCLUDED
10c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo
11c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Motypedef float Matrix4x4[16];
12c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Motypedef float Matrix3x3[9];
13c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo
14c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo// result = mat1 * mat2
15c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Moextern void Matrix4x4_Multiply(Matrix4x4 result,
16c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo                               Matrix4x4 mat1, Matrix4x4 mat2);
17c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo
18c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo// dst = src
19c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Moextern void Matrix4x4_Copy(Matrix4x4 dst, Matrix4x4 src);
20c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo
21c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Moextern void Matrix4x4_LoadIdentity(Matrix4x4 mat);
22c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo
23c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo// mat = ScaleMatrix(sx, sy, sz) * mat
24c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Moextern void Matrix4x4_Scale(Matrix4x4 mat,
25c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo                            float sx, float sy, float sz);
26c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo
27c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo// mat = TranslateMatrix(tx, ty, tz) * mat
28c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Moextern void Matrix4x4_Translate(Matrix4x4 mat,
29c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo                                float tx, float ty, float tz);
30c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo
31c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo// mat = RotateMatrix(angle, ax, ay, az) * mat
32c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Moextern void Matrix4x4_Rotate(Matrix4x4 mat, float angle,
33c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo                             float ax, float ay, float az);
34c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo
35c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo// mat = FrustumMatrix(left, right, bottom, top, near, far) * mat
36c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Moextern void Matrix4x4_Frustum(Matrix4x4 mat,
37c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo                              float left, float right,
38c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo                              float bottom, float top,
39c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo                              float near, float far);
40c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo
41c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Moextern void Matrix4x4_Perspective(Matrix4x4 mat, float fovy, float aspect,
42c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo                                  float nearZ, float farZ);
43c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo
44c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo// [x,y,z] = mat(3x3) * [x,y,z]
45c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Moextern void Matrix4x4_Transform(Matrix4x4 mat, float *x, float *y, float *z);
46c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo
47c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo#endif  // MATRIXOP_H_INCLUDED
48c8ab85b5ab0cf6bc500d8b31cfcb199a7107c8e8Zhenyao Mo
49