<p>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 &lt; 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. </p>

CC BY-SA 3.0
2018-02-21T07:07:52.393Z
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.
Tare
CC BY-SA 3.0
2018-02-21T07:13:40.700Z
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]: https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm
  [2]: https://en.wikipedia.org/wiki/Cyrus%E2%80%93Beck_algorithm
  [3]: https://en.wikipedia.org/wiki/Clipping_(computer_graphics)#Algorithms
Tare
CC BY-SA 3.0
2018-02-21T16:38:05.843Z
@Tare Im not using openGL or directX actually. Im writing a simple ray tracer and there is preciously little info to start
Manh Nguyen Huu
CC BY-SA 3.0
2018-02-21T23:40:37.523Z
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.
Mauricio Cele Lopez Belon
<3d><clipping>
How to do clipping in camera space?
Manh Nguyen Huu
# How to do clipping in camera space?

(Asked by: username_0 on 2018-02-21)

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.

**Tags:** 3d, clipping

> **Comments:**
> **username_1**: 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.  
> **username_1**: 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]: https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm   [2]: https://en.wikipedia.org/wiki/Cyrus%E2%80%93Beck_algorithm   [3]: https://en.wikipedia.org/wiki/Clipping_(computer_graphics)#Algorithms  
> **username_0**: @username_1 Im not using openGL or directX actually. Im writing a simple ray tracer and there is preciously little info to start  
> **username_2**: 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.  

---

## 0 answers

