[Include] Rotations.inc
#20

I have a small problem with GetRotationMatrixFromEuler.

I'm trying to calculate a quaternion based on z angle (direction) and the surface angle (rx and ry) to apply correct rotations to an NPC Vehicle.

What I do is getting the rotation matrix for the facing angle, and if the surface isn't flat I further rotate the matrix with the x and y rotation.

After that I get the Matrix as Quaternion to use with FCNPC_SetQuaternion.

Код:
new Float:matrix[4][4];
GetRotationMatrixFromEuler(matrix, 0.0, 0.0, rz, euler_samp);
RotateMatrixWithEuler(matrix, surface_rx, surface_ry, 0.0, euler_samp);

GetQuatFromMatrix(matrix, qw, qx, qy, qz);
This works perfectly fine, except when the facing angle is 180.0 (or very close to it). If it's 180.0, the z angle of the returned quaternion is 0.0.

I've removed RotateMatrixWithEuler for testing, however it still happened so it's not that part.

I'm pretty sure that it isn't an issue with FCNPC as I was using another method before which worked (the quaternion is almost the same, except the z angle under these circumstances).

I'm not sure if I'm doing something wrong, but the fact that it works for all other scenarios tells me it should be correct.

Do you have an idea what it could be?

EDIT: I'm now converting the Matrix to Euler angles, and the Euler Angles to a Quaternion. This extra step fixed it.
Reply


Messages In This Thread
Rotations.inc - by Nero_3D - 14.08.2016, 01:19
Re: Rotations.inc - by PT - 14.08.2016, 11:11
Re: Rotations.inc - by Sanady - 15.08.2016, 01:37
Re: Rotations.inc - by Nero_3D - 06.01.2017, 23:59
Re: Rotations.inc - by Crayder - 06.02.2017, 18:25
Re: Rotations.inc - by Nero_3D - 10.02.2017, 13:37
Re: Rotations.inc - by Crayder - 10.02.2017, 17:09
Re: Rotations.inc - by AbyssMorgan - 10.02.2017, 17:13
Re: Rotations.inc - by ball - 16.06.2017, 16:44
Re: Rotations.inc - by Nero_3D - 16.06.2017, 21:43
Re: Rotations.inc - by Nero_3D - 11.08.2017, 20:03
Re: Rotations.inc - by Admigo - 03.12.2017, 13:28
Re: Rotations.inc - by Nero_3D - 04.12.2017, 02:29
Re: Rotations.inc - by kennydalglish - 04.12.2017, 06:27
Re: Rotations.inc - by AbyssMorgan - 04.12.2017, 08:04
Re: Rotations.inc - by Nero_3D - 04.12.2017, 23:01
Re: Rotations.inc - by kennydalglish - 05.12.2017, 15:54
Re: Rotations.inc - by Nero_3D - 06.12.2017, 00:22
Re: Rotations.inc - by kennydalglish - 08.12.2017, 21:47
Re: Rotations.inc - by NaS - 08.03.2018, 15:02
Re: Rotations.inc - by Nero_3D - 16.03.2019, 21:26

Forum Jump:


Users browsing this thread: 4 Guest(s)