Simple but annoying Bug VEC_ROTATE

Posted By: SeaCancer

Simple but annoying Bug VEC_ROTATE - 03/14/12 21:13

today I found very simple but very annoying Bug,,

It is related to the:
vec_rotate (VECTOR* vDir, ANGLE* vAng)

this function is useful in many programming issues like camera and movement vectors

However, this function is not giving correct results if the vector that you want to rotate is not aligned to the axis

i.e: vector (10,10,10) if you want to rotate it around the origin by angles 90,45,0

you will have very funny results that are totally wrong at all

so try to avoid this function now
also:
ang_rotate

same error!

It only gives right results if you want to rotate a vector that is aligned to the xyz axis, like vector (10,0,70)

or if you rotate a vector without changing the tilt componant
i.e rotate vector (10,10,10) using the angles (90,0,0)
this will work (only accept pan angle)
Posted By: SeaCancer

Re: Simple but annoying Bug VEC_ROTATE - 03/15/12 00:52

I got the problem clearly now laugh

if you have a vector not aligned to the xyz axis
example camera_dir (10,20,30)

Now, if you want vec_rotate to rotate this vector by a "tilt" angle only, it will destroy the "pan" angle that you do not want to change

and if you want vec_rotate to rotate a vector by a pan angle & tilt, here is the disaster laugh
Posted By: EvilSOB

Re: Simple but annoying Bug VEC_ROTATE - 03/15/12 04:46

You still arent being clear (to me at least) with what you are trying to achieve.

There are many different vector/angle manipulation functions, and I suspect you
just need to find the 'right' one, which isnt always easy.
OR there is a chance that you are hitting the dreaded 'gimbal lock' issue.
If vec_rotate was ACTUALLY bugged, it would be affecting a great many people...

Can you give a few SIMPLE examples of what results you are expecting...
eg:
(10,10,10) + (0,15,0) = (10,25,10)
(20,20,20) + (15,20,25) = (35,40,45)
and the like...


Posted By: SeaCancer

Re: Simple but annoying Bug VEC_ROTATE - 03/15/12 14:44

ok, i will write a simple code in no time laugh
Posted By: SeaCancer

Re: Simple but annoying Bug VEC_ROTATE - 03/15/12 14:56

here we go:

ANGLE test;

function EvilSOB ()
{
var vectot_test [3];
vec_set (vectot_test,vector (10,10,10));
vec_rotate (vectot_test, vector(0,0,0)); // rotation angles change here
vec_to_angle (test,vectot_test);
}

just put the angle test as "watched" variable, you can see that the angles of this vector is (45,35.26,0), this is 100% right

Now let us rotate it another 45 pan:
the result is (90,35.26,0), this is 100% right too laugh

NOW, let us rotate it 30 pan and 10 tilt just change the rotation angles to 30,10,0 in the code
the result is: 81,42,0 this is totally wrong!
the right values are (75,45.26,0)

NOW, let us rotate it 10 tilt just change the rotation angles to 0,10,0 in the code
the result is: 51,42,0 this is totally wrong!
the right values are (45,45.26,0)

So, the calculations of tilt are affecting the pan and vice versa





Posted By: SeaCancer

Re: Simple but annoying Bug VEC_ROTATE - 03/15/12 15:03

Ops, I forgot to say that ang_rotate will do the same error
Posted By: Tobias

Re: Simple but annoying Bug VEC_ROTATE - 03/15/12 21:07

In a 3 dimensional rotation, rotating a vector changes all angles unless in special cases when the vector had only one nonzero coordinate. Look for "Euler angles" the manual, there you find how a 3D rotation is defined. vec_rotate has certainly no bug, this is just normal math. I dont know what you want to do but maybe you want a relative rotation and not a absolute? You need ang_add then. Look in the manual for examples.

For your own safety I move this out of the bug forum laugh - people use vec_rotate a thousand times since 10 years all in their projects and would kill you if it suddenly behaved different and all the projects would not work anymore.
Posted By: maslone1

Re: Simple but annoying Bug VEC_ROTATE - 03/15/12 21:39

Don't say `kill` :-) . Just terminate :-)
Posted By: SeaCancer

Re: Simple but annoying Bug VEC_ROTATE - 03/26/12 15:35

Hi Tobias, Hi maslone1


ang_add did the same frown

my background in math is good, look I will tell you something, Just try it:

set a vector to the value of: (10,10,10);
by logic the absolute pan is 45 and the tilt is 35.26

NOW, rotate it 30 pan and 10 tilt
the new angles will be: 81,42,0 this is totally wrong!

OR:
asume that I want to increase the tilt only, to rise the camera as example, VEC_ROTATE will change my pan,, why?? I want the pan angle fixed

I solved this issue by adding 2-3 lines of code, but I am writting this for other users
the right values are (75,45.26,0)
© 2024 lite-C Forums