Scripts / Fixing wobble on 'Z' axis?

Author
Message
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 1st Aug 2020 23:30
Anyone know how to fix the wobble or opposite tilt
when rotating objects on the 'Z' axis?
Example;
An object is rotated 45 degrees on the 'Z' axis.
Then you rotate it around 180 degrees on the 'Y' axis.
Now the object is opposite rotation on 'Z' axis...

How could someone work with the object in that regard?!
Thanks.
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 1st Aug 2020 23:59
That's how Euler angles work, that's why you need to use Quaternions for rotation.

Read up about it on the web there are plenty of sites that will explain it to you in gory detail.
Been there, done that, got all the T-Shirts!
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 24th Dec 2020 16:32
Hmmm... looked into this the other day, to see what I can see.
There's a few sites that tackle this issue, how to break the gimble lock when rotating
objects 3D, but I can't seem to translate their postings and make it work in GG lua.
But I threw together a test script for the Quaternion library, trying to convert Euler to
Quaternions. Problem is, it did nothing... and I realize now that all I am doing is flipping
values around-- but actually not accomplishing any Q. usefulness.
Anyone found one of those sites that will show the formula to translate into GG lua?

I have only a few weak, basic math brain-cells, so this video seems good for a professor
of higher math. https://www.youtube.com/watch?v=zjMuIxRvygQ


PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 24th Dec 2020 17:10
what are you trying to do with it? maybe you can just use the RotateX / Y / Z commands? these are local so you won't have to worry about the maths
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 24th Dec 2020 17:42
Assuming xa, ya, za are an entities current angles (as returned by GetEntityPosAng for example) then:
local deg, rad = math.deg, math.rad

local q1 = Q.FromEuler( rad( xa ), rad( ya ), rad( za ) )

local q2 = Q.FromEuler( <angles to rotate by> )

local fq = Q.Mul( q1, q2 )

xa, ya, za = Q.ToEuler( fq )

RotateObject( objId, deg( xa ), deg( ya ), deg( za ) )

Is the code you are looking for.


Been there, done that, got all the T-Shirts!
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 24th Dec 2020 17:45
So for example if you wanted to 'roll' by 45 degrees the <angles to rotate by> bit would be 0, 0, rad( 45 )
Been there, done that, got all the T-Shirts!
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 24th Dec 2020 17:54
"what are you trying to do with it?"
Trying to rotate an object (plane for example) around any of 360 degrees,
with it banked left or right ('z')-- also climbing or diving ('x') and not gimble
lock (ie wobble).
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 24th Dec 2020 18:44
Alrighty, plugging them in now...
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 26th Dec 2020 20:41
Update;
So... this did create a quaternions rotation (at least I assume that it did since
that's the intent)-- and I see two different rotation patterns.
It just didn't "make all my dreams come true!" lol
I don't know how to incorporate this into the task as outlined. I came across
this conundrum also in Google searches that quaternions aren't the end all
solution-- that a q. angle doesn't auto-magically create an angle your object
needs, but more consideration is involved.

It seems like you have to kinda split or mesh euler and q. angles together in
a complex equation or hard regulation to get a proper winged flight effect...?
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 26th Dec 2020 22:58 Edited at: 26th Dec 2020 22:59
To specify the actual orientation of an object in GG you have to specify it in Euler angles in degrees. (world coordinates)

To specify a rotation quaternion you need to first work out what rotation you want, then specify that in the Q.FromEuler call. i.e. pitch angle, yaw angle, roll angle (in radians)

So if you start off with your known orientation (i.e. from GetObjectPosAng call) in degrees Euler, convert them to radians and then create a quaternion from those angles.

Then create a second quaternion specifying the rotation you want to apply.

Then use Q.Mul to generate the resulting quaternion from rotating the first by the second.

Convert back to Euler angles, convert to degrees and call RotateObject to apply the final orientation to the object.

IOW, the code I gave above.

You still need to check for Euler gimbal lock condition, this occurs when the Y angle is very close to 90 or -90, I usually check for > 89.99995 or similar. The simplest way of avoiding gimbal lock is to not apply the RotateObject call when you detect it, i.e. simply apply whatever the old angles were. This does create a subtle jump across the 90 E/W line but it is not very noticeable.

The "Forward' direction of an object is the +Z direction btw, if it is facing in any other direction then the above isn't going to look right. In that case stick the model in a 3D modelling app and rotate it to face the right way.

Another 'gotcha' to watch out for is that GG automatically rotates characters to face the player, i.e. their "forward" is the -Z direction, also make sure there is no rotation specified in the fpm file cos that can cause confusion as well.
Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 27th Dec 2020 10:50 Edited at: 27th Dec 2020 12:08
is this for smooth rotation (i.e. slowly rotating an object in game) or is it for instant rotation (i.e. can allow big jumps in rotation)?
edit: also noticed the RotateX/Y/Z commands are not local anymore, must have got bugged during one of the updates
assuming the Rotate commands worked correctly this is how it should work
press Q/E to do barrel roll, F/C to flip and A/D to turn

but as i say, it doesn't work correctly as the Rotate commands are not working as intended - probably something to do with being updated to Max's system
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11

Attachments

Login to view attachments
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 27th Dec 2020 14:29
If the Rotate commands ever worked properly I wouldn't have needed to develop the quatlib in the first place!


Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 27th Dec 2020 16:04
Quote: "If the Rotate commands ever worked properly I wouldn't have needed to develop the quatlib in the first place!"

lol, nah your libs are great but the rotate commands did used to work - they're just tricky to use as they require knowing the fps (which is something GG doesn't actually give) and any fluctuation in FPS causes the rotation to come out of sync (hence why i reset the rotation after a full spin) and they don't really work for instant rotation as they're intended for visual rotation over multiple frames.
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 27th Dec 2020 17:57
"IOW, the code I gave above."
Yes! Thanks, great- using that. But am I missing something else?
The gimbal lock I don't think is the issue...?

If you guys would indulge me and try this script?
It's what I am using to test all this with. I placed the little pallet
looking bridge segment in the map; //bridges//wood bridge mid//

First I turn the object on 'x' axle and a little 'z' axle then control is selected for 'y' ...
of course as it's rotated, these angles get all over the place.
But this is what I'm seeing:




PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 27th Dec 2020 19:32 Edited at: 27th Dec 2020 19:33
3 degree rotation per frame?

That's a bit high, that would be 180 degrees per second at 60 FPS!

The quaternion code looks fine, you should simply see the entity rotating around it's Y axis very quickly. Assuming you have physics off for the entity! If not you'll need CollisionOff( e )/CollisionOn( e ) around the SetRotation command.
Been there, done that, got all the T-Shirts!
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 27th Dec 2020 19:51
@smallg
Yep, everything's just fine if your object is rotated a complete 360 in one
plane (axis). The task is to try to rotate an object 30 degrees on the 'x',
20 degrees on the 'z', and then spin it continuously on the 'y' axis while
still at the other angles --without a sine-wave wobble effect.
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 28th Dec 2020 11:39
Quote: "Yep, everything's just fine if your object is rotated a complete 360 in one
plane (axis). The task is to try to rotate an object 30 degrees on the 'x',
20 degrees on the 'z', and then spin it continuously on the 'y' axis while
still at the other angles --without a sine-wave wobble effect."

it would work if the commands were working as they used to, however amen's method in your code works fine for your case as long as you follow his guidance
Quote: "3 degree rotation per frame?
That's a bit high, that would be 180 degrees per second at 60 FPS!
The quaternion code looks fine, you should simply see the entity rotating around it's Y axis very quickly. Assuming you have physics off for the entity! If not you'll need CollisionOff( e )/CollisionOn( e ) around the SetRotation command."

i think i adjusted it to 360*GetElapsedTime() and the rotation was very smooth
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 28th Dec 2020 13:47
Quote: "i think i adjusted it to 360*GetElapsedTime() and the rotation was very smooth"


Yes, GetElapsedTime() should give the number of milliseconds the previous frame took to complete so is a good way of making things move at the same rate regardless of frame rate.

I'm not sure when that command made an appearance but I recall having issues with it at some point so I do it another way in my scripts.

Been there, done that, got all the T-Shirts!
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 28th Dec 2020 17:59
"however Amen's method in your code works fine for your case as long as you follow his guidance "

Does it? Getting pure quaternions is a crucial step, and VERY nice to know, thanks for the tips! But it's not the end of the procedure! How did the tests of the script I posted go for you? Q. rotation seems it would work great for wheels and sprockets, etc, but not full aircraft 3D rotation. There is still a relational equation when you rotate in 3d-- and include quaternions. Anyone know that equation?

I revised my script to include all 3 axis of rotation-- with quaternions. That by itself
isn't getting proper aircraft / "free flight" style mechanics.

Let me post a video about the goal in mind. He's setting up an airplane. (I already
had all the features he shows here implemented several months ago ), --and found
this video yesterday.
Now we're just missing the proper 3D aircraft rotation of object.
...can just watch minute: 1:00 to 1:30...
https://www.youtube.com/watch?v=lCulq9J0Y9E


PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 28th Dec 2020 19:39


Been there, done that, got all the T-Shirts!
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 29th Dec 2020 20:44
That's cool.
Looks like camera rotations-- which are already set for
quaternions if I am remembering correctly.
Will have a go at it.
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 29th Dec 2020 20:55
Not sure what you mean by that but all angles in GG are Euler.

Every rotation you see in those videos* is done using the same code I posted earlier in the thread, the camera is simply set to either be inside the spitfire or outside and positioned and rotated to follow the plane.

(*not just the plane fuselage but control surfaces, undercarriage, instruments, control yoke etc. In fact the machine gun 'bullets' are aimed using quaternions too)
Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 29th Dec 2020 21:38
Quote: "all angles in GG are Euler."

he's probably thinking of lights which use quaternion rotation.
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 29th Dec 2020 22:32
Eh, lights use vectors.
Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 30th Dec 2020 10:14
either way it's not euler
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 30th Dec 2020 13:56
Cos it's not angles, it's a vector!
Been there, done that, got all the T-Shirts!
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 30th Dec 2020 16:55
Well guys if you want to know my opinion, over a year ago, or probably
about two years! I was trying to get a swimming script working.
[[- a script separate from GamePlayerControl -]]

For some reason all I was aware of was camera angles, and at the time I
swear that they (the 'y') used -90 to 90 through all quadrants... so that it was
impossible for me to get a grasp on how to use them through a full rotation.

There's a thread on that somewhere back there....
Come to find out, if I had just used Player angles, I might have been better off...
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 30th Dec 2020 18:06
Yes, straight north is 0, east is 90 south is 0, west is -90. Those are the Euler angle values for World Y rotation and is why the gimbal lock positions are when facing East or West.

If you specify Y angles outside that range the engine wraps them and as long as the X and Z angles are 0 the outcome is the same, for example if you specify 270 under the covers that is converted to -90.

You have to remember that GG is primarily designed as a FPS so Lee wasn't expecting dynamic entities to have any 'pitch' or 'roll' component as they move around (basically the only character rotation is around the Y axis).

Euler angles are an absolute nightmare to use for anything more complicated than that, which is why quaternions were invented.
Been there, done that, got all the T-Shirts!
PM

Login to post a reply

Server time is: 2024-12-22 02:19:44
Your offset time is: 2024-12-22 02:19:44