3rd June 2006 17:47 UTC
major code help plz
okay. so i have this preset that i'm making. an extension of wireframe which is essentially a texer that moves around the window but only along one axis (x, -x, y, -y) at a time.
one night i decided to add a little mouse input, that when your mouse is over the avs screen the texer will follow your mouse around, again only moving along one axis at a time. sounded easy to me at the time, but it's been almost a week now and i'm starting to loose it. i almsot have it but this one little bit is stopping me. i'll paste what i have here and see if anyone can help me out.
init
dc=0; n=1; xs=0.03; ys=0.04; xl=0.9; yl=0.9; x1=-0.03; y1=0; x2=0; y2=0
frame
(original movement code)
x1=x1+if(equal(dc,0),xs,if(equal(dc,1),-xs,x1a));
x1a=if(above(x1,xl),assign(dc,1),if(below(x1,-xl),assign(dc,0),0));
y1=y1+if(equal(dc,2),ys,if(equal(dc,3),-ys,0));
y1a=if(above(y1,yl),assign(dc,3),if(below(y1,-yl),assign(dc,2),0));
nb=if(below(getspec(0,0,0.5),0.1),assign(dc,4),0);
(resets x1 and y1 if the particle escapes the screen - bug fix)]
xr=if(above(abs(x1),1),assign(x1,0),0);
yr=if(above(abs(x1),1),assign(y1,0),0);
(checks if mouse is on screen)
mx=getkbmouse(1); my=getkbmouse(2);
osx=if(below(abs(mx),1),1,0);
osy=if(below(abs(my),1),1,0);
os=band(osx,osy);
(finds the distance between the mouse and the particle and rounds to a whole number)
difx=(mx-x2)*10|1;
dify=(my-y2)*10|1;
(pretty much speaks for itself)
xay=if(above(difx,dify),1,0);
yax=if(above(dify,difx),1,0);
(new movement code in place of x1/y1)
x2=x2+if(___,if(above(difx,0),xs,if(below(difx,0),if(difx,-xs,0),0)),0);
y2=y2+if(___,if(above(dify,0),ys,if(below(dify,0),if(dify,-ys,0),0)),0);
beat
dc=rand(5)-1;
point
x=if(os,x2,x1);
y=if(os,y2,y1);
(switches between x1/y1 and x2/y2 when mouse is on screen)
at the moment this works.. kinda. when the mouse is on screen the particle follows the mouse, but doesn't move along one axis at a time. what i need is something to put in place of the ___ in x2/y2 (xay and yax kinda work). something that determines if difx is bigger or smaller than dify (i think i've got this with xay/yax) and then causes the largest value to enable its corresponding x2/y2 movement. for example if difx was greater than dify, ___ would turn on, and stay on until the x2 movement causes difx to equal 0 (moves the particle along the x-axis until it's in line with the mouse), then switch and turn on the y2 movement and shift the particle along the y axis until dify equaled 0 (the particle aligns itself with the mouse in the y axis and in this case would end up right under the cursor).
but this also needs to work the other way if dify is greater than difx. so really i need 2 things, one for x and one for y, but both with the ability to override the other if it is greater than it, until it reaches 0 and then lets the other take over. if that makes any sense.
any help would be very much appreciated.