Sabzi
12-04-2012, 11:42 AM
So it's not really a math problem, well, kinda ...
I have a little problem with my openGL homework.
I don't want to go into details so I go straight to the point.
We want to simulate the movement of a helicopter which only moves towards it's nose. (yep, fuck physics we got enough of that part in the homework anyway)
So first of course the helicopter is going forward and it's movement vector is (1, 0, 0).
Now we use quaternions to roll/pitch/yaw the helicopter so we got the helicopters quaternion. R for example rolls it with 20°.
The problem is that the formula we use to rotate the movement vector with the quaternion is not working/buggy.
But here it is anyway:
Quaternion temp(0, heli);
//heliQ.Normalize(); //not sure if this is needed
Quaternion a = heliQ.Inverse();
Quaternion b = heliQ%temp;
temp = b%a;
heli = temp.GetAxis();
glutPostRedisplay();
heliQ being the quaternion, heli being the movement vector. We were kinda trying things so maybe it's not pretty. % operator is quaternionXquaternion.
We wrote the inverse part too, we are quiet sure it's okay, but I post it too just in case:
float abs = sqrtf(s*s+d.x*d.x+d.y*d.y+d.z*d.z);
float abs2 = abs*abs;
Vector c = d*-1;
Quaternion temp(s, c);
return temp*(1/abs2);
d is the vector.
We were also debugging this so it's split apart too.
Thanks!
p.s.: How was the code highlight? I remember there was a way to for example c++ highlight, but I don't remember how.
p.s.s: And if you are really curious the physics part of the homework is to follow the helicopter with a camera that is bound to the helicopter by a rubber rope while it's also on a ballon with a normal rope. Balloon is affected by gravity, lift force(whatever in english), and air resistance. Good luck us ...
I have a little problem with my openGL homework.
I don't want to go into details so I go straight to the point.
We want to simulate the movement of a helicopter which only moves towards it's nose. (yep, fuck physics we got enough of that part in the homework anyway)
So first of course the helicopter is going forward and it's movement vector is (1, 0, 0).
Now we use quaternions to roll/pitch/yaw the helicopter so we got the helicopters quaternion. R for example rolls it with 20°.
The problem is that the formula we use to rotate the movement vector with the quaternion is not working/buggy.
But here it is anyway:
Quaternion temp(0, heli);
//heliQ.Normalize(); //not sure if this is needed
Quaternion a = heliQ.Inverse();
Quaternion b = heliQ%temp;
temp = b%a;
heli = temp.GetAxis();
glutPostRedisplay();
heliQ being the quaternion, heli being the movement vector. We were kinda trying things so maybe it's not pretty. % operator is quaternionXquaternion.
We wrote the inverse part too, we are quiet sure it's okay, but I post it too just in case:
float abs = sqrtf(s*s+d.x*d.x+d.y*d.y+d.z*d.z);
float abs2 = abs*abs;
Vector c = d*-1;
Quaternion temp(s, c);
return temp*(1/abs2);
d is the vector.
We were also debugging this so it's split apart too.
Thanks!
p.s.: How was the code highlight? I remember there was a way to for example c++ highlight, but I don't remember how.
p.s.s: And if you are really curious the physics part of the homework is to follow the helicopter with a camera that is bound to the helicopter by a rubber rope while it's also on a ballon with a normal rope. Balloon is affected by gravity, lift force(whatever in english), and air resistance. Good luck us ...