At 7/29/12 09:18 AM, zanzlanz wrote:
xS = Math.sin((xPixel+xRot)/180*Math.PI);
yS = Math.sin(yPixel/180*Math.PI);
zS = Math.cos((xPixel+xRot)/180*Math.PI);
>.> Why isn't this working?
I like your idea of using a frustrum. A lot. But that didn't quite work. (Kinda made it worse).
If you step through the spherical coordinates solution you see that the x coordinate is dependant on the y which indeed was to be expected, but it's not what we want because humans don't see like that, you equations were correct from the start, they only lack the part where you con make them turn up and down.
That is controlled exclusively by the zS and yS components, so basically what you need to do right now is rotate them by a certain degree which is easily done using matrix multiplication like so
|| x' || = || cos a -sin a|| || x ||
|| y' || || sin a cos a || || y ||
which in turn gets you
x' = x * cos a - y * sin a
y' = x * sin a + y * cos a
where a is the degree you are turning it by
there was a flaw in my initial suggestion
yS2 = yS * Math.cos((yPixel + yRot)/180*Math.PI) - zS * Math.sin((yPixel + yRot)/180*Math.PI);
zS2 = yS * Math.sin((yPixel + yRot)/180*Math.PI) + zS * Math.cos((yPixel + yRot)/180*Math.PI);
should be
yS2 = yS * Math.cos((yRot)/180*Math.PI) - zS * Math.sin((yRot)/180*Math.PI);
zS2 = yS * Math.sin(( yRot)/180*Math.PI) + zS * Math.cos((yRot)/180*Math.PI);
because there is no sense in including the position of the pixel on screen in this rotation, you already have the ray direction, you just want to alter them all to point upwards
If this doesn't work either I'm going to try and hack something together see if I can get it right.