HarmonyOS 如何获取 matrix4.Matrix4Transit 对象具体的矩阵值?

如何获取 matrix4.Matrix4Transit 对象具体的矩阵值

我需要获取具体的矩阵值用于OpenGL渲染

阅读 510
1 个回答

您可以使用getRectangleById获取组件大小、位置、平移缩放旋转及仿射矩阵属性信息参考链接:

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-arkui-uicontext-V5\#getrectanglebyid

示例demo:

import matrix4 from '@ohos.matrix4';
import componentUtils from '@ohos.arkui.componentUtils';

@Entry
@Component
struct Utils {
@State x: number = 120;
@State y: number = 10;
@State z: number = 100;
@State value: string = '';
private matrix1 = matrix4.identity().translate({ x: this.x, y: this.y, z: this.z });

build() {
  Column() {
    Image($r("app.media.img"))
      .transform(this.matrix1)
      .translate({ x: 20, y: 20, z: 20 })
      .scale({ x: 0.5, y: 0.5, z: 1 })
      .rotate({
        x: 1,
        y: 1,
        z: 1,
        centerX: '50%',
        centerY: '50%',
        angle: 300
      })
      .width(300)
      .height(100)
      .key("image_01")
    Button('getRectangleById')
    .onClick(() => {
      this.value = JSON.stringify(componentUtils.getRectangleById("image_01"))
    }).margin(10).id('onClick')
    Text(this.value)
      .margin(20)
      .width(300)
      .height(300)
      .borderWidth(2)
  }.margin({left: 50})
}
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进