# 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.

## 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];
drawTriangle(vBuff);
}
}


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: clipped: thanx in advance.

##### 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

would

ABC
ACD
AEF

be any different from

BCD
BDE
BEF
BFA

???

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

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
19
5. 5

• 14
• 26
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631771
• Total Posts
3002253
×