blob: 80f3fd6ad06dfee29e1020ef2e2e671e90b80c3a [file] [log] [blame]
Romain Guy08ae3172010-06-21 19:35:50 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Romain Guy85bf02f2010-06-22 13:11:24 -070017#ifndef ANDROID_MATRIX_H
18#define ANDROID_MATRIX_H
Romain Guy08ae3172010-06-21 19:35:50 -070019
Romain Guyf6a11b82010-06-23 17:47:49 -070020#include <SkMatrix.h>
21
Romain Guy08ae3172010-06-21 19:35:50 -070022namespace android {
23
24///////////////////////////////////////////////////////////////////////////////
25// Classes
26///////////////////////////////////////////////////////////////////////////////
27
28class Matrix4 {
29public:
30 Matrix4() {
31 loadIdentity();
32 }
33
34 Matrix4(const float* v) {
35 load(v);
36 }
37
38 Matrix4(const Matrix4& v) {
39 load(v);
40 }
41
Romain Guyf6a11b82010-06-23 17:47:49 -070042 Matrix4(const SkMatrix& v) {
43 load(v);
44 }
45
Romain Guy08ae3172010-06-21 19:35:50 -070046 void loadIdentity();
47
48 void load(const float* v);
49 void load(const Matrix4& v);
Romain Guyf6a11b82010-06-23 17:47:49 -070050 void load(const SkMatrix& v);
Romain Guy08ae3172010-06-21 19:35:50 -070051
52 void loadTranslate(float x, float y, float z);
53 void loadScale(float sx, float sy, float sz);
54 void loadRotate(float angle, float x, float y, float z);
55 void loadMultiply(const Matrix4& u, const Matrix4& v);
56
57 void loadOrtho(float left, float right, float bottom, float top, float near, float far);
58
59 void multiply(const Matrix4& v) {
60 Matrix4 u;
61 u.loadMultiply(*this, v);
62 load(u);
63 }
64
65 void translate(float x, float y, float z) {
66 Matrix4 u;
67 u.loadTranslate(x, y, z);
68 multiply(u);
69 }
70
71 void scale(float sx, float sy, float sz) {
72 Matrix4 u;
73 u.loadScale(sx, sy, sz);
74 multiply(u);
75 }
76
77 void rotate(float angle, float x, float y, float z) {
78 Matrix4 u;
79 u.loadRotate(angle, x, y, z);
80 multiply(u);
81 }
82
83 void copyTo(float* v) const;
Romain Guyf6a11b82010-06-23 17:47:49 -070084 void copyTo(SkMatrix& v) const;
Romain Guy08ae3172010-06-21 19:35:50 -070085
86 void dump() const;
87
Romain Guyf6a11b82010-06-23 17:47:49 -070088private:
Romain Guy08ae3172010-06-21 19:35:50 -070089 inline float get(int i, int j) const {
90 return mMat[i * 4 + j];
91 }
92
93 inline void set(int i, int j, float v) {
94 mMat[i * 4 + j] = v;
95 }
96
97 float mMat[16];
98}; // class Matrix4
99
100///////////////////////////////////////////////////////////////////////////////
101// Types
102///////////////////////////////////////////////////////////////////////////////
103
104typedef Matrix4 mat4;
105
106}; // namespace android
107
Romain Guy85bf02f2010-06-22 13:11:24 -0700108#endif // ANDROID_MATRIX_H