Archive: Pixel Placement


28th June 2004 06:07 UTC

Pixel Placement
Is there a way to define a superscope by a certain pixel position, rather than ratio?


28th June 2004 10:09 UTC

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.


28th June 2004 10:29 UTC

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 :p


28th June 2004 11:51 UTC

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.


29th June 2004 00:57 UTC

I'll try what WOTL said, as it seems to be the one that would work.


29th June 2004 07:24 UTC

Hmm, seriously, Jaak, in case you are right, I will need to remake quite a lot of my scopes :(


29th June 2004 07:52 UTC

you should use megabufs for those scopes then
wotl: i think it was 1/(w-1) and 1/(h-1)


1st July 2004 22:22 UTC

Why the extra -1?

If screenwidth (w) is, say, 300 pixels,
then 1 pixel is 1/w (1 / 300 = 0.003333333-> ).

Or am I wrong?


2nd July 2004 21:10 UTC

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.


3rd July 2004 02:24 UTC

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


3rd July 2004 13:42 UTC

So if your screensize is 300x300 then w=h=150 and not 300?!? WTF?


3rd July 2004 16:27 UTC

Um no WOTL.

Width in pixels = 300pixels
Width in 'avs units' = 2 (from -1 to 1).

1 pixel = 2 / 300 = 2 / w


5th July 2004 11:19 UTC

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


5th July 2004 16:15 UTC

Okay, I get it now. Thanks


6th July 2004 04:22 UTC

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?


6th July 2004 06:33 UTC

Nemo: Perhaps there are some rounding errors on the angle, in any case it's faster to just use +/- 0.707 rather than sin/cos.


4th August 2004 10:59 UTC

check my reply to this thread: http://forums.winamp.com/showthread....45#post1429445