OLD | NEW |
1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
4 */ | 4 */ |
5 | 5 |
6 /** @file matrix.cc | 6 /** @file matrix.cc |
7 * Implements simple matrix manipulation functions. | 7 * Implements simple matrix manipulation functions. |
8 */ | 8 */ |
9 | 9 |
10 //----------------------------------------------------------------------------- | 10 //----------------------------------------------------------------------------- |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 void identity_matrix(Matrix_t mat) { | 51 void identity_matrix(Matrix_t mat) { |
52 memset(mat, 0, sizeof(Matrix_t)); | 52 memset(mat, 0, sizeof(Matrix_t)); |
53 mat[0] = 1.0; | 53 mat[0] = 1.0; |
54 mat[5] = 1.0; | 54 mat[5] = 1.0; |
55 mat[10] = 1.0; | 55 mat[10] = 1.0; |
56 mat[15] = 1.0; | 56 mat[15] = 1.0; |
57 } | 57 } |
58 | 58 |
59 void multiply_matrix(const Matrix_t a, const Matrix_t b, Matrix_t mat) { | 59 void multiply_matrix(const Matrix_t a, const Matrix_t b, Matrix_t mat) { |
60 // Generate to a temporary first in case the output matrix and input | 60 // Generate to a temporary first in case the output matrix and input |
61 // matrix are thes same. | 61 // matrix are the same. |
62 Matrix_t out; | 62 Matrix_t out; |
63 | 63 |
64 out[0] = a[0] * b[0] + a[4] * b[1] + a[8] * b[2] + a[12] * b[3]; | 64 out[0] = a[0] * b[0] + a[4] * b[1] + a[8] * b[2] + a[12] * b[3]; |
65 out[1] = a[1] * b[0] + a[5] * b[1] + a[9] * b[2] + a[13] * b[3]; | 65 out[1] = a[1] * b[0] + a[5] * b[1] + a[9] * b[2] + a[13] * b[3]; |
66 out[2] = a[2] * b[0] + a[6] * b[1] + a[10] * b[2] + a[14] * b[3]; | 66 out[2] = a[2] * b[0] + a[6] * b[1] + a[10] * b[2] + a[14] * b[3]; |
67 out[3] = a[3] * b[0] + a[7] * b[1] + a[11] * b[2] + a[15] * b[3]; | 67 out[3] = a[3] * b[0] + a[7] * b[1] + a[11] * b[2] + a[15] * b[3]; |
68 | 68 |
69 out[4] = a[0] * b[4] + a[4] * b[5] + a[8] * b[6] + a[12] * b[7]; | 69 out[4] = a[0] * b[4] + a[4] * b[5] + a[8] * b[6] + a[12] * b[7]; |
70 out[5] = a[1] * b[4] + a[5] * b[5] + a[9] * b[6] + a[13] * b[7]; | 70 out[5] = a[1] * b[4] + a[5] * b[5] + a[9] * b[6] + a[13] * b[7]; |
71 out[6] = a[2] * b[4] + a[6] * b[5] + a[10] * b[6] + a[14] * b[7]; | 71 out[6] = a[2] * b[4] + a[6] * b[5] + a[10] * b[6] + a[14] * b[7]; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 multiply_matrix(z_matrix, xy_matrix, mat); | 127 multiply_matrix(z_matrix, xy_matrix, mat); |
128 } | 128 } |
129 | 129 |
130 void translate_matrix(GLfloat x, GLfloat y, GLfloat z, Matrix_t mat) { | 130 void translate_matrix(GLfloat x, GLfloat y, GLfloat z, Matrix_t mat) { |
131 identity_matrix(mat); | 131 identity_matrix(mat); |
132 mat[12] += x; | 132 mat[12] += x; |
133 mat[13] += y; | 133 mat[13] += y; |
134 mat[14] += z; | 134 mat[14] += z; |
135 } | 135 } |
136 | 136 |
OLD | NEW |