itowns icon indicating copy to clipboard operation
itowns copied to clipboard

[CameraUtils] getTransformCameraLookingAtTarget modifies the camera position when called at initialization

Open AnthonyGlt opened this issue 1 year ago • 1 comments

When calling CameraUtils.getTransformCameraLookingAtTarget(...) multiple times at the initialization of the scene, the camera is not at the state (position, tilt ...) it should be.

Context

While developping a feature, I encounter this behavior during the initialization of the scene (cf video). The camera moves by itself under the map and then come back up but in a different state. I can pinpoint the origin of the issue to this function getTransformCameraLookingAtTarget

Screencast from 03-05-2023 16:48:12.webm

Steps to Reproduce (for bugs)

Add this line somewhere which is called multiple times: CameraUtils.getTransformCameraLookingAtTarget(...)

For example, in preUpdate function in src/Layer/TiledGeometryLayer.js, add : let temp = CameraUtils.getTransformCameraLookingAtTarget(context.view, context.view.camera.camera3D); The result is in the screenshots (top: without the line, bottom: with it). We can see that the scene is not the same.

Expected Behavior

Same camera state with or without calling getTransformCameraLookingAtTarget

Actual Behavior

Different tilt of the camera Difficult to tilt it again

Possible Cause/Fix/Solution

Conflict in rig's value when there is multiple calls.

Screenshot from 2023-05-24 16-09-29

Screenshot from 2023-05-24 16-10-48

AnthonyGlt avatar May 24 '23 14:05 AnthonyGlt

Comes from

setFromPositions(view, cameraPosition) 
    -->    this.setTargetFromCoordinate
         -->      this.target.position.set(0, 0, altitude);

AnthonyGlt avatar May 24 '23 15:05 AnthonyGlt