Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / I have 2 problems

Author
Message
Figgle666
22
Years of Service
User Offline
Joined: 26th Feb 2003
Location:
Posted: 26th Feb 2003 07:22
I have been thinking and thinking about this...and I gave up my ego long ago. I dont know how to do this :{


1)I need to be able to select a 3d object on a 2d screen.
*This must be done with a mouse and is critical.

2)I need to find out how to make 1 object have more than one animation (can't figure out the 'append object animation')

If I don't get problem #1 solved, then I can't really continue my game. (Distance between object and camera is about 10000, but I need flexible code that can do less distance than that, but not greater than that.)

Thanks guys/girls
Blanka
22
Years of Service
User Offline
Joined: 26th Feb 2003
Location: United Kingdom
Posted: 26th Feb 2003 15:39
Why not have for problem one, a RGB command, say you have a blue shape on a pink background, when the mouse is over the blue it will say its over it...

hard to explain... but get the RGB values of the mouse, and if they are the same colours as the object, then the mouse is over it, if the mouse is over it and the user clicks, then the object will be selected.

Blazer
22
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: United States
Posted: 26th Feb 2003 15:52
I've had this code for a while now, evrytime I send it out it seems to be usefull (blows the dust off of it)

`-----------------------------------------------
`Converting 2D Clicks into 3D space
`Version 2.0
`Now works with different resolutions
`Ronald L. Erickson .....a.k.a. WOLF
`-----------------------------------------------

SYNC ON
SYNC RATE 0

ScWidth# = 640
ScHeight# = 480

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 ISTANCE 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

ps: I didn't make it, I just kept it

As I walk through the vally of the shadow of death, I will fear no evil.
- Psalms 23:4
Blazer
22
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: United States
Posted: 26th Feb 2003 15:53
shoot:



As I walk through the vally of the shadow of death, I will fear no evil.
- Psalms 23:4
Figgle666
22
Years of Service
User Offline
Joined: 26th Feb 2003
Location:
Posted: 26th Feb 2003 16:53
eeee....almost helps...just had to change the movement part. Otherwise, thanks Blazer.

Login to post a reply

Server time is: 2025-05-16 19:31:02
Your offset time is: 2025-05-16 19:31:02