rsMatrix.h revision d19f10d43aa400e1183aa21a97099d02074131a2
1/*
2 * Copyright (C) 2009 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
17#ifndef ANDROID_RS_MATRIX_H
18#define ANDROID_RS_MATRIX_H
19
20
21
22// ---------------------------------------------------------------------------
23namespace android {
24namespace renderscript {
25
26struct Matrix
27{
28    float m[16];
29
30    inline float get(int i, int j) const {
31        return m[i*4 + j];
32    }
33
34    inline void set(int i, int j, float v) {
35        m[i*4 + j] = v;
36    }
37
38    void loadIdentity();
39    void load(const float *);
40    void load(const Matrix *);
41
42    void loadRotate(float rot, float x, float y, float z);
43    void loadScale(float x, float y, float z);
44    void loadTranslate(float x, float y, float z);
45    void loadMultiply(const Matrix *lhs, const Matrix *rhs);
46
47    void multiply(const Matrix *rhs) {
48        Matrix tmp;
49        tmp.loadMultiply(this, rhs);
50        load(&tmp);
51    }
52    void rotate(float rot, float x, float y, float z) {
53        Matrix tmp;
54        tmp.loadRotate(rot, x, y, z);
55        multiply(&tmp);
56    }
57    void scale(float x, float y, float z) {
58        Matrix tmp;
59        tmp.loadScale(x, y, z);
60        multiply(&tmp);
61    }
62    void translate(float x, float y, float z) {
63        Matrix tmp;
64        tmp.loadTranslate(x, y, z);
65        multiply(&tmp);
66    }
67
68
69
70};
71
72
73
74}
75}
76
77
78
79
80#endif
81
82
83
84
85