Hi guys,
this code was originally writen for a thread in Newcomers Corner.
It`s a way to find which side of a cube your mouse is over.You can think how this can be applied for something.The author of the thread originaly wanted to use it for his sanbox editor.It can take place somwhere.
We are using 6 dummy plains which are positioned at every cube side.Then we check if they are present at mouse position with "pick object" comand.It`s nothing complicated.
For this code you can use any image to texture the plains.I prefered 1x1 black bmp.
sync on : sync rate 60
backdrop on
`set image colorkey 0,0,0
load image "texture.bmp",1
Size = 10
CubeX = 0
CubeY = 0
CubeZ = 0
for cube = 1 to 7
make object cube cube,Size
position object cube,20*cube-80,0,0
next cube
make camera 1
position camera 1,0,30,-100
for plain = 100 to 105
make object plain plain,10,10
`set object plain,1,1,0,1,0
texture object plain,1
`set object transparency plain,1
next plain
do
text 0,0,"fps: "+str$(screen fps())
text 0,20,"connector: "+str$(connector)
text 0,40,"side: "+str$(side)
control camera using arrowkeys 1,1,1
connector = pick object (mousex(),mousey(),1,7)
side = pick object (mousex(),mousey(),100,105)
if connector>0
for plain = 100 to 105
show object plain
next plain
CubeX = object position x(connector)
CubeY = object position y(connector)
CubeZ = object position z(connector)
position object 100,CubeX-(Size*0.5)-1,CubeY,CubeZ
rotate object 100,0,90,0
position object 101,CubeX+(Size*0.5)+1,CubeY,CubeZ
rotate object 101,0,90,0
position object 102,CubeX,CubeY-(Size*0.5)-1,CubeZ
rotate object 102,0,90,90
position object 103,CubeX,CubeY+(Size*0.5)+1,CubeZ
rotate object 103,0,90,90
position object 104,CubeX,CubeY,CubeZ-(Size*0.5)-1
rotate object 104,0,0,0
position object 105,CubeX,CubeY,CubeZ+(Size*0.5)+1
rotate object 105,0,0,0
endif
if connector = 0
for plain = 100 to 105
hide object plain
next plain
endif
sync
loop
Happy to share!
Where there is a will, there is a way.
I often edit my posts, that`s who i am