2 registered members (AndrewAMD, juanex),
1,247
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Gimbal Lock
#175374
12/30/07 11:32
12/30/07 11:32
|
Joined: Mar 2006
Posts: 2,758 Antwerp,Belgium
frazzle
OP
Expert
|
OP
Expert
Joined: Mar 2006
Posts: 2,758
Antwerp,Belgium
|
Most of us programmers may have already encountered this annoying problem which is quite hard to get right There is already a topic about arbitrary rotation but it seems this solution only works if the angles are predetermened before runtime and thus changing the angles during runtime will still give an inaccurate rotation around the pan or z axis while tilt equals 90 or -90 degrees. I've tried most methodes like c_rotate with setting the USE_AXISR, inverting the angles for local rotation, using ang_rotate and ang_add but none of it will work. This code gives the most accurate rotation: Code:
var temp2[3]; vec_set(temp,vector(my.pan,0,0)); vec_rotate(temp,vector(-my.pan,0,0)); // local rotation by inverting the angle vec_to_angle(temp2,temp); // converting from vec to ang ang_rotate(test.pan,temp2); // rotating initial angle by entity's pan angle
The result of this code is that the entity rotates around his z-axis (panning) while tilt is 90 or -90 degrees but the rotation is not only around the z-axis but also around his x-axis(rolling) at the same time and too fast as well ^^ All help is welcome Thanks in progress Frazzle
Antec® Case Intel® X58 Chipset Intel® i7 975 Quad Core 8 GB RAM DDR3 SSD OCZ®-VERTEX2 3.5 x4 ; HD 600 GB NVIDIA® GeForce GTX 295 Memory 1795GB
|
|
|
Re: Gimbal Lock
[Re: frazzle]
#175375
12/30/07 19:45
12/30/07 19:45
|
Joined: Dec 2006
Posts: 78 Nevada, USA
Futurulus
Junior Member
|
Junior Member
Joined: Dec 2006
Posts: 78
Nevada, USA
|
What are you trying to accomplish with this -- i.e. what are temp, temp2, and my in this case? I had this problem before because I needed my player to rotate arbitrarily in a zero-G game, but ang_rotate worked pretty well for me. For example, if you want a player to rotate around its own Z-axis (pan), no matter how that axis is oriented, when the D key is pressed: Code:
while(1) { //... if(key_d) { ang_rotate(my.pan, vector(-5 * time_step, 0, 0)); } //... wait(1); }
This might not be exactly what you want though...
|
|
|
Re: Gimbal Lock
[Re: Futurulus]
#175376
12/30/07 20:40
12/30/07 20:40
|
Joined: Mar 2006
Posts: 2,758 Antwerp,Belgium
frazzle
OP
Expert
|
OP
Expert
Joined: Mar 2006
Posts: 2,758
Antwerp,Belgium
|
First of all, thank you for your input Second, I tried this already several times and it indeed works which I knew afront as well but if seems that the rotation afterwards isn't quite accurate anymore when the tilt/roll/pan value of the enitity changes I'm trying to make an entity rotate while standing on a wall so when the normal.z equals 0 and tilt equals 90 or -90 degrees.But I think I'll mesh around with ang_rotate abit more ^^ Btw, 'temp' is a predefined variable such as 'player'. 'Temp2' is a vector I used for putting through the angle towards the entity. 'My' is a predefined pointer I use for this entity. Thanks in progress Frazzle
Antec® Case Intel® X58 Chipset Intel® i7 975 Quad Core 8 GB RAM DDR3 SSD OCZ®-VERTEX2 3.5 x4 ; HD 600 GB NVIDIA® GeForce GTX 295 Memory 1795GB
|
|
|
Re: Gimbal Lock
[Re: frazzle]
#175378
12/31/07 04:58
12/31/07 04:58
|
Joined: Jun 2005
Posts: 656
Grafton
User
|
User
Joined: Jun 2005
Posts: 656
|
It can be done, If I understand correctly what you mean. This DEMO of one of my ongoing projects demonstrates some possibilities and is made without using Julz's quaternions for GS, but I am working on a rewrite that will use that method instead. I would suggest you check into using them.
|
|
|
Re: Gimbal Lock
[Re: Grafton]
#175379
12/31/07 05:16
12/31/07 05:16
|
Joined: Mar 2001
Posts: 3,298 Beverly, Massachusetts
Rhuarc
Expert
|
Expert
Joined: Mar 2001
Posts: 3,298
Beverly, Massachusetts
|
Although a much bigger thing to tackle, it sometimes yields the most sure-shot way to get consistnet and unbreakable results: http://en.wikipedia.org/wiki/QuaternionQuaternions can be used to represent rotation without ugly grimbal lock- the downside is they are more complex and more process intense. You could easily store all of your angle information using quaternions and do your operations there, then convert the quaternion to a euler angle. Just two cents
|
|
|
Re: Gimbal Lock
[Re: Rhuarc]
#175380
12/31/07 05:34
12/31/07 05:34
|
Joined: Aug 2005
Posts: 1,558 HK
vlau
Serious User
|
Serious User
Joined: Aug 2005
Posts: 1,558
HK
|
I have the similar problem too. jumpman has ask this question about 2 months ago, I hope it can be solved with liteC->atan2 but I'm not sure.
|
|
|
Re: Gimbal Lock
[Re: vlau]
#175381
12/31/07 09:24
12/31/07 09:24
|
Joined: Mar 2006
Posts: 2,758 Antwerp,Belgium
frazzle
OP
Expert
|
OP
Expert
Joined: Mar 2006
Posts: 2,758
Antwerp,Belgium
|
@ Futurulus Here's a visual Ignore the numbers, that's for debugging issues. As you can see, the entity is standing on a vertical wall as you have mentioned. I'm trying to let it rotate about its z-axis. I got that part working correctly but say when I want to run up the ceiling or back at the floor. Then the angles will change due to ang_rotate giving an incorrect motion. But I think I'm getting close to a potential solution @ Grafton Thanks for the demo but I was already aware of this as well ^^ Quaternions are indeed the answer but I don't want to use them since I trying to create a wallwalking/ceilingwalking system which only uses 3dgs native angles (Euler). @ Rhuarc The downside you're talking about is also one of the problems. I've thought about using quaternions only when the tilt value of an entity equal 90 or -90. So when other tilt values are reached, using Euler's angles. But it's process intense like you mentioned thus using it only for that reason would be unlogic @ vlau Basically, I know all those topics since this past week, I've spend hours in searching for a solution on this forum. Some were helpful like the one you've mentioned But the only problem is that this code from the manual takes a direction vector into account which is the camera. Since my code is based pure on angles, I can't really use it ^^ About LC, I'm actually more a c-script fan Thanks again for all of your input Thanks in progress Frazzle
Antec® Case Intel® X58 Chipset Intel® i7 975 Quad Core 8 GB RAM DDR3 SSD OCZ®-VERTEX2 3.5 x4 ; HD 600 GB NVIDIA® GeForce GTX 295 Memory 1795GB
|
|
|
Re: Gimbal Lock
[Re: Shadow969]
#175383
12/31/07 16:27
12/31/07 16:27
|
Joined: Mar 2006
Posts: 2,758 Antwerp,Belgium
frazzle
OP
Expert
|
OP
Expert
Joined: Mar 2006
Posts: 2,758
Antwerp,Belgium
|
Indeed But I think there's a methode that can solve it but it's abit a work around ^^ Cheers Frazzle
Antec® Case Intel® X58 Chipset Intel® i7 975 Quad Core 8 GB RAM DDR3 SSD OCZ®-VERTEX2 3.5 x4 ; HD 600 GB NVIDIA® GeForce GTX 295 Memory 1795GB
|
|
|
|