Ray Tracing Up-side-down

Started by
14 comments, last by Pipo DeClown 20 years ago
quote:Original post by davepermen
i guess mac has 0,0 at left-top, while windows has it at left-bottom


Nope - SDL behaves the same on all platforms. (Otherwise it wouldn''t be very cross-platform, now would it?)

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

Advertisement
Windows has 0,0 on top left too; interestingly a lot of bmps prefer to be saved top-down though.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

quote:Original post by superpig
quote:Original post by davepermen
i guess mac has 0,0 at left-top, while windows has it at left-bottom


Nope - SDL behaves the same on all platforms. (Otherwise it wouldn''t be very cross-platform, now would it?)


sure, but what if sdl defines the origin at a common place, but the mac-os itself has it different? the original tutorial doesn''t state its sdl if i remember correctly. or has it changed recently?



If that''s not the help you''re after then you''re going to have to explain the problem better than what you have. - joanusdmentia

davepermen.net
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

IIRC, the Mac endians are reversed from PC. Dunno if it has any relevance.

And having programmed on a Mac before, yes, the coordinate system is EXACTLY the same as on a PC.

1 2 3 4..
1
2
3
4
..
I''ve used the same web page when making my own ray tracer. As others have said windows takes the top-left pixel to be the origin. With the positive X axis moving right, and the positive Y axis moving down. However, the coordinate system that the raytracer uses has its origin in the center of the picture, and importantly a positive Y axis moving up as other posters have mentioned. (Left or right handedness isn''t an issue here since both have positive Y as up.) To see this take a look at your ray direction code and have a think about where the ray for the central pixel goes:-

currDirection.mX = x - width/2;
currDirection.mY = y - height/2;

Substitue width/2, height/2 for the central pixel:-

currDirection.mX = width/2 - width/2;
currDirection.mY = height/2 - height/2;

currDirection.mX = 0;
currDirection.mY = 0;

Now take pixel 0,0 top-left of your window, but above and left of the images origin.

currDirection.mX = x - width/2;
currDirection.mY = y - height/2;

Substitue 0, 0:-

currDirection.mX = 0 - width/2;
currDirection.mY = 0 - height/2;

currDirection.mX = -width/2;
currDirection.mY = -height/2;

So we''ve placed this ray in the negative quadrent of the image, below and left of the images origin. Not what we expected. Hence, as you''ve found, the Y axis needs to be reversed between the image coordinates and the screen coordinates:-

currDirection.mX = x - width/2;
currDirection.mY = height/2 - y;

Which explains that you do need to reverse the Y axis, but not why the original website does not. Maybe its a bug with his code, or a difference with mac screen coordinates?
It''s not a bug in his code, since I downloaded his and compiled FINE. 100% complete ABSOLUTELY fine!!


But now, I don''t care anymore. Because I don''t want to track the bug anymore, since it''s obvious that there is none.

I''m using Lab-Rats:
currDirection.mX = x - width/2;
currDirection.mY = y - height/2;


Thanks all! Now it''s time to work on the techniques!!

--
You''re Welcome,
Rick Wong
- sitting in his chair doing the most time-consuming thing..

This topic is closed to new replies.

Advertisement