Hello folks.
My Goal:
I have a camera orientation data from photogrammetry software: frustum parameters and transformation matrix. What i need is to check if a given point is inside each camera frustum or outside it.
My problems
-
I do not understand how to set
Cesum.Camera()
orientation the same way as i set orientation forCesium.FrustumGeometry
-
Is
cullingVolume.computeVisibility
the right approach to check if the point is visible by camera?
First problem description:
Lets say i have each camera defined as:
camera = {
label: 'label'
transform : Cesium.Matrix4,
sensor : {
width: W,
height: H
f : F
}
};
I calculate position and orientation from Matrix4
var matrix3 = Cesium.Matrix4.getMatrix3(transform, new Cesium.Matrix3());
var rotationMatrix = Cesium.Matrix3.getRotation(matrix3,new Cesium.Matrix3())
var rotationQuaternion = Cesium.Quaternion.fromRotationMatrix(rotationMatrix, new Cesium.Quaternion())
var positionOnEllipsoid = Cesium.Matrix4.multiplyByPoint(camera.transform, new Cesium.Cartesian3(), new Cesium.Cartesian3())
I create frustum geometry:
var frustumGeometry = new Cesium.FrustumGeometry({
frustum : frustum,
origin : positionOnEllipsoid,
orientation : frustumOrientation,
});
var frustumGeometryInstance = new Cesium.GeometryInstance({
geometry : frustumGeometry,
attributes : {
color :Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.fromCssColorString('#498AD6'))
},
id : camera.label
});
var frustumPrimitive = camerasPrimitives.add(new Cesium.Primitive({
geometryInstances : frustumGeometryInstance,
appearance : new Cesium.PerInstanceColorAppearance({
closed: true,
grid:true,
flat : true
})
}));
And it works. Frustum geometries are located in the right position and oriented the right way.
To set the Cesium.Camera
i calculate Cesium.HeadingPitchRoll
:
var rotationQuaternion = Cesium.Quaternion.fromRotationMatrix(rotationMatrix, new Cesium.Quaternion())
var hpr = Cesium.HeadingPitchRoll.fromQuaternion(rotationQuaternion, new Cesium.HeadingPitchRoll())
Then I create a new Cesium.Camera()
as:
var cameraToBeChecked = new Cesium.Camera(scene);
cameraToBeChecked.setView({
destination : cartesianPosition,
orientation: {
heading : hpr.heading,
pitch : hpr.pitch,
roll : hpr.roll
}
});
And, the camera orientation is wrong. What I am doing wrong? How to orient new Cesium.Camera()
properly with rotationMatrix
or Quatrneion
or HeadingPitchRoll
?
Second problem description:
To check if point given by user is Inside or Outside the camera frustum i use:
var userDefinedPoint = new Cesium.Cartesian3(.....)
var cullingVolume = frustum.computeCullingVolume(cameraToBeChecked.position,cameraToBeChecked.direction, cameraToBeChecked.up)
if (cullingVolume.computeVisibility(new Cesium.BoundingSphere(userDefinedPoint, 0.0)) === Cesium.Intersect.INSIDE || Cesium.Intersect.INTERSECTING ) {
console.log(camera.label + ' is INSIDE')
} else {
console.log(camera.label + ' is OUTSIDE')
};
Is this a right way do do that?
Best regards,
Ilia Shevelev