blob: 4130b8e5afd48033e195caae71e30d2a2859c8ea [file] [log] [blame]
Jason Sams326e0dd2009-05-22 14:03:28 -07001/*
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
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080026struct Matrix {
Jason Sams326e0dd2009-05-22 14:03:28 -070027 float m[16];
28
29 inline float get(int i, int j) const {
30 return m[i*4 + j];
31 }
32
33 inline void set(int i, int j, float v) {
34 m[i*4 + j] = v;
35 }
36
37 void loadIdentity();
38 void load(const float *);
39 void load(const Matrix *);
40
41 void loadRotate(float rot, float x, float y, float z);
42 void loadScale(float x, float y, float z);
43 void loadTranslate(float x, float y, float z);
44 void loadMultiply(const Matrix *lhs, const Matrix *rhs);
45
Jason Sams8ce125b2009-06-17 16:52:59 -070046 void loadOrtho(float l, float r, float b, float t, float n, float f);
47 void loadFrustum(float l, float r, float b, float t, float n, float f);
48
Jason Sams3a97c592009-09-30 17:36:20 -070049 void vectorMultiply(float *v4out, const float *v3in) const;
50
Jason Sams326e0dd2009-05-22 14:03:28 -070051 void multiply(const Matrix *rhs) {
52 Matrix tmp;
53 tmp.loadMultiply(this, rhs);
54 load(&tmp);
55 }
56 void rotate(float rot, float x, float y, float z) {
57 Matrix tmp;
58 tmp.loadRotate(rot, x, y, z);
59 multiply(&tmp);
60 }
61 void scale(float x, float y, float z) {
62 Matrix tmp;
63 tmp.loadScale(x, y, z);
64 multiply(&tmp);
65 }
66 void translate(float x, float y, float z) {
67 Matrix tmp;
68 tmp.loadTranslate(x, y, z);
69 multiply(&tmp);
70 }
Jason Sams326e0dd2009-05-22 14:03:28 -070071};
Jason Sams3a97c592009-09-30 17:36:20 -070072
Jason Sams326e0dd2009-05-22 14:03:28 -070073}
74}
75
76
77
78
79#endif
80
81
82
83