How to use OrbitalCamera and OrbitalControls in only some parts of your program?

Hi! I have the following in my program:

        val camera = OrbitalCamera(Vector3.UNIT_Z * 1000.0, Vector3.ZERO, 90.0, 0.1, 2000.0)
        val controls = OrbitalControls(camera, keySpeed = 10.0)

        extend(camera)
        extend(controls)

which affects everything I draw with drawer. How can I draw things that are not affected by the camera?

You’d do this by not using the camera as an extension and setting the view and projection matrices manually.

val camera = OrbitalCamera(Vector3.UNIT_Z * 1000.0, Vector3.ZERO, 90.0, 0.1, 2000.0)
val controls = OrbitalControls(camera, keySpeed = 10.0)
extend(controls)
extend {
    camera.update(deltaTime)
    // -- draw in ortho here
    
    drawer.isolated { 
        drawer.perspective(camera.fov, width.toDouble() / height, camera.near, camera.far)
        drawer.view = camera.viewMatrix()
        drawer.drawStyle.depthWrite = true
        drawer.drawStyle.depthTestPass = DepthTestPass.LESS_OR_EQUAL
        // draw in perspective here
    }
   // -- draw in ortho here
}
1 Like

Thanks! That works almost perfectly. With that change I get a side effect: polygons seem to have the wrong z-sorting. Why could that be?
2020-03-16-134434_462x455_scrot

Note: to make it compile I used camera.update(deltaTime)

To get the right behaviour you need to enable depth writing and testing. The conventional settings are:

drawer.drawStyle.depthWrite = true
drawer.drawStyle.depthTestPass = DepthTestPass.LESS_OR_EQUAL

Adviced is to place them inside the isolated block.