Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by M_D. 04/26/24 20:22
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (PeroPero), 788 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Gimbal Lock #175374
12/30/07 11:32
12/30/07 11:32
Joined: Mar 2006
Posts: 2,758
Antwerp,Belgium
frazzle Offline OP
Expert
frazzle  Offline 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 Offline
Junior Member
Futurulus  Offline
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 Offline OP
Expert
frazzle  Offline 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] #175377
12/30/07 23:16
12/30/07 23:16
Joined: Dec 2006
Posts: 78
Nevada, USA
Futurulus Offline
Junior Member
Futurulus  Offline
Junior Member

Joined: Dec 2006
Posts: 78
Nevada, USA
Ah... let me see if I understand this.
Quote:

I'm trying to make an entity rotate while standing on a wall so when the normal.z equals 0


Your wall is vertical then...
Quote:

and tilt equals 90 or -90 degrees


...and your entity (a gun turret maybe?) is stuck to the side of the wall, facing either straight up or straight down. Is that right?
Quote:

if seems that the rotation afterwards isn't quite accurate anymore


You probably won't get pinpoint accuracy with 3 decimal places of precision, which is the best a var can manage.

With the bigger picture, though, I still don't understand what you are trying to do. I work better with a visual goal in mind, thinking about a gun turret or a spy camera or whatever. Unless that's proprietary information...

Re: Gimbal Lock [Re: frazzle] #175378
12/31/07 04:58
12/31/07 04:58
Joined: Jun 2005
Posts: 656
G
Grafton Offline
User
Grafton  Offline
User
G

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 Offline
Expert
Rhuarc  Offline
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/Quaternion

Quaternions 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


I no longer post on these forums, keep in touch with me via:
Linkedin.com
My MSDN blog
Re: Gimbal Lock [Re: Rhuarc] #175380
12/31/07 05:34
12/31/07 05:34
Joined: Aug 2005
Posts: 1,558
HK
V
vlau Offline
Serious User
vlau  Offline
Serious User
V

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 Offline OP
Expert
frazzle  Offline 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: frazzle] #175382
12/31/07 12:12
12/31/07 12:12
Joined: Oct 2006
Posts: 873
S
Shadow969 Offline
User
Shadow969  Offline
User
S

Joined: Oct 2006
Posts: 873
Yep, i haven't managed to make aligning to ground work as i wanted. It works perfectly on walls and slopes, but if the wall has a pan non-equal to 0, 90, 180 or 270 aligning becomes innacurate and kinda random

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 Offline OP
Expert
frazzle  Offline 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
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1