Move an object along its own axis
#1

I searched a lot on stack exchange and other coding sites, also on math related sites. But I just couldn't find what I needed.

So, what I want to do sounds simple, but it probably isn't.

In short, I need to be able to calculate 3 (6 but the other three are inverted) vectors from any X,Y,Z Euler rotation.

- vector along X axis
- vector along Y axis
- vector along Z axis

The ultimate problem is respecting all 3 axes at once plus the axis order (xzy if I'm right).

This comes very close:
PHP код:
vx = -cos(yaw)sin(pitch)sin(roll)-sin(yaw)cos(roll)
vy = -sin(yaw)sin(pitch)sin(roll)+cos(yaw)cos(roll)
vz =  cos(pitch)sin(roll
yaw is X, pitch is Z and roll is Y. Z and Y rotation work perfectly, but X is not interpolated correctly. Probably because of the rotation order, but I didn't manage to fix that.
I read the corresponding wikipedia article, but didn't manage to "convert" the given matrix for XZY angles.

Maybe someone has done something similar already, or has an idea how to solve it.

I'm happy about every working solution, but there should be a working way without quaternions and much conversion.

Any help is greatly appreciated!
Reply
#2

It is important to note that facing angles (rotation around Z-axis) in GTA SA are counterclockwise (for some reason). So what you may think is 10° is in fact -10° (or 350°). This may or not be the cause of your problem. I can't tell because I'm absolutely terrible with trigonometry.
Reply
#3

https://lmgtfy.com/?q=3dtryg
Reply
#4

Quote:
Originally Posted by Vince
Посмотреть сообщение
It is important to note that facing angles (rotation around Z-axis) in GTA SA are counterclockwise (for some reason). So what you may think is 10° is in fact -10° (or 350°). This may or not be the cause of your problem. I can't tell because I'm absolutely terrible with trigonometry.
Yes, I know that and that formula is in fact for counter-clockwise angles. The problem here is the order of rotations.
But thanks for the input.

Quote:
Originally Posted by AbyssMorgan
Посмотреть сообщение
Yes, I did search for several hours. Your 3dtryg include does NOT cover what I am looking for. Did you notice that I need a rY parameter and your include does have ONE function supporting that?
If it was just rx and rz, I would not need an include, but use the tryg. functions. rx and rz as such are useless when ry is involved, because that results in a completely different direction.
I need to be able to interpolate on 3 axes, not 2.

Don't get me wrong, your include is nice and I used it before, but I already searched through it for this task.

Next time please read carefully.
Reply
#5

I am not sure what you mean with

vector along X axis
vector along Y axis
vector along Z axis

Usually if you have a rotation you can get the forward, right or up vector, for XZY it should be

Right Vector

X = cos(pitch) * cos(roll)
Y = sin(yaw) * sin(roll) + cos(yaw) * cos(roll) * sin(pitch)
Z = cos(pitch) * sin(yaw) * sin(pitch) - cos(yaw) * sin(roll)

Forward Vector (roll doesn't matter)

X = -sin(pitch)
Y = cos(yaw) * cos(pitch)
Z = cos(pitch) * sin(yaw)

Up Vector

X = cos(pitch) * sin(roll);
Y = cos(yaw) * sin(pitch) * sin(roll) - cos(roll) * sin(yaw);
Z = cos(yaw) * cos(roll) + sin(yaw) * sin(pitch) * sin(roll);

Source: https://en.wikipedia.org/wiki/Euler_...otation_matrix
Reply
#6

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
I am not sure what you mean with

vector along X axis
vector along Y axis
vector along Z axis

Usually if you have a rotation you can get the forward, right or up vector, for XZY it should be

Right Vector

X = cos(pitch) * cos(roll)
Y = sin(yaw) * sin(roll) + cos(yaw) * cos(roll) * sin(pitch)
Z = cos(pitch) * sin(yaw) * sin(pitch) - cos(yaw) * sin(roll)

Forward Vector (roll doesn't matter)

X = -sin(pitch)
Y = cos(yaw) * cos(pitch)
Z = cos(pitch) * sin(yaw)

Up Vector

X = cos(pitch) * sin(roll);
Y = cos(yaw) * sin(pitch) * sin(roll) - cos(roll) * sin(yaw);
Z = cos(yaw) * cos(roll) + sin(yaw) * sin(pitch) * sin(roll);

Source: https://en.wikipedia.org/wiki/Euler_...otation_matrix
Thanks a lot. I was on that page too, but I was trying to make one formula for all directions.

This seems more logical and works perfectly.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)