I'm trying to understand how to use camera with usesOrthographicProjection = true
. I need to set it up so when we first see the scene, the object should be viewable in full.
I used the Xcode's SceneKit template, adjust a little bit about the camera (all the code is in viewDidLoad
). Using default
camera (perspective projection), it looks like this:
cameraNode.position = SCNVector3(x: 0, y: 0, z: ship.boundingBox.max.z + 20)
Next, I tried to set the orthographic projection, now it looks like this:
cameraNode.camera?.usesOrthographicProjection = true
cameraNode.position = SCNVector3(x: 0, y: 0, z: ship.boundingBox.max.z + 20)
No matter how I tried to change the camera position, it still looks the same as the image above. I've tried using GLKMatrix4MakeOrtho
to no avail. Nothing works. What should I do the change the first view impression?
cameraNode.camera?.usesOrthographicProjection = true
// let width = Float(UIScreen.main.bounds.size.width)
// let width: Float = 9
// let glMat = GLKMatrix4MakeOrtho(-width/2,
// width/2,
// -width/2,
// width/2,
// 1,
// 1000)
// let glMat = GLKMatrix4MakeOrtho(ship.boundingBox.min.x,
// ship.boundingBox.max.x,
// ship.boundingBox.min.y,
// ship.boundingBox.max.y,
// ship.boundingBox.min.z,
// ship.boundingBox.max.z)
// cameraNode.camera?.projectionTransform = SCNMatrix4FromGLKMatrix4(glMat)
cameraNode.position = SCNVector3(x: 0,
y: 0,
z: ship.boundingBox.max.z + 20)