Quote: "I'm trying a version of this right now only with edges."
You'll want 3 points or you dont get the full orientation
I'd probably position the other vertices using this calculation:
// Project: FloatingObject
// Created: 2019-11-28
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Orbiting Object Around Camera" )
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
TempObjectID=CreateObjectBox(1,1,1)
ObjectID=CreateObjectBox(1,1,1)
do
print("Right klick to drag object")
Print("FPS: "+str(ScreenFPS(),0))
SP_ControlCamera()
if GetRawMouseRightState()
/******************************/
/* Orbiting Calculation Start */
/******************************/
CamAngleX#=GetCameraAngleX(1)
CamAngleY#=GetCameraAngleY(1)
CamAngleZ#=GetCameraAngleZ(1)
CamX#=GetCameraX(1)
CamY#=GetCameraY(1)
CamZ#=GetCameraZ(1)
cosCamX#=cos(CamAngleX#)
sinCamX#=sin(CamAngleX#)
cosCamY#=cos(CamAngleY#)
sinCamY#=sin(CamAngleY#)
dist#=2
X#=sinCamY# * dist# * cosCamX# * dist# + CamX#
Z#=cosCamY# * dist# * cosCamX# * dist# + CamZ#
Y#=-sinCamX# * dist# * dist# + CamY#
SetObjectPosition(ObjectID,X#,Y#,Z#)
/******************************/
/* Orbiting Calculation End */
/******************************/
endif
Sync()
loop
/******************/
/* Dont mind this */
/******************/
function SP_ControlCamera()
#constant KEY_ESC 27
#constant KEY_PAGEUP 33
#constant KEY_PAGEDOWN 34
#constant KEY_LEFT 37
#constant KEY_UP 38
#constant KEY_RIGHT 39
#constant KEY_DOWN 40
#constant KEY_END 35
#constant KEY_HOME 36
#constant KEY_SHIFT 16
#constant KEY_S 83
local speed# as float
local JoystickSize# as float
global CameraAngleNewX# as float
global CameraAngleNewY# as float
global PointerX# as float
global PointerY# as float
global PointerStartX# as float
global PointerStartY# as float
global PointerDragX# as float
global PointerDragY# as float
global CameraAngleX# as float
global CameraAngleY# as float
global VelocityZ# as float
global VelocityX# as float
global VelocityY# as float
speed#=20*GetFrameTime()
if GetRawKeyState(KEY_SHIFT) then speed#=50*GetFrameTime()
VelocityZ#=SP_CurveValue(VelocityZ#,0,10.0)
VelocityX#=SP_CurveValue(VelocityX#,0,10.0)
VelocityY#=SP_CurveValue(VelocityY#,0,10.0)
// move the camera with keys
if GetKeyboardExists()=1
if(GetRawKeyState(87)) then VelocityZ#=SP_CurveValue(VelocityZ#,speed#,10.0)
if(GetRawKeyState(83)) then VelocityZ#=SP_CurveValue(VelocityZ#,-speed#,10.0)
if(GetRawKeyState(65)) then VelocityX#=SP_CurveValue(VelocityX#,-speed#,10.0)
if(GetRawKeyState(68)) then VelocityX#=SP_CurveValue(VelocityX#,speed#,10.0)
if(GetRawKeyState(81)) then VelocityY#=SP_CurveValue(VelocityY#,-speed#,10.0)
if(GetRawKeyState(69)) then VelocityY#=SP_CurveValue(VelocityY#,speed#,10.0)
else
JoystickSize#=GetVirtualHeight()*0.25
SetJoystickScreenPosition(GetScreenBoundsLeft()+JoystickSize#*0.5,GetScreenBoundsBottom()-JoystickSize#*0.5,JoystickSize#)
MoveCameraLocalZ( 1, -GetJoystickY() * speed# )
MoveCameraLocalX( 1, GetJoystickX() * speed# )
endif
MoveCameraLocalZ(1, VelocityZ# )
MoveCameraLocalX(1, VelocityX# )
MoveCameraLocalY(1, VelocityY# )
// rotate the camera
PointerX#=GetPointerX()
PointerY#=GetPointerY()
if GetPointerPressed()=1
PointerStartX#=PointerX#
PointerStartY#=PointerY#
CameraAngleX#=GetCameraAngleX(1)
CameraAngleY#=GetCameraAngleY(1)
endif
if GetPointerState()=1
PointerDragX#=(PointerX#-PointerStartX#)
PointerDragY#=(PointerY#-PointerStartY#)
endif
CameraAngleNewX#=SP_CurveAngle(CameraAngleNewX#,CameraAngleX#+PointerDragY#,7.0)
CameraAngleNewY#=SP_CurveAngle(CameraAngleNewY#,CameraAngleY#+PointerDragX#,7.0)
SetCameraRotation(1,CameraAngleNewX#,CameraAngleNewY#,0)
endfunction
function SP_CurveValue(current# as float, destination# as float, speed# as float)
local diff# as float
if speed# < 1.0 then speed# = 1.0
diff# = destination# - current#
current# = current# + ( diff# / speed# )
endfunction current#
function SP_CurveAngle(current# as float, destination# as float, speed# as float)
local diff# as float
if speed# < 1.0 then speed# = 1.0
destination# = SP_WrapAngle( destination# )
current# = SP_WrapAngle( current# )
diff# = destination# - current#
if diff# <- 180.0 then diff# = ( destination# + 360.0 ) - current#
if diff# > 180.0 then diff# = destination# - ( current# + 360.0 )
current# = current# + ( diff# / speed# )
current# = SP_WrapAngle( current# )
endfunction current#
function SP_WrapAngle( angle# as float)
local iChunkOut as integer
local breakout as integer
iChunkOut = angle#
iChunkOut = iChunkOut - mod( iChunkOut, 360 )
angle# = angle# - iChunkOut
breakout = 10000
while angle# < 0.0 or angle# >= 360.0
if angle# < 0.0 then angle# = angle# + 360.0
if angle# >= 360.0 then angle# = angle# - 360.0
dec breakout
if breakout = 0 then exit
endwhile
if breakout = 0 then angle# = 0.0
endfunction angle#