terrain normals

Blitz3D Forums/Blitz3D Programming/terrain normals

hi all... In the current shadow libry I'm working on, creating terrain receivers uses towl meshes.
It grabs the terrainheight() to figure out the placement of the vertex... how exactly can I get the normal of the point on the terrain? (to apply to vertexnx#, vertexny# & vertexnz#)
I need this to figure out which polygons not to create so the shadows don't appear where there is no light.
thankyou for reading :)

You could try picking the terrain and then use the returned PickedNX/NY/NZ ?

I would do that, but I'm avoiding using "pick" commands, because I think they could get in the way for people who want to use shaKAL, but also want to use pick commands for other things... I used to use them for lame bots looking for wall collisions

There 3 ways to get the normal

1. Use Pick (the easiest and most likely fastest if you pick with a dy of 0.1. get terrainY and pick from terrainy - 0.05 with dy = 0.1 :) )

2. Use collisions

3. Interpolate them through 3 terrain high values doing the normal calculation yourself. (N = (e1 x e2)/|e1 x e2| where e1 = vector from point 1 to 2 and e2 = vector from point 1 to 3)

I think option 3 would be the quickest ... you need 3 points to calculate the normal using cross product ...

ax# = x1 - x0
ay# = y1 - y0	
az# = z1 - z0	
bx# = x2 - x1
by# = y2 - y1
bz# = z2 - z1	
Nx# = ( ay * bz ) - ( az * by )
Ny# = ( az * bx ) - ( ax * bz )
Nz# = ( ax * by ) - ( ay * bx )
;only use this part if normals need to be normalised / faster without
Ns# = Sqr( Nx * Nx + Ny*Ny + Nz*Nz )
Nx = Nx / Ns
Ny = Ny / Ns
Nz = Nz / Ns


Stevie