我最终试图在我的房子顶部画一个多边形。我能做到。
问题是,在缩小、放大和旋转(或相机移动)时,多边形不会粘在我房子的顶部。我得到了很大的帮助这个答案 https://stackoverflow.com/a/35992537/1735836。所以,现在我正在尝试查看示例代码,但我需要学习很多 Cesium 方法和功能。
我试图遵循的示例代码位于黄金标准似乎已融入现有的相机控制器中 https://github.com/AnalyticalGraphicsInc/cesium/blob/1.19/Source/Scene/ScreenSpaceCameraController.js#L696-L711.
I call testMemousePosition 为 Cartesian3,SceneMode 为 3D,所以挑选地球仪被执行。
这是我的代码:
var pickedPosition;
var scratchZoomPickRay = new Cesium.Ray();
var scratchPickCartesian = new Cesium.Cartesian3();
function testMe(mousePosition) {
if (Cesium.defined(scene.globe)) {
if(scene.mode !== Cesium.SceneMode.SCENE2D) {
pickedPosition = pickGlobe(viewer, mousePosition, scratchPickCartesian);
} else {
pickedPosition = camera.getPickRay(mousePosition, scratchZoomPickRay).origin;
}
}
}
var pickGlobeScratchRay = new Cesium.Ray();
var scratchDepthIntersection = new Cesium.Cartesian3();
var scratchRayIntersection = new Cesium.Cartesian3();
function pickGlobe(viewer, mousePosition, result) {
var globe = scene.globe;
var camera = scene.camera;
if (!Cesium.defined(globe)) {
return undefined;
}
var depthIntersection;
if (scene.pickPositionSupported) {
depthIntersection = scene.pickPosition(mousePosition, scratchDepthIntersection);
}
var ray = camera.getPickRay(mousePosition, pickGlobeScratchRay);
var rayIntersection = globe.pick(ray, scene, scratchRayIntersection);
var pickDistance;
if(Cesium.defined(depthIntersection)) {
pickDistance = Cesium.Cartesian3.distance(depthIntersection, camera.positionWC);
} else {
pickDistance = Number.POSITIVE_INFINITY;
}
var rayDistance;
if(Cesium.defined(rayIntersection)) {
rayDistance = Cesium.Cartesian3.distance(rayIntersection, camera.positionWC);
} else {
rayDistance = Number.POSITIVE_INFINITY;
}
var scratchCenterPosition = new Cesium.Cartesian3();
if (pickDistance < rayDistance) {
var cart = Cesium.Cartesian3.clone(depthIntersection, result);
return cart;
}
var cart = Cesium.Cartesian3.clone(rayIntersection, result);
return cart;
}
这是我的问题:
结果如下:
以下是让此代码正常工作的我的问题:
1. 如何将 scene.pickPositionSupported 设置为 true?我在 Windows 10 上使用 Chrome。我在示例代码中找不到任何与此相关的内容,而且我在文档或 Google 上也没有太多运气。
2. 为什么 rayIntersection 没有被设置?光线和场景在空的 Cartesian3 中具有值和 scrapRayIntersection。
我想如果我能让这两个语句正常工作,我可能就能让 pickGlobe 方法的其余部分正常工作。
WebGL 图形报告:
我点击了获取 WebGL和立方体在旋转!