Archive: Rotating SS


13th July 2002 19:44 UTC

Rotating SS
Hey guys. I'm having problems with a SS effect I'm trying to create, and I think you might be able to help me.
I'm trying to make a rotating oscilliscope, however what I have right now is very heavily distorted at certain angles. The code is below.


Init:
n=100; t=0;

Beat:


Frame:
t=t+.05;

Pixel:
d=(i-.5)*2;
r=t;
x=cos(r)*d+v/3*cos(r);
y=sin(r)*d+v/3*cos(r);

Thanks,
~Keaton


14th July 2002 19:55 UTC

Quick answer:
This is the rotation around an axis (or upon a plane) for any object:
x=cos(t)*x1+sin(t)*y1;
y=sin(t)*x1-cos(t)*y1;
where t is theta, the angle for the rotation in radians, and x1/y1 are the original coordinates for the object. So a rotating straight oscilloscope would have this formula:
frame:
t=t+0.05;
pixel:
x=cos(t)*(i*2-1)+sin(t)*v/3;
x=sin(t)*(i*2-1)-cos(t)*v/3;


14th July 2002 20:21 UTC

now for the next question.... heheheh
How do I make the size of the line with respect to the window constant. If you notice, the way the code works now, the line doesn't fill the entire diagonal. Now, I know that the line remains the same length the way it is, but how can I change it to always go from one edge of the window to the other (or start 1/2 of the way in and go to 1/2 of the way the other direction, etc)?


15th July 2002 13:17 UTC

This is more of a hack, but you could make the line length sqrt(2). That way it will be exactly the length of a diagonal, and invisible areas will be clipped off at the edges when not visible.


I think the *exact* formula for scaling-constant for x,y so that they fill up the screen is:

min(tan(x),1/tan(x)) (take the minimum of tangent and cotangent as scaling factor).

Just make sure you never rotate exactly horizontally, vertically or diagonally... (because then tan(x) is infinity or zero). Start with an angle value of 0.001 or something.