rsMatrix4x4.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (C) 2009-2012 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. #ifndef ANDROID_RS_MATRIX_4x4_H
  17. #define ANDROID_RS_MATRIX_4x4_H
  18. #include "rsType.h"
  19. // ---------------------------------------------------------------------------
  20. namespace android {
  21. namespace renderscript {
  22. struct Matrix4x4 : public rs_matrix4x4 {
  23. float get(uint32_t col, uint32_t row) const {
  24. return m[col*4 + row];
  25. }
  26. void set(uint32_t col, uint32_t row, float v) {
  27. m[col*4 + row] = v;
  28. }
  29. void loadIdentity();
  30. void load(const float *);
  31. void load(const rs_matrix4x4 *);
  32. void load(const rs_matrix3x3 *);
  33. void load(const rs_matrix2x2 *);
  34. void loadRotate(float rot, float x, float y, float z);
  35. void loadScale(float x, float y, float z);
  36. void loadTranslate(float x, float y, float z);
  37. void loadMultiply(const rs_matrix4x4 *lhs, const rs_matrix4x4 *rhs);
  38. void loadOrtho(float l, float r, float b, float t, float n, float f);
  39. void loadFrustum(float l, float r, float b, float t, float n, float f);
  40. void loadPerspective(float fovy, float aspect, float near, float far);
  41. // Note: This assumes that the input vector (in) is of length 3.
  42. void vectorMultiply(float *v4out, const float *v3in) const;
  43. bool inverse();
  44. bool inverseTranspose();
  45. void transpose();
  46. void logv(const char *s) const;
  47. void multiply(const rs_matrix4x4 *rhs) {
  48. loadMultiply(this, rhs);
  49. }
  50. void rotate(float rot, float x, float y, float z) {
  51. Matrix4x4 tmp;
  52. tmp.loadRotate(rot, x, y, z);
  53. multiply(&tmp);
  54. }
  55. void scale(float x, float y, float z) {
  56. Matrix4x4 tmp;
  57. tmp.loadScale(x, y, z);
  58. multiply(&tmp);
  59. }
  60. void translate(float x, float y, float z) {
  61. Matrix4x4 tmp;
  62. tmp.loadTranslate(x, y, z);
  63. multiply(&tmp);
  64. }
  65. };
  66. } // namespace renderscript
  67. } // namespace android
  68. #endif // ANDROID_RS_MATRIX_4x4_H