Could someone with sparky's collision DLL test this out for me please? My DarkBasic program hasn't been working correctly lately so I can't try it out and I
really need it.
All you have to do is run a program with an object set to collision on with sparky's DLL in group 'GroupNum' and see if the return value of the second function after calling the first function is the number of the object on screen under the mouse cursor.
` Object Selection using the mouse
` By Luke810
` A function for use with sparky's DBCcollision DLL to find the
` object the mouse is over in a 3d environment
` Converts the screen coordinates to normal coordinates and
` forms 2 points on the unit circle then rotates them based on the
` mouse position and camera angles to obtain a vector in 3d space that
` extends out from the mouse. The array MouseVector(6) must be dimensioned
` prior to the function's call.
` Parameters:
` StartDist: The distance away from camera that the first
` vector endpoint should be
` EndDist: The distance away from camera that the second
` vector endpoint should be
` Flag: Must be set to one if the display mode is changed
` and when running the function the first time
Function Get_Mouse_Vector(StartDist, EndDist, Flag)
if Flag
ScreenCenterX = screen width() / 2
ScreenCenterY = screen height() / 2
AspectRatio = screen width() / screen height()
endif
MouseX = mousex()
MouseY = mousex()
DeltaX = ScreenCenterX - MouseX
DeltaY = MouseY - ScreenCenterY
CamAngX# = 360 - camera angle x()
CamAngY# = wrapvalue(90 - camera angle y() )
CamAngZ# = 360 - camera angle z()
StartX# = (DeltaX * StartDist) / AspectRatio
StartY# = (DeltaY * StartDist) / AspectRatio
StartZ# = StartDist
EndX# = (DeltaX * EndDist) / AspectRatio
EndY# = (DeltaY * EndDist) / AspectRatio
EndZ# = EndDist
CosCamAngZ# = cos(CamAngZ#)
SinCamAngZ# = sin(CamAngZ#)
VectorStartX# = (CosCamAngZ# * StartX#) - (SinCamAngZ# * StartY#)
VectorStartY# = (CosCamAngZ# * StartY#) + (SinCamAngZ# * StartX#)
VectorEndX# = (CosCamAngZ# * EndX#) - (SinCamAngZ# * EndY#)
VectorEndY# = (CosCamAngZ# * EndY#) + (SinCamAngZ# * EndX#)
CosCamAngX# = cos(CamAngX#)
SinCamAngX# = sin(CamAngX#)
VectorStartZ# = (CosCamAngX# * StartZ#) + (SinCamAngX# * VectorStartY#)
VectorStartY# = (CosCamAngX# * VectorStartY#) - (SinCamAngX# * StartZ#)
VectorEndZ# = (CosCamAngX# * EndZ#) + (SinCamAngX# * VectorEndY#)
VectorEndY# = (CosCamAngX# * VectorEndY#) - (SinCamAngX# * EndZ#)
CosCamAngY# = cos(CamAngY#)
SinCamAngY# = sin(CamAngY#)
OldVectorStartZ# = VectorStartZ#
OldVectorEndZ# = VectorEndZ#
VectorStartZ# = (CosCamAngY# * VectorStartX#) + (SinCamAngY# * VectorStartZ#)
VectorStartX# = (CosCamAngY# * OldVectorStartZ#) + (SinCamAngY# * VectorStartX#)
VectorEndZ# = (CosCamAngY# * VectorEndX#) + (SinCamAngY# * VectorEndZ#)
VectorEndX# = (CosCamAngY# * OldVectorEndZ#) + (SinCamAngY# * VectorEndX#)
MouseVector(1) = camera position x() + VectorStartX#
MouseVector(2) = camera position y() - VectorStartY#
MouseVector(3) = camera position z() + VectorStartZ#
MouseVector(4) = camera position x() + VectorEndX#
MouseVector(5) = camera position y() - VectorEndY#
MouseVector(6) = camera position z() + VectorEndZ#
endfunction
` Finds the object the mouse is over using sparky's DBCcollision
` DLL and the vector points calculated from 'Get_Mouse_Vector(StartDist, EndDist, Flag)'
` The Object intersection is how you want to set up the IntersectObjectDBC function from
` the DLL if you want to get objects from a group instead of searching all objects
` ( Ex: If you want to choose a character on a map that also uses the sparky raybased collision
` system and you dont want the map objects number returned)
Function Get_Object_Selected(GroupNum)
x1# = MouseVector(1)
y1# = MouseVector(2)
z1# = MouseVector(3)
x2# = MouseVector(4)
y2# = MouseVector(5)
z2# = MouseVector(6)
result = IntersectObjectDBC(GroupNum, 1, x1#, y1#, z1#, x2#, y2#, z2#, 0)
endfunction result