I am programming a bezier patch program. There’s no real point to it, more a proof of concept than anything else, but a problem keeps cropping up. At the far end of the quad strip, a fan of triangles keeps appearing. The code for the patch in its totality is below, please excuse the formatting errors due to autowrap:
struct Vector
{
float x, y, z;
};
Vector point (Vector a, Vector b, Vector c, float u)
{
Vector temp;
if (u > 1 | | u < 0) return Vector( 0.0f, 0.0f, 0.0f);
temp.x = (a.x * powf(u, 2)) + (2*b.x * u) - (2*b.x * powf(u, 2)) + c.x - (2*c.x * u) + (c.x * powf(u, 2));
temp.y = (a.y * powf(u, 2)) + (2*b.y * u) - (2*b.y * powf(u, 2)) + c.y - (2*c.y * u) + (c.y * powf(u, 2));
temp.z = (a.z * powf(u, 2)) + (2*b.z * u) - (2*b.z * powf(u, 2)) + c.z - (2*c.z * u) + (c.z * powf(u, 2));
return temp;
}
void Bezier(BPatch patch, int divs)
{
int v, t;
float u, x;
Vector temp[3];
Vector *last; //, *curr;
last = new Vector[divs+1];
for (v=0; v <= divs;v++)
{
u = ((float)v)/((float)divs);
temp[0] = point (patch.anchors[0][0], patch.anchors[1][0], patch.anchors[2][0], u);
temp[1] = point (patch.anchors[0][1], patch.anchors[1][1], patch.anchors[2][1], u);
temp[2] = point (patch.anchors[0][2], patch.anchors[1][2], patch.anchors[2][2], u);
glBegin(GL_QUAD_STRIP); // Begin a new quad strip
for (t=0; t <= divs;t++)
{
x = ((float)t)/(float)divs); glVertex3d(last[t].x, last[t].y, last[t].z); // Old Point
last[t] = point (temp[0], temp[1], temp[2], x);
glVertex3d(last[t].x, last[t].y, last[t].z); // New Point
}
glEnd(); // END the triangle srip
}
If you’ve slogged through the code, can you see the problem? Because I’ve been looking at this for a bit now and find myself at a complete loss as to what the problem is. Thanks for reading.