Note that you have to set the distance. You could convert it into a raycast that checks for collision in your scene.
In which case, you could make the depth 1, calculate the first point, then a very large number, calculate the second point. Then use those two points to cast your ray
// Project: test20
// Created: 2019-01-06
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "test20" )
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 ) // since version 2.0.22 we can use nicer default fonts
type point
x as float
y as float
z as float
endtype
world as point
depth = 50
box = CreateObjectBox(1, 1, 1)
SetObjectColor(box, 0xff, 0, 0, 0xff)
do
world.x = Get3DVectorXFromScreen( GetPointerX(), GetPointerY() ) * Depth + GetCameraX(1)
world.y = Get3DVectorYFromScreen( GetPointerX(), GetPointerY() ) * Depth + GetCameraY(1)
world.z = Get3DVectorZFromScreen( GetPointerX(), GetPointerY() ) * Depth + GetCameraZ(1)
SetObjectPosition(box, world.x, world.y, world.z)
Print( ScreenFPS() )
Sync()
loop