in frame:
p=0;
In per point:
p=p+1;
x=xp1*equal(p,1)+xp2*equal(p,2)+xp3*equal(p,3);
y=yp1*equal(p,1)+yp2*equal(p,2)+yp3*equal(p,3);
where xp1, xp2, xp3, yp1, yp2 and yp3 are coordinates. Make sure n equals the number of p you use, all n higher than p snap to coords (0,0).
Works in 3D as well.
dont use multiply, just chunks of ifs, multiplication is slow, but the ifs will be quite faster... especialy if your little scope consists of 100 points 😛
I don't think this is what he meant..
You can use px=1/w for instance for 1 pixel in width and py=1/h for 1 pixel in height. or 2/h, 3/h for two or three pixels etc.
1 pixel is 2/w (-1 .. 1 = 2 units), but you might need to add 1/w to coordinates to make sure you are on the center of a pixel.
Same for y.
also, if you run into problems (as i did just recently) with points being a pixel off, avs does some wonky rounding and i *think* it turns out that avs rounds down to the nearest pixel when the value is above zero, and up if the value is below zero. so if you have a point that is at 100.5 pixels, it will round to 100, but if it's -100.5, it'll round to -100 instead of -101
the way i fixed it is just adding 1/w (1/2 pixel) to x and y.
stupidgoddamnroundingerrors
ok 2/(w-1)
pixels on screen go from 0..(w-1) whereas AVS has a coordinate range of -1..1
so to go from pixels to avs coords, you
- divide by (w-1)
- multiply by 2
- subtract 1
in other words
xavs=xpix/(w-1)*2-1;
if you have 2 pixels and want the distance, in avs coordinates:
xavs1=xpix1/(w-1)*2-1;
xavs2=xpix2/(w-1)*2-1;
xavs2-xavs1=xpix2/(w-1)*2-1-(xpix1/(w-1)*2-1);
=xpix2/(w-1)*2-xpix1/(w-1)*2;
=(xpix2-xpix1)/(w-1)*2;
if xpix2-xpix1 is 1 pixel then you get xavs2-xavs1=2/(w-1)
same thing for y coords just with h instead of w
Kinda on the same subject:
I was making a scope that I wanted to move in perfect 45 degree angles.
The code went something like:
xm=xm+sin(mr)*speed;
ym=ym+cos(mr)*speed;
mr=$PI/2*var+$PI/4;
x=xm; y=ym;
For the most part, it did move in 45 degrees, but every 10 pixels or so, it would move up a pixel, then back down 10 pixels later. This sounds like what Atero was talking about. Does anyone know how to fix this?