blob: 3f9a2d1820b4363c093149518d4e114cc8d73aaf [file] [log] [blame]
Jason Samsfcf72312011-04-20 15:09:01 -07001/*
2 * Copyright (C) 2011 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#include "rsMatrix2x2.h"
18#include "rsMatrix3x3.h"
19#include "rsMatrix4x4.h"
20
21#include "stdlib.h"
22#include "string.h"
23#include "math.h"
24
25using namespace android;
26using namespace android::renderscript;
27
28void Matrix3x3::loadIdentity() {
29 m[0] = 1.f;
30 m[1] = 0.f;
31 m[2] = 0.f;
32 m[3] = 0.f;
33 m[4] = 1.f;
34 m[5] = 0.f;
35 m[6] = 0.f;
36 m[7] = 0.f;
37 m[8] = 1.f;
38}
39
40void Matrix3x3::load(const float *v) {
41 memcpy(m, v, sizeof(m));
42}
43
44void Matrix3x3::load(const rs_matrix3x3 *v) {
45 memcpy(m, v->m, sizeof(m));
46}
47
48void Matrix3x3::loadMultiply(const rs_matrix3x3 *lhs, const rs_matrix3x3 *rhs) {
49 for (int i=0 ; i<3 ; i++) {
50 float ri0 = 0;
51 float ri1 = 0;
52 float ri2 = 0;
53 for (int j=0 ; j<3 ; j++) {
54 const float rhs_ij = ((const Matrix3x3 *)rhs)->get(i, j);
55 ri0 += ((const Matrix3x3 *)lhs)->get(j, 0) * rhs_ij;
56 ri1 += ((const Matrix3x3 *)lhs)->get(j, 1) * rhs_ij;
57 ri2 += ((const Matrix3x3 *)lhs)->get(j, 2) * rhs_ij;
58 }
59 set(i, 0, ri0);
60 set(i, 1, ri1);
61 set(i, 2, ri2);
62 }
63}
64
65void Matrix3x3::transpose() {
66 int i, j;
67 float temp;
68 for (i = 0; i < 2; ++i) {
69 for (j = i + 1; j < 3; ++j) {
70 temp = get(i, j);
71 set(i, j, get(j, i));
72 set(j, i, temp);
73 }
74 }
75}
76