Use easing (Distance function included)
Camera will flip if crossing an axis
// Project: test78
// Created: 19-11-22
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "test78" )
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( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 )
box = createobjectbox(1, 1, 1)
SetObjectPosition(box, 10, 10, 10)
do
if GetRawKeyPressed(32)
SetObjectPosition(box, random(0, 200) - 100, random(0, 200) - 100, random(0, 200) - 100)
endif
CameraPan(box)
Print( ScreenFPS() )
Sync()
loop
function CameraPan(obj as integer)
x as float
y as float
z as float
nx as float
ny as float
nz as float
ease as float
x = GetCameraAngleX(1)
y = GetCameraAngleY(1)
z = GetCameraAngleZ(1)
SetCameraLookAt(1, GetObjectX(obj), GetObjectY(obj), GetObjectZ(obj), 0)
nx = GetCameraAngleX(1)
ny = GetCameraAngleY(1)
nz = GetCameraAngleZ(1)
ease = 0.2
SetCameraRotation(1, 0, 0, 0)
SetCameraRotation(1, x + (nx - x) * ease, y + (ny - y) * ease, z + (nz - z) * ease)
endfunction
function Distance3D(f as integer, t as integer)
dist as float
dist = sqrt((GetObjectX(f) - GetObjectX(t))^2 + (GetObjectY(f) - GetObjectY(t))^2 + (GetObjectZ(f) - GetObjectZ(t))^2 )
endfunction dist
Camera and object movement (Positions object withing 9-10 units of camera)
// Project: test78
// Created: 19-11-22
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "test78" )
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( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 )
box = CreateObjectCone(2, 1, 4)
SetObjectPosition(box, 0, 2, 0)
FixObjectPivot(box)
RotateObjectLocalX(box, 90)
FixObjectPivot(box)
do
if GetRawKeyPressed(32)
SetObjectPosition(box, random(0, 50) - 25, random(0, 50) - 25, random(0, 50) - 25)
endif
ObjectPan(box)
CameraPan(box)
Sync()
loop
function ObjectPan(obj as integer)
x as float
y as float
z as float
nx as float
ny as float
nz as float
ease as float
ease = 0.1
x = GetObjectAngleX(obj)
y = GetObjectAngleY(obj)
z = GetObjectAngleZ(obj)
SetObjectLookAt(obj, GetCameraX(1), GetCameraY(1), GetCameraZ(1), 0)
dist as float
dist = Distance3D(obj)
print(dist)
if dist > 10
MoveObjectLocalZ(obj, dist * ease)
elseif dist < 9
MoveObjectLocalZ(obj, -dist * ease)
endif
nx = GetObjectAngleX(obj)
ny = GetObjectAngleY(obj)
nz = GetObjectAngleZ(obj)
SetObjectRotation(obj, 0, 0, 0)
SetObjectRotation(obj, x + (nx - x) * ease, y + (ny - y) * ease, z + (nz - z) * ease)
endfunction
function CameraPan(obj as integer)
x as float
y as float
z as float
nx as float
ny as float
nz as float
ease as float
x = GetCameraAngleX(1)
y = GetCameraAngleY(1)
z = GetCameraAngleZ(1)
SetCameraLookAt(1, GetObjectX(obj), GetObjectY(obj), GetObjectZ(obj), 0)
nx = GetCameraAngleX(1)
ny = GetCameraAngleY(1)
nz = GetCameraAngleZ(1)
ease = 0.2
SetCameraRotation(1, 0, 0, 0)
SetCameraRotation(1, x + (nx - x) * ease, y + (ny - y) * ease, z + (nz - z) * ease)
endfunction
function Distance3D(f as integer)
dist as float
dist = sqrt((GetObjectX(f) - GetCameraX(1))^2 + (GetObjectY(f) - GetCameraY(1))^2 + (GetObjectZ(f) - GetCameraZ(1))^2 )
endfunction dist