vertex/face orientation

BlitzMax Forums/MiniB3D Module/vertex/face orientation

ima747(Posted 2010) [#1]
I need to put a sprite in a position dictated by a loaded mesh (either at a vertex, or in the center of a face, either will work) and then rotate the sprite to the same orientation as the face (or figure out what is "out" according to the vertex... if that makes sense).

I'm not working with textures or UV coords etc. etc. I need to actually position an entity at a point dictated by a mesh (easy for vertexes, just get the XYZ of the vertex) and rotate it so it's facing out from the mesh (this is not away from the center, as that would only work for a sphere).

I have no clue how to go about finding an appropriate orientation. I assume I should do something along the lines of calculate the average position between the 3 points that make up a face to find it's center, then try to calculate the face normal and somehow I should be able to extrapolate the orientation from that... but it feels like there should be an easier way. or at least one I might understand...


jhocking(Posted 2010) [#2]
Aren't there commands already in place for getting the normal of a face?


ima747(Posted 2010) [#3]
There's vertex normal but It doesn't seem to do what I need...


ima747(Posted 2010) [#4]
The vertex normal might do what I need but the values I get are pretty strange... they're not degrees and they don't seem to be radians... VertexNY() seems to yield the pitch if multiplied by 90... but NX and NZ don't give seem to give me the yaw and extend beyond 1 quite often so ... I'm quite confused.


jhocking(Posted 2010) [#5]
It's probably returning a unit vector:
http://en.wikipedia.org/wiki/Unit_vector

Long story short, that's a vector 1 unit long where one end is (0, 0, 0) and the numbers returned are the coordinates of the other end.


ima747(Posted 2010) [#6]
hmmm, would make sense for the values I see from the raw mesh. When I run UpdateNormals() on the mesh however some of the values go over 1 (or under -1)... perhaps update normals is just weird... I can't find any examples of how to extract the pitch/yaw from the (probable) vector, so I'm going to try some hackey methods as a work around...


Robert Cummings(Posted 2010) [#7]
I made an insect "game" demo in code archives for blitz3D somewhere, where a swarm of insects run around the room over any surface.

From memory I believe I used line picks and go the normal and used tformangle or such to orient it away. I really cant remember much but go and check it out if you like.


ima747(Posted 2010) [#8]
Thanks I'll take a look.

Currently I position the element at the coords of the normals and then point it at 0,0,0 to get the angle and then move it to the position of the vertex. Works well but the move and point step could be done away with if I could find the math to calculate the pitch and yaw from the normal... but it's fast enough as is for me for now.