This code works fine if you substitute for cubes or spheres,
Even if you create a plain and then convert it to a mesh and create plain/meshes from that...
But if you use plains as objects the screen goes blank.
`*******************************************************************************
`* By: DMiTR0S [email protected] *
`*******************************************************************************
`*******************************************************************************
`* Free License Agreement. *
`* *
`* The user/developer agrees to include a visible credit to "Dmitri Kuschev" *
`* within your programs documentation and or web site. *
`* *
`* The user/developer agrees to NOT offer the this source code for Sale. *
`* *
`* Providing the user/Developer agrees in full to the previous Free *
`* License Agreement clauses, the user/developer may use this source *
`* code FREELY in all their products, commercial or otherwise. *
`* *
`*******************************************************************************
ViewMatrix=2
ProjectionMatrix=3
EndVector=1
Autocam Off
r=Make Matrix4(ViewMatrix)
r=Make Matrix4(ProjectionMatrix)
r=Make Vector3(EndVector)
Sync Rate 0
Sync On
Position Camera 500, 25, 0
make object cube 1,10
For num=10 To 50
Make Object plain num, 10, 10
Set Object num, 0, 1, 0, 0
Position Object num, RND(1000), RND(200), RND(1000)
Next num
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
YRotate Camera WrapValue(Camera Angle Y()+(MouseMoveX()/4.0))
XRotate Camera Wrapvalue(Camera Angle X()+(MouseMoveY()/4.0))
EndIf
2DTo3D(EndVector, ViewMatrix, ProjectionMatrix, 3000.0)
If MouseClick()=1
For num=10 To 30
Collision#=Intersect Object(num, Camera Position X(), Camera Position Y(), Camera Position Z(), X Vector3(EndVector), Y Vector3(EndVector), Z Vector3(EndVector))
If Collision# > 0.0
Print "Hitting object ",check
Print "Distance to object:", Collision#
Color Object num, RGB(255,0,0)
Else
Color Object num, RGB(255,255,255)
EndIf
Next check
EndIf
hold=MouseClick()
Set Cursor 0, 0
Print Screen Fps()
Print "END: ", X Vector3(EndVector), " : ", Y Vector3(EndVector), " : ", Z Vector3(EndVector)
Print "START: ",Camera Position X(), " : ", Camera Position Y(), " : ", Camera Position Z()
Sync
Loop
End
Function 2DTo3D(Vector, ViewMatrix, ProjectionMatrix, Range#)
X#=2.0*(Mousex()*1.0)/(Screen Width()*1.0)-1.0
Y#=1.0-2.0*(MouseY()*1.0)/(Screen Height()*1.0)
Set Vector3 Vector, X#, Y#, 1.0
View Matrix4 ViewMatrix
Projection Matrix4 ProjectionMatrix
r=Inverse Matrix4(ViewMatrix, ViewMatrix)
r=Inverse Matrix4(ProjectionMatrix, ProjectionMatrix)
Transform Coords Vector3 Vector, Vector, ProjectionMatrix
Normalize Vector3 Vector, Vector
Multiply Vector3 Vector, Range#
Transform Coords Vector3 Vector, Vector, ViewMatrix
Projection Matrix4 ProjectionMatrix
EndFunction