scaling issue when projecting uiview in front of scenekit camera

191 Views Asked by At

content

  • first i have a 360 (equirectangular) image viewer by applying the image as a texture onto a sphere with the scenekit camera at the center.
  • then i enter a "drawing mode" where i can use my finger to draw on a transparent UIView
  • when i'm done, i take the drawing and apply it to my sphere as an annotation

problem (with video example)

the problem is in this 3rd step, the scale isn't saved correctly.

https://www.dropbox.com/s/a2l3vvx92sa3cgh/drawing_defect_trimmed_480p.mp4?dl=0

temporary solution i was able to add a magic number to the expected scale which lessens the scaling problem, but it is still a little bit off and obviously suboptimal from a technical perspective.

e.g. “scale_used = expected_scale + magic_constant”

implementation details

  • I am projecting a UIView in front of a Scene Kit camera at some custom distance in the Scene Kit world and trying to make it so the new Scene Kit node will have exactly the same visual size.

  • the approach is to calculate the perspective projection of the item, located in the world at drawingContentItem.distance using camera zNear - “(screenHeight * distance / Float(zNear))”.

  • Then we assume that size of visible world of scene kit is from -1000 to 1000; and the view angle is 60 degrees; and calculate the ratio of scene Kit near plane view to UIView - “(sceneScreenHeight / nearPlaneHeightInWorlCoordinates)”.

  • that gives us the finalHeight of drawing in the world coordinates and we use this to calculate the scale.

  • But it seems that there is some mistake in the formula and it causes the need for the magical number. :(

0

There are 0 best solutions below