[Tutorial] OPL Rotation with Quaternions

Page 1 of 2 12 LastLast
Results 1 to 25 of 28
  1. #1
    Sorcerer Supreme _Varis_ is offline
    Member +Rank
    May 2008 Join Date
    479Posts

    [Tutorial] OPL Rotation with Quaternions

    If you don't feel like math, use my tool. :P

    http://devcrate.com/repository/.Tool...sions/QGen.exe

    ***********************************

    See the lower half of my post for how to rotate objects by multiple amounts on multiple axes with one quaternion expression!


    ***********************************

    Preface

    This guide is aimed primarily at those who already understand the mathematical concepts at work here. Using this software involves rudimentary knowledge of trigonometry. If you don't know what this is, just stop reading here and go learn that.

    As TheDeathArt has said, don't try to use software that is smarter than you.

    * * *

    Background

    Kal (along with most software that involves the positioning of objects in a 3D coordinate system) utilizes quaternions to determine rotations of objects in the client; traditional Euler rotations using three angles are too ambiguous to be of any use to a computer.

    A quaternion is a set of four values (W X Y Z) that are used in to specify a rotation in 3D space. To specify a particular rotation one needs to determine the axis about which the rotation is being made and the angle by which the object is to be rotated.

    * * *

    The OPL Editor

    The interface of TheDeathArt's OPL Editor consists of:

    -The filepath to the object (figure this one out for yourself)
    -The vertical position of the object in the client (self-explanatory)
    -Four fields labeled W, X, Y, and Z (the quaternion components)
    -The scale of the object (again, self-explanatory)

    To fill out the filepath, vertical position, and scale, all one needs is a very basic knowledge of Kal. The actual rotation of the object requires some thinking, and in some cases involving rotation in multiple directions, complex multiplication of quaternions (this is slightly more difficult than single rotations, they just take more time). I'll be dealing with that in a later guide; although most rotations dealt with in the Kal client are single quaternions, such as those used for rotating buildings and other objects along the Z axis only.

    Each quaternion, as I mentioned before, has four components: W, X, Y, and Z. W determines the angle by which you will be rotating the object. W is cos( θ / 2 ). X, Y, and Z define the axis around which the object will be rotated. They reference a point on the unit sphere (for those of you who have not taken trigonometry, this is just the unit circle in three dimensions). A line segment is drawn from the origin to this point, and that becomes the axis around which the rotation occurs. X, Y, and Z are all multiplied by sin( θ / 2 ).

    Thus:

    W = cos( θ / 2 )
    X = X*sin( θ / 2 )
    Y = Y*sin( θ / 2 )
    Z = Z*sin( θ / 2 )

    So a rotation of 30 degrees about the z axis (0 0 1) would be:

    W = cos( 15
    Last edited by _Varis_; 30-12-08 at 02:57 AM.


  2. #2
    Newbie GrAfIc is offline
    MemberRank
    Jun 2007 Join Date
    12Posts

    Re: [Guide] OPL Rotation with Quaternions

    it doesnt work -.-
    Tested it , objects transforms into anoying lines who appear/disapear all the time...

  3. #3
    Newbie GrAfIc is offline
    MemberRank
    Jun 2007 Join Date
    12Posts

    Re: [Guide] OPL Rotation with Quaternions

    nvm , it does work
    apperantly it doesnt takes . as comma.

    tx for the guide :)

  4. #4
    Member Proven is offline
    MemberRank
    Sep 2007 Join Date
    25Posts

    Re: [Guide] OPL Rotation with Quaternions

    I dont know whether this is allowed to ask but how to rotate a object about two axis?

    for example 90

  5. #5
    Member Grimm-D is offline
    MemberRank
    Jul 2008 Join Date
    LithuaniaLocation
    45Posts

    Re: [Guide] OPL Rotation with Quaternions

    sin90 goes for z axis
    sin45 for x

  6. #6
    Member Gallardo1 is offline
    MemberRank
    Jul 2008 Join Date
    32Posts

    Re: [Guide] OPL Rotation with Quaternions

    in your case: θ = 90

  7. #7
    Sorcerer Supreme _Varis_ is offline
    Member +Rank
    May 2008 Join Date
    479Posts

    Re: [Guide] OPL Rotation with Quaternions

    Rotating on one axis, then doing a separate rotation on another axis can get kind of annoying. The way in which this is done is multiplying the actual quaternions together.

    I have a half-done guide on this on my HD somewhere; I'll finish it.

  8. #8
    Member Proven is offline
    MemberRank
    Sep 2007 Join Date
    25Posts

    Re: [Guide] OPL Rotation with Quaternions

    That would be very nice. Thanks for your help.

  9. #9
    aka Reb3lzrr Boarderkoen is offline
    Grand MasterRank
    Aug 2006 Join Date
    boskoopLocation
    669Posts

    Re: [Guide] OPL Rotation with Quaternions

    _Varis_ help me out here. I'm having trouble calculating the Quaternions value for an object with multi- axis rotation.

    In example:
    10 degrees on the X Axel
    45 degrees on the Y Axel
    180 degrees on the Z Axel

    How is this suppose to be calculated?
    X=Sin(10/2);
    Y=Sin(45/2);
    Z=Sin(180/2);
    W=??????

  10. #10
    Sorcerer Supreme _Varis_ is offline
    Member +Rank
    May 2008 Join Date
    479Posts

    Re: [Guide] OPL Rotation with Quaternions

    I've got a writeup of how to do that done. I'll post it tomorrow.

  11. #11
    Grand Master CptKenpachi is offline
    Grand MasterRank
    Sep 2006 Join Date
    ManchesterLocation
    876Posts

    Re: [Guide] OPL Rotation with Quaternions

    so im guessing the W is the 4th dimension?

  12. #12
    Sorcerer Supreme _Varis_ is offline
    Member +Rank
    May 2008 Join Date
    479Posts

    Re: [Guide] OPL Rotation with Quaternions

    No. The i, j, and k are the fourth dimension. They are the imaginary coefficients. All of the unit vectors that can be made with a quaternion fall on a hypersphere. A hypersphere is a four-dimensional figure that we cannot really truly represent in our three-dimensional world. The imaginary parts of the quaternion make up the fourth dimension.

    I did not mention these imaginary numbers because in our case, we can prettymuch ignore them when using quaternions to rotate objects in Kal.

  13. #13
    Sorcerer Supreme _Varis_ is offline
    Member +Rank
    May 2008 Join Date
    479Posts

    Re: [Guide] OPL Rotation with Quaternions

    Added part two.

    Boarderkoen, that should answer your question.

  14. #14
    aka Reb3lzrr Boarderkoen is offline
    Grand MasterRank
    Aug 2006 Join Date
    boskoopLocation
    669Posts

    Re: [Guide] OPL Rotation with Quaternions

    thanks _Varis_ !!

    You just made my day.I've been trieing to understand Quaternions for some time. You just made it simple. Thanks

    Gz reb3lzrr

    //Edit I made an application that caculates the quaternion very easily ( Idk why the numbers a slightly off _Varis_'s numbers in the GUIDE). I'll release if ppl are intrested
    Attached Thumbnails Attached Thumbnails quaternioncalculator.jpg  
    Last edited by Boarderkoen; 10-09-08 at 03:02 PM.

  15. #15
    Grand Master Flohle is offline
    Grand MasterRank
    Oct 2006 Join Date
    GermanyLocation
    1,942Posts

    Re: [Guide] OPL Rotation with Quaternions

    Quote Originally Posted by Boarderkoen View Post
    //Edit I made an application that caculates the quaternion very easily ( Idk why the numbers a slightly off _Varis_'s numbers in the GUIDE). I'll release if ppl are intrested
    I think it's usefull :) and maybe it's faster, too.

    :kisss:interested:kisss:but not for money xD :2gunsfiring_v1:

  16. #16
    Grand Master CptKenpachi is offline
    Grand MasterRank
    Sep 2006 Join Date
    ManchesterLocation
    876Posts

    Re: [Guide] OPL Rotation with Quaternions

    awww man, definately would like this lil tool, spending 10 minutes changing coordinate values for a object all the time, loging in and loging out lots and lots and lots lol.

    definately helpful tool,

    GJ koen

  17. #17
    aka Reb3lzrr Boarderkoen is offline
    Grand MasterRank
    Aug 2006 Join Date
    boskoopLocation
    669Posts

    Re: [Guide] OPL Rotation with Quaternions

    Quote Originally Posted by Flohle View Post
    I think it's usefull :) and maybe it's faster, too.

    :kisss:interested:kisss:but not for money xD :2gunsfiring_v1:
    Quote Originally Posted by CptKenpachi View Post
    awww man, definately would like this lil tool, spending 10 minutes changing coordinate values for a object all the time, loging in and loging out lots and lots and lots lol.

    definately helpful tool,

    GJ koen

    It's definatly faster,, expesialy when calculating multi-axel rotations.

    Ofcourse I'll releases it for free, it only took me a half an hour. And because I see ppl are intrested in it. It will be here on RZ somewhere tomorrow ;)

    Gz reb3lzrr

  18. #18
    Sorcerer Supreme _Varis_ is offline
    Member +Rank
    May 2008 Join Date
    479Posts

    Re: [Guide] OPL Rotation with Quaternions

    Yay, I'm obsolete. This guide took me hours to research, and you wrote your program in 30 minutes. Least I was useful enough to have a programmer make a tool. ^^ /begs for credit

    I made an excel sheet that does what your program does yesterday. Guess I won't be needing to upload it now. :D

    Glad I was able to help you out.

    I will say this though... before you release it, change the , to . in the quaternion output. It may lead people to put it into the editor, which based on what Grafic said, messes things up.

  19. #19
    null zig is offline
    Grand MasterRank
    Jul 2007 Join Date
    685Posts

    Re: [Guide] OPL Rotation with Quaternions

    where can i get the program?

  20. #20
    Your omega Dopestar is offline
    Grand MasterRank
    Aug 2006 Join Date
    the NetherlandsLocation
    3,191Posts

    Re: [Guide] OPL Rotation with Quaternions

    like said it should be on here today, if not he will release it soon

  21. #21
    null zig is offline
    Grand MasterRank
    Jul 2007 Join Date
    685Posts

    Re: [Guide] OPL Rotation with Quaternions

    k thanks dope

  22. #22
    null zig is offline
    Grand MasterRank
    Jul 2007 Join Date
    685Posts

    Re: [Guide] OPL Rotation with Quaternions

    Boarderkoen please give us this tool.
    thanks :D

  23. #23
    Grand Master CptKenpachi is offline
    Grand MasterRank
    Sep 2006 Join Date
    ManchesterLocation
    876Posts

    Re: [Guide] OPL Rotation with Quaternions

    stfu leech.

    go play outside or summin until he puts it up.

  24. #24
    aka Reb3lzrr Boarderkoen is offline
    Grand MasterRank
    Aug 2006 Join Date
    boskoopLocation
    669Posts

    Re: [Guide] OPL Rotation with Quaternions

    Well, a little delay:

    http://forum.ragezone.com/showthread...60#post4062260 their you go

  25. #25
    null zig is offline
    Grand MasterRank
    Jul 2007 Join Date
    685Posts

    Re: [Guide] OPL Rotation with Quaternions

    ty man realy helped me :D



Page 1 of 2 12 LastLast

Advertisement