I asked this on the Amethyst forum, but haven’t gotten any responses. Given an Isometry
, I’m trying to get the direction of travel, as well as the direction of local up/left/right/behind. After taking an example I was given, logging my position/direction of travel, and changing it until I got values that made sense, I have:
let mut direction = transform.isometry().rotation * Vector::z();
direction *= -1.;
info!("Direction: {:?}", direction.data);
Initially when I instantiate an object and set its Euler angles to 0,0,0, I get:
[INFO][onslaught] Direction: [-0.0, -0.0, -1.0]
And this is correct. If I fly in the direction of travel, my Z coordinate does indeed decrease, and rotation seems to set these correctly. So, things I’m confused about:
- The first example I was given in the Amethyst thread has me do the following to get a forward vector:
let mut direction = transform.isometry().rotation.inverse() * Vector::z();
But the presence or absence of .inverse()
makes absolutely no difference here. It’s only by multiplying the rotation by -1 that I get a rotation in the correct direction. I’d have thought multiplying by -1 was an inverse. Am I misunderstanding why that’s there? I haven’t done this level of math in 20 years and wasn’t good at it then, unfortunately.
- Another example had me calling
transform.isometry().rotation.matrix().row(2)
, and that looks a bit cleaner in that I’m just getting data without cloning or modifying anything. Unfortunately, there’s no.matrix()
method on the rotation. I got this to compile:
let rotation = transform.isometry().rotation;
let mut direction = rotation * Vector::z();
direction *= -1.;
info!("Direction: {:?}", direction.data);
let direction2 = &rotation.coords.row(2);
info!("Direction2: {}, {}, {}", direction2[0], direction2[1], direction2[2]);
And I wanted to see if the values equalled, but I get a matrix index out of bounds error.
So in short, my code seems to work, but I’m not sure why. Calling .inverse()
on the rotation has no effect, and it seems like inverting a rotation should do something to the direction vector, even if it isn’t what I ultimately want. The second example looks a bit cleaner, and I’d like to compare their results, but I can’t make it work. Anyhow, I don’t like writing code that I don’t understand. I’m also a bit confused on why I may have been told to call .inverse()
. Given that the direction I get is in fact opposite of the one I need, it seems like an inverse method should give me what I want. But that it does nothing makes me wonder.
Thanks.