i dont know why but i was struggling really bad on this one. I had lots of people show me code functions, some examples but it just wasn't enough detail for me to figure it out. There is allot of information on the internet on how its calculated also.... but again not enough detail for me to figure it out.
then i stumbled on this
http://fullonsoftware.co.uk/snippets/content/Math_-_Calculating_Face_Normals.pdf
I some how managed to link that with some stuff Phaelax explained to me ages ago.... and came up with this:
(im using a few arrays in there to store my values)
function calculatenormals1(v1,v2,v3)
//v1 is your first vertex consisting of x,y,z representing a point in 3d space
x1#=matrix_object1#[v1,0]
y1#=matrix_object1#[v1,1]
z1#=matrix_object1#[v1,2]
//v2 is your second vertex consisting of x,y,z representing a point in 3d space
x2#=matrix_object1#[v2,0]
y2#=matrix_object1#[v2,1]
z2#=matrix_object1#[v2,2]
//v3 is your third vertex consisting of x,y,z representing a point in 3d space
x3#=matrix_object1#[v3,0]
y3#=matrix_object1#[v3,1]
z3#=matrix_object1#[v3,2]
//now the math
ax#=(x2#-x1#)
ay#=(y2#-y1#)
az#=(z2#-z1#)
bx#=(x3#-x1#)
by#=(y3#-y1#)
bz#=(z3#-z1#)
nx#=(ay#*bz#)-(az#*by#)
ny#=(bz#*ax#)-(bx#*az#)
nz#=(ax#*by#)-(ay#*bx#)
//now to normalize it to 1.0
leng#=sqrt((nx#*nx#)+(ny#*ny#)+(nz#*nz#))
nx#=(nx#/leng#)
ny#=-(ny#/leng#)
nz#=(nz#/leng#)
// reset normals with new values
matrix_vertexdatanormals(v1,nx#,ny#,nz#)
matrix_vertexdatanormals(v2,nx#,ny#,nz#)
matrix_vertexdatanormals(v3,nx#,ny#,nz#)
endfunction
this seams to do the trick but i had to invert the y axis.... im not sure why.
so this is a triangle and it sets all vertex points to the same direction calculated.
I know its possible to do a smoother job but this is the first time i ever got it to work.
I will attach my matrix functions to demonstrate it in a few mins...
Sign up for NaGaCreMo!