Welcome to Fractal Forums

Fractal Software => Programming => Topic started by: ker2x on July 28, 2011, 04:15:09 PM




Title: 3D to 2D Orthographic projection
Post by: ker2x on July 28, 2011, 04:15:09 PM
hello !

I'm reading : http://en.wikipedia.org/wiki/3D_projection
and produced this code :
Code:
u = x * 10.0 / z
v = y * 10.0 / z

However, it seems to be totally flawed with negative values of Z (and obviously when Z = 0).

Any idea/implementation to do an orthographic projection that works please ? :)


Title: Re: 3D to 2D Orthographic projection
Post by: marius on July 28, 2011, 11:48:49 PM
hello !

I'm reading : http://en.wikipedia.org/wiki/3D_projection
and produced this code :
Code:
u = x * 10.0 / z
v = y * 10.0 / z

However, it seems to be totally flawed with negative values of Z (and obviously when Z = 0).

Any idea/implementation to do an orthographic projection that works please ? :)

Not sure I follow. Clearly, Z <= 0 means those bits are behind the viewer, hence not visible? Look up view frustum. Generally ones defines a near and a far pane and only cares about bits inside the frustum. Larger than 180 degree fields of view get weird, of course.

Why would you want ortho anyways? Perspective is quite a bit more visually appealing.


Title: Re: 3D to 2D Orthographic projection
Post by: A Noniem on July 29, 2011, 11:39:42 AM
If z < 0, z is behind the camera, so there is no need to draw it (you don't have eyes in your head do you?)
if z = 0, z is inside the camera, so things get a bit tricky there as well.
I'm not sure if you're familiar with the term view frustrum, but you might wanna read http://en.wikipedia.org/wiki/Viewing_frustum

Normally a view frustrum is used in perspective projections, but you can use a near and far plane just as well in an orthographic projections. This means that check whether z in a certain range. near plane <= z <= far plane. Ofcourse the near plane has to be greater than 0 and the far plane is normally not infinite.

And in response to marius, projective projections are indeed nicer, it does however take a lot more knowledge and a lot of matrix stuff in order to do so, so I wouldn't recommend using it if he doesn't even have an orthographic projection.


Title: Re: 3D to 2D Orthographic projection
Post by: ker2x on July 29, 2011, 12:54:15 PM
thank you both of you.
i was to used to draw at 0.0 and put a camera/eye somewhere at +Z (the GL/GLut way).
I modified my code to draw somewhere on +Z and now it works as expected :)

Perspective is more complex and more cpu intensive, and really don't need that.  :angry:


Title: Re: 3D to 2D Orthographic projection
Post by: A Noniem on July 29, 2011, 01:26:42 PM
Last year I had a course graphics at the university where I pretty much learned everything I know about graphics. The nice thing is that all the lectures are on youtube and Vimeo (and they are in English) If you want to know more about this (for example perspective projections/lightning/shadows/etc) those video's are definitely worth taking a look at.

http://www.youtube.com/playlist?list=PL3259824CD60C3C27

Every lecture is 2x 45min.


Title: Re: 3D to 2D Orthographic projection
Post by: ker2x on July 29, 2011, 01:30:30 PM
wow ! Thank you very much !  :embarrass: