Here's a simple question:
suppose I have a 3d mesh stored in an xfile, and i wish to
rotate the mesh so that a given face is pointing "up" towards world y+

To make it simpler lets assume the mesh is a ball constructed of triangles.
How can we use the triangle definition to calculate a rotation matrix that would
rotate the ball around to bring that triangle to the top?
Or to the Front?
Or the Side?
Or to suit the Camera?
We can calculate the Plane from the Triangle's vertex data.
Do we calculate the planar normal and then somehow use that to rotate the mesh?
Posted on 2002-08-03 10:11:57 by Homer
Posted on 2002-08-03 10:38:03 by bitRAKE
nice but heavy ..
there must be a simpler way to calculate a rotation matrix that brings one plane into another.
That must be it..
we calculate the plane of the triangle,
then calculate that plane's current rotation matrix,
then invert that matrix ... am i right?
Someone who listened in math got a simple explanation?
Posted on 2002-08-03 13:02:57 by Homer
EvilHomer2k...this is what i remember from Math class:

So you want to rotate a triangle in space using a matrix.

First imagine a cube with one face directly towards you. Inside that face draw a triangle with the two vertices of the base being the lower left and right corners. The peak of the triangle is the mid-point of the top of the face.
``````     ___________
/\
/  \
/    \
__________``````
You get the picture.

Call the lower left vertix pt1, lower right pt2, peak pt3

The matrix for the triangle in x,y,z coordinates is:

pt1 = [0,0,0]
pt2 = [1,0,0]
pt3 = [.5,1,0]

Now what if you wanted to rotate the triangle so that it was on the top face. Its coordinates in that case would be:

pt1 = [0,1,0]
pt2 = [1,1,0]
pt3 = [.5,1,1]

Notice that the only difference is that some of the 0s are now 1s but the original values in the first matrix are still there. This is because the triangle only rotated 90 degrees.

So how do you show the triangle smoothly move from one position to another? Just make those values that change go slower. In other word increment those values that changed from 0 to 1 in small increments. (e.g. (.1),(.2),(.3),(.4)....(1)) but increase each one uniformly (unless you want a stretch effect)

Its just a matter of inrementing or decrementing variables.

All other coordinates of your ball can be relative to the one triangle.

Not sure if this will help you but i thought i would take a shot.

:alright:
Posted on 2002-08-03 14:47:26 by IwasTitan
I think you just get the normal, convert that to a metirx then as you say, invert and multiply everything by it. I think... :)
Posted on 2002-08-03 16:52:56 by Eóin
Afternoon, E?in.

Using the normals would only work if, when averaged together, they are identical to the faces' normal.

Instead of averaging the normals of each vertice on the face, maybe it'd be better to just avarage the position vertices themselves?

Cheers,
Scronty
Posted on 2002-08-03 19:49:08 by Scronty
bitRake...thanx for the edit
I'm useless with the keyboard

:alright:
Posted on 2002-08-03 22:10:32 by IwasTitan
Sorry Scronty, I ment get the normal of the paticular face you want at the top, thanks for clearing that up :alright:
Posted on 2002-08-04 06:20:06 by Eóin
I solved the problem, and then I found a real solution (typical :tongue: )

For my application I have a (roughly) spherical World with my Player located
on one of many triangles, at some rather arbitrary coordinate yet nontheless located on the plane of and within the bounds of a single triangle.
I wanted to rotate the world and the player to bring the player to the top.
My solution was to trace a ray from the centre of the planet to the unrotated 3d coordinate of the player on the planet's surface. This gives me a triaxial set of rotation angles (xy,xz,yz) which I could apply using a YawPitchRoll matrix.
In my case, however, and yes I am breaking rules here but rules shmules...
I simply used that Ray to define the World Up Vector for Rending :tongue:
This is the first (maybe only) time I'll ever change the World UP, but to me it presented a shortcut, because this ray truly does point up at all times, in the frame of reference of a player located on that surface and standing vertically.

The REAL Solution I later found was to use the handy dandy D3DXRotationAxisMatrix (think that's right) function, used to create a rotation matrix for an arbitrary axis (any 2 points in 3d space).

Thanks for the rebound as always.
Posted on 2002-08-06 03:31:15 by Homer
You know, I prefer your solution to the "REAL" solution. Your solution is a thousand times more efficient.
Posted on 2002-08-06 12:14:09 by Eóin