Quote: "complicated, which he must be aware helping to newbies.I think his snippet here is more a show-off than help."
I got carried away... I meant to have a function that found which side of the cube it was on, and then make a separate system... but then the code kinda became too engrained with the other code and... meh. Still, I got it working, if you want to take a look at the code:
type info
conNum as integer `number of connectors
rodNum as integer `number of rodz
maxCon as integer `maximum number of connectors
firstCon as integer `start range of connectors
conSize as float `size of the connectors (they're cubes
rodLen as float `size of the connecting rods
endtype
type connectorInfo
xoff as float
yoff as float
zoff as float
xrot as float
yrot as float
endtype
type connector
x as float
y as float
z as float
memblocknum as integer `using a memblock to store which objects are attached. Easier to work with.
`memblock will have room for 12 words. one for each possible connector/connectorrod space.
endtype
type connectorRod
x as float
y as float
z as float
objnum as integer
oneCon as integer
xrot as float
yrot as float
zrot as float
endtype
set display mode 1280,800,32
autocam off
global dim connector(0) as connector
global dim connectorRod(0) as connectorRod
initialize_G()
initialize_rot()
createConnector(0,0,0)
for x=1 to 2
for y=1 to 3
buildUponConnector(1,x,y)
next
next
click=0
do
yrotate camera 0,camera angle y()+mousemovex()/5.0
xrotate camera 0,camera angle x()+mousemovey()/5.0
move camera 0,(upkey()-downkey())*.005
if mouseclick()=1 and click=0
click=1
obj=pick object(mousex(),mousey(),0,10000)
if obj>=G.firstCon and obj<=G.firstCon+G.maxCon
conNum=obj-G.firstCon
x=camera position x()-connector(conNum).x
nx=sign(x)
y=camera position y()-connector(conNum).y
ny=sign(y)
z=camera position z()-connector(conNum).z
nz=sign(z)
hide object obj
j1=find free object()
make object plane j1,G.conSize+.05,G.conSize+.05
a11=intternary(intequals(nx,-1),1,2)
a21=1
position object j1,connector(conNum).x+rotInfo(a11,a21).xoff*(0.5*G.conSize+.05),connector(conNum).y+rotInfo(a11,a21).yoff*(0.5*G.conSize+.05),connector(conNum).z+rotInfo(a11,a21).zoff*(0.5*G.conSize+.05)
rotate object j1,rotInfo(a11,a21).xrot,rotInfo(a11,a21).yrot,0
j2=find free object()
make object plane j2,G.conSize+.05,G.conSize+.05
a12=intternary(intequals(ny,-1),1,2)
a22=2
position object j2,connector(conNum).x+rotInfo(a12,a22).xoff*(0.5*G.conSize+.05),connector(conNum).y+rotInfo(a12,a22).yoff*(0.5*G.conSize+.05),connector(conNum).z+rotInfo(a12,a22).zoff*(0.5*G.conSize+.05)
rotate object j2,rotInfo(a12,a22).xrot,rotInfo(a12,a22).yrot,0
j3=find free object()
make object plane j3,G.conSize+.05,G.conSize+.05
a13=intternary(intequals(nz,-1),1,2)
a23=3
position object j3,connector(conNum).x+rotInfo(a13,a23).xoff*(0.5*G.conSize+.05),connector(conNum).y+rotInfo(a13,a23).yoff*(0.5*G.conSize+.05),connector(conNum).z+rotInfo(a13,a23).zoff*(0.5*G.conSize+.05)
rotate object j3,rotInfo(a13,a23).xrot,rotInfo(a13,a23).yrot,0
obj2=pick object(mousex(),mousey(),0,10000)
sync
wait 500
delete object j1
delete object j2
delete object j3
if obj2=j1 then buildUponConnector(conNum,a11,a21)
if obj2=j2 then buildUponConnector(conNum,a12,a22)
if obj2=j3 then buildUponConnector(conNum,a13,a23)
show object obj
endif
endif
if mouseclick()=0 then click=0
sync
loop
end
function maxmum(a as float, b as float)
if a>b then exitfunction a
endfunction b
function sign(n as float)
if n>0 then exitfunction 1
if n<0 then exitfunction -1
endfunction 0
function makeImageStuff()
cls rgb(125,125,255)
ink rgb(0,0,0),rgb(0,0,0)
for n=30 to 40
circle 50,50,n
next n
get image 1,1,1,100,100
cls
endfunction
function buildUponConnector(conNum as integer,a1 as integer, a2 as integer)
createConnectorRod(conNum,a1,a2)
createConnector(ternary(equals(rotInfo(a1,a2).xoff,0),connector(conNum).x,connector(conNum).x+rotInfo(a1,a2).xoff*G.rodLen+rotInfo(a1,a2).xoff*G.conSize*.05),ternary(equals(rotInfo(a1,a2).yoff,0),connector(conNum).y,connector(conNum).y+rotInfo(a1,a2).yoff*G.rodLen+rotInfo(a1,a2).yoff*G.conSize*.05),ternary(equals(rotInfo(a1,a2).zoff,0),connector(conNum).z,connector(conNum).z+rotInfo(a1,a2).zoff*G.rodLen+rotInfo(a1,a2).zoff*G.conSize*.05))
`G.conNum and G.rodNum still have the objects created in the last lines
write memblock word connector(G.conNum).memblocknum,4*(((3-a1)-1)*3+a2-1),G.rodNum `store the rodnum in the new connector
write memblock word connector(G.conNum).memblocknum,4*(((3-a1)-1)*3+a2-1)+2,conNum `store the other connector in the new connector
write memblock word connector(conNum).memblocknum,4*((a1-1)*3+a2-1)+2,G.conNum `store the new connector in the one we're adding to
`rotInfo(3-a1,a2) gives the opposite direction as rotInfo(a1,a2)
endfunction
function equals(a as float, b as float)
if a=b then exitfunction 1
endfunction 0
function intequals(a as integer,b as integer)
if a=b then exitfunction 1
endfunction 0
function removeConnector(conNum as integer)
for x=0 to 5
a=memblock word(connector(conNum).memblocknum,4*x)
b=memblock word(connector(conNum).memblocknum,4*x+2)
if a>0
delete object connectorRod(a).objnum
for n=0 to 5
if memblock word(connector(b).memblocknum,4*n+2)=conNum
write memblock dword connector(b).memblocknum,4*n,0
endif
next
endif
next x
delete object conNum-G.firstCon
array delete element connector(),conNum
endfunction
function removeRod(objNum as integer)
for x=1 to G.rodNum
if connectorRod(x).objnum=objNum
conNum=connectorRod(x).oneCon
for n=0 to 5
if memblock word(connector(conNum).memblocknum,4*n)=x
write memblock word connector(conNum).memblocknum,4*n,0
conNum=memblock word(connector(conNum).memblocknum,4*n+2)
break
endif
next n
for n=0 to 5
if memblock word(connector(conNum).memblocknum,4*n)=x
write memblock word connector(conNum).memblocknum,4*n,0
break
endif
next n
delete object objNum
array delete element connectorRod(),x
break
endif
next x
endfunction
function createConnectorRod(conNum as integer,a1 as integer, a2 as integer)
array insert at bottom connectorRod()
inc G.rodNum
obj=find free object(G.maxCon+G.firstCon+1, 1000000)
make object box obj,G.conSize,G.conSize,G.rodLen
connectorRod(G.rodNum).objnum=obj
connectorRod(G.rodNum).xrot=rotInfo(a1,a2).xrot
connectorRod(G.rodNum).yrot=rotInfo(a1,a2).yrot
connectorRod(G.rodNum).zrot=0
rotate object obj,rotInfo(a1,a2).xrot,rotInfo(a1,a2).yrot,0
connectorRod(G.rodNum).x=ternary(rotInfo(a1,a2).xoff=0,connector(conNum).x,connector(conNum).x+rotInfo(a1,a2).xoff*0.5*G.rodLen+rotInfo(a1,a2).xoff*G.conSize*0.5)
connectorRod(G.rodNum).y=ternary(rotInfo(a1,a2).yoff=0,connector(conNum).y,connector(conNum).y+rotInfo(a1,a2).yoff*0.5*G.rodLen+rotInfo(a1,a2).yoff*G.conSize*0.5)
connectorRod(G.rodNum).z=ternary(rotInfo(a1,a2).zoff=0,connector(conNum).z,connector(conNum).z+rotInfo(a1,a2).zoff*0.5*G.rodLen+rotInfo(a1,a2).zoff*G.conSize*0.5)
position object obj,connectorRod(G.rodNum).x,connectorRod(G.rodNum).y,connectorRod(G.rodNum).z
connectorRod(G.rodNum).oneCon=conNum
write memblock word connector(conNum).memblocknum, 4*((a1-1)*3+a2-1), G.rodNum
endfunction
function ternary(a as boolean, b as float, c as float)
if a then exitfunction b
endfunction c
function intternary(a as boolean, b as integer, c as integer)
if a then exitfunction b
endfunction c
function createConnector(x as float, y as float, z as float)
inc G.conNum,1
make object cube G.conNum+G.firstCon,G.conSize+.05
position object G.conNum+G.firstCon,x,y,z
texture object G.conNum+G.firstCon,1
color object G.connum+G.firstCon,rgb(0,0,255)
array insert at bottom connector()
connector(G.conNum).x=x
connector(G.conNum).y=y
connector(G.conNum).z=z
connector(G.conNum).memblocknum=find free memblock()
make memblock connector(G.conNum).memblocknum,2*12
for x=0 to 23
write memblock byte connector(G.conNum).memblocknum,x,0
next x
endfunction
function initialize_G()
global G as info
G.conNum=0
G.rodNum=0
G.firstCon=1
G.maxCon=100
G.conSize=.2
G.rodLen=1
endfunction
function initialize_rot()
global dim rotInfo(2,3) as connectorInfo
for x=1 to 2 `I don't think you have to initialize this but... meh.
for y=1 to 3
rotInfo(x,y).xoff=0
rotInfo(x,y).yoff=0
rotInfo(x,y).zoff=0
rotInfo(x,y).xrot=0
rotInfo(x,y).yrot=0
next y
next x
`(1,1->3) is negative x, y, and z (for (1,1),(1,2),(1,3) respectively)
`(2,1->3) is positive x, y, and z
rotInfo(1,1).xoff=-1
rotInfo(2,1).xoff= 1
rotInfo(1,2).yoff=-1
rotInfo(2,2).yoff= 1
rotInfo(1,3).zoff=-1
rotInfo(2,3).zoff= 1
rotInfo(1,1).yrot=90 `negative signs are trivial since we're dealing with two sided planes, but consistency is nice.
rotInfo(2,1).yrot=-90
rotInfo(1,2).xrot=90
rotInfo(2,2).xrot=-90
rotInfo(1,3).yrot=0
rotInfo(2,3).yrot=180
endfunction
But you might want to ignore that. Actually... some of it is unnecessarily over-complicated. I think here's a great way to do what you want, and it's what the code I wrote uses:
1. create six planes around the connector cube (one on top, bottom, sides, whatever, with corresponding rotation
2. hide the connector cube
3. use pick object, and find which plane the mouse is clicking
4. now you know which plane it is, use it's direction to build another connector in that direction
5. delete the six planes, and show the connector cube.
All the complications in my code rise from finding the cube's direction, and building another connector in that direction. I just like using funny data structures for some reason... it's mainly to avoid writing the same thing over again (like large chunks of code similar but with a couple values changed).
I think I'm going to tidy up my code a lot... Maybe try and write a tutorial of it, actually. I feel unhelpful
Oh right, the giant weird array lookup things in the do loop in my code is just there because I didn't want to make six, just three... so I did a bunch of weird stuff to determine the direction. Totally unnecessary.
Quote: "maybe i should rewrite some of my code..."
the types and memblocks stuff I was using isn't necessary... as long as you're using arrays, or something that can be expanded to multiple objects, you're good ta go!