Spaces & Cross Product • Math for Game Devs [Part 2]
Вставка
- Опубліковано 9 тра 2024
- Part two! let's talk about space
If you are enjoying this series, please consider supporting me on Patreon!
🧡 / acegikmo
00:00:00 - Quick recap
00:01:01 - Dot product recap
00:06:51 - Asgmt. 1 solution (Radial trigger)
00:18:16 - Asgmt. 2 solution (Look-at trigger)
00:35:07 - Questions
00:42:24 - Spaces
00:53:26 - Asgmt. 3 solution (Space transformation)
01:18:43 - World to local
01:34:14 - Matrices
02:15:20 - Cross product
Assignments:
Asgmt. 4 (Bouncing laser)
Asgmt. 5 (Mesh surface area)
Asgmt. 6 (The turret)
docs.google.com/document/d/1N...
Originally streamed as a course for students at futuregames.se/, who were super kind to let me both stream this live as well as upload it here! so massive thanks to the people at FutureGames!!
💖 Patreon ❱ / acegikmo
🐦 Twitter ❱ / freyaholmer
📺 Twitch ❱ / acegikmo
💬 Discord ❱ / discord
🌸 Instagram ❱ / freya_holmer
✫ Video Production by Higher Vision:
➥ / highervision1
➤ Edited by Stelly: / stelly47050876 - Наука та технологія
I found these classes a couple of days ago, awesome stuff! I really like how you present practical use cases for the things you are teaching.
You are a legend I never understood this at uni, so i just moved on and used things, did things but didnt understand it enough to do anything without googling it and seeing someone elses solution, this just made everything super easy in that i can finally work things out myself saving some time!
Thank you so much for this series! :)
This is very informational. Specially the 3D stuff around cross products and how we use them in the games. Thank you Freya
I think I've finally had an "aha!" moment around transformations between coordinate spaces... The key that I was missing was in visualising the basis vectors of each coordinate space as having the same origin, then the transform for "each individual axis" is nothing more than a scaling factor!! Particularly so, since they're unit length.
I had trouble previously understanding exactly why we could multiply a point by the basis vectors of the transform, and for that to somehow manifest as a rotation. (It's wierd, I've learned so much beyond this fundamental principle and only just now "getting" it).
Thanks @Tim, I feel similar; your shared insight was the last piece I needed! "aha"!
When you get that, all the things you thought you knew about GPUs and parallelism come into sharp focus.
3b1b
not importand so thankyou
I've learned more in two days watching these videos than 6 months taking math classes
Thank you so much for the course!
very nice material, thanks for the effort
For those having trouble undeerstanding how the "orientation" and "scale"(the 3x3 part) frorm the matrix change our vector I recommend the first3 videos from "three blue one brown" channel's Essence of linear algebra"(if youre very lazy just watch the 3rd one,but I really recommend all of them) where he has a really nice visualization for this where any vector on the plane is defined as being made up of basis vectors(normal x, y, z vector aka our transform.right/up/forward - except they get normalized in unity) and so if you change basis vectors - you "warp" all defined vectors(space itself!).
This is actually where doing exercise 3 helps a bit as well, as its a good example of this.
The TL;DR version of it is: every vector can be defined as made up of scaled up basis vectors, so for example: a vector (2;3) is actually 2 * transform.right(gives us (2;0) normally) + 3 * transform.up ( gives us (0;3) normally) and if you change the basis vectors to be something else you "warp" all vecots with it.Very hard to explain in words,the animation in that video makes this 100x easier to understand.
Edit: do beware that I think he orientates the basis vector definitions into a column as opposed to the rows we see here, which can confuse people(like me).
Edit2: Nevermind,it was changed in this video as well.(I still find it harder to understand with basis vectors being columns for some reason, cant seem to multiply in my head)
thank you, you are saving my life
Before the video starts, I’m already pushing like! You give us a lot of value! Ever since I found your channel, the concept of online teaching has given me a whole new meaning! Thank you very much! :)
ME TOO!!
man i just love that ,,aha! i finally got it ! ,, feeling !! that's why i like programming.. at first its complicated , but then you have that amazing aha moment where you feel the power in your veins mixed with happines and a feeling of satisfaction
Great stuff!
Hey, many many thanks for this series! Where can I find more assignments or problems to practice this kind of gameplay development? I would like to practice gameplay which includes more math stuff.
Learned a lot. Thank you
Your channel is amazing! Thanks a lot for sharing your knowledge :)
when u started explaining world to local it was so confusing I suddenly forgot all the vector stuff from last video. 🤣
After being confused and banging my head for 4 hours, finally got what Freya did with the space transformations exercise. Thank you.
1:46:56 You're wrong about the forth row of 4x4 transformation matrix as needed for "matrix multiplication to work". You may multiply 3x4 matrix by 4x1 [augmented] vectors without a problem, getting correct 3x1 vectors as result. The reason to have the fourth row is to map points in 3D space to vectors in projective 4D space, so every point on a vector in 4D space corresponds to the same point in 3D space. So for linear transformations you need 3x4 matrix, for projection transformation you need 4x4 matrix.
Your teaching is amazing, love from India
1:31:26 and now I draw tow vectors to visualize the view horizontal of the enemy/player. Instead of just a circle it's now just a part of the circle which can be easily adjusted by the viewAngle. I have been learning those stuff for 2 years, tho I didn't figure that out. it looks like we human need to use more time on thinking of how to use what we learned lol. Btw thanks for those videos. I'll probably watch them all hopefully you have many of them
Freya, you're a very good teacher. That's rare.
really nice videos for people that want an introduction to math in game dev, very cool seeing someone actually explain the math using geometry aswell instead of just numerical representations, altou;
3:34 there is a way to compute the "projection vector" of "a onto b", namelly; "vector v", no nesesity for unit vectors with this projection formula:
(b.a / b.b) . b = v
That formula will give u the projection vector "a onto b" (vector v), where vector "v" is in the direction of vector "b", and the lenght of "v" is independent of the lenght of "b", for example:
if b is scaled by a factor of 3, then the formula would look like this;
(3b . a / 3b . 3b) . 3b = v
if we factor the 3´s we get:
[3 * 3 * (b . a) / 3 * 3*(b . b)] . b
so, as u can see, all the 3´s asosiated to the b´s get canceled and we get the previous formula (b.a / b.b) . b = v
"v" will be dependent on the lenght of "a" sinse thats the vector we are projecting onto b.
This formula is used when u dont know the angle teta.
Thank you, best math teacher~
I agree
Hi Freya, thanks for sharing your knowledge, you are awesome!
I got the same results on converting local position to world position with a different approach.
I made a V2 desiredWorldPosition -> V2 parentToChildPosition = desiredWorldPosition - parent.position -> child.position = parent position + parentToChildPosition.
Amazing video, thank you very much.
Thanks for the great video I would love to see more cross-product videos with practice like how to make hot seekers missile in unity
Watching your vids befor emy calc 3 exam lmao. Super super helpful.
Math with disgruntled cat noises in the background is best math! Thank you so much for doing this, it is so super helpful!!
disagree wholeheartedly about the cat noises .
@@jull1234 Yeah, I've come to hate the cat with a passion during the lectures, so damn annoying.
Thank you learned a lot
Thanks! Useful!
thanks, very useful!
Thank You!
Thank you!
Really good
Really love your series! I tested the transform.Direction function and it doesn't return a normalized Vector, so be aware of that.
ah yeah, looks like the defining feature of it is that it ignores scale, unlike vector, so it keeps the same vector length as the input
I personally never use it because I never have a use case for it, and when I want normalized directions I usually use TransformVector anyway
Thanks!
I fell asleep watching product review videos and woke up to this playing
I love your videos
Insanely smart
Correction: at 1:42:00 Freya says that the x basis is the first row. That's not true. It's the first column. Unity uses column major matrices so that's maybe why it might be easy to make the mistake.
please make a video about field of view effects I really want a depth video about that from you
Just discovered your vids, watched your vid on bezier curves, then went looking for more and found math for games part 1....
ive been doing low level, realtime embedded control applications for donkeys years with NO MATH. I SUCK at math lol... because every time i try learn it i fall asleep listening to someone speak in a language I do not understand.
not only are you very beautiful
"So we don't have to press the play button.. cause that's gross!" :D - love it.
I have to watch these videos with headphones on now because Thor convinced my cat that there's a poor neglected cat friend trapped in my bookshelf speakers, and she keeps trying to bust him out of there.
I just love the way you teach...
Same
@@yudoball same here. Hypnotic
Thor's meows really adds a certain "Je nes sais quoi" to game development.
The 3.c assingment could be to transform a local space of an object to the local space of another object.
You use the 4th row and column of the matrix because translation isn't actually a linear equation, so you do a shear in 4 dimensions instead.
Ed: I just deleted part of this that was ridiculously wrong. My apologies to anyone who read it.
Fantastic videos Freya! . Did you thought on use a 3d app to explain math? ( Blender for example). I always thought that way, would be more visual and less abstract.
I find that they are more clunky and harder to draw freehand in! but I do use Unity when I have to visualize something accurately in 3D
An addendum regarding the optimization in regards to spaces @ ca. 53:11. Instead of just doing everything in local space, it's often better to just pre-multiply all the space transforms into a single transform and uploading that to the GPU in a uniform buffer. Then you just need to compute a 4x4 MVP projection matrix once per frame per rendered object, then this matrix can be used for all its vertices or whatever you need it for. And IMO, this characteristic of linear algebra is its biggest strength; e.g. if you need need to perform a complex chain of transforms (lerping between animation key frames in object space, applying local space transforms, applying world space transforms, etc; then you just need to do the calculation once and then you can re-use the resulting transformation as a single matrix operation millions of times in a massively parallel manner. And this also explains why GPU designs and graphics pipelines are the way that they are and why linear algebra is so ubiquitous in scientific simulations, machine learning, etc. And as a small tangent, this is also one of the benefits with tessellation for rigged meshes since you can apply the more "individual" and complex animation transforms while its in its low poly state and then do the tessellation step afterwards to reap the benefit of not having to do the costlier transforms on a magnitudes greater number of vertices (and instead just have to do much cheaper and more scalable transforms during the tessellation stage of the render pipeline). Of course, there are some less positive trade-offs as well which is why tessellation is slowly being phased out in cutting edge engines like UE in favour of more modern alternatives.
Left hand coordinate system rule
Cross product AxB,
- use left hand, point all fingers in direction of A, orient hand to be able to curl fingers towards closest way to B, extended thumb will be the resultant direction of cross product.
28:47"lookness" was exactly the name I would use. Good choice. ;]
2:04:08 so what u are doin is basically a change of basis?
The fucn which is LocalToWorld...shouldn't it be renamed WorldToLocal?? as we are converting wold coordinates to local space
Yeah I got really confused about this as well??
Exactly. I think that too. I think correct one is WorldToLocal.
Wouldn't the 4th row in the basis matrix affect the result only if you use the w coordinate after the matrix multiply ?
What I dont understant at 3:20 regarding the dot product is, since B is projecting on to a normalized A (Which is extended to infinity) And A's length is 1 due to normalization. Wont the dot product be greater than one according to the graph you drew?
40:50 the closer humanity have got to time travel
I was about to comment on Task 2 reminding me about Amnesia Dark Decent and looking at mob/lights and next phrase is pretty much "..in a horror game..." (Just finished it again, great game)
"it's also a good gang sign. if u'r left-hand crew or right-hand crew u can do yr gizmos" LOL 2:24:44
NEAT
Nice video!
Where can I the real axis? :D I loved it
Great we can use Vectors to present data from the energy feedback from sensors: gyroscopes, accelerometers, magnotometers to the Kalman Filter matrix vector complex equations to be solved by a computer to solve a real world control systems engineering such as a US Navy Military Drones as well as those used by Robotics manufactured by Boston Robotics... etc... etc... :)
Your cat makes me think there's a cat in my ceiling, i'm paranoid
Is the math concrete weather we disagree on the topography?
how did you achieve the alpha blend on your webcam? i coded my own using bitwise operations on GDI bitmaps but it was never as smooth as it should be, suffered numerous aborations and artifacts.
This is a problem i sunk over 100 hours in, shamefully.
Hi Freya, which smart pen do you use?
I can't code for the life of me so I did the assignments in Excel and used diagrams for visualization (that one year studying civil engineering did pay off). All vectors were simply two numbers written next to each other.
If you can do it in excel, you'll be able to learn coding in no time. It's really not that different.
Pick up a programming book and you'll be able to do it :D
I'm halfway through, so forgive me if it's answered later on but I wanted to understand, if the basis is always 1 for x and 1 for y... why even multiply the vector? Isn't it just the vector's points already? What's the point that I'm missing and how does that multiplication translate it to global space
Ok, I think I understand when going through matrix section. Seems like it's really not 1, it's the dot product to apply the rotation.
I am a bit confused. So, is the result of cross-product defined by the handedness of the coordinate system? Because in Unity we use the left-handed rule, as the coordinate system is left-handed, and in pure math, we use the right-handed rule (as in Source Engine, Blender, Maya.. etc)
the cross product is independent of handedness! handedness is only a matter of how we display it all
1:57:54. Pygame developer: Fine! I'll do it by myself
I am 0....everything vectors out from this Dot. What will trigger events? Me? Self is playing along. BUT, who wrote the program? Need more information.
Long Story short for Dot Product.
1. You need at least 1 normalized Vector to project into another. A common use is to project a not normalized one into a normal surface.
2. You ends up with two possibilities:
Not-Normalized x Normalized & Normalized by Normalized.
Normalized x Normalized: Exclude the length of the vector and end up with only a direction:
1 (same direction),
0 ( perpendicular ),
-1 (Opposite).
Not-Normalized x Normalized: dot returns a length in a scalar.
This scalar represents how far the direction projected along the distance axis
== values -> Same direction
- values -> Towards opposite direction
+ values -> Towards Same Direction
Scalar length : How far it projected
What tablet are you using? Please asnwer me
you should be teaching in my uni lol
@2:20:36 anyone know where I can get one of these models of the axis origin cursor thing?
not sure, I 3D-printed and painted my own!
@@acegikmo I figured it was something like that :) It looks so good btw!
noice
Basically this shows understanding 3d vectors, view transformation, etc. is vastly more important in the real world (infact you might not even need that last part, many things just set up 3d/2d for you). If you ever got a degree from some university, they probably tried to ruin your mind with stuff you won't remember like memorizing derivatives and integrals, yet it's only important to know what those are and not the memorization. I agree with how to use these concepts, and as self-taught it's always been easier to understand what things like lines, rays, shapes, etc. are doing. Redoing the math isn't needed because many renderers can just do it for you already. Memorizing things like laws of SIN/COS and shapes doesn't even matter because those are referencable, just like everything when you make a real application of math in programming. I even find myself looking up references even in common things like web programming. However if someone were to just not know these concepts here, they'd have some trouble with C++ and getting things to work how they want because vectors, magnitude, and those things need to be understood at least.
🙏🙏🙏🙏
shouldnt 4x4 matrix be used to encode 4d space and 3x3 to encode 3d? in order to transform 2d space you only need to multiply it by a 2x2 matrix. am i missing smth here?
3x3 is only enough to encode 3D rotation, but not translation. similarly, a 2x2 can only encode 2D rotation, but not a 2D position in addition to that
@@acegikmo ah, got it, thanks a lot!
미모와 지성을 갖춘 개발 여신이 나타났다
About Asgmt. 3 solution (Space transformation):
I've had to take some time to figure out where the coordinates of the local space origin were coming from, as I'm new to programming, and Unity, Godot, and all this all environment.
After a while I've noticed that it was given by the transform.position of the object the script is attached to, right?
So I've got confused by variables' naming:
What I think should be named "worldOffset" is the transform.position of the object itself, isn't it?
What you've called "worldOffset" is in fact the Vector2 value we want to be drawn in the local space, the one we give the coordinates in the Public Vector2, am I correct?
I think it would be better for understanding if this Vector2 was named something like finalPt or resultPt. What do you think?
That's just a kind of a suggestion, as I'm just learning this through your amazing courses and could've gotten it all wrong, haha.
Thank you for the amazing classes. The course is very exciting and fun to watch. :D
She called it worldOffset because it is the difference between the object and the point in question expressed in world-space coordinates. What I mean is that the coordinates of the worldOffset vector describe a certain combination of the world-space basis vectors. The process of transforming the point from world-space into local-space is just the process of expressing that worldOffset vector in terms of the local-space basis vectors rather than the world-space basis vectors. Conceptually, the worldOffset vector and what you might call the localOffset vector are the same vector, it's just that they are stored in the computer differently because one describes a combination of the world-space basis vectors and the other describes a combination of the local-space basis vectors.
Example? If you're making an AoE and you want the Aoe to align with a sloped ground when a player casts it.
Edit: Not even 5 miniutes later. @ 2:30 Lol, I know where this is going.
Great stuff but the cat's really distracting. Give Thor some kibble or something to keep him busy 😛
He’s just a bean
Perhaps with a little bit of catnip...hahah
If the basis vector is always 1 then why ever even multiply by it... it will always come out the same as the local space point... I hope you understand what I mean ... you still ended up with the same vector (2,1)
the basis vector has a length of 1, but it's pointing in a specific world space direction
@@acegikmo but for that step particularly I’m having a hard time wrapping my head around how multiplying the local space point by 1 ever does anything but give back the same local space point...so if the local space point was (500,300) you already have the vector... I’m hope I don’t sound too stupid because maybe I missed where direction factored in here
@@bradbland9307 because you're it just multiplying by one, you're multiplying by a direction vector with the length of 1, which could point in any direction
so effectively what you're doing is getting the basis vector (in world space) scaled by the corresponding local space coordinate, to get a world space offset
@@acegikmo I think where I get confused a lot is thinking that the values in a direction vector are 1 but it’s the length of that vector that’s 1 unit in relation to the units in the space your working with ... Is that correct?.... Btw thanks for your response
@@bradbland9307 kinda yeah, though in reality it's a little more complicated, but, kinda yes~ (hard to elaborate on my phone in UA-cam comments, but you're welcome to join my discord and ask in there!)
Meow on 1:48:21 :)
wow this could have been shortened to 20min, super tedious for my taste, even from a beginner's perspective
Matrices and cross product to complicated
Wtf i thought i hated math
you are so cuteeeee
This is called 'Spaces & Cross Product: Math for Game Devs' but you don't provide the math for the cross product?
because 99% of people watching this will use an engine that has a cross() function built in, so it's not exactly necessary
but if people want the math you can totally look it up! it's everywhere on the internet~
Great video, thanks, but dang your cat is annoying 😅
Is she shy to look straight into the camera lol. I was making sure she isn’t talking to my chair.
she's looking at her screen. you know, where she actually draws the matrixes and numbers, which is hard to do when you're looking at the cam instead >.>
@@quinndelcarmen1384 still even when she wasn’t doing anything
@@saiyanpridezbudokitenkaich3444 lol....the camera is on an angle so why would she turn around and face it? thats so random dude. this isnt a news broadcast. When shes not "doing anything" shes probably looking at the diagram and figuring out what to explain/draw next.
She is so cute
He
omg ur so smart.. please will you marry me? 💍😂
i want to put that cat in a bag and play football with it
pdf file