Ok! Some time ago i find this code:
SYNC ON
SYNC RATE 0
ScWidth# = 1024
ScHeight# = 768
SET DISPLAY MODE ScWidth#,ScHeight#,16
AUTOCAM OFF
SET CAMERA RANGE 1,100000
RED = RGB(255,0,0)
BLUE = RGB(0,0,255)
MAKE OBJECT PLAIN 2,1000,1000
XROTATE OBJECT 2,90
COLOR OBJECT 2,BLUE
`THIS MAKES AND HIDES THE CLICK POINT OBJECT
MAKE OBJECT CUBE 1,20
HIDE OBJECT 1
POSITION OBJECT 1,0,0,0
MAKE OBJECT CONE 3,30
POSITION OBJECT 3,0,0,0
XROTATE OBJECT 3,90
FIX OBJECT PIVOT 3
COLOR OBJECT 3,RED
`VARIABLES THAT NEED TO BE SET
WPX# = 0
WPZ# = 0
CamPosAdj = 1
CamRotAdj = 1
CamDistance# = 500
XcamL# = 30
YcamL# = 0
CamRotInc# = 1
ZoomInc# = 3
ZoomINmax# = 50
ZoomOUTmax# = 1500
SCROLLspeed# = 5
`Figure out Angle to Top of Screen depending on Resolution
`----------------------------------------------------------
ScRefL1# = ATAN(ScWidth# / ScHeight#)
ScRefDist1# = CamDistance# * COS(ScRefL1#)
YscreenMAXl# = ATAN(ScRefDist1# / CamDistance#)
`--------------------
POSITION MOUSE 400,300
`----------------------------------------------------------
`THIS STARTS THE MAIN LOOP
`----------------------------------------------------------
DO
`-------------------------------------
`THIS IS FOR CAMERA POSITIONING
`-------------------------------------
IF CamPosAdj = 1
SINofXcamL# = SIN(XcamL#)
CamY# = CamDistance# * SINofXcamL#
CamLEGsq# = (CamDistance# * CamDistance#) - (CamY# * CamY#)
CamLEG# = SQRT(CamLEGsq#)
Xcam# = CamLEG# * SIN(YcamL#)
Zcam# = CamLEG# * COS(YcamL#)
POSITION CAMERA WPX# - Xcam#,CamY#,WPZ# - Zcam#
CamPosAdj = 0
ENDIF
`----------------------------------------------------------
`THIS IS FOR CAMERA ROTATION
`----------------------------------------------------------
IF CamRotAdj = 1
XROTATE CAMERA XcamL#
YROTATE CAMERA YcamL#
CamRotAdj = 0
ENDIF
`----------------------------------------------------------
`THIS IS FOR MOUSE SCROLLING
`----------------------------------------------------------
IF MouseY() < 20 OR MouseY() > (ScHeight# - 20) OR MouseX() < 20 OR MouseX() > (ScWidth# - 20)
Xscroll# = ScrollSpeed# * SIN(YcamL#)
Zscroll# = ScrollSpeed# * COS(YcamL#)
IF MouseY() < 20
WPX# = WPX# + Xscroll#
WPZ# = WPZ# + Zscroll#
ENDIF
IF MouseY() > 580
WPX# = WPX# - Xscroll#
WPZ# = WPZ# - Zscroll#
ENDIF
IF MouseX() < 20
WPX# = WPX# - Zscroll#
WPZ# = WPZ# + Xscroll#
ENDIF
IF MouseX() > 780
WPX# = WPX# + Zscroll#
WPZ# = WPZ# - Xscroll#
ENDIF
CamPosAdj = 1
CamRotAdj = 1
ENDIF
`----------------------------------------------------------
`THIS MONITORS FOR DIFFERENT KEYPRESSES
`----------------------------------------------------------
KEYPRESS$ = INKEY$()
`----------------------------------------------------------
`THIS USES THE UPKEY TO REDUCE THE CAMERAS X ROTATION
`----------------------------------------------------------
IF UPKEY() = 1
XcamL# = XcamL# - CamRotInc#
IF XcamL# < 1
XcamL# = 1
ENDIF
CamPosAdj = 1
CamRotAdj = 1
ENDIF
`----------------------------------------------------------
`THIS USES THE DOWNKEY TO INCREASE THE CAMERAS X ROTATION
`----------------------------------------------------------
IF DOWNKEY() = 1
XcamL# = XcamL# + CamRotInc#
IF XcamL# > 90
XcamL# = 90
ENDIF
CamPosAdj = 1
CamRotAdj = 1
ENDIF
`----------------------------------------------------------
`THIS USES THE LEFTKEY TO DECREASE THE CAMERAS Y ROTATION
`----------------------------------------------------------
IF LEFTKEY() = 1
YcamL# = YcamL# - CamRotInc#
IF YcamL# < 0
YcamL# = 359
ENDIF
CamPosAdj = 1
CamRotAdj = 1
ENDIF
`----------------------------------------------------------
`THIS USES THE RIGHTKEY TO DECREASE THE CAMERAS Y ROTATION
`----------------------------------------------------------
IF RIGHTKEY() = 1
YcamL# = YcamL# + CamRotInc#
IF YcamL# > 359
YcamL# = 0
ENDIF
CamPosAdj = 1
CamRotAdj = 1
ENDIF
`----------------------------------------------------------
`THIS USES THE "+" KEY TO ZOOM IN
`----------------------------------------------------------
IF KEYPRESS$ = "+"
CamDistance# = CamDistance# - ZoomInc#
IF CamDistance# < ZoomINmax#
CamDistance# = ZoomINmax#
ENDIF
CamPosAdj = 1
CamRotAdj = 1
ENDIF
`----------------------------------------------------------
`THIS USES THE "-" KEY TO ZOOM OUT
`----------------------------------------------------------
IF KEYPRESS$ = "-"
CamDistance# = CamDistance# + ZoomInc#
IF CamDistance# > ZoomOUTmax#
CamDistance# = ZoomOUTmax#
ENDIF
CamPosAdj = 1
CamRotAdj = 1
ENDIF
`----------------------------------------------------------
`TO CONVERT 2D MOUSECLICKS INTO 3D SPACE
IF MOUSECLICK() = 1
MoX = MOUSEX()
MoY = MOUSEY()
ViewLowLegL# = 90 - XcamL# - YscreenMAXl#
COSvLLL# = COS(ViewLowLegL#)
ViewLegDist# = CamY# / COSvLLL#
SINyScreenMaxL# = SIN(YscreenMAXl#)
ScreenHeight# = ViewLegDist# * SINyScreenMaxL#
ScreenDistSQ# = (ViewLegDist# * ViewLegDist#) - (ScreenHeight# * ScreenHeight#)
ScreenDist# = SQRT(ScreenDistSQ#)
YScreenFactor# = ScreenHeight# / (ScHeight# / 2)
`THIS GETS A 2D Y-DISTANCE FROM CENTER
IF MoY < (ScHeight# / 2)
YmoDist# = (ScHeight# / 2) - MoY
ENDIF
IF MoY >= (ScHeight# / 2)
YmoDist# = ((ScHeight# / 2) - 1) - MoY
ENDIF
IF YmoDist# > 0
SceenViewDistY# = YmoDist# * YScreenFactor#
YPointL2# = ATAN(SceenViewDistY# / ScreenDist#)
YPointL# = ViewLowLegL# + YscreenMAXl# + YPointL2#
YPosLEG# = CamY# * TAN(YPointL#)
ENDIF
IF YmoDist# < 0
SceenViewDistY# = YmoDist# * YScreenFactor# * -1
YPointL2# = ATAN(SceenViewDistY# / ScreenDist#)
YPointL# = ViewLowLegL# + YscreenMAXl# - YPointL2#
YPosLEG# = CamY# * TAN(YPointL#)
ENDIF
`THIS GETS A 2D X-DISTANCE FROM CENTER
IF MoX < (ScWidth# / 2)
XmoDist# = ((ScWidth# / 2) * -1) + MoX
ENDIF
IF MoX >= (ScWidth# / 2)
XmoDist# = (((ScWidth# / 2) - 1) * -1) + MoX
ENDIF
`HANDLE MoY FIRST
threeDYdist# = YmoDist# * YScreenFactor#
SINofvLLL# = SIN(ViewLowLegL#)
ViewBotLeg# = ViewLegDist# * SINofvLLL#
Ydist1L# = 90 - XcamL#
YposLEG# = YposLEG# - CamLEG#
`HANDLE MoX
ScreenWidth# = ScreenHeight# / (ScHeight# / ScWidth#)
DistTOScreen# = ScreenDist# / COS(YPointL2#)
XAngle# = ATAN(ScreenWidth# / DistTOScreen#)
ViewLegY_c# = CamY# / COS(YPointL#)
ViewXwidth# = ViewLegY_c# * TAN(XAngle#)
XScreenFactor# = ViewXwidth# / (ScWidth# / 2)
XposLEG# = XmoDist# * XScreenFactor#
ClickPosL2# = ATAN(XposLEG# / YposLEG#)
ClickPosL# = WRAPVALUE(YcamL# + ClickPosL2#)
ClickPos_c# = YposLEG# / COS(ClickPosL2#)
ZclickPos# = ClickPos_c# * COS(ClickPosL#)
XclickPos# = ClickPos_c# * SIN(ClickPosL#)
Xclick# = XclickPos# + WPX#
Zclick# = ZclickPos# + WPZ#
POSITION OBJECT 1,Xclick#,0,Zclick#
CamPosAdj = 1
CamRotAdj = 1
`MOVE SELECTED OBJECT
POINT OBJECT 3,Xclick#,0,Zclick#
ObjPosX# = OBJECT POSITION X(3)
ObjPosZ# = OBJECT POSITION Z(3)
IF ObjPosX# <> Xclick# OR ObjPosZ# <> Zclick#
DBX# = Xclick# - ObjPosX#
DBZ# = Zclick# - ObjPosZ#
DistanceBetween# = SQRT(DBX# * DBX# + DBZ# * DBZ#)
IF DistanceBetween# <= 5
MOVE OBJECT 3,DistanceBetween#
ENDIF
IF DistanceBetween# > 5
MOVE OBJECT 3,5
ENDIF
ENDIF
ENDIF
`----------------------------------------------------------
FPS=SCREEN FPS()
SET CURSOR 0,0
PRINT FPS
SYNC
LOOP
I use it, but I can't figure out why does it work! Could somebody try to explain it to me?
Thanx!