Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BoundingSphere.fromOrientedBoundingBox is incorrect #5334

Closed
hpinkos opened this issue May 17, 2017 · 0 comments
Closed

BoundingSphere.fromOrientedBoundingBox is incorrect #5334

hpinkos opened this issue May 17, 2017 · 0 comments

Comments

@hpinkos
Copy link
Contributor

hpinkos commented May 17, 2017

image

var viewer = new Cesium.Viewer('cesiumContainer');
var center = new Cesium.Cartesian3(4887501.122078268, 786198.1296201526, 4008900.532512873);
var halfAxis = new Cesium.Matrix3(-127.27149886828649, -680.2575869826898,58.31047687474563,
                                  792.6634927382382, -109.22340123515842,9.362436720703323,
                                  0,844.0437859967432,48.20690839996962);
var obb = new Cesium.OrientedBoundingBox(center, halfAxis);
var bs = Cesium.BoundingSphere.fromOrientedBoundingBox(obb);

var radius = bs.radius;
var geometry = Cesium.GeometryPipeline.toWireframe(Cesium.EllipsoidGeometry.createGeometry(new Cesium.EllipsoidGeometry({
    radii : new Cesium.Cartesian3(radius, radius, radius),
    vertexFormat : Cesium.PerInstanceColorAppearance.FLAT_VERTEX_FORMAT
})));

viewer.scene.primitives.add(new Cesium.Primitive({
    geometryInstances : new Cesium.GeometryInstance({
        geometry : geometry,
        modelMatrix : Cesium.Matrix4.fromTranslation(bs.center),
        attributes : {
            color : new Cesium.ColorGeometryInstanceAttribute(1.0, 0.0, 0.0, 1.0)
        }
    }),
    appearance : new Cesium.PerInstanceColorAppearance({
        flat : true,
        translucent : false
    }),
    asynchronous : false
}));

geometry = Cesium.GeometryPipeline.toWireframe(Cesium.BoxGeometry.createGeometry(Cesium.BoxGeometry.fromDimensions({
    dimensions : new Cesium.Cartesian3(2.0, 2.0, 2.0),
    vertexFormat : Cesium.PerInstanceColorAppearance.FLAT_VERTEX_FORMAT
})));

viewer.scene.primitives.add(new Cesium.Primitive({
    geometryInstances : new Cesium.GeometryInstance({
        geometry : geometry,
        modelMatrix : Cesium.Matrix4.fromRotationTranslation(obb.halfAxes, obb.center, new Cesium.Matrix4()),
        attributes : {
            color : new Cesium.ColorGeometryInstanceAttribute(1.0, 0.0, 1.0, 1.0)
        }
    }),
    appearance : new Cesium.PerInstanceColorAppearance({
        flat : true,
        translucent : false
    }),
    asynchronous : false
}));

viewer.camera.flyToBoundingSphere(bs, {
    duration: 0,
    offset: new Cesium.HeadingPitchRange(0, -Cesium.Math.PI_OVER_TWO, 5000)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant