View Matrix4,
World Matrix4 and
Projection Matrix4 work only with last created camera.
MainCamera=1
SecondCamera=2
make camera MainCamera
Color Backdrop MainCamera, RGB(0,0,0)
make camera SecondCamera
set camera view SecondCamera,0,0,50,50
position camera SecondCamera,500, 25, 0
point camera SecondCamera,500, 25, 0
`*******************************************************************************
`* 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
Make Matrix 1,1000,1000,30,30
r=Make Matrix4(ViewMatrix)
r=Make Matrix4(ProjectionMatrix)
r=Make Vector3(EndVector)
Sync Rate 0
Sync On
Position Camera MainCamera, 500, 25, 0
Make Object Plain 1, 50.0, 50.0
YRotate Object 1, 180.0
Make Mesh From Object 1, 1
Delete Object 1
For num=10 To 50
Make Object num, 1, 22
Set Object num, 0, 1, 0, 0
Position Object num, RND(1000), RND(200), RND(1000)
Next num
rem *******************************************************
rem *******************************************************
position camera SecondCamera, object position x(10), object position y(10)+100, object position z(10)
point camera SecondCamera, object position x(10), object position y(10), object position z(10)
rem *********************************************************
rem 888888888888888888888888888888888888888888888888888888888
Do
If UpKey()=1 Then Move Camera MainCamera, 1
If DownKey()=1 Then Move Camera MainCamera, -1
If MouseClick()&&2
If hold=0
hold=1
dump=MouseMoveX()
dump=MouseMoveY()
EndIf
YRotate Camera MainCamera, WrapValue(Camera Angle Y(MainCamera)+(MouseMoveX()/4.0))
XRotate Camera MainCamera, Wrapvalue(Camera Angle X(MainCamera)+(MouseMoveY()/4.0))
EndIf
2DTo3D(EndVector, ViewMatrix, ProjectionMatrix, 3000.0, MainCamera)
If MouseClick()&&1
For num=10 To 50
Collision#=Intersect Object(num, Camera Position X(MainCamera), Camera Position Y(MainCamera), Camera Position Z(MainCamera), X Vector3(EndVector), Y Vector3(EndVector), Z Vector3(EndVector))
If Collision# > 0.0
Print "Hitting object ",num
Print "Distance to object:", Collision#
Color Object num, RGB(255,0,0)
Else
Color Object num, RGB(255,255,255)
EndIf
Next num
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(MainCamera), " : ", Camera Position Y(MainCamera), " : ", Camera Position Z(MainCamera)
Sync
Loop
End
Function 2DTo3D(Vector, ViewMatrix, ProjectionMatrix, Range#, Camera)
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
`-----------------------
CX#=Cos(Camera Angle X(Camera))
SX#=Sin(Camera Angle X(Camera))
CY#=Cos(Camera Angle Y(Camera))
SY#=Sin(Camera Angle Y(Camera))
CZ#=Cos(Camera Angle Z(Camera))
SZ#=Sin(Camera Angle Z(Camera))
r=Make Vector3(100)
r=Make Vector3(101)
r=Make Vector3(102)
Set Vector3 100, Camera Position X(Camera), Camera Position Y(Camera), Camera Position Z(Camera)
Set Vector3 101, -1.0*SZ#*(-1.0*SX#)+CZ#*SY#*CX#+Camera Position X(Camera), CZ#*(-1.0*SX#)+SZ#*SY#*CX#+Camera Position Y(Camera), CY#*CX#+Camera Position Z(Camera)
Set Vector3 102, -1.0*SZ#*CX#+CZ#*SY#*SX#, CZ#*CX#+SZ#*SY#*SX#, CY#*SX#
Build LookAt LHMatrix4 ViewMatrix, 100, 101, 102
`-----------------------
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
EndFunction