Math in Game Development Summit: A Visual Guide to Quaternions and Dual Quaternions

Поділитися
Вставка
  • Опубліковано 30 кві 2024
  • Sometimes people say "Quaternions are 4 dimensional". They are trying to scare you. It's no more true than "3x3 matrices are 9 dimensional", and no more helpful either. There is a concrete, 3D way to visualize quaternions. In this GDC 2023 session, Hamish Todd dives into how quaternions are created, interpolated, and composed together.
    GDC returns to San Francisco in March 2025! For more information, be sure to visit our website and follow the #GDC2025 hashtag on social media.
    Subscribe to the GDC newsletter and get regular updates via Facebook, Twitter, LinkedIn, or RSS.
    Join the GDC mailing list: www.gdconf.com/subscribe
    Follow GDC on Twitter: / official_gdc
    GDC talks cover a range of developmental topics including game design, programming, audio, visual arts, business management, production, online games, and much more. We post a fresh GDC video every day. Subscribe to the channel to stay on top of regular updates, and check out GDC Vault for thousands of more in-depth talks from our archives.

КОМЕНТАРІ • 75

  • @3DWithLairdWT
    @3DWithLairdWT Місяць тому +35

    I wrote the Quaternion shader library for a FAANG company, and still I found this to be a great and informative presentation where I learned some new things.
    Amazing presentation :D

  • @gregsmith80
    @gregsmith80 Місяць тому +46

    I'm in the first 5 minutes and this has already clarified quaternions better than anything else in the past 10 years.

    • @hamish_todd
      @hamish_todd Місяць тому +9

      Thank you!

    • @lawrenceredmacher4382
      @lawrenceredmacher4382 Місяць тому +3

      I'm 7 minutes in and it's still all just x y and z which are just plain euler coordinates, still no explaining where the "w" comes in...

    • @gregsmith80
      @gregsmith80 Місяць тому +2

      @@hamish_todd I finished the talk and loved it. Really amazing how well you were able to communicate such a complicated topic in such an easily digestible way. Thank you for this!

    • @gregsmith80
      @gregsmith80 Місяць тому +1

      @@lawrenceredmacher4382 w just answers "How much do we spin around the vector XYZ?" and that's laid out pretty early in the video, but really understanding what that means and why we use it is the remaining 40mins or so.

    • @gregsmith80
      @gregsmith80 Місяць тому +2

      @@hamish_todd You showed how we are able to perform a translation using double quaternions and mentioned that they're used in Blender et al. Maybe you said this and I've missed it, but you're saying that if I make something move in a straight line in Blender, it's using a double quaternion under the hood to "rotate" around an axis that's infinitely far away?
      This talk has totally lit my mind on fire. I'll be piecing things together for at least the next few ways. It kinda feels like "Euler's identity over time", if that makes sense. Most explanations gloss over the fact that quaternions aren't really that useful for creating an instantaneous rotation, but one that occurs over time and the emphasis on interpolation made that click for me.

  • @AnkitSinghKushwah
    @AnkitSinghKushwah 17 днів тому +2

    oh man, there was a time when I thought I wish there was a visual tutorial on Quaternions. Quaternion is such a bad boy. No interviewers ever dared to ask questions around that cuz they themselves are not confident how it works. Thank you so much for putting so much passion in this.

  • @atlas4074
    @atlas4074 Місяць тому +10

    This was a great explanation of quaternions and dual quaternions. They finally make sense to me

  • @Comenta-san
    @Comenta-san Місяць тому +31

    me explaining to my parents how playing games is just as constructive as studying math :

    • @trajectoryunown
      @trajectoryunown Місяць тому +11

      Just show them some formulas for Pokemon stat calculations. If that doesn't work, follow it up with a detailed presentation on methods used for encountering or breeding a shiny Pokemon with perfect IVs. Be sure to detail all of the calculations and explain how multi-variable manipulation is absolutely essential in order to achieve the desired outcome. Then draw parallels between that and how your interest in videos game mechanics is actually congruent with their insistence on mathematical studies.
      They'll be begging you to play video games after that.

  • @Edgar-uh5zj
    @Edgar-uh5zj Місяць тому +25

    quaternions. the endboss of rotations.

  • @diribigal
    @diribigal 15 днів тому

    Very nice presentation! I wish there were some combination of this and Marc ten Bosch's "Let's remove Quaternions from every 3D Engine"

  • @bpdhoplite
    @bpdhoplite 26 днів тому +4

    Ive only been programming for a year and Im following everything hes saying. Fantastic presentation here lmao

  • @Baelfyr
    @Baelfyr 28 днів тому

    Amazing talk, really helped me to understand quaternions, just starting my game dev career and i have to say, quaternions are something i need to get use to, but this certainly helped a lot.

  • @sarahlynn7807
    @sarahlynn7807 Місяць тому +3

    This is probably the most useful GDC talk i've seen in a long time.

  • @sleepymushroom9403
    @sleepymushroom9403 Місяць тому

    This was a new interesting topic to get into

  • @FUZASHIII
    @FUZASHIII Місяць тому +3

    Very clearly explained, thank you !

  • @jacobgosen3812
    @jacobgosen3812 18 днів тому +1

    I just want to say Todd that you are so gifted at teaching, this video is a downright inspiration and a testament to the idea that there is no concept too difficult to teach! I am someone who has struggled with Quaternions for years and yet after this presentation it makes complete sense to me, I don't know what dark magic you are using over there but it is working.
    If you ever read this, I hope you have genuinely great day and that life is treating you well.

  • @UlissesSampaio
    @UlissesSampaio Місяць тому

    Great video! Though I wish you had more time to explain how each element of the Double-quaternion works.

  • @torgo_
    @torgo_ Місяць тому +85

    my mommy is letting me use the ipad today

    • @lulairenoroub3869
      @lulairenoroub3869 Місяць тому +5

      You were barely 2
      And it did ask the things we designed it to do
      Now look at you

    • @Cenikid
      @Cenikid 25 днів тому

      Same

  • @rodrigoetoobe2536
    @rodrigoetoobe2536 Місяць тому +10

    "If you cannot build something with a concept you think you understand, you don't understand that concept." -

  • @hampuseden9402
    @hampuseden9402 Місяць тому +3

    I need the second talk

  • @modernsolutions6631
    @modernsolutions6631 18 днів тому +1

    @hamish_todd
    Am i on the right track here?
    I have a tidally locked rigid body on a circular orbit around the origin of the local coordinate system, i can represent that movement as a dual quaterion function of the position over time, where i move the center of rotation along the circular path (sin(r*t),cos(r*t),0) and also do a rotation "in the same (or similar in case of axial tilt) direction" to offset the rotation with a skrewniness so both happen once per orbit (keeping the /2 in mind)?

    • @hamish_todd
      @hamish_todd 18 днів тому

      Humm, you've chosen a slightly difficult example to start with, but perhaps you are working with orbital dynamics?
      "dual quaterion function of the position" - I think you might have misunderstood, because the idea of dq's is that they do rotation *and* position. You may well want a dual quaternion that is a function of time. But you would be much less likely to want one as a function of position

    • @modernsolutions6631
      @modernsolutions6631 4 дні тому

      @hamish_todd
      Let me clarify the relevant bit. I was a bit ambigious.
      I can represent the movement *and rotation* of that tidally locked planet as a dual quaterion function *defining* the position *and rotation* over time
      I do and did want a dual quaternion valued function over time. So the rest of my question remains the same.
      I do not work a lot with orbital dynamics. Having one body orbit another is just the easiest way to get a circular tidally locked movement i can think of. 😅

    • @hamish_todd
      @hamish_todd 4 дні тому

      ​@@modernsolutions6631 Alrighty!
      We are picturing the earth and the moon. The earth is at the origin. The moon is, **before** we apply any transform, *also* at the origin, and our goal is to make a transform that will put it in the correct place and orientation, given time t.
      First, we translate it to a place in its orbit. It is "4" away from earth on average, in units of 100,000s of km. An example of a dual quat that'll translate 4 units in the x direction is 1+2e01. Why 2 instead of 4? Same reason as the angle-halving thing :)
      We now want to rotate the moon around the earth - it will stay tidally locked as we do so because it is as if we are rotating the moon and the line connecting the earth and the moon as a single rigid body :)
      An example of a rotation that'll do this is cos(pi/6) + sin(pi/6)*e13 - that'll rotate by pi/3 radians (because angle doubling again!). But hey, actually we want a function of time, so that's cos(t) + sin(t)*e13, so the time is the angle.
      Now, we *multiply those together*, because we want to move the earth to somewhere in the orbit and *then* rotate it.
      (cos(t) + sin(t)*e13) * (1+2e01) = cos(t) + sin(t)*e13 + cos(t)*2*e01 + sin(t)*e13*e01 (distributivity)
      = cos(t) + sin(t)*e13 + cos(t)*2*e01 + sin(t)*e30 (commuting e13 and e01 and using the fact that e1e1 = 1)
      And that's the answer :) apply that dual quat to the moon and itwill do the correct thing

  • @budgetarms
    @budgetarms Місяць тому +1

    I have seen Hamish Todd give presentations before, really cool.

  • @killavus
    @killavus 28 днів тому

    Is there any chance to get an access to software you're using for demos? I'd love to tinker around with quaternion values to understand them better :).

    • @hamish_todd
      @hamish_todd 25 днів тому +1

      UA-cam won't let me put a link in here... it's "ed" on my github!

  • @JansthcirlU
    @JansthcirlU 28 днів тому +1

    obligatory Geometric Algebra plug

  • @marcthenarc868
    @marcthenarc868 Місяць тому

    I decided to follow this using UE5. While the initial rotations worked fine and are pretty straightforward, doing the Q addition doesn't yield a slanted object.
    FQuat q(0.f, 1.f, 1.f, 0.f); // Which should be the addition of FQuat(0.f, 1.f, 0.f, 0.f) + FQuat(0.f, 0.f, 1.f, 0.f)
    SetActorRotation(q); // All axis are aligned along X, Y and Z, not slanted.

    • @HansPeter-gx9ew
      @HansPeter-gx9ew Місяць тому

      I am pretty sure UE5 (and UNity) internally normalize the quaternions; have you logged the quaternion data just after init?

    • @hamish_todd
      @hamish_todd Місяць тому +1

      A 180 rotation around the axis between (say) x and y will have this effect: it will swap x and y, and it'll send z to -z. So as you say, the axes are "aligned"! Unless I am misunderstanding you.
      Perhaps I shouldn't have chosen that example... try 0,0.8,0.6,0 instead. You'll see that that rotates the thing 180 degrees around an axis that is slightly closer to the axis that gets 0.8 than the axis that gets 0.6.

    • @CyberWolf755
      @CyberWolf755 29 днів тому

      Make sure you are using Quaternions not Rotators.
      In Blueprints, they have a different color and name

  • @JoesCaribbeanVanLife
    @JoesCaribbeanVanLife 22 дні тому +1

    1 minute in and I'm lost.
    P.S. i have a bachelor's in comp animation. 😂

    • @hamish_todd
      @hamish_todd 22 дні тому +2

      Haha the 4D thing? The point of that slide is to say that quaternions are **not** 4D!

  • @meanmole3212
    @meanmole3212 19 днів тому

    Why is the halfway rotation represented in w as 0.7 and not 0.5?

    • @hamish_todd
      @hamish_todd 19 днів тому +4

      Good question!
      If it had been {w=0.5, z=0.5, y=0, x=0} instead of {w=0.7, z=0.7, y=0, x=0}... it would have changed nothing! Both of those are the same rotation. It also would have represented the same rotation if it was {w=0.01, z=0.01, y=0, x=0} or {w=999, z=999, y=0, x=0}. This is what I mean when I talk about the "amount of red paint and blue paint" thing. If you've got 0.5 red and 0.5 blue or 999 red and 999 blue, and you mix them, you always get purple.
      I could have chosen any number. So why did I choose 0.7?
      Because 0.7² + 0.7² ≈ 1, so if you have {w=0.7, z=0.7, y=0, x=0} it's a "normalized" quaternion. These are the "safest" ones to work with. In Unity, you *have* to work with them otherwise things go weird. Outside of unity, it's not super important, but it can be a good idea to keep to normalized quaternions for "numerical stability", which can avoid some obscure kinds of bug 🙂

    • @meanmole3212
      @meanmole3212 18 днів тому +1

      @@hamish_todd Thanks!

  • @WrenKainIV
    @WrenKainIV 24 дні тому +1

    Nice. Didn't understand a thing. Things rotate, I guess. Thank god there are plugins, libraries and templates for these things. Made by people who understand this 😂

    • @hamish_todd
      @hamish_todd 24 дні тому +2

      Oh, sorry to hear! Could you say where I lost you? Were you understanding the part with the 180s, where {x=1,y=0,z=0,w=0} is a 180 around the x axis?

    • @WrenKainIV
      @WrenKainIV 24 дні тому +1

      @@hamish_todd ah don't worry about it. I was a bit exaggerating. Sure I got the whole idea behind the rotations and the simple coordinate systems, but I couldn't resist making a bit of a low effort joke because all the details just fly over my head as a no-code designer. When you have premade extensions for most engines that handle this stuff for you, you end up not appreciating enough the fact that those are built by people who have the brain to understand the topic of your lecture in more detail.

  • @ScaredReferee
    @ScaredReferee Місяць тому +1

    Such a great talk. You can really tell he was a middle school teacher. We need more of those and less "academics" in the videogame industry.

  • @mattboudreaux_pb
    @mattboudreaux_pb Місяць тому

    Amazing presentation. Well done, @hamish_todd.

  • @rameshdevasi6720
    @rameshdevasi6720 18 днів тому

    support Gdevelop software

  • @joseluispcr
    @joseluispcr Місяць тому +1

    You realy should have started this talk with where would i use this stuff

    • @hamish_todd
      @hamish_todd Місяць тому +7

      All game engines 😁

    • @sarahlynn7807
      @sarahlynn7807 Місяць тому +4

      Try to do multiple rotations in 3D without them and quickly bash your head through the wall with things not turning out as you intended.
      Quaternions are essential 3D math.
      It's like asking when you'd use vectors, while living in a world filled with vectors everywhere, every moment you're moving.

    • @ChrisCarlos64
      @ChrisCarlos64 Місяць тому +3

      The candy wrapper effect demonstrates one of the uses. Another is avoiding something known as "Gimbal lock" which you can look up. Overall there are many advantages, just need to do some research on your end if you wish to pursue it, right?

  • @T.R.A.I.N.I.N.G.
    @T.R.A.I.N.I.N.G. Місяць тому

    it's all differential geometry. beautiful, reality and simulated reality both.

  • @sagrgywejhxcvx
    @sagrgywejhxcvx 9 днів тому +1

    why is he hiding?

  • @largeuselessness
    @largeuselessness Місяць тому

    never expect i could see 3b1b in gdc rofl

  • @BoredToBoard
    @BoredToBoard Місяць тому

    Math is short for mathematics; therefore, there is no sense in adding an ‘s, to a shortened form of a word in case you want to provide some context to your UK/Aussie mates lol

    • @koifish528
      @koifish528 Місяць тому +2

      it's not plural, because no british person says "maths are my favourite subject".
      no one treats the full word as plural now that i actually think about it, "mathematics are my favourite subject" is wrong

    • @BoredToBoard
      @BoredToBoard Місяць тому

      You’re right that it’s not plural as mathematics encompasses a singular field of study. I didn’t mean to type so have edited to remove that one misplaced ‘plural, noting I’m traveling and listening to this. However, the adjective mathematic becomes a noun when adding the ‘s’ for mathematics. So, when you shorten mathematics to maths it was an incorrect interpretation of linguistics. Will it change in UK? No, as everyone here uses Maths

    • @trajectoryunown
      @trajectoryunown Місяць тому +3

      @@koifish528 So what you're saying is there's actually no reason at all for saying "maths"?
      +1 Point for America

    • @kierengracie6883
      @kierengracie6883 Місяць тому +2

      Good luck with your studies of stat and math. It would be terribly inconsistent if you abbreviated statistics to stats so I'm pleased to hear that you don't do that. Go USA /s. PS stat are my 2nd favorite [sic] subject lol ;)

  • @Leocesar3D-mx6rm
    @Leocesar3D-mx6rm Місяць тому

    I knew that flat Earth theory was true all along! Take it, all you ball lovers.

  • @arc-sd8sk
    @arc-sd8sk Місяць тому +1

    f*rst

  • @samueldeandrade8535
    @samueldeandrade8535 Місяць тому +1

    0:51 what a awful way to give a lecture. After this statement I realised this guy has nothing to intelectually offer me.

    • @hamish_todd
      @hamish_todd Місяць тому +8

      Give me a chance! See what you think of the first few minutes.
      Like I say, it's not *false* to say quats are 4D. But it's no more accurate than saying 3x3 matrices are 9D. Everyone knows that the second statement would be a useless thing to say, but for some reason they don't apply the same logic to quats.

    • @samueldeandrade8535
      @samueldeandrade8535 Місяць тому

      @@hamish_todd maaan ... it is such a bad decision to start a lecture like that, even antagonizing 3Brown1Blue and Numberphile. Not that I care too much about those channels, I actually dislike 3B1B. But it shows some lack of understanding about the what impress people, especially kids. I can totally agree that just saying
      "Quaternions ... 4 dimensional"
      is, let's say, not enough. A better statement would be
      "a 4 dimensional space that makes us understand 3 dimensional rotations"
      would be better, far better. You could even compare with the 9 dimensional space of 3×3 matrices, that are related to 3 dimensional rotations too. But just criticizing a valid statement AND two known and likable channels that make videos about the subject, is NOT a good idea at all.
      I don't know if I should watch your lecture. I will probably get more annoyed and will annoy you too.

    • @hamish_todd
      @hamish_todd Місяць тому +8

      Grant is a friend of mine and I know James too. I'm fully planning on sending this video to them (when the next one is released). Grant (and Ben, another acquaintance of mine who he made it with) wasn't completely satisfied with his quats explanation.
      I think that even your second statement, "a 4 dimensional space that makes us understand 3 dimensional rotations" is misleading. It's like saying "the space of bacon, lettuce, and tomato sandwiches, including bread, is a 4 dimensional space that makes us understand how to make lunch".
      Completely up to you whether you feel like watching lecture. I understand the reaction. But you won't know what you are disagreeing with unless you watch the first 25m (the rest is about dual quats, not as relevant)

    • @samueldeandrade8535
      @samueldeandrade8535 Місяць тому

      @@hamish_todd well, we definitely disagree. Especially because I think that calling the statement I mentioned as "misleading" is very ... weird, given that quaternions were found because Hamilton wanted to represent algebraically 3D rotations in a similar way he already knew complex numbers represent 2D rotations.
      Loved your comparison though, about space of bacon, lettuce, etc. Hahahahahahaha.
      I really don't see any reason to avoid talking about the 4 dimensionality of quaternions and/or their historically justified relation with 3D rotations.

    • @user-ic5nv8lj9d
      @user-ic5nv8lj9d 24 дні тому +1

      the whole purpose of quaternions is to rotate 3D objects without the issues you usually encounter with matrices, they have a very specific use for 3D and not 4D. i've never seen a single person using quaternions in 4D and that's not the point of it either way.