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.

Code Snippets / [DBP] Complete Global Rotation

Author
Message
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 14th Aug 2009 03:44 Edited at: 14th Aug 2009 03:45
Many of us have experienced problems with the fact that Dark Basic always does local X rotations on objects.

Well, here's my solution.

It basically works by taking the position of any vertex on an object, and treats it as a vector. Then, it rotates this vector 3 times, one for each axis, by multiplying it with a rotation matrix. Then, it simply repositions the vertex, and voĆ­la - global rotation!

I knew I'd never have to resort to buying EZ Rotate.


Here's the code. The function to use it very simple: almost like the DarkBasic command, except you don't put in an absolute value for rotation, but a relative one. In other words, it will constantly rotate your object by this value if you put it in the loop - just like with the local rotation ones.



Tell me of any problems and/or improvements you can think of.

Cheers



[Edit]

Damn. Not posted here in a while and forgot to put it as [DBP]. Could a mod fix this please? Thank you.
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 14th Aug 2009 16:53
Quote: "Many of us have experienced problems with the fact that Dark Basic always does local X rotations on objects."


Not sure what you mean. DBPro uses Euler angles which represent a rotation across all 3 axis relative to the global frame, they are done in the order of X, Y then Z. Thus from the initial frame, X is globally rotated which will appear to be the same as doing a local X rotation from a global Euler rotation of 0,0,0 but otherwise it wouldn't, so what's the problem you're trying to fix/overcome?

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 14th Aug 2009 18:11
Run this code:



Use the arrowkeys to rotate the cube. Notice when you Y rotate, it always rotates around the global Y axis. It's not the same case with the X axis. That's the problem I'm trying to overcome.
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 14th Aug 2009 22:50 Edited at: 16th Aug 2009 01:13
I feel bad for ruining your work a little, but LowerLogic once coded these rotation functions:

(fully copied from the .dba he provided)


It includes local, global and custom axis rotations and uses the DBP Euler angles (no vertex magic).

Ron Erickson
Moderator
21
Years of Service
User Offline
Joined: 6th Dec 2002
Location: Pittsburgh, PA, USA
Posted: 14th Aug 2009 22:55
Quote: "I knew I'd never have to resort to buying EZ Rotate."


Global rotation is available in the FREE version of EZrotate (plus a lot more)

The Enhanced version of EZrotate does much, much, more than just global rotation.

Also, I just did a quick speed comparison. Using your method took about 750 miliseconds to perform 10,000 times. To do the same thing in EZrotate (which includes setting up EZrotate, checking for keypresses, applying rotation, and rotating your object to EZrotate's results) takes about 15 miliseconds to perfom 10,000 times.


a.k.a WOLF!
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 14th Aug 2009 23:13
Hello.

Sven, that's pretty cool actually. Way over my head though, haha.

Ron, didn't know that! I was just kidding anyway, haha. I knew it's much more feature rich than mine. Mine naturally is slow because of having to loop through all the vertexes. It's the only way I could figure it out.

By the way, is EZRo available for DarkGDK?

Thanks
Ron Erickson
Moderator
21
Years of Service
User Offline
Joined: 6th Dec 2002
Location: Pittsburgh, PA, USA
Posted: 15th Aug 2009 03:53
No problem Zotoaster!

I can remember a couple people not being happy that there was a not-free version of EZrotate. They would ignore the fact that there IS a free version of it. When you said you knew you wouldn't have to "resort" to buying it, I just wasn't sure if you were one of the few that I mentioned above.

This is one of those problems that are very difficult to wrap your mind around how it all works. So kudos to you for coming up with a solution (even if it is slow). A working solution that is on the slow side is MUCH better than no solution at all.

I don't have a free version of EZrotate available for DarkGDK. I just never got around to putting one together. There is a not-free version. If you buy EZrotate for DBpro, you get the DarkGDK version too.

Ron


a.k.a WOLF!
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 15th Aug 2009 05:17
Quote: "Use the arrowkeys to rotate the cube. Notice when you Y rotate, it always rotates around the global Y axis. It's not the same case with the X axis. That's the problem I'm trying to overcome."


Looks fine to me. I think I see what you're doing though, you're trying to add global rotation to the object rather than simply set it as Rotate Object does.

Login to post a reply

Server time is: 2024-05-05 04:55:04
Your offset time is: 2024-05-05 04:55:04