Fake ortho cam – ShiVa Engine

Fake ortho cam

Setting up a fake isometric camera is very simple. First, the camera setup. The secret relies on setFieldOfView: a very low number (minimum is 1) makes the projection “isometric”, and this never needs to be changed. Changing the y position using setTranslation will zoom in and out (keep the same factor for x, y, z to not change the isometric angle). And last, lookAt allow us to move the camera on the screen, focusing on a grid coordinate:

--------------------------------------------------------------------------------
function Game.onInit (  )
--------------------------------------------------------------------------------
    application.setCurrentUserScene ( "Start" )
    -- isometric camera setup begins!
    local hCamera = application.getCurrentUserActiveCamera ( )
    -- restricting the field of view makes the projection "isometric".
    camera.setFieldOfView ( hCamera, 1 )
    -- change translation y to zoom in and out. keep same factor for x, y and z
    -- according to the desired isometric angle. if all three have the same
    -- value, the projection will be symmetric.
    object.setTranslation ( hCamera, 75, 75, 75, object.kGlobalSpace )
    -- change x, z to position the camera focusing on a grid coordinate.
    object.lookAt ( hCamera, 1, 0, 1, object.kGlobalSpace, 1 )
--------------------------------------------------------------------------------
end
--------------------------------------------------------------------------------
-----------------------------------------------------------------------------
--BONUS BONUS BONUS BONUS BONUS BONUS BONUS BONUS BONUS BONUS BONUS BONUS
--It is possible to add a control to rotate the camera around the scene, if needed. Just use a
--combination of rotateAround and lookAt. As an example set this on onEnterFrame in the
--User Main AI:
-----------------------------------------------------------------------------
--------------------------------------------------------------------------------
function Game.onEnterFrame (  )
--------------------------------------------------------------------------------
    local hCamera = application.getCurrentUserActiveCamera ( )
    -- rotate around grid coordinate 5, 7 with the camera focused on that cell.
    object.rotateAround ( hCamera, 5, 0, 7, 0, 1, 0, object.kGlobalSpace )
    object.lookAt ( hCamera, 5, 0, 7, object.kGlobalSpace, 1 )
--------------------------------------------------------------------------------
end
--------------------------------------------------------------------------------



Need more answers?

  • slackBanner