blob: 11ce42eb4a86e83d26ce7e73ca1feacb66c0f3f5 [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
Jason Sams3a97c592009-09-30 17:36:20 -070026struct Matrix
Jason Sams326e0dd2009-05-22 14:03:28 -070027{
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
Jason Sams8ce125b2009-06-17 16:52:59 -070047 void loadOrtho(float l, float r, float b, float t, float n, float f);
48 void loadFrustum(float l, float r, float b, float t, float n, float f);
49
Jason Sams3a97c592009-09-30 17:36:20 -070050 void vectorMultiply(float *v4out, const float *v3in) const;
51
Jason Sams326e0dd2009-05-22 14:03:28 -070052 void multiply(const Matrix *rhs) {
53 Matrix tmp;
54 tmp.loadMultiply(this, rhs);
55 load(&tmp);
56 }
57 void rotate(float rot, float x, float y, float z) {
58 Matrix tmp;
59 tmp.loadRotate(rot, x, y, z);
60 multiply(&tmp);
61 }
62 void scale(float x, float y, float z) {
63 Matrix tmp;
64 tmp.loadScale(x, y, z);
65 multiply(&tmp);
66 }
67 void translate(float x, float y, float z) {
68 Matrix tmp;
69 tmp.loadTranslate(x, y, z);
70 multiply(&tmp);
71 }
72
73
74
75};
Jason Sams3a97c592009-09-30 17:36:20 -070076
Jason Sams326e0dd2009-05-22 14:03:28 -070077
78
79}
80}
81
82
83
84
85#endif
86
87
88
89