Greetings,
As a recent purchaser of DB Classic I've finally found a problem thats stumped me for a bit. Seeing as I could probably spend more time trying things I thought this would be a great way to introduce myself a bit and get a little feedback.
I've been hovering in the background for quite a while (over a year or so)reading the forums and enjoying the various aspects of DB as a beginners tool to programming. Then I finally got it and started to play around with things.
As a little background I'm interested in space games quite a bit and Evochron Legends creator inspired me to explore DB and see what I could play around with. So on that note I'll describe a little about what I've come accross and what I was thinking.
Since my logic and coding skills are a bit on the humble side I started to play around with taking 3D objects and moving them around with the commands to get a feel for things with the intention of eventually creating a simple scrolling shooter in 3D. For now though its simply an instrument for learning to code and becoming familiar with DB.
So on to the problem I've come accross...
I started with the intention of trying to figure out a method for limiting an object which is bound to the mouse to the screen in 3D space while having the camera tilted and a specific angle to a plain. I'm sorry if thats a poor description, it should make a little more sense when you run the code...
Anyway looking at the code...I decided I would make a 3d object, place it at 0,0,0 then position the camera. I would then run a test to find where exactly the 3d space positions are for the edge of the camera screen. So I end up checking the Object Screen X and Y of the object while incrimenting its position along the X and Y in 3d space until it reaches the known resolution boundries
of the screen resolution.
The problem...well I got the X numbers just fine but when I try the exact same method for the Object Screen Y it freezes up and I'm a little confused as to why since it appears to be the same. So I thought I would come here and post the code to see if someone sees something I don't in my logic.
Now I'm pretty sure there is an easyer way to gather this data using some kind of math which eludes me for the time being so feel free to suggest another method. Just be gental please, I know my code might be a little unkempt and dis-organized and I'm still curious why its freezing and how to get it working even if there are better ways.
Looking forward to the grilling.
Heres the code (I hope)...
Set Display Mode 800, 600, 32
GOSUB Startup
rem Main Loop
Main_Loop:
Do
gosub Display_Info
sync
Loop
`End the program if something breaks loose
end
Startup:
sync on
sync rate 34
SET EMULATION OFF
backdrop on
`Matrix
make matrix 1,100.0,300.0,10,30
position matrix 1,-50,0,0
`Object used to test boundries
make object cube 101,5
position object 101,0,0,0
rem Camera Setup
`SET CAMERA TO OBJECT ORIENTATION 1
SET CAMERA RANGE 1,5000
position camera 0,30,-30
Point camera 0,0,0
VAR_CheckScreenWid=screen width()
VAR_CheckScreenHei=screen height()
VAR_CheckX=0
`X WORKS FINE
while VAR_CheckRightX = 0
dec VAR_CheckX,1
position object 101,VAR_CheckX,0,0
VAR_CheckObjScreenX = Object screen X(101)
if VAR_CheckObjScreenX <= 10
VAR_RightXPosition = Object Position X(101)
VAR_CheckRightX = 1
endif
endwhile
while VAR_CheckLeftX = 0
inc VAR_CheckX,1
position object 101,VAR_CheckX,0,0
VAR_CheckObjScreenX = Object screen X(101)
if VAR_CheckObjScreenX >= VAR_CheckScreenWid-10
VAR_LeftXPosition = Object Position X(101)
VAR_CheckLeftX = 1
endif
endwhile
`PROBLEM STARTS HERE WITH Y
remstart `UNREM HERE FOR FREEZING<---------------
VAR_CheckY=0
VAR_CheckTopY=0
position object 101,0,0,0
while VAR_CheckTopY = 0
dec VAR_CheckY,1
position object 101,VAR_CheckY,0,0
VAR_CheckObjYScreen=OBJECT SCREEN Y(101)
if VAR_CheckObjYScreen<=10
VAR_TopYPosition = Object Position Y(101)
VAR_CheckTopY = 1
endif
endwhile
remend ` UNREM HERE FOR FREEZING<----------------
remstart
while VAR_CheckBottomY = 0
inc VAR_CheckY,1
position object 101,0,VAR_CheckY,0
VAR_CheckObjScreenY = Object screen Y(101)
if VAR_CheckObjScreenY > VAR_CheckScreenHei-10
VAR_BottomYPosition = Object Position Y(101)
VAR_CheckBottomY = 1
endif
endwhile
remend
`PROBLEM ENDS HERE
return
Display_Info:
Rem Converts stuff to strings for display.
VER_ScreenWidth$=STR$(SCREEN WIDTH())
VER_ScreenHeight$=STR$(SCREEN HEIGHT())
VER_ScreenDepth$=STR$(SCREEN DEPTH())
VER_MouseXPosition$=STR$(MOUSEX())
VER_MouseYPosition$=STR$(MOUSEY())
VER_Scancode$=STR$(scancode())
VAR_PlayerShipXPos$=STR$(OBJECT SCREEN X(101))
VAR_PlayerShipYPos$=STR$(OBJECT SCREEN Y(101))
VAR_DisXMin$=STR$(VAR_RightXPosition)
VAR_DisXMax$=STR$(VAR_LeftXPosition)
VAR_DisYMin$=STR$(VAR_TopYPosition)
VAR_DisYMax$=STR$(VAR_BottomYPosition)
Rem Displays various troubleshooting information
text 10,10,"FPS: "+str$(screen fps())+" Polys: "+str$(statistic(1))
text 10,50,"Video Ram Available: "+STR$(SYSTEM DMEM AVAILABLE())
text 10,110,"System Ram Available: "+STR$(SYSTEM SMEM AVAILABLE())
text 10,80,"Total Ram Available: "+STR$(SYSTEM TMEM AVAILABLE())
text 10,150,"Screen Width: "+VER_ScreenWidth$
text 10,180,"Screen Height: "+VER_ScreenHeight$
text 10,210,"Screen Bitdepth: "+VER_ScreenDepth$
text 10,250,"Mouse X Position: "+VER_MouseXPosition$
text 10,280,"Mouse Y Position: "+VER_MouseYPosition$
text 10,380,"Scancode: "+VER_Scancode$
text 10,470,"Objects X Screen Pos: "+VAR_PlayerShipXPos$
text 10,482,"Objects Y Screen Pos: "+VAR_PlayerShipYPos$
text 10,500,VAR_DisXMin$
text 10,512,VAR_DisXMax$
text 10,524,"THIS SHOULD BE A SMALL POSITIVE/NEGATIVE INTIGER: "+VAR_DisYMin$
text 10,536,"THIS SHOULD BE A SMALL POSITIVE/NEGATIVE INTIGER: "+VAR_DisYMax$
return
P.S. Bare with me as this is quite litterally my first post here and I try and figure out the buttons and features.