Get Vector between two points while using local coordinate space

Imagine I have a origin Point A at some certain coordinate at an height of 0m.
Now I want to get the Vector between the camera position (Point B) and that Point A.
Usually I could just use
Cartesian3.subtract(PointB, PointA)
, but I do not want to have it in world space, but local Point A space.
E.g.: If camera is exactly 10 meters above Point A and 1m to the east, I would want to get the Vector (1, 0, 10).
So I thought I can use
Cesium.Transforms.eastNorthUpToFixedFrame(PointA, Ellipsoid.WGS84, transform)
and Matrix4.multiplyByPointAsVector(transform, PointB, localCamVector).
But this is not working yet.

Then I also tried to multiplyByPointAsVector the PointA with Matrix4.multiplyByPointAsVector(transform, PointA, localOriginVector) and subtracted both with Cartesian3.subtract(localCamVector, localOriginVector).
This value seems to be more correct since the value are not thousands of meters long when I have the camera close to the origin, but still is not correct. When I move the camera to the east I can still see that x,y,z is manipulated and not just x.

Just found out how it would work:

    const sceneOriginPosition = new Cartesian3.fromDegrees(exampleLongitude, exampleLatitude, 0, Ellipsoid.WGS84)
    const camPosition = camera.positionWC

    const transform = Cesium.Transforms.eastNorthUpToFixedFrame(sceneOriginPosition, Ellipsoid.WGS84, new Matrix4())

    const inv = Matrix4.inverseTransformation(transform, new Matrix4())
    const globalCamOffset = Cartesian3.subtract(camPosition, sceneOriginPosition, new Cartesian3())
    const localCamOffset = Matrix4.multiplyByPointAsVector(inv, globalCamOffset, new Cartesian3())
1 Like