If the user tries to use the only available camera for anything other than a single base camera, it will twitch and spin uncontrollably when the X angle nears +/-90 degrees. The issue surfaces when the user attempts to reset the camera back to an original orientation after using it for another purpose. The quirky camera behavior will occur whether using float values to transfer the camera angles or also a hidden guide object. This renders the only available camera as ultimately useless for anything other than one render point in a scene. It can't be used for render images for shadows, shaders, depth maps, mirrors, cube mapping, or anything else since it can't be reliably set back to its original rotation alignment without this spinning and twitching behavior. Either the float values need to be expanded to support whatever internal precision length the camera's rotations use or a command set like DBPro's 'SetObjectToCameraOrientation', 'SetCameraToObjectOrientation', and 'SetObjectToObjectOrientation' with 1:1 precision needs to be implemented.
I've provided sample code that includes both a float value transfer method as well as trying to use a hidden object that polls the camera's and object's angle values directly. I've also reported the issue on GitHub here:
https://github.com/TheGameCreators/AGK-Studio/issues/900 Here is sample code to demonstrate (just let it run for about 5-10 seconds):
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "CameraRotationBug" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
` SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 60, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
rem create background sky sphere to keep track of state of camera
CreateRenderImage(18,512,512,0,0)
SetRenderToImage(18,0)
for i = 0 to 100 step 10
sr=0:sg=128:sb=0
DrawBox(i,0,i+0.25,100,MakeColor(sr,sg,sb),MakeColor(sr,sg,sb),MakeColor(sr,sg,sb),MakeColor(sr,sg,sb),1)
sr=128:sg=128:sb=0
DrawBox(0,i,100,i+0.25,MakeColor(sr,sg,sb),MakeColor(sr,sg,sb),MakeColor(sr,sg,sb),MakeColor(sr,sg,sb),1)
next i
Render2DFront()
SetRenderToScreen()
CreateObjectSphere(1,100,20,20)
SetObjectImage(1,18,0)
SetObjectLightMode(1,0)
SetObjectCullMode(1,0)
SetObjectPosition(1,0,0,0)
SetObjectRotation(1,0,0,0)
rem attempt to use a hidden guide object in index 47 to reset camera orientation rather than floats, both fail
CreateObjectPlane(47,1,1)
SetObjectVisible(47,0)
SetCameraRotation(1,0,0,0)
RotateCameraLocalY(1,89.1)
RotateCameraLocalX(1,89.7)
RotateCameraLocalZ(1,0.1)
count=0:countmove#=0.005
SetCameraRange(1,1,100000)
do
Print("Camera angles will spin and twitch as X approaches near vertical (+/- 90)")
Print("Note how Y angle bounces between about 90 and 270")
Print("Camera can also flip 180 degrees up-side-down")
Print("X: "+str(GetCameraAngleX(1)))
Print("Y: "+str(GetCameraAngleY(1)))
Print("Z: "+str(GetCameraAngleZ(1)))
RotateCameraLocalX(1,countmove#)
rem this is where things break when trying to use the camera for anything other than a single base camera
rem such as render image captures for shaders, shadows, depth maps, angle measurements, etc
cx#=GetCameraAngleX(1)
cy#=GetCameraAngleY(1)
cz#=GetCameraAngleZ(1)
rem hidden guide object method
SetObjectRotation(47,GetCameraAngleX(1),GetCameraAngleY(1),GetCameraAngleZ(1))
SetCameraRotation(1,cx#,cy#,cz#) ` float value method
` SetCameraRotation(1,GetObjectAngleX(47),GetObjectAngleY(47),GetObjectAngleZ(47)) ` hidden guide object method
count=count+1
if count>100
countmove#=-countmove#
count=0
endif
Sync()
if GetRawKeyState(27)>0 then end
loop