Skip to content
Forum Archive

Pixel Placement

17 posts

horse-fly#

Pixel Placement

Is there a way to define a superscope by a certain pixel position, rather than ratio?
Deamon#
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.
Jaak#
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 😛
Warrior of the Light#
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.
Shylent#
Hmm, seriously, Jaak, in case you are right, I will need to remake quite a lot of my scopes 🙁
Warrior of the Light#
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?
UnConeD#
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.
dirkdeftly#
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
UnConeD#
Um no WOTL.

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

1 pixel = 2 / 300 = 2 / w
TomyLobo#
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
NemoOrange#
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?
UnConeD#
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.