normals algorithm

SPASE_1976

Addon Developer
Addon Developer
Joined
May 10, 2008
Messages
137
Reaction score
0
Points
0
Any1 know how to get the normals from a triangle ?
the triangle is part of a sphere but could describe a mountain
so its not always surface

just asking
 
1. Go to www.google.com
2. Type in "Calculating normal vector for a triangle" (without quotes)
3. Click "Search"
4. ???
5. Profit!
 
Okay then, I'll help you out more:

cross product.

Google that.
 
Normalizing triangles (or plains) defined by 3 points?

P, Q, R are points in the triangle (or on the plain)

P (X1, Y1, Z1)
Q (X2, Y2, Z2)
R (X3, Y3, Z3)

V1, V2 are vectors:

V1 = PQ
V2 = PR

V1 = Q - P = (X2 - X1, Y2 - Y1, Z2 - Z1)
V2 = R - P = (X3 - X1, Y3 - Y1, Z3 - Z1)

N is normal (being calculated by cross product):

The result of a corss product of two vector is a vector, perpendicular to the plain. It's calculated like this:

If Q1 and Q2 are two vectors:
Q1 = (X1, Y1, Z1)
Q2 = (X2, Y2, Z2)

Then cross product C is:

C = Q1 x Q2 = (Y1*Z2 - Y2*Z1, Z1*X2 - Z2*X1, X1*Y2 - X2*Y1)

So in the case of vectors V1 and V2:

N = V1 x V2 = ((Y2 - Y1) * (Z3 - Z1) - (Y3 - Y1) * (Z2 - Z1), (Z2 - Z1) * (X3 - X1) - (Z3 - Z1) * (X2 - X1), (X2 - X1) * (Y3 - Y1) - (X3 - X1) * (Y2 - Y1))


Hope this helps. Yea, I know, very confusing with all the long lines, but if you go over it slowly, you'll see that I just added the components of vectors V1 and V2 into equation for cross product... and I got my V1 and V2 vectors by going from point P to point Q and from point P to point R. You have to subtract the second one from the first to get the vector.


-----Posted Added-----


One more thing to watch out for:

If V1 and V2 are two vectors, then
V1 x V2 = - V2 x V1

The thing is... if you do it from the other way, you're gonna end up with a normal facing the other way.
 
RisingFury thanx i''try it

You know i am making an addon to produce automatically
what brian jones did with his 'moon3d' but i wont give it away for free :P
you can choose the resolution of the mesh , the mesh gets optimized
you can make any planet/moon you like....and i am stuck to the math

i can use shipedit to make the normals but we all know what shipedit does to the meshes...:(

only RisingFury and wurumpe will get a copy
 
So wait...you're making...another version of Orulex?
 
More competition on that field is welcome in my eyes.

@SPASE_1976: Wow, thanks. I'm honored :)
Good luck with your build :)

Except it won't be competing, since he's already said he's not going to give it to anyone....
 
its better than orulex , its suitable to your cpu lol

geee its very confusing..
RisingFury r u sure its correct ?
 
its better than orulex , its suitable to your cpu lol

geee its very confusing..
RisingFury r u sure its correct ?

His equations are correct, and welcome to the world of graphics--the equations are complex.

Even if your program were significantly better than Orulex (which seems doubtful, given various clues in this thread), if no one gets to use it, there's no point.
 
Well, if it's false I'll fail my math exam next month :P:lol:

Let me write it down on paper and upload it, just give me a few minutes :)

Hielor: There *is* a point. Even if nothing ends up getting released, or nothing gets anything near finished, he'll still have learned things that will make him a better programmer :)

How many programs have you made that haven't gotten released? :P
 
if u show me how to get the rest 2 normals u get an extra copy

just in case you intentionally delete the first you will have a backup
 
DSC05338.JPG

(http://www.unrealaddicts.com/forums/Janez/DSC05338.JPG - Direct link if you need it)

Sorry for the large image, I don't have a scanner here...
Oh and hopefully you can read my handwriting.


One thing I'd like to point out here. I took vectors PQ and QR. If the triangle has an orientation of P --> Q --> R, the normal will be PQ x QR
If the orientation is P --> R --> Q, the normal will be QR x PQ = - PQ x QR

I don't know which way the triangles in the meshes are rotated though, so if your result is all screwy, just reverse the normal in the function that calculates it.
 
You definetelly will get a free copy!!!!!!

eat that artlav orulex is history :)

i used notepad's 'search and replace ' to make things more clear

V1 = Q - P = (A, B, C)
V2 = R - P = (K, L, M)
N = V1 x V2 = ((B) * (M) - (L) * (C), (C) * (K) - (M) * (A), (A) * (L) - (K) * (B))

Thank you again friend i'll add you to my friends list (if someone can tell me how to do that too!)
 


needs more work at the optimization issue..


Somehow, it looks very slow. Usually this amount of surface detail is done using normal mapping or bump mapping. If you just used plain triangles to make all the detail, how fast can it be? Maybe 1 or 2 FPS on a fast video card?

Good luck with your work on this. Although I'd prefer it to be free of course :P
 
those 2 sections of the sphere have 126000 triangles / 63755 vertices
the easiest way is to make the optimization by using a 3d prog (ie blender) after creating a very hires mesh but mountains could be shorted (and if thats the the final case i might give it)

NOTE : the prog does a vertex position optimization
 
Back
Top