Could someone help me in making this snippet to detect plains instead of boxes?
It will detect plains, and then for some reason it blanks out the screen. (No good if you can't see em...)
This snippet is a hard for me to understand.
Any help would be greatly appreciated.
-----------------------
Remstart
--3d Mouse selection by Kensupen--
This is a demo of how to use Intersect Object in DBPro to do Mouse to 3D World selection.
It creates a vector from the camera position out 3000 units based on the mouse X & Y
Then uses intersent object to get the Object number(s) and Distance(s)
This code will work even though the camera can be pointed in any direction, but not rotated on the Z axis
Instructions for snippet:
RMB click to MouseLook
Upkey to Move forward
Downkey to move backward
LMB to target
Remend
Global DKMatView As Integer
Global DKVector As Integer
Global DKLineEnd As Integer
Global DKMaxY# As Float
autocam off
make matrix 1,1000,1000,30,30
set light range 0,1000000000
DKVector=1
DKLineEnd=2
DKMatView=3
DKObject=59999
DKFOV#=45.0
DefaultFOV#=61.930722089872112754955664756038
DKMaxY#=Tan(DKFOV#/2.0)
r=Make Matrix4(DKMatView)
r=Make Vector3(DKVector)
r=Make Vector3(DKLineEnd)
Sync Rate 0
Sync On
Set Camera FOV DKFOV#
position camera 500,25,0
`Make start and end objects for vector
Make Object Sphere 59998, 100
Position Object 59998, 0.0, 0.0, 0.0
hide object 59998
Make Object Sphere DKObject, 1.0
Position Object DKObject, 0.0, 0.0, 0.0
hide object 59999
rem *************************************************
rem *************************************************
rem **************************************************
`Make cubes to target with the mouse
for cub=10 to 50
rem ????????????????????????????????????????????????????????????
rem make object cube cub,50
make object plain cub,50,50
position object cub,rnd(1000),rnd(200),rnd(1000)
next cub
Do
if upkey()=1 then move camera 1
if downkey()=1 then move camera -1
if mouseclick()=2
if hold=0
hold=1
dump=mousemovex()
dump=mousemovey()
endif
mmx#=mousemovex()
mmy#=mousemovey()
yrotate camera wrapvalue(camera angle y()+(mmx#/4.0))
xrotate camera wrapvalue(camera angle x()+(mmy#/4.0))
endif
if mouseclick()=1
sx#=object position x(59999)
sy#=object position y(59999)
sz#=object position z(59999)
ex#=object position x(59998)
ey#=object position y(59998)
ez#=object position z(59998)
for check=10 to 50
if intersect object(check,sx#,sy#,sz#,ex#,ey#,ez#)>0
print "Hitting object ",check
print "Distance to object:",intersect object(check,sx#,sy#,sz#,ex#,ey#,ez#)
color object check,rgb(255,0,0)
else
color object check,rgb(255,255,255)
endif
next check
endif
set point light 0,camera position x(),camera position y(),camera position z()
DKObjectUnderMouse(DKObject, 1.0)
DKObjectUnderMouse(59998, 3000.0)
if mouseclick()=0 then hold=0
set cursor 0,0
print screen fps()
print "END:",object position x(59998),":",object position y(59998),":",object position z(59998)
print "START:",object position x(59999),":",object position y(59999),":",object position z(59999)
Sync
Loop
End
Function DKObjectUnderMouse(Object, Range#)
`Function by DMiTR0S
DKNMouseX#=1.0-2.0*(Mousex()*1.0)/(Screen Width()*1.0)
DKNMouseY#=1.0-2.0*(MouseY()*1.0)/(Screen Height()*1.0)
DKAspectratio#=1.3333333333333333
DKCameraspaceY#=DKNMouseY#*DKMaxY#
DKCameraspaceX#=(-1.0*DKNMouseX#*DKAspectratio#)*DKMaxY#
DKCameraspaceZ#=1.0
View Matrix4 DKMatView
r#=Inverse Matrix4(DKMatView, DKMatView)
Set Vector3 DKVector, Range#*DKCameraspaceX#, Range#*DKCameraspaceY#, Range#*DKCameraspaceZ#
Transform Coords Vector3 DKLineEnd, DKVector, DKMatView
Position Object Object, X Vector3(DKLineEnd), Y Vector3(DKLineEnd), Z Vector3(DKLineEnd)
EndFunction