Normals and a Shere (And bashing my head through a wall)

Started by
7 comments, last by CpMan 22 years, 11 months ago
This problem is driving me crazy: I generate a sphere using the longitude, lattitude algorithm found on this site. Then to do the normals, I look at each triangle speratly and generate my normals. But the normals come out so the triangles alternate between unlit and lit, thus black and colored. And when the sphere rotates around, so the left half (or right half but not top and bottom) shows, the inside is shown. Why might this be. I''ve never had this problem before.
VSEDebug Visual Studio.NET Add-In. Enhances debugging in ways never thought possible.
Advertisement
make sure your normals are normalized (of unit length). If they''re not, the rendering of the triangles will be all messed up as you describe.

c
For normals of a sphere, the best way is to calculate vertex normals simply as the vector from the center of the sphere to each vertex. Its MUCH easier, assuming you want smooth shading.
but the vectors must be normalized.
Thanks Terran, it was driving me crazy. Couldn''t understand why it was working like that. Another thing. I make the sphere first and then translate the vertices left, right, etc to make a random object. The normal thing happens there too AND trnaslated versus no translated has a significant performance difference, even with the same numkber of triangles. Got any ideas. Sorry about the spelling on the title, it should read Normals and a Sphere (And bashing my head through a wall)
VSEDebug Visual Studio.NET Add-In. Enhances debugging in ways never thought possible.
Its till not working, even with your suggestion. When I rotate the object, around the x axis (so the hemispheres flip), and step through it frame by frame, I can see that the normals are crossing over between back and front, giving oval type artifacts until its completly black, any more suggestions.
VSEDebug Visual Studio.NET Add-In. Enhances debugging in ways never thought possible.
...Would be nice...note: I''m using the Sun MicroSystem''s code found on this site.
VSEDebug Visual Studio.NET Add-In. Enhances debugging in ways never thought possible.
I think your problem is front-face-culling. Sof the triangles are in clockwise order, while others are counterclockwise. D3D uses this information to find out what direction a polygon is facing. If it''s facing away from you, it doesn''t draw the backside but just plain nothingness. Try either

1. Changing the culling every second step
or
2. Reverse the order of every second triangle

Good luck then

- Sleepwalker
- Sleepwalker
if you describe your sphere using polar coords then normals fall straight out:

x = r * sin(A) * cos(B);
y = r * sin(A) * sin(B);
z = r * cos(A);

is a sphere. with radius r, now its fairly clear that for a unit vector, r=1 so your normals are

nx = x/r;
ny = y/r;
nz = z/r;

of course to avoid these costly divisions, you should work out the normals first and then multiply by r to get the coords.

alistair

This topic is closed to new replies.

Advertisement