I'm still working on my bezier patch viewer I posted about earlier and I'm having a couple of problems.
Firstly, you can get an executable of it here (327k).
The source is also there(26.6k). It has VC7 project files but should compile in g++ (have to uncomment USE_VC7 in s3d_defs.h though), however you need the wxWindows toolkit to compile it.
Now to the problems:
1) At some point in the patch the normals all twist around and start pointing down (run the app and crank up the divisions a couple of times and you'll see what I mean, there's a black area). WTF? I sort of understand how it might happen but I have no idea how to fix it.
Here's the chunk of code looping around creating vertices:
If it doesn't make sense to you grab the source and look at the UpdateMesh() function in the Bezier.cpp file. I should change this function completely to something better but for now I just want this to work because its so close.
2) I'm getting a lot of rendering errors/weird artifacts when gouraud shading. Grab the executable and try it, you will see what I mean. There's no clear pattern to my eyes so its really hard to determine what is wrong. My triangle rasterizer is a bit of a mess anyhow , perhaps I should try to clean it up a bit first and tweak it, but maybe someone here can spot the problem right away.
Firstly, you can get an executable of it here (327k).
The source is also there(26.6k). It has VC7 project files but should compile in g++ (have to uncomment USE_VC7 in s3d_defs.h though), however you need the wxWindows toolkit to compile it.
Now to the problems:
1) At some point in the patch the normals all twist around and start pointing down (run the app and crank up the divisions a couple of times and you'll see what I mean, there's a black area). WTF? I sort of understand how it might happen but I have no idea how to fix it.
Here's the chunk of code looping around creating vertices:
Code:
for( int yc=0; yc<=quad_dim; yc++ )
{
s = 0.0f;
for( int xc=0; xc<=quad_dim; xc++ )
{
// v0:
CVec3 pre( pow3(s), pow2(s), s );
CVec3 post( pow3(t), pow2(t), t );
CVec3 pre2( 3*pow2(s), 2*s, 1.0f, 0.0f ); // 2nd derivative pre
CVec3 post2( 3*pow2(t), 2*t, 1.0f, 0.0f ); // 2nd derivative post
CVec3 tmp2, tmp3, tmp4;
tmp3 = pre * mgmx;
x[0] = tmp3 ^ &post;
tmp3 = pre * mgmy;
y[0] = tmp3 ^ &post;
tmp3 = pre * mgmz;
z[0] = tmp3 ^ &post;
// Calc normals:
tmp2 = pre * mgmx;
tmp3[0] = tmp2 ^ &post2;
tmp2 = pre * mgmy;
tmp3[1] = tmp2 ^ &post2;
tmp2 = pre * mgmz;
tmp3[2] = tmp2 ^ &post2;
tmp2 = pre2 * mgmx;
tmp4[0] = tmp2 ^ &post;
tmp2 = pre2 * mgmy;
tmp4[1] = tmp2 ^ &post;
tmp2 = pre2 * mgmz;
tmp4[2] = tmp2 ^ &post;
tmp3.Normalize();
tmp4.Normalize();
n0 = tmp4 * &tmp3;
n0.Normalize();
// Create vertex:
v0 = Vertex( x[0], y[0], z[0], n0[0], n0[1], n0[2], r, g, b );
tri_mesh[++curv] = new Vertex( &v0 );
s += step;
}
t += step;
}
2) I'm getting a lot of rendering errors/weird artifacts when gouraud shading. Grab the executable and try it, you will see what I mean. There's no clear pattern to my eyes so its really hard to determine what is wrong. My triangle rasterizer is a bit of a mess anyhow , perhaps I should try to clean it up a bit first and tweak it, but maybe someone here can spot the problem right away.