Master13,
Don't get impatient so quickly, especially with people who are trying to help you. If we don't understand...we don't understand. That's all there is to it. Just then take the small amount of effort it takes to clearly and definitively explain your problem to us. Good communication is key. There's some wisdom for your soul.
Now back to the going matter. I suppose your problem is
trying to select 3d objects with a selection box. First, here's an example:
REM setup program
sync on
sync rate 60
REM program variables
selectstate as boolean
pickstep_x as integer
pickstep_y as integer
firstcube as integer
lastcube as integer
pickedcube as integer
pickintegrity as integer
displaypoints as boolean
global box_x as integer
global box_y as integer
global mx as integer
global my as integer
pickintegrity=20
firstcube=2
lastcube=10
dim selectedcubes(lastcube)
REM setup camera
autocam off
position camera 0,-5,10,-60
rotate camera 0,15,10,0
REM ground
make object plain 1,60,60
xrotate object 1,90
REM randomly sized and positioned cubes
for cubenum=firstcube to lastcube
make object cube cubenum,rnd(4)
rotate object cubenum,0,rnd(360),0
position object cubenum,-30+rnd(60),object size(cubenum)/2,-30+rnd(60)
next cubenum
REM -------------------
REM ---- MAIN LOOP ----
REM -------------------
repeat
center text screen width()/2,15,"Press space bar to show/hide pick object points"
REM these variables are used to keep code from being executed several times during one mouse click and one spacekey press
oldspacekey=newspacekey
newspacekey=spacekey()
oldmouseclick=newmouseclick
newmouseclick=mouseclick()
REM turn drawstate on
if selectstate=0 and newmouseclick=1 and oldmouseclick<>1
selectstate=1
box_x=mousex()
box_y=mousey()
endif
REM turn drawstate off
if selectstate=1 and newmouseclick=0 and oldmouseclick<>0
selectstate=0
REM unselect any selected cubes and recolor them white
for cubenum=firstcube to lastcube
if selectedcubes(cubenum)=1
selectedcubes(cubenum)=0
color object cubenum,rgb(255,255,255)
endif
next cubenum
endif
REM show/hide pick object points within selection box
if newspacekey=1 and oldspacekey<>1
if displaypoints=0
displaypoints=1
else
displaypoints=0
endif
endif
REM draw selection box
if selectstate=1
draw_selection_box()
REM check for any object within box using several pick object commands placed uniformly throughout box
pickstep_x=int((mx-box_x)/pickintegrity)
pickstep_y=int((my-box_y)/pickintegrity)
for pick_y=box_y to my step pickstep_y
for pick_x=box_x to mx step pickstep_x
if displaypoints=1 then circle pick_x,pick_y,1
pickedcube=pick object(pick_x,pick_y,firstcube,lastcube)
REM adjust cube array slot to toggle selected/nonselected states
if pickedcube>0
if selectedcubes(pickedcube)=0
selectedcubes(pickedcube)=1
REM colore selected object
color object pickedcube,rgb(255,0,0)
endif
endif
next pick_x
next pick_y
endif
sync
until something=1
end
REM -------------------
REM ---- FUNCTIONS ----
REM -------------------
function draw_selection_box()
mx=mousex()
my=mousey()
ink rgb(255,0,0)
line box_x,box_y,mx,box_y
line box_x,box_y,box_x,my
line box_x,my,mx,my
line mx,my,mx,box_y
endfunction
The key here is preciseness of the selection. Simply checking if an object's screen coordinate is within the selection box is not precise at all. This is because that coordinate is a single 2d point. Therefore, if your object takes up a large area of the screen, the box will still only select it if the object's origin(a single 2d point on the screen) is within the box. So, you can have the box covering half the object before it's ever selected.
So, whatda' we do? We use a series of
pick object commands placed uniformly at several points throughout the box. The more the points covered the higher the precision of the selection box. In the example code above I have set the
pickintegrity to 20. So the object check for loop will position the pick object command at 400 seperate points within the selection box...20 columns across and 20 rows down. This works quite well, and is very fast.
*Note:The selection box would probably be even more precise if every other row were offset on the x axis.