View Full Version : Normals

Hi,

Could someone correct me if I am wrong :

If I want all the normals to point towards the viewer (ie pointing out of the screen), shouldn't the z value of normal vector lie between 0 and 1. If the z value (normal vector) is negative then the polygon points should be reversed in other direction and new normal should be calculated ie (Vertices 1,2,3 of triangle should be changed to vertices 1,3,2).

Thanks a lot

D Pal

mikael_aronsson

01-23-2002, 10:45 AM

If you have a triangle that is facing the viewer (the default with out any transformations) then the normals z should be 1 (x and y = 0), the "length" of the normal should always be 1, if you reverse the triangle it is facing away from the viewer and z should be -1.

But instead of messing with this yourself, you should do a search on google for "cross product", I am sure youi will find examples in C or any other language you might be interested in, you use this to calculate the normal for you so you don't need to mess around with it yourself.

Just an idea.

Mikael

MrShoe

01-23-2002, 03:32 PM

What do you mean so that you dont have to mess with it yourself?? To calculate the normal to a triangle all you have to do is turn 2 of its 3 sides into a normalised vector and take the cross product between th resulting vectors to give you the normal. Then you have to normalise it again though. unfortunatly i forgot what the formula for cross product is though...

guille

01-24-2002, 01:25 AM

C = Cross(A,B) = (Ay*Bz - Az*By, Az*Bx - Ax*Bz, Ax*By - Ay*Bx)

Do not forget to normalize C

=] g

[This message has been edited by guille (edited 01-24-2002).]

mikael_aronsson

01-24-2002, 04:41 AM

That was what I meant with "don't mess with it yourself", use the crossproduct instead of sitting and try to figure out the normal by hand, sorry if the post was not clear enough.

Mikael

Furrage

01-24-2002, 07:34 AM

Originally posted by MrShoe:

What do you mean so that you dont have to mess with it yourself?? To calculate the normal to a triangle all you have to do is turn 2 of its 3 sides into a normalised vector and take the cross product between th resulting vectors to give you the normal. Then you have to normalise it again though. unfortunatly i forgot what the formula for cross product is though...

Don't normalise the vectors till after you get the cross product. Normalising them before ("turn 2 of its 3 sides into a normalised vector") is just a waste of time.

Hi,

It seems I was not clear what I wrote. Here is my second attempt and please pardon me.

Consider a triangle with co-ordinates (1,0,0),(0,1,0) and (0,0,1). The normal (not normalized) would be (-1,-1,-1). But If I consider (1,0,0),(0,0,1) and (0,1,0) then normal is (1,1,1). My question is which of the above triangle would be facing out towards the screen ?

Thanks

D Pal

Furrage

01-24-2002, 08:15 AM

+z faces the screen, -z faces away from the screen.

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.