Scripts / quaternions (again) now a proper Lua module with example script

Author
Message
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 20th Feb 2017 21:33
Simply place the unzipped directory (quatlib_example) into the scriptbank directory, attach the quatrotate.lua to a couple of small crates and enjoy.

Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
Blacknyt46
8
Years of Service
User Offline
Joined: 29th Feb 2016
Location:
Posted: 20th Feb 2017 22:00
Thanks again! I'll have to give it a try.
Jim C
Pirate Myke
Forum Support
13
Years of Service
User Offline
Joined: 31st May 2010
Location: El Dorado, California
Posted: 22nd Feb 2017 17:39
Thank you.
Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz, 2400 Mhz, 4 Core(s), 4 Logical Processor(s), 8gb RAM, Nvidia gtx660, Windows 7 Pro 64bit, Screen resolution 1680 x 1050.

Bolt Action Gaming
GameGuru Tool Maker
10
Years of Service
User Offline
Joined: 24th Oct 2013
Location: Harrisburg, PA (USA)
Posted: 23rd Feb 2017 18:18
Very nice. This will couple well the free vectorial library for lua.
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 23rd Feb 2017 22:11
Vectors are dead easy in Lua, no real need for a library for them, this routine rotates a vector specified as x,y,z values around an origin using Euler angles:


Angles have to be in radians as it compliments the quaternion library which also needs radians.
Been there, done that, got all the T-Shirts!
PM
cybernescence
GameGuru Master
11
Years of Service
User Offline
Joined: 28th Jan 2013
Playing: Cogwheel Chronicles
Posted: 1st May 2017 10:37
@AmenMoses:

This quaternion lib is a great addition to GG - thank you so much. Works really well.

Is there a quaternion to euler calc that works exactly as your library currently does except that it will return the yaw/heading angle in a series range of incrementing degrees?

For example currently the returned yaw angle will return 0-90 degrees for "world" 0-90, then 90-0 for world 90-180, 0 to -90 for world 0 to -90 then -90 to 0 for world -90 to -180. Something to do with using asin for yaw?

This doesn't effect the way the objects are rendered using SetRotation, but it does change the entity y angle so it no longer points in the models 'forward' direction. I know you have vector calcs that compensate for this, but I have a lot of scripts that rely on entity y angle corresponding to front/forward movement of entity - which they no longer appear to after being rotated by quaternions and using SetRotation.

The closest I've been able to get is using this -



However the bank/roll angle only works correctly between -90 and 90 world angle (rolls the opposite way beyond 90), though heading/yaw and attitude/pitch seem ok.

No worries if it can't be done (I may well be missing something too - I'm a quaternion novice) - just thought I'd ask the flight dynamic coding expert

Cheers.
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 1st May 2017 11:59 Edited at: 1st May 2017 15:05
The Euler angles returned are the 'world' Euler angles, i.e. what you need to render the object in GG orientations.

They are not 'yaw', 'pitch' and 'roll'!!

Understanding this is quite tricky.

Usually the restricted angle (gimble lock position) is pitch, think of an airplane, you can't physically 'pitch' more than 90 degrees as that is straight 'up', similarly you can't have a pitch below -90. In GG that restricted angle is the y angle (because z is 'north' rather than 'up' and y is 'up').

In quaternion math qr = qa * qb, qa is the current orientation and qb is the combined pitch, yaw and roll you want to apply to it, qr is then the resulting orientation.

Take a look at the helicopter scripts to see how I handle the problem of real world angles, probably not the neatest way of doing it but it works.
Been there, done that, got all the T-Shirts!
PM
cybernescence
GameGuru Master
11
Years of Service
User Offline
Joined: 28th Jan 2013
Playing: Cogwheel Chronicles
Posted: 1st May 2017 14:35
OK, no worries, I shall work it out. Thanks.

Login to post a reply

Server time is: 2024-04-26 14:27:25
Your offset time is: 2024-04-26 14:27:25