Here is the simple version of how i computed normal but get the same error.
Initially lets assume we have the triangular mesh. While displaying those triangles… i find out the vector between the two edges and compute the cross product the get the normals at each vertex of the triangle. For triangle ABC, i get the vector AB and AC, the get the cross product between them to get the normal at point A. likewise for B and C.
I am computing this one time only and storing it on display list and displaying by calling display list.
The triangular meshes are for dataset 64 x 64 x 64 so i have taken center[3] as {32,32,32}
I am rotating and translating the object in both x and y direction with zooming facility
here is the code for that:-
glTranslatef(cube_center[0], cube_center[1], cube_center[2]);
glTranslatef(-(cube_center[0] * zoomfactor), -(cube_center[1] * zoomfactor),-(cube_center[2] * zoomfactor));
glScalef(zoomfactor, zoomfactor, zoomfactor);
glTranslatef(deltax, deltay, deltaz);
glTranslatef(cube_center[0], cube_center[1], cube_center[2]);
glRotatef(rX, 1, 0, 0);
glRotatef(rY, 0, 1, 0);
glTranslatef(-cube_center[0], -cube_center[1], -cube_center[2]);
variables meaning:
zoomfactor is initially 1.
rX and rY stores the rotation in x and y direction.
deltax and deltay stores the translation on x and y direction.
I am calling the display list that draws my object after calling this code above.
I have attached the figures for this configuration of mine.
Problem 1: fig3.png -> showing problem where some triangles are very bright or very dark as compared to its neighbouring triangles.
Problem 2: fig4.png -> claws like artifact.
For problem 1, i have tried to make the z value of normal negative if its positive but it didn’t helped.
I dont have any clue about the problem 2 but i see those artifacts when rX goes from 90 to 100,and also for any combination rotation of rX and rY.
i would be very grateful if anyone can help me with this…
thank you