This is of course all just thinking out loud.
> and then using that cross product of that and the inverse normal to
> get the x, y and z components I desire, but it seems I'm very wrong.
That's not a well-defined concept. You have to define what it is you
want better. A triangle does not, inherently, have a "rotation," any
more than it has a "translation." Those concepts can only be defined in
reference to some other state.
Also, normals don't have inverses, as they are vectors, not transforms.
Perhaps what you want is a rotation that takes the normal from the state
the triangle has in an untransformed mesh, and rotates the triangle to
match the new normal? The problem is that there is an infinity of such
rotations, because the triangle can be rotated any degree around the
normal. Perhaps what you want is the shortest circular rotation that
will make the identity normal align with the current triangle normal? Or
do you want the rotation that will make all vertices of the original
triangle align with the current triangle? In all these cases, the
assumed reference is an "untransformed" triangle, but if your triangle
mesh is static (doesn't move), then the rotation will always be identity.
So, if you can define what it is you want, then perhaps someone can help
you come up with how to get that. Or perhaps it falls out directly from
the definition.
Sincerely,
jw
To put what Rodrigo and John said in simpler terms:
What you said does not make much sense to us. Why don't you tell us what
you are trying to accomplish, so we can try to guide you to the
"easier"/correct solution?
Are you by any chance trying to convert between local/world coordinates?
The dGeomTriMeshGetTriangle() function returns the triangle in world
coordinates. To get local coordinates, just access the trimesh data you
provided to ODE instead of doing the inverse rotation+translation transform.
--
Daniel K. O.
"The only way to succeed is to build success yourself"
I'm just speculating, maybe you want the initial ray to have the
smallest possible angle with the bouncing ray that is constrained to
be in the plane of the triangle (and any direction would be fine if
the ray was exactly parallel to the normal). In this case you can find
the direction of the second ray by just projecting the initial ray to
the plane of the triangle. A simple way to do that is to first project
the ray on the normal and subtract that from the ray.
Hope that helps.
-Gazi
dVector3 output, trinormal ray;
dCROSS(output,=,ray,trinormal);
dCROSS(output,=,trinormal,output);
dNormalize(output);
where trinormal is the triangle normal and ray is the ray's direction
(destination-origin if you have it in segment notation).
output will contain the normalized direction of the projected ray.
You may notice this is very similar to what I described before, getting
the orthonormal basis for the triangle.