代码之家  ›  专栏  ›  技术社区  ›  swiss_knight

如何在CesiumJS中绘制gizmo

  •  0
  • swiss_knight  · 技术社区  · 4 年前

    如何绘制一个gizmo,通过给它一个位置,方向,最终在一个平面上给它一个比例 CesiumJS 应用

    gizmo指的是使用(x、y、z)矢量的三轴右手坐标系,理想情况下表示为(RGB)值,例如:

    enter image description here enter image description here enter image description here

    我希望我可以通过将这样的参考框架放置在物体原点的位置(例如,使用其坐标)来描述任何物体(例如glTF)的方向 longitude, latitude and elevation )并遵循其定义的方向 heading, pitch and roll 值,该值必须按照三个给定角度的原始顺序(第一个航向、第二个俯仰和第三个滚转)从 LTP-ENU (0,0,0) convention (x=0=东,y=0=北,z=0=向上)。

    检查员不是一个选项。

    0 回复  |  直到 4 年前
        1
  •  2
  •   ZhefengJin    4 年前

    您可以使用DebugModelMatrixperic。
    这是 Sandcastle
    示例代码

    const viewer = new Cesium.Viewer("cesiumContainer");
    
    const position = Cesium.Cartesian3.fromDegrees(-107.0, 40.0, 300000.0);
    
    const redSphere = viewer.entities.add({
        name: "Red sphere with black outline",
        position: position,
        ellipsoid: {
            radii: new Cesium.Cartesian3(300000.0, 300000.0, 300000.0),
            material: Cesium.Color.RED.withAlpha(0.5),
            outline: true,
            outlineColor: Cesium.Color.BLACK,
        },
    });
    
    const heading = Cesium.Math.toRadians(10);
    const pitch = Cesium.Math.toRadians(50);
    const roll = Cesium.Math.toRadians(0);
    
    const hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
    
    const frame = Cesium.Transforms.headingPitchRollToFixedFrame(position, hpr);
    
    viewer.scene.primitives.add(new Cesium.DebugModelMatrixPrimitive({
        modelMatrix: frame,
        length: 800000,
        width: 3.0
    }));
    
    viewer.zoomTo(viewer.entities);