#### Archived

This topic is now archived and is closed to further replies.

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

This topic is 6291 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites
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

##### Share on other sites
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.

##### Share on other sites
but the vectors must be normalized.

##### Share on other sites
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)

##### Share on other sites
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.

##### Share on other sites
...Would be nice...note: I''m using the Sun MicroSystem''s code found on this site.

##### Share on other sites
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

##### Share on other sites
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

1. 1
Rutin
23
2. 2
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 15
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631757
• Total Posts
3002150
×