<%@ include file="../../check-login.jsp" %> Subdivision.org: problem with normals Catmull clark <% session.setAttribute ( "messageNum", new Integer ( 1080 ) ); %>

problem with normals Catmull clark

Posted by suneel on November 13, 2004 at 04:01:14:

hi i was trying to implement the catmull clark subdivision. i am having trouble in calculating the normals. i calculate the normals based on tangent vectors , but i am not getting it rt.i am using a cube with 6 faces, each having a valence of 3 intially. below is the sample of my code

----------------------
while(currFace!=NULL)
{
currEdge = currFace->edge;
do
{
currVert = currEdge->vert;
valence = currVert->valence;

tu[0] = 0.0f; tu[1] = 0.0f; tu[2] = 0.0f;
tv[0] = 0.0f; tv[1] = 0.0f; tv[2] = 0.0f;
normal[0] = 0.0f; normal[1] = 0.0f; normal[2] = 0.0f;

currVert->edge = currEdge;
valence = currVert->valence;


An = 1 + cos(twoPi/valence) + cos(PI/valence)*(sqrt(2*(9+cos(2*PI/valence))));

do
{
nextSymmEdge = currEdge->next->symm;
cosF = (cos((twoPi*i)/valence) +cos((twoPi*(i+1))/valence));

f1x = currEdge->face->faceCenter->x; f1y = currEdge->face->faceCenter->y; f1z = currEdge->face->faceCenter->z;
f2x = nextSymmEdge->face->faceCenter->x; f2y = nextSymmEdge->face->faceCenter->y; f2z = nextSymmEdge->face->faceCenter->z;

tu[0]+= (An*cos(((twoPi*i)/valence)*currEdge->midVertex->x + cosF*f1x));
tu[1]+= (An*cos(((twoPi*i)/valence)*currEdge->midVertex->y + cosF*f1y));
tu[2]+= (An*cos(((twoPi*i)/valence)*currEdge->midVertex->z + cosF*f1z));

tv[0]+= (An*cos(((twoPi*i)/valence)*nextSymmEdge->midVertex->x + cosF*f2x));
tv[1]+= (An*cos(((twoPi*i)/valence)*nextSymmEdge->midVertex->y + cosF*f2y));
tv[2]+= (An*cos(((twoPi*i)/valence)*nextSymmEdge->midVertex->z + cosF*f2z));
i++;
currEdge = nextSymmEdge;

}while(currEdge!=currVert->edge);

normal = norm(cross(tu,tv));

currEdge->vert->normal = normal;
i=0;

----------------------------------

if anyone knows whats wrong with this pls tell me. sometimes my cube becomes bright and sometimes very dark as i rotate it.


Follow Ups:



Post a Followup

Name:
E-Mail:

Subject:

Comments:

Optional Link URL:
Link Title:
Optional Image URL: