Jump to content
  • Advertisement
Sign in to follow this  

clipping help

This topic is 3772 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've recently had to adjust my renderer to support polygons with x amount of vertices but the problem is when I try and clip a polygon (using the sutherland hodgman algorithm) with more than three vertices the textures start to dance. I have a polygon structure that holds an array of vertices and the number of vertices as an unsigned int, I basically pass two pointers to two of these structures into the function and it output's the result to the second structure,
int clip(const Polygon *p1, Polygon *p2, const Plane &plane)
   Vertex P = p1->vertices[p1->nVertices-1]; // previous point
   Vertex C;                               // current point
   int tracker = 0;

   for(int a = 0; a < p1->nVertices; a++) {
      C = p1->vertices[a];
         if(dotProduct(C, plane.normal) > plane.dist) { // current point inside
            if(dotProduct(P, plane.normal) > plane.dist) { // both points inside
               p2->vertices[tracker++] = C;
            } else { // current point inside but previous not
               linePlaneIntersection(P, C, plane, p2->vertices[tracker++]);
               p2->vertices[tracker++] = C;
         } else
         if(dotProduct(P, plane.normal) > plane.dist) { // previous point inside but current not
            linePlaneIntersection(P, C, plane, p2->vertices[tracker++]);
      P = C;

   p2->nVertices = tracker;

   return tracker;

to draw the polygon I use:

void drawPolygon(Polygon p) {

   Vertex vBuff[3];

   vBuff[0] = p.vertices[0];

   for(int a = 1; a < p.nVertices-1; a++) {
      vBuff[1] = p.vertices[a];
      vBuff[2] = p.vertices[a+1];

I have a .x file that has 1 face with 4 vertex indices(0, 1, 2, 3), when I use this the texture seems to warp, but if i change it to 2 faces with indices: (0, 1, 2) and (0, 2, 3) it works perfectly. Here's two screen shots: not clipped: Not Clipped clipped: Clipped thanx in advance.

Share this post

Link to post
Share on other sites
I'm sure it's somthing to do with the drawing order, would it matter what vertex you start at? eg.

polygon ABCDEF



be any different from



[Edited by - staticVoid2 on March 23, 2008 1:51:31 PM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!