0

Suppose, the near and far values of gluPerspective are 1 and 100 respectively. I want to clip the portion of the triangle having z values greater than (-near) or less than (-far) and divide the remaining polygon into two triangles like the following images.

Considering Far plane:

Considering near plane:

Another Case:

I have calculated the intersection points in the following way: z_clip=-far (for considering far plane) or z_clip=-near (for considering near plane)

For example: I f we consider edge between (x1,y1,z1) and (x2,y2,z2), then:

co-efficient = (z_clip - z1) / (z2 - z1)
xc = x1 + co-efficient * (x2 - x1)
yc = y1 + co-efficient * (y2 - y1)
zc = z_clip

(xc,yc,zc) will be a point of intersection. Similarly, I can calculate another point of intersection for other edge. For example: edge between (10, 0, -50) and (0, 0, -150) will be cut in the point (5, 0, -100).

Original Triangle:

0 0 -150
10 0 -50
0 10 -50

After Clipping:

Triangle1:
0 10 -50
5 0 100
0 5 -100

Triangle2:
10 0 -50
0 5 -100
0 10 -50

Am I right in my calculation procedure or is there anything wrong in the procedure?

user5411115
  • 101
  • 1
  • 9
  • Looks good to me. You might need to cope with the very rare case of the triangle intersecting both the near and far planes. – Salix alba Nov 17 '16 at 17:36
  • Yes I have thought about that case too. But is the idea of z_clip=-far or z_clip=-near correct? I mean z_clip will be always equal to -far or -near right? @Salix alba – user5411115 Nov 17 '16 at 17:39
  • I have made an edit. can you please have a look? @Salix alba – user5411115 Nov 17 '16 at 20:20

0 Answers0