Align to Vector help

Blitz3D Forums/Blitz3D Programming/Align to Vector help

QuickSilva(Posted 2003) [#1]
Can anybody offer a simple to understand description of how to use the aligntovector command as I cannot get it to work and cannot figure it out from Marks driver prog. What exactly is a vector and if I have a terrain with a simple cube driving over it how can I go about aligning it to the hills of the terrain?

Jason.


Miracle(Posted 2003) [#2]
Well, think about a 3D space with an origin (0,0,0) and some point away from the origin (x,y,z). The line from the origin to that x,y,z point is a vector. So the command "AlignToVector entity,x,y,z,1" will align the entity's X axis along that vector. The vector 1,0,0 and the vector 1000,0,0 will give you the same result; the length of the vector doesn't matter, just the direction it's pointing.

As for aligning an entity to a surface ... I suppose you could find the normal of the surface you're touching, and then align your model's Y axis to that normal. (A normal is a 1-unit-long vector which points straight out 90 degrees from the surface of a triangle.) I haven't looked at driver.bb recently, though, so he may have a better idea than I do.


QuickSilva(Posted 2003) [#3]
Thanks for the help, just one other quick question, how can I find the normal of a surface?

Jason.


FlameDuck(Posted 2003) [#4]
The normal vector of a surface is the cross product of the respective vectors. The first vector is (v1x-v0x,v1y-v0y,v1z-v0z) and the second vector (v1x-v0x,v1y-v0y,v1z-v0z) where v0x is the triangles first vertixs x coordinate, v1x if the second vertexs x coordinate and so on. Then build a 3x3 matrix with the unit vectors i,j and k in the first row, the first vector in the second and the second vector in the last, solve the matrix and you have the surface normal (aka. the cross product) where the i represents your x magnitude, j your y magnitude and k your z magnitude. Alternatively there might be a SurfaceNormal command or something. Usually you would use the PickedNX or CollisionNX commands tho', but it all depends on what you're trying to acheive. In your example a simple LinePick from above and then using AlignToVector on the PickedNX,NY and NZ should do the trick. Don't forget to set your EntityPickMode.