blob: 8e4a586763fa7e8726b84b71f368160c83b6d82d [file] [log] [blame]
Jason Sams326e0dd2009-05-22 14:03:28 -07001/*
Stephen Hines411f5992012-07-10 15:38:09 -07002 * Copyright (C) 2009-2012 The Android Open Source Project
Jason Sams326e0dd2009-05-22 14:03:28 -07003 *
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
Jason Sams87fe59a2011-04-20 15:09:01 -070017#ifndef ANDROID_RS_MATRIX_4x4_H
18#define ANDROID_RS_MATRIX_4x4_H
Jason Sams326e0dd2009-05-22 14:03:28 -070019
Jason Sams87fe59a2011-04-20 15:09:01 -070020#include "rsType.h"
Jason Sams326e0dd2009-05-22 14:03:28 -070021
22
23// ---------------------------------------------------------------------------
24namespace android {
25namespace renderscript {
26
Jason Sams87fe59a2011-04-20 15:09:01 -070027struct Matrix4x4 : public rs_matrix4x4 {
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -070028 float get(uint32_t col, uint32_t row) const {
29 return m[col*4 + row];
Jason Sams326e0dd2009-05-22 14:03:28 -070030 }
31
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -070032 void set(uint32_t col, uint32_t row, float v) {
33 m[col*4 + row] = v;
Jason Sams326e0dd2009-05-22 14:03:28 -070034 }
35
36 void loadIdentity();
37 void load(const float *);
Jason Sams87fe59a2011-04-20 15:09:01 -070038 void load(const rs_matrix4x4 *);
39 void load(const rs_matrix3x3 *);
40 void load(const rs_matrix2x2 *);
Jason Sams326e0dd2009-05-22 14:03:28 -070041
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);
Jason Sams87fe59a2011-04-20 15:09:01 -070045 void loadMultiply(const rs_matrix4x4 *lhs, const rs_matrix4x4 *rhs);
Jason Sams326e0dd2009-05-22 14:03:28 -070046
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);
Jason Sams87fe59a2011-04-20 15:09:01 -070049 void loadPerspective(float fovy, float aspect, float near, float far);
Jason Sams8ce125b2009-06-17 16:52:59 -070050
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -070051 // Note: This assumes that the input vector (in) is of length 3.
Jason Sams3a97c592009-09-30 17:36:20 -070052 void vectorMultiply(float *v4out, const float *v3in) const;
53
Jason Sams87fe59a2011-04-20 15:09:01 -070054 bool inverse();
55 bool inverseTranspose();
56 void transpose();
57
Jason Samsf47fb9b2011-04-22 14:24:17 -070058 void logv(const char *s) const;
Jason Sams87fe59a2011-04-20 15:09:01 -070059
60
61 void multiply(const rs_matrix4x4 *rhs) {
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -070062 loadMultiply(this, rhs);
Jason Sams326e0dd2009-05-22 14:03:28 -070063 }
64 void rotate(float rot, float x, float y, float z) {
Jason Sams87fe59a2011-04-20 15:09:01 -070065 Matrix4x4 tmp;
Jason Sams326e0dd2009-05-22 14:03:28 -070066 tmp.loadRotate(rot, x, y, z);
67 multiply(&tmp);
68 }
69 void scale(float x, float y, float z) {
Jason Sams87fe59a2011-04-20 15:09:01 -070070 Matrix4x4 tmp;
Jason Sams326e0dd2009-05-22 14:03:28 -070071 tmp.loadScale(x, y, z);
72 multiply(&tmp);
73 }
74 void translate(float x, float y, float z) {
Jason Sams87fe59a2011-04-20 15:09:01 -070075 Matrix4x4 tmp;
Jason Sams326e0dd2009-05-22 14:03:28 -070076 tmp.loadTranslate(x, y, z);
77 multiply(&tmp);
78 }
Jason Sams326e0dd2009-05-22 14:03:28 -070079};
Jason Sams3a97c592009-09-30 17:36:20 -070080
Jason Sams326e0dd2009-05-22 14:03:28 -070081}
82}
83
Stephen Hines411f5992012-07-10 15:38:09 -070084#endif // ANDROID_RS_MATRIX_4x4_H