Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / So, Why is Z Rotation Global?

Author
Message
Chris Tate
DBPro Master
8
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 6th Mar 2017 03:13
I was wondering why some of my entities where not rotating as expected; and found out that rotating on the Z axis is global and not local like the rotation on the X and Y axis. What's reason for this? If you turn an object left, it turns left, if you pitch it up, it pitches up, but if you roll it right, it rolls east.

+ Code Snippet
While running the provided example code you will notice that while pressing the space-bar key; the object rotates on the Y axis locally, but on the Z axis globally. In other words, no matter what angle the object; rolling it around on the Z axis will pivot the object on the global Z axis.

This is new to me I guess. The solution I am using is to Z rotate the root limb; which rotates locally as you can see when you uncomment the limb rotation command in the snippet.
Derek Darkly
5
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 6th Mar 2017 13:40 Edited at: 7th Mar 2017 12:44
Are you sure that fixed it?
ZROTATE OBJECT 1, I#
ROTATE LIMB 1, 0, 0, 0, I#
When I switch between these two lines they do the exact same thing for me!


[update] Whoops, yes i see what you mean now. I never noticed myself but it has popped up on the forums several times.
Send your parents to noisy sprite demo hell... enter the D-Zone
Chris Tate
DBPro Master
8
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 6th Mar 2017 22:27
So when you press the spacebar, the object will rotate on the Y axis. Once I reach 90 degrees on the Y axis, rotating the object on the object's Z axis spins it from east to west. Doing the same with the limb rotation, the object will spin locally, so that when rotated by 90 degrees on the Y axis, the object spins from south to north, a 90 degree turn from east to west; the behaviour which is local to the object rather than pivoted around a global coordinate space.

If they do the same thing on your version of the language even when rotated 90 degrees on the Y axis; please let me know. Thanks for your time; I'd appreciate your feedback.
revenant chaos
10
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 7th Mar 2017 00:05 Edited at: 7th Mar 2017 00:46
Quote: " rotating on the Z axis is global and not local like the rotation on the X and Y axis. What's reason for this?"

I think that when multiplying rotation matrices for the world matrix,"new" rotations are applied globally to the rotations that come before it. DBPro uses XYZ rotation order by default. In my recent work with skeletal animation I found limb rotations are performed locally in ZYX rotation order. You could try using set object rotation zyx but then X rotation would always be applied globally. The pitch, turn, and roll commands might be what you are looking for, but they don't play nicely with the other rotation commands. If you need to switch between local and global rotations, something like the ezrotate plugin might be your best option.
Shrimpalimpa
User Offline
Joined: 7th Mar 2017
Location: Idaho
Posted: 7th Mar 2017 05:21
I really feel like EZrotate is the way to go (note: I've never used EZrotate). I once tried to make an FPS game starring a spherical man on a quest of some sort and I spent 2 months trying to figure out how to program the ability to look up. I tried to use trigonometry, different commands, and looking in forums but nothing worked. However, I did find out how to make an object orbit around another one pretty well (thanks to my trust in the POINT OBJECT command, so I guess that counted for something).

Not being able to look up because of the whole global rotation is actually what killed that project for me. If I were to get back into it, I would probably just try EZrotate like Revenant Chaos said. Good luck!
Chris Tate
DBPro Master
8
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 8th Mar 2017 01:13
It is really wield. In one vehicle prototype I built, the vehicle rolls as expected; but in another it does what happens in the cube example provided. I think I have the free version of EZrotate somewhere on my system, I will try what you all suggested revenant chaos.

It is a real shame you encountered that look up problem Shrimpalimpa; I have found no problem using X rotation commands to get the characters to look up; perhaps you problem is the reverse of what I am experiencing where in some circumstances an object simply does not roll as expected.

Derek Darkly, indeed the issue has been mentioned in the past; I was not expecting the problem to occur in the game because of the Z rotation working in a prototype.
Derek Darkly
5
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 8th Mar 2017 23:43
Quote: "Derek Darkly, indeed the issue has been mentioned in the past; I was not expecting the problem to occur in the game because of the Z rotation working in a prototype."



I'm calling "good use of semicolon" there.

Yeah, I've learned (from Chafari i think) that using Limb zero is also best when trying to resize an object. And now for rotating too!
All in all DBP is imperfect, but the possibilities are still there. (Evochron, for example! I think that's the right title.)

However, Pasky's 20-liner chess is still the most impressive DBP code I've seen. I love minimalism. Something from nothing impresses me greatly.
Whoops.. I'm rambling now....

Send your parents to noisy sprite demo hell... enter the D-Zone
Chris Tate
DBPro Master
8
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 9th Mar 2017 01:47 Edited at: 9th Mar 2017 01:48
Well, the oils used on the somewhat delayed Last Supper painting by Leonardo DaVinci may not have been optimal, but a work of art is a work of art whether large or small, often the smaller paintings carry the most historical value. Applying that to games, you will find that the top industry performers which stand the test of time where not built with the best tools on the market.

The Z rotation command is inconsistent, but this is not quite a brick wall. It can work with certain objects constructed a certain way, I have seen flight simulations and my own prototypes work with object Z rotation; but on this occasion it did not. Something corrupting the 3D structure is causing a untimely discrepancy. Using low-level matrix rotation will even produce the incorrect result.

Oh well, no matter; of the many problems encountered, this is the only problem I cannot solve, so who's complaining. Luckily I do not need to solve it to finish the job. No matter what kind of long-term project be it video game development running a local pub, encountering such brick walls and crappy situations is part of the experience; working around such restrictions and flaws is part of what we do; right Derek?
Morcilla
14
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 9th Mar 2017 10:51
I strongly advice to use absolute rotations for the object set up only, just after it is created.
An object is usually rotated during set-up to give it an absolute alignment with your game main XYZ axis, using the global rotation Xrotate, Yrotate and Zrotate commands.

Sometimes it helps to change the rotation axis order of the object, to obtain the desired results, with Set Object Rotation ZYX and such, mainly due to Gimbal lock rotations.
Once the object is pointing to the global desired direction, perform a Fix Object Pivot command to make the changes permanent.

All other run-time rotations, like handling a plane in a flight simulator, should be performed with local rotations commands, Turn, Pitch and Roll, mainly to avoid Gimbal lock again, but you'll have to decide at your code what local rotation is performed first, second and third.

EZRotate of course can be very useful, and should allow even more freedom degrees with the local rotations of an object, but in most common scenarios it shouldn't be strictly needed.
Chris Tate
DBPro Master
8
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 10th Mar 2017 04:34
That was informative and helpful; thanks for the advice. I will give it a go.
Rudolpho
11
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 12th Mar 2017 15:58
What do you mean with "global" and "local" rotations?

If you rotate an object on its own, the rotation is global (unless said object is glued to another one in which case the rotation will be relative to that object's/limb's transform).
By default, DBPro rotations are applied first around the Z axis, then Y and finally the X axis. As revenant chaos pointed out you can inverse this to instead use XYZ application order if you want to, or do the math yourself and manually set an object's rotation matrix.
In the default case this then means that your Z-rotation will always be around the cardinal Z-axis, while the Y rotation will be local to the rotation around the (global) Z-axis and the X-rotation relative to the object's rotation around the Z and Y axes. The object's transform is applied prior to the root limb's so you can have that one's Z-rotation be relative to the XY (and of course Z too if you have any) rotation of the object. However if you put all rotation on the root limb you will end up with the same situation where the Z rotation is done first and so on.

I'm unsure whether this is the actual problem you're hinting at here though, so sorry if I misunderstood.
Morcilla
14
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 13th Mar 2017 11:45 Edited at: 13th Mar 2017 15:12
Quote: "What do you mean with "global" and "local" rotations?"

Global or absolute rotations are performed with the XRotate Object, YRotate Object and ZRotate Object commands, that must be feed with an angle measured against the main XYZ coordinate frame.
Global rotation of an object can be found out with the Object Angle X, Object Angle Y and Object Angle Z commands.

Local or relative rotations are performed with the Turn Object Left, Turn Object Right, Pitch Object Up, Pitch Object Down, Roll Object Left and Roll Object Right commands.
These commands take any angle given for rotation as an angle measured from the object current orientation, and using the object local XYZ axis as reference.
As stated at the DBPro user manual for local rotation:
Quote: "The rotation is independent of any axis orientation and allows free motion. The value of the angle can be positive or negative. The object number must be specified using an integer value. The angle must be specified using a real value. Be aware that you cannot use EULER ANGLES in combination with this command. Euler angles are accessed with the ROTATE OBJECT command, whereas Freeflight commands are accessed with the TURN, PITCH and ROLL commands."


To comment that, as it says, it is not recommended to mix both rotations types at run-time. So, I would always setup the object with global rotation and then (after fixing object pivot) use local rotations for the game play.

In practical coding, it is only needed one of each local rotation commands, let's say for example, Turn Object Left, Pitch Object Up and Roll Object Left, and feed them with positive and negative values. Negative angles make these work like their opposite (Turn Object Right, Pitch Object Down and Roll Object Right).

More tips would be to apply control over the local angles with the use of variables. Since there is no command to return local rotations angles, always use a variable to pre-calculate the angle for the next frame, and to have the current local rotation stored somewhere.
Chris Tate
DBPro Master
8
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 16th Mar 2017 12:36 Edited at: 16th Mar 2017 12:37
Rudolpho I was mistaken. Now I understand that there is an ordering system implemented.

At the time I did not think that these were global rotation commands because the first two axes could be rotated locally using X Rotate / Y Rotate but not the third. But that is as you stated because of the ZYX order. As can be seen if we replaced Z Rotate with X Rotate and held down spacebar in the example would rotate object on its local X axis no matter what angle it is on the Y, but not the other way around.

From a 3D modelling standpoint there is usually no ordering; if I use local rotation commands in a 3D editor such as Blender or Valve Hammer ; I get local rotation on all 3 axes. If I use global rotation on all 3 axes, I get global rotation, no matter what order. Here, we have this ordering system.

I stopped using the relative Turn/Pitch/Roll Object commands because I need to work with absolute angles; things are loosely coupled and I need to keep a record of auto-steering/aiming angle changes.

Now I am using the solution Morcilla suggested and will be using the physics system to perform more of the vehicle's simulation.

Login to post a reply

Server time is: 2017-07-20 21:36:19
Your offset time is: 2017-07-20 21:36:19