rsMatrix3x3.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  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. #include "rsMatrix2x2.h"
  17. #include "rsMatrix3x3.h"
  18. #include "rsMatrix4x4.h"
  19. #include "stdlib.h"
  20. #include "string.h"
  21. #include "math.h"
  22. namespace android {
  23. namespace renderscript {
  24. void Matrix3x3::loadIdentity() {
  25. m[0] = 1.f;
  26. m[1] = 0.f;
  27. m[2] = 0.f;
  28. m[3] = 0.f;
  29. m[4] = 1.f;
  30. m[5] = 0.f;
  31. m[6] = 0.f;
  32. m[7] = 0.f;
  33. m[8] = 1.f;
  34. }
  35. void Matrix3x3::load(const float *v) {
  36. memcpy(m, v, sizeof(m));
  37. }
  38. void Matrix3x3::load(const rs_matrix3x3 *v) {
  39. memcpy(m, v->m, sizeof(m));
  40. }
  41. void Matrix3x3::loadMultiply(const rs_matrix3x3 *lhs, const rs_matrix3x3 *rhs) {
  42. // Use a temporary variable to support the case where one of the inputs
  43. // is also the destination, e.g. left.loadMultiply(left, right);
  44. Matrix3x3 temp;
  45. for (int i=0 ; i<3 ; i++) {
  46. float ri0 = 0;
  47. float ri1 = 0;
  48. float ri2 = 0;
  49. for (int j=0 ; j<3 ; j++) {
  50. const float rhs_ij = ((const Matrix3x3 *)rhs)->get(i, j);
  51. ri0 += ((const Matrix3x3 *)lhs)->get(j, 0) * rhs_ij;
  52. ri1 += ((const Matrix3x3 *)lhs)->get(j, 1) * rhs_ij;
  53. ri2 += ((const Matrix3x3 *)lhs)->get(j, 2) * rhs_ij;
  54. }
  55. temp.set(i, 0, ri0);
  56. temp.set(i, 1, ri1);
  57. temp.set(i, 2, ri2);
  58. }
  59. load(&temp);
  60. }
  61. void Matrix3x3::transpose() {
  62. int i, j;
  63. float temp;
  64. for (i = 0; i < 2; ++i) {
  65. for (j = i + 1; j < 3; ++j) {
  66. temp = get(i, j);
  67. set(i, j, get(j, i));
  68. set(j, i, temp);
  69. }
  70. }
  71. }
  72. } // namespace renderscript
  73. } // namespace android