Confused about Orthographic Projection of camera in SceneKit

I suppose, you can’t see your 3D objects in the scene using GLKMatrix4MakeOrtho, due to the fact that so many classes of GLKit for iOS and macOS are deprecated now.

In order to see your 3D object, you need to manually set Far Z Clipping parameter in Attributes Inspector. These two fields are near and far clipping planes of the frustum of your Orthographic Camera. A default value of Far=100 doesn’t allow you see the scene further than 100 units away.

enter image description here

Then use a Scale property to set a scale factor for your objects in an ortho view.

In order to use it programmatically via GLKMatrix4MakeOrtho, you need to import GLKit and OpenGL modules (as well as all the necessary delegate protocols) into your project at first.

import GLKit
import OpenGL

// Obj-C GLKMatrix4

GLK_INLINE GLKMatrix4 GLKMatrix4MakeOrtho(float left, 
                                          float right,
                                          float bottom, 
                                          float top,
                                          float nearZ, 
                                          float farZ) {
    float ral = right + left;
    float rsl = right - left;
    float tab = top + bottom;
    float tsb = top - bottom;
    float fan = farZ + nearZ;
    float fsn = farZ - nearZ;

    GLKMatrix4 m = { 2.0f / rsl, 0.0f, 0.0f, 0.0f,
                     0.0f, 2.0f / tsb, 0.0f, 0.0f,
                     0.0f, 0.0f, -2.0f / fsn, 0.0f,
                     -ral / rsl, -tab / tsb, -fan / fsn, 1.0f };

    return m;
}

Also, on iOS, GLKit requires an OpenGL ES 2.0 context. In macOS, GLKit requires an OpenGL context that supports the OpenGL 3.2 Core Profile.

But remember! Many GL Features are deprecated, so you’d better use Metal framework. Look at deprecated classes of GLKit.

Leave a Comment