1
$\begingroup$

I don't even know where to start. So far, the only progress I have gotten is checking the z value of each vertex of each triangle. If all three vertices' z values > absolute value of far or < absolute value of near, then I dont draw that triangle. It seems wrong somehow, though I dont get why. Im using the right hand rule, if that info is necessary.

$\endgroup$
  • $\begingroup$ Just to make sure you don't do work you don't need to do: you are aware that OpenGL and DirectX do clipping on their own, right? One thing you also may consider is at which axis you are looking. Some rendering APIs look along negative z when in camera space, so if you clip depending on positive z values but look along the negative z axis, then there would be an error in your case. For the original question: there are algorithms for clipping, that calculate which parts of triangles you need to draw. It has been some time though, so I'd need to look up even the names. $\endgroup$ – Tare Feb 21 '18 at 7:07
  • $\begingroup$ Upon a quick search, the two algorithms we looked at in university where [Cohen-Sutherland][1] and [Cyrus-Beck][2]. They are only for line clipping thought - Polygons need their own algorithms. I suggest looking into the [Wikipedia algorithm list][3] to get a feeling for what you have to consider when trying to do clipping yourself. [1]: en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm [2]: en.wikipedia.org/wiki/Cyrus%E2%80%93Beck_algorithm [3]: en.wikipedia.org/wiki/Clipping_(computer_graphics)#Algorithms $\endgroup$ – Tare Feb 21 '18 at 7:13
  • $\begingroup$ @Tare Im not using openGL or directX actually. Im writing a simple ray tracer and there is preciously little info to start $\endgroup$ – Manh Nguyen Huu Feb 21 '18 at 16:38
  • $\begingroup$ Just define 6 3D-planes for the frustum. Near clipping and far clipping planes should have normal aligned with z-axis in camera space. The other four planes should be defined according to the field-of-view angle that you defined. All plane normals should point to the inside of the clipping volume. Then you have to calculate polygon intersection with each plane and clip accordingly. $\endgroup$ – Mauricio Cele Lopez Belon Feb 21 '18 at 23:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.