Swift -meaning of viewportSize parameter of projectPoint(_:orientation:viewportSize:)

168 Views Asked by At

The Apple doc for

func projectPoint(_ point: simd_float3, orientation: UIInterfaceOrientation, viewportSize: CGSize) -> CGPoint

says:

viewportSize

The size, in points, of the view in which the camera image is to be presented.

I'm not clear what the view in which the camera image is to be presented means? Does that mean that I should put in the screen dimensions for the viewportSize?

let screenDimensions = UIScreen.main.bounds.size
let position = node.position

camera.projectPoint(simd_float3(position), orientation: .portrait, viewportSize: screenDimensions)
2

There are 2 best solutions below

0
Lance Samaria On

I just noticed the link also said:

Return Value

The projection of the specified point into a 2D pixel coordinate space whose origin is in the upper left corner and whose size matches that of the viewportSize parameter.

This suggests that you can put whatever size you want. The screen dimensions would be suffice if necessary.

1
Jiawei Huang On

You should use view.bounds.size corresponding to the view you are projecting into.