Hi
i would like to "lock" my camera in the center of the screen with SetCameraLookAt().
I have made a little code which works, but I have a little difference for the center of the the view between move and rotate :
// Project: 3D_cameralookatcenter
// Created: 2016-06-25
// set window properties
SetWindowTitle( "3D_cameralookatcenter" )
SetWindowSize( 1024, 768, 0 )
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
GeneralX = 0
GeneralY = 0
GeneralZ = 0
// create a plane to see the X/Y plane
CreateObjectPlane(1,100,100)
SetObjectRotation(1,90,0,0)
// create some objects so see it
FOr i= 2 to 10
r = 5
CreateObjectBox(i,r,r,r)
r = 40
SetObjectPosition(i,random(-r,r),random(-r,r),random(-r,r))
next
//set the camera position
SetCameraPosition(1,0,50,-50)
SetCameraLookAt(1,0,0,0,0)
SetPrintSize(12)
do
Print("Left to move the camera (pan), control + middle to rotate the camera")
Print("When moving then rotating, you can see a little difference for the center of the camera")
//camera is locked at the center of the screen.
// move the camera
if ( GetRawMouseLeftPressed () )
startx1# = GetPointerX()
starty1# = GetPointerY()
angx# = GetCameraAngleX(1)
angy# = GetCameraAngleY(1)
endif
if ( GetRawMouseLeftState() = 1 )
new_x# = GetPointerX()
new_y# = GetPointerY()
MoveCameraLocalX( 1, -new_x# + startx1#)
MoveCameraLocalY( 1, new_y# - starty1# )
GeneralX = GeneralX - new_x#+startx1#
startx1# = new_x#
GeneralY = GeneralY + new_y#-starty1#
starty1# = new_y#
endif
// Rotate the camera,
IF GetRawKeyState(17) // key control
if GetRawMouseMiddlePressed()
startx1# = GetPointerX()
starty1# = GetPointerY()
angx# = GetCameraAngleX(1)
angy# = GetCameraAngleY(1)
SetCameraLookAt(1,GeneralX,GeneralY,GeneralZ,0)
//CAmZ = GetcameraZ(1)
endif
if GetRawMouseMiddleState() = 1
new_x# = GetPointerX()
new_y# = GetPointerY()
MoveCameraLocalX( 1,-new_x#+startx1#)
startx1# = new_x#
MoveCameraLocalY( 1, new_y#-starty1# )
starty1# = new_y#
SetCameraLookAt(1,GeneralX,GeneralY,GeneralZ,0)
endif
endif
Print( ScreenFPS() )
Sync()
loop
Do you knwo How I can fixe that ?
Thanks
AGK2 tier1 - http://www.dracaena-studio.com