karansher / computer-graphics-ray-casting

Computer Graphics Assignment about Ray Casting
1 stars 0 forks source link

Viewing rays #7

Closed JanardanS closed 1 year ago

JanardanS commented 1 year ago

When drawing a ray, im confused on this conversion from i,j of a pixel to u,v. I tired to implement using the tutorial that its

-1/2 width + (i + 1/2)width_pixel 1/2 width - (j + 1/2)height_pixel

But im confused on what to do since after implementing this, it produces an image like this..

image

Im not sure whats wrong with the formula though.

JanardanS commented 1 year ago

Never mind found out the problem. Closing this issue.

yuetsai93 commented 1 year ago

Hey @JanardanS would you mind share what problem is causing this? I'm having a similar issue where my shapes seem to be 'out of order' and I've been stuck on it for hours :( For the formulas you posted above I see the second one uses width as well as height. I thought it should be only width or only height in calculating each one. I think my formulas are slightly different from yours where I multiply -1 for the height one comparing to the ones on the slides

JanardanS commented 1 year ago

So in tutorial, the person posted that you should convert into camera space from pixel by doing the following operation,

-1/2 width + (i + 1/2)width_pixel 1/2 width - (j + 1/2)height_pixel

But this is actually not true. Particularly, the second equation should have height, not width instead, which makes sense as you are traversing in the v direction, which is based on height, not width. So, it should be

-1/2 width + (i + 1/2)width_pixel 1/2 height - (j + 1/2)height_pixel

As for the multiply by -1, this is because we are using a different pixel coordinate system than the ones in the slides. That's why these formulas look a bit different.

Hope this helps!

yuetsai93 commented 1 year ago

thanks a lot for the explanation! I found my problem :D