Math for Game Developers - Rotation Quaternions

Поділитися
Вставка
  • Опубліковано 26 жов 2024

КОМЕНТАРІ • 95

  • @dbuezas
    @dbuezas 10 років тому +112

    Very intuitive explanation! I can finally slerp myself into bed without gimbal locking my neck.

    • @lilcatfriend4575
      @lilcatfriend4575 5 років тому +4

      I know this is an old comment but this has to be the best comment on youtube

    • @dbuezas
      @dbuezas 4 роки тому +1

      @@lilcatfriend4575 Don't ask me how I got back here, but thanks

    • @fishasses
      @fishasses 2 роки тому

      @@dbuezas maybe u can find your way back again

    • @levuong6502
      @levuong6502 Рік тому

      im dead 🤣🤣🤣

    • @dbuezas
      @dbuezas Рік тому +1

      @@fishasses long term review: still no gimbal locked neck. Much superior than the euclidean brand

  • @CMDrRedstone
    @CMDrRedstone 3 роки тому +2

    I spent too long trying to wrap my head around this concept and got it instantly the moment you explained it. Thank you so much!

  • @loreleidavinsky6970
    @loreleidavinsky6970 3 роки тому +1

    the simple approach of picking examples and examining predicted output is what got me to a working implementation of Quaternion rotations. Thank you so, so much!
    Edit: Also, normalization lol

  • @shakaama
    @shakaama 10 років тому +224

    oh screw this, i'm going to be a stripper.

    • @ImpalaSS1996
      @ImpalaSS1996 10 років тому +11

      Omg I almost spit out my coffee - LOLOL!

    • @DXenakis
      @DXenakis 6 років тому +1

      axaxxaxaaxxa

    • @bakdiabderrahmane8009
      @bakdiabderrahmane8009 5 років тому +1

      you almost got me killed with this i can't laugh because every one is a sleep

    • @Eleyvie
      @Eleyvie 5 років тому +25

      But you'll still need to calculate your rotations around the pole. :-)

    • @yagizugur6942
      @yagizugur6942 4 роки тому +3

      I wonder what are you doing for now ? Stripper or game developer

  • @rdmmuller
    @rdmmuller 10 років тому +4

    Dude. This video is kahn academy status. Your pragmatic explanation clearly imparted an intuitive knowledge of quaternions. I would consider myself an experienced 3d game developer. Keep up the good work. Matrix math will forever only make me mildly flaccid.

  • @caesarcch3879
    @caesarcch3879 7 років тому +2

    Thank you, thank you, thank you, you are a legend, I wasted three hours fixing my code, and at the end found that video, thank you again!

  • @Math_oma
    @Math_oma 8 років тому +4

    Nice video on the quaternions. I dabble in quaternion and hypercomplex number stuff from the pure mathematical point of view and it is indeed difficult to understand why multiplying quaternions together in the right way gives a rotation. The best I've been able to do, and this only fairly recently, is start at the Rodrigues rotation formula and show how one can algebraically get to the formula using quaternion multiplication.

    • @JorgeVinoRodriguez
      @JorgeVinoRodriguez  8 років тому

      Lately I've been subscribing to the geometric algebra way of doing things, with pseudoscalars.

    • @Math_oma
      @Math_oma 8 років тому

      I'm currently reading about geometric algebra and it seems like a fascinating topic from the little I've read. I'm a big fan of the bivector and wedge product concepts.

    • @APaleDot
      @APaleDot 4 роки тому

      @@Math_oma
      Damn, this conversation is some expert foreshadowing...

  • @HartleySan
    @HartleySan 10 років тому +6

    This is the best explanation of quaternions I have seen yet. Also, I kept thinking that you sound like Owen Wilson, which cracked me up. Like you said though, I'm still having trouble fully visualizing the concept of a "four-dimensional hypersphere". Yikes!

    • @JorgeVinoRodriguez
      @JorgeVinoRodriguez  10 років тому

      Yeah that's a tough one. A circle is a two dimensional shape where every point is the same distance from the center. A sphere is a three dimensional shape where every point is the same distance from the center. A hypersphere is a four dimensional shape where every point is the same distance from the center. They're all the same thing but different number of dimensions. Obviously you can't think in four dimensions so you just have to use your imagination for the 4D version.

  • @JorgeVinoRodriguez
    @JorgeVinoRodriguez  11 років тому +1

    There are 360 degrees in a circle, and 2pi radians in a circle. So I divide by 360 to get a 0-1 normalized value and then multiply by 2pi to get radians. I did that to make it more clear, but if you simplify 2pi/360 (cancel the 2) you get pi/180. Same thing! :)

  • @thomasschobben5427
    @thomasschobben5427 11 років тому

    Thank you ! I was just a little bit troubled about the (angleInDegree / 360 * PI * 2) , I always use the angleInDegree/ 180 * PI version. I understand that you used it to explain the Degree-> Radian conversion

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

    a super nice video!!

  • @Xardas105
    @Xardas105 4 роки тому +1

    Better optimization would be a*0.5 instead of a/2, division requires 24 cpu cycles while multiplication only uses 2.

    • @HoD999x
      @HoD999x 2 роки тому

      did you test that? i would expect compilers/cpus to optimize this for you. also, both are floating point operations....

    • @Xardas105
      @Xardas105 2 роки тому

      @@HoD999x Nope, just saying it as a technicality, but it doesnt matter anyways. Won't be a difference with todays CPUs anyways, doesnt really matter.

  • @DavePoo
    @DavePoo 10 років тому

    10:20 - The angle you are rotating by is actually Tangent( Length(n) / a ) - this angle can't be calculated when a = 0.

  • @FJmus1C
    @FJmus1C 11 років тому

    Awesome Vids! I totally love them and finally am motivated to start playing again.

  • @bvssvni
    @bvssvni 11 років тому

    Thank you! I am trying to learn to use dual quaternions for rigid bodies.

  • @sinx2247
    @sinx2247 6 років тому +1

    so what do i actually do with the quaternion to get the final x,y,z positions of the point that im rotating?

    • @JorgeVinoRodriguez
      @JorgeVinoRodriguez  6 років тому

      Try the next video, I think it will answer your question :) ua-cam.com/video/Ne3RNhEVSIE/v-deo.html

  • @vexedev
    @vexedev 8 років тому

    Curious as to how to turn a rotation encoded in a quaternion to a rotation encoding that OpenGL understands (matrix) for use in the ModelToWorld matrix. Also curious what would happen to the scale values since they're also stored in the 3x3 matrix (first diagonal) that represents the rotation... confused.

    • @JorgeVinoRodriguez
      @JorgeVinoRodriguez  8 років тому +1

      +vexe The code to convert a quat to a matrix is kinda boring, actually. You rotate the unit x, y, z vectors by the quaternion and then use that as each column of the matrix. You can simplify the math a bit from that and you get something like this: github.com/BSVino/Grotto/blob/master/common/math/matrix.cpp#L266
      Converting the other way, you need to calculate the axis of rotation and degree of rotation, then you construct the quaternion accordingly. For the axis you can probably just get away with a cross product of the rotated vector with the basis vector. For the angle, it's just a little trig. That should do you, but there are faster ways to do it, see: github.com/BSVino/Grotto/blob/master/common/math/quaternion.cpp#L47
      If any of the basis vectors of the matrix are length other than 1 then you'll get an incorrect result in the quaternion. I'm unsure if you can use quats to store scaled values - I imagine yes, but in practice scaling only very rarely happens in games, so quats are always normalized. When you do need scaling, you can apply it separately since both operations are linear.

    • @vexedev
      @vexedev 8 років тому

      +Jorge “Vino” Rodriguez Thanks for the reply. I don't use scaling that often, but it's handy for situations where you have a crate and you want different variations of it, instead of having the artist do different versions you could just scale it. Although I do have to admit this is not the common case and scaling does seem to make other calculations more complicated.
      How about uniform scaling though? does that make things any easier?
      If we build each transformation matrix separately i.e. translate, rotation (via quaternions or w/e) and scale, and then multiply those and give that to opengl, what is the problem in doing that?

    • @JorgeVinoRodriguez
      @JorgeVinoRodriguez  8 років тому

      +vexe I don't think uniform would make it any easier to build the right quat.
      Rotation and scaling are linear so it doesn't matter what order you do those two in, but when you add translation into the mix it becomes noncommutative, so you have to be careful. Usually I find it easier to think about it conceptually if you do the translation last. I have some other videos where I do this.

  • @jovanrakocevic8263
    @jovanrakocevic8263 7 років тому

    Would there be any point in using quaternions if I almost never want to roll the camera (or maybe a little, like leaning in fps?). I implemented a camera using them with a lot of headache and i figured in the end my angle was always 90 degrees meaning they never really rolled anywhere. So basically it was pointless...

    • @JorgeVinoRodriguez
      @JorgeVinoRodriguez  7 років тому

      I always encourage people to consider using euler angles in situations where they model the underlying system well. Cameras are well modeled by pitch/yaw/roll, so I tend to use euler regularly in camera systems.

  • @HLanka
    @HLanka 7 років тому +1

    My processor is a Intel dual core x64. I'm using matrices for the rotations of my XNA game. I'm using mesh rotations for animations . When I play for a while(~30s) , The body parts of the human model goes bigger and spin of the world. I could 100% confirm that the translation of matrix is 0. People are saying this is because inaccuracy of the processor. So, Will using Quaternions help to solve the matter? (I'm calling this as "matrix mutation bug")

    • @JorgeVinoRodriguez
      @JorgeVinoRodriguez  7 років тому +1

      When you do many operations on floating point numbers they tend to drift and get slightly larger or smaller. You may be able to fix it by just re-normalizing the matrix columns. Quaternions will also help as they re-normalize themselves automatically.

    • @HLanka
      @HLanka 7 років тому

      Thanks for the reply. But I just fixed it by reconstructing matrices at the edges of animations.

    • @JorgeVinoRodriguez
      @JorgeVinoRodriguez  7 років тому +1

      Great!

  • @slayemin
    @slayemin 11 років тому

    Whoa... how did you do the "copy, paste paste" without selecting the text you wanted to copy and copying it into your clipboard? (around 7:12)

  • @darkexior
    @darkexior 4 роки тому

    Thank you so much

  • @Maikelp
    @Maikelp 11 років тому

    Thank you very much for the videos sir, they're great!

  • @TheoryAndGames
    @TheoryAndGames 9 років тому

    I applied your quaternion multiplication with another vector, but when I see it in actual rotation in the graphics, when trying to rotate the Z axis, everything only goes diagonally..instead of going in circle about the Z axis...any idea?

    • @JorgeVinoRodriguez
      @JorgeVinoRodriguez  9 років тому

      Elvis Machuca Tough to say, are you using an existing quaternion library or did you build your own?

    • @TheoryAndGames
      @TheoryAndGames 9 років тому

      Jorge Rodriguez I tried to convert library into Java.

    • @TheoryAndGames
      @TheoryAndGames 9 років тому

      Jorge Rodriguez after I make the quaternion unit length 1, as you specify...I use this quaternion matrix:
      public CMatrix3f getRotationMatrix(){
      CMatrix3f m = new CMatrix3f();
      m.setVertex(0, new CVector3D(1f - 2f*(v.y*v.y) - 2f*(v.z*v.z), 2f*(v.x*v.y) - 2f*(v.z*w), 2f*(v.x*v.z) + 2f*(v.y*w)));
      m.setVertex(1, new CVector3D(2f*(v.x*v.y) + 2f*(v.z*w), 1f - 2f*(v.x*v.x) - 2f*(v.z*v.z), 2f*(v.y*v.z) - 2f*(v.x*w)));
      m.setVertex(2, new CVector3D(2f*(v.x*v.z) - 2f*(v.y*w), 2f*(v.y*v.z) + 2f*(v.x*w), 1f - 2f*(v.x*v.x) - 2f*(v.y*v.y)));
      return m;
      }
      to multiply it with a vector point, but still, the only axis that seems to work is the Z-Axis everything else pivots the wrong the way. You probably are going to say, that I am missing something....any idea?

    • @TheoryAndGames
      @TheoryAndGames 9 років тому

      Elvis Machuca this matrix comes out of the quaternion class object, converting from quaternion to matrix, so I can do matrix multiplication with a vector point

    • @JorgeVinoRodriguez
      @JorgeVinoRodriguez  9 років тому

      If your goal is just to rotate a vector then you shouldn't have to convert it to a matrix first. I have another video on how to rotate a vector with a quat, have you seen that?

  • @krisitak
    @krisitak 9 років тому

    What is W? I couldn't get it. In which video I can check this out?

    • @JorgeVinoRodriguez
      @JorgeVinoRodriguez  9 років тому +1

      krisitak w is just the fourth component in the four dimensional vector that is the quaternion. It's (x, y, z, w).

    • @krisitak
      @krisitak 9 років тому +1

      Thanks Jorge. I wasn't thinking clearly when I asked the question. I watched it again and understood it. Thanks for the cool tutorials.

  • @francescorizzi2601
    @francescorizzi2601 3 роки тому

    Can someone please tell me how the hell does the unit quaternion have HALF THETA in the formula? I cannot find any simple explanation for this :/

    • @JorgeVinoRodriguez
      @JorgeVinoRodriguez  3 роки тому +1

      Watch this video ua-cam.com/video/eo2HNCTV78s/v-deo.html

  • @TheKthSign
    @TheKthSign 9 років тому

    nice video...but i still couldn't understand the part where you represent (theta, n hat) as the quaternion form (cos(theta/2), n hat * sin(theta /2)..

    • @JorgeVinoRodriguez
      @JorgeVinoRodriguez  9 років тому +1

      Shizumaru18 You want a rotation of theta around the axis n hat, but you have to add the cos and sin in order to make the quaternion unit length. If it's not unit length it will change the length of the vector that you're rotating, which is no bueno. So you add cos and sin to keep it unit length.

    • @TheKthSign
      @TheKthSign 9 років тому

      Jorge Rodriguez Hmm..shouldn't a unit quaternion be (cos(theta), sin(theta) * n hat) = 1 instead of (cos(theta/2), sin(theta/2) * n hat) .. I didn't watch the next video though...

    • @JorgeVinoRodriguez
      @JorgeVinoRodriguez  9 років тому

      Shizumaru18 nope it is correct as is. Watch the next videos for the explanation.

  • @carlosgranados9301
    @carlosgranados9301 8 років тому

    Wow this really helped!

  • @usop1239
    @usop1239 6 років тому

    what application for quaternion?

  • @zechordlord
    @zechordlord 11 років тому

    Great idea, these videos!

  • @RivenbladeS
    @RivenbladeS 5 років тому

    Please give code to study it

  • @veggiet2009
    @veggiet2009 9 років тому

    It's interesting how python represents these numbers:
    Quaternion
    Quaternion
    Quaternion
    Quaternion
    Quaternion

    • @JorgeVinoRodriguez
      @JorgeVinoRodriguez  9 років тому +1

      veggiet2009 6.1232 etc is zero. Notice it says e-17 at the end, that means *10^-17 which makes the number very small. The calculations that produced those numbers were slightly inaccurate, which is normal for computers.

    • @JorgeVinoRodriguez
      @JorgeVinoRodriguez  9 років тому +1

      veggiet2009 oh and .707106... is sqrt (2) / 2.

  • @calmsh0t
    @calmsh0t 5 років тому

    I dont get what w is??

  • @deletevil
    @deletevil 4 роки тому

    Sir you rock! :D

  • @OmegaCraftable
    @OmegaCraftable 10 років тому

    Is it sad that I immediately recognised 0.707 as root two over two? :P

    • @JorgeVinoRodriguez
      @JorgeVinoRodriguez  10 років тому +1

      Not sad and actually it's awesome and super useful :)

    • @ronfrancis6012
      @ronfrancis6012 9 років тому

      +Jorge “Vino” Rodriguez
      Well, I recognised it as sin(45) or cos(45), so I got it completely wrong!

    • @JorgeVinoRodriguez
      @JorgeVinoRodriguez  9 років тому

      Same thing though, really! :)

  • @polyspastos
    @polyspastos 4 роки тому

    what a missed opportunity not calling it s hat

  • @JorgeVinoRodriguez
    @JorgeVinoRodriguez  11 років тому

    Hahaha I'll never run out of math.

  • @pipunx
    @pipunx 11 років тому

    Hyperspheres wtf ?!

  • @colinkiama
    @colinkiama 6 років тому

    this video + this video: ua-cam.com/video/jlskQDR8-bY/v-deo.html = Finally, I understand! 😭

  • @jamesrockford2626
    @jamesrockford2626 6 років тому

    "we" lol

  • @NeostormXLMAX
    @NeostormXLMAX 5 років тому

    WTF IS W THAT WAS NOT EXPLAINED

    • @JorgeVinoRodriguez
      @JorgeVinoRodriguez  5 років тому

      Whereas x y z are an axis of rotation, w is the amount of rotation. However, it scales by cos of the angle, so if there's no rotation it's 1 and as you rotate it progresses towards zero.

  • @jonathanxdoe
    @jonathanxdoe 3 роки тому

    Too much ehhh mmm errr. Quite annoying