当前位置:   article > 正文

cesium primitive 移动 缩放 旋转 矩阵

cesium primitive 移动 缩放 旋转 矩阵

旋转参考:cesium 指定点旋转rectangle Primitive方式 矩阵篇-CSDN博客

平移参考:cesium 调整3dtiles的位置 世界坐标下 相对坐标下 平移矩阵-CSDN博客

一、primitive方式添加polygon
  1. let polygonInstance = new Cesium.GeometryInstance({
  2. geometry: Cesium.PolygonGeometry.fromPositions({
  3. positions: Cesium.Cartesian3.fromDegreesArray([
  4. ...p1,
  5. p2[0], p1[1],
  6. ...p2,
  7. p1[0], p2[1]
  8. ]),
  9. height: 0,
  10. vertexFormat: Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT
  11. }),
  12. attributes: {
  13. color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.fromCssColorString('#00ff00').withAlpha(0.5))
  14. }
  15. });
  16. let polygonPrimitive = new Cesium.Primitive({
  17. geometryInstances: [polygonInstance],
  18. undisplayable: true,
  19. appearance: new Cesium.PerInstanceColorAppearance({
  20. flat: true,
  21. translucent: false
  22. })
  23. });
  24. viewer.scene.primitives.add(polygonPrimitive);

二、平移

以p1为原点,将p1移动到(113.392209, 38.095546),其他几个点相对p1移动

  1. let origin = Cesium.Cartesian3.fromDegrees(...p1);
  2. let offset = Cesium.Cartesian3.fromDegrees(
  3. 113.392209, 38.095546
  4. );
  5. let translate = Cesium.Cartesian3.subtract(
  6. offset,
  7. origin,
  8. new Cesium.Cartesian3()
  9. );
  10. polygonPrimitive.modelMatrix = Cesium.Matrix4.fromTranslation(translate)

三、缩放

以p1为原点,在x轴方向缩放2倍大小

  1. let origin = Cesium.Cartesian3.fromDegrees(...p1);
  2. let localToWorld_Matrix = Cesium.Transforms.eastNorthUpToFixedFrame(origin);
  3. let worldToLocal_Matrix = Cesium.Matrix4.inverse(localToWorld_Matrix, new Cesium.Matrix4);
  4. let scaleMatrix = Cesium.Matrix4.fromScale(new Cesium.Cartesian3(2, 1, 1));
  5. let localScaleMatrix = Cesium.Matrix4.multiply(scaleMatrix, worldToLocal_Matrix, new Cesium.Matrix4);
  6. let worldMatrix = Cesium.Matrix4.multiply(localToWorld_Matrix, localScaleMatrix, new Cesium.Matrix4);
  7. polygonPrimitive.modelMatrix = worldMatrix;

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/458964
推荐阅读
相关标签
  

闽ICP备14008679号