 Howdy guys. All right, so in this next intro to vex video, what we're going to do is talk about vector rotations. All right, so how do we go about controlling our rotations when we use something like the copy to points? All right, okay. And so let's take a look at how we go about rotating a normal. That's probably the best way to visualize it and to begin with. So we're going to build something like this. All right, we're basically going to rotate our objects in a very controlled manner. Usually, you know, in a lot of the videos I've done in the past, we just, you know, fill in the orient or the at rot attribute with some random number, which usually looks good, you know, when you're working on levels and stuff like that for games, usually you want sort of some sort of random rotation. In this case, I want to know how to control my rotations in a custom way. I want a lot of control over it. So we're going to build up that. So let's create a new geometry node and call this just custom rotation or whatever you want to call it, you know, so say custom rotation, and we'll hit enter to jump inside. Now let's turn on the grid just so I have something to look at. And I'm going to drop down a line. All right, and by default, I have my line set up with the x direction. All right, and I've also made it sure that it sits right in the middle. Now, you don't have to do that. I just have that as my default because I use it quite often that way. And I'm going to go and add a couple more points to this guy like so. Okay, cool. And let's initialize these points with some normal. So I'm going to drop down a point expression node. This is a great way to initialize an element or a component of these points, when you just need to really set one of them. So in this case, I'm going to set the normal by hitting this attribute drop down right here and selecting normal from the drop down. You can see by default, I get a normal attribute attached to my points, but they're all zeroed out. So we need to give it some sort of default value. In this case, I'm going to point the normal in the z direction. So this vector right here defines a z pointing normal. All right, so I'm just going to hit enter on that and turn on my normal display so we can take a look here. Okay, so what I want to do when I go and copy points or copy an object to these points. All right, I want it to, you know, rotate around the y axis, let's say. So there's a little green axis right here. I want it to rotate around the y axis in a controllable manner, along this point, okay, or along the line. So a way to do that, let's drop down a wrangle node. The way to do that is with quaternions. Okay, so quaternions are really hard to explain, you know, the actual math behind. I probably would do a terrible job explaining it, but it's basically an efficient way to model rotations in 3D space. All right, it was developed many, many moons ago, I think in like 1843 or something like that by a person's name, I can't remember off the top of my head, but they were developed so that we could rotate things efficiently. And it's, you know, largely used in the CG world. So to do that, to build a quaternion vets, we need to do a couple of things first. We need to first just determine what angle or how much rotation we want to do. So I'm going to create a new local variable and call this angle. All right, so we're going to declare a new channel float. All right. And I'm going to hit the spare parameter button there. So now we have a way to control that value down here interactively. And I'm going to set it to something like, I don't know, 45 degrees. All right, I'm going to start in degrees because that's usually easier to think about, you know, when we're talking about rotations, I usually like to think in degrees. Okay, so to make a quaternion in vets, we need to declare a new vector for, all right, because the quaternion function that we're going to utilize returns a vector for. All right, so this local variable is a vector for, I'm going to call it rot. And we are going to utilize that quaternion function. All right, so let's go and pop open the help for this guy. So that way we can see it. Let's have it for reference. Okay, so we have a couple of overrides for this particular function. So we can provide it a matrix three, we can provide it a float or a vector, or we can provide it just a vector. All right, so we're going to use the second one that that's, I find the easiest one to utilize, it makes most sense, you can visualize it pretty easily. Okay, and so what I'm going to do is I'm going to feed it our angle value. Okay, and then I need to feed it some sort of axis. Now, like I said before, I want to rotate these normals on the y direction. Okay, currently they're all pointing in the z direction. If we look at our little gizmo down here, so I need to provide it the y direction as an axis. And we can do that because we can just type in 010, that's the world up axis. Okay, cool. So now we have this quaternion. And then one thing we need to make sure that we do is read the documentation because you can see down here is it says that the quaternion, it creates a vector for representing a quaternion from angle axis. Okay, and what it's not telling us is that the angle here needs to be fed in as radians. Okay, so there it is. It's actually right there. The angle is specified in radians. Okay, and currently my angle channel is coming in as a degree. So we just need to convert it to radians like so. So you utilize that radians function. So now we take those degrees, and now they're in radians. So now we have a proper quaternion rotation around the y-axis. Okay, and now what we can do is we can rotate these guys. So if I come down here, and I say that at normal is now equal to a new vector that's rotated with this quaternion right here. So to do that we use the q rotate function. And all we need to do is feed it the rotation in quaternion format and the current normal or the current vector we want to rotate. All right, so when I do that and turn on this attribute angle, you can see we are now rotating around the y-axis. Look at that. How cool is that? All right, so now when we go and create a object to copy onto those points there, so let's just make a box. Something simple. All right, and now I have my box here. Cool. And what I want to do here is I actually want to go and make one of the faces or at least this face that's facing in the z-direction blue. That way we can see our orientation on our box. Okay, so what I'm going to do is drop down a color node and we'll set some base color. All right, I'm going to assign this to the primitives and let's put kind of like an orange color on this like I did before. And I'm going to copy this guy and we are going to then colorize primitive two. And this one is going to be blue. All right, because when we copy an object to points, the copy to points node is going to use this normal as the way to orient your models. All right, and this normal basically represents that forward direction in z. So that's why I colored the primitive blue there so we can see that rotation or that orientation happening. So now if I put in the copy to points node and then feed in these two guys like so, you can see now we are rotating appropriately. Let me turn off my normals now. We don't need those or the primitive numbers. So if I come back to my wrangle node, start playing with this angle, you can see when I get to 180, we should be all the way around. All right, 270. We should be all facing this way. How cool is that? Let's make this a little bit smaller. All right, there you go. And we can take this even further by basically multiplying the angle by the gradients along the curve. All right, so we're going to create some u value or a value that goes from 0 to 1 based off the length of the curve. And to do that, we can just say float gradients is equal to our point number. So at pt num divided by the number of points coming into our input 0 there or the first input minus 1. Okay, and then we have to make sure that we cast all these guys to floats because they come in as integers and we need a float value for our gradient. Cool. So now we've got this gradient. I can just go down here and multiply our angle by the gradients. Oh, look at that. We now have a nice smooth fall off. So if I were to start rotating these guys, you can see they're rotating more where we're at the end of the curve. Pretty cool stuff. Awesome. All right, we could take this even further by rotating a second vector. In this case, let's say we want to rotate our up vector. All right, so let's do this. Let's create our up vector. I'm going to say v at up is equal to world up. So we're going to start there. So we're just going to initialize it there. All right, and then I want to basically do the same thing. All right, we can take any number of these vectors and rotate them and you get really crazy effects when you start to layer all this stuff together. So let's just copy this whole section here and we'll paste it down here like so. And I'm going to call this rot b. And we're going to take in the angle. And what I want to do this time is rotate along our normal. So you can see here if I turn on my normals again, I actually want to use this as my axis. All right, so we're going to basically rotate this way now because our up normal is facing up. And we can actually take a look at this. So if I select this attribute or angle now to hit x on the keyboard, it'll automatically throw down a visualized node for me. And I can come in here and set this to a marker because I want to look at a vector and that vector is going to be up. So currently our up vectors pointing straight up and y. So let's actually pull this guy down just a bit. It's a little big. And now what I want to do is I want to basically rotate this yellow vector the up vector using the current points normal as the axis. Okay, so this time I'm going to say rot b is equal to this quaternion now, but around the normal axis. All right, so all we need to do now is just say that at up is now equal to the q rotate of our rot b and at up because that's the vector that we want to rotate. So give it the quaternion and then we give it the vector that we want to rotate by that quaternion. And when we do that, you can see we're now rotating that y vector as well. Now all of our boxes are being rotated along that vector as well. Pretty cool. All right, then what I did, you know, just for the demo purposes, I went and created a copy to point or not a copy to points, a copy and transform. There we go. And pump that guy into there. And then I think I just put like 0.1 here, a little bit more. I just made a bunch of copies. That's all I did. All right. That's a really cool way to get a bunch of really cool, you know, visualization type animations, whatever you're doing, you know, these types of patterns are really cool. But it's a great exercise and just learning how to rotate your normals or any vector for that matter. All right, so one thing I wanted to point out before I actually close out the video is let's say you're not really sure, you know, how the code for VEX actually works. All right. Well, what we can do is we can actually utilize VOPs for all this stuff. Okay, so let's throw down a point VOP and take a look at the version without writing code. Okay, so in this case, what I'd have to do is jump in here. Let's actually turn on our points and our normals. So we have our initial normals there. So inside of a point VOP, what we would do is we would come in here and drop down a parameter because we need to define our angle, just like we did in VEX. Okay, so this is going to be called angle. And I want this to be within zero to 360, let's say. And it's going to be a float. That's good. And then what I want to do is throw down a quaternion. So let's take that quaternion. All right, because we need to build a quaternion to feed into our rotation. Okay, so the axis then is going to be a constant. Okay, and this constant is going to be a vector, or not all that would work too. There we go. So now we got the up VEC. And I need to convert my angle now into radians. So let's do degrees to radians. We'll feed that into the angle, use that as the axis, the world up axis. So now we have our quaternion. And what I want to do is I want to throw down the q rotate or rotate by quaternion. So now we can pump in the quaternion here and pull in the normal, our current normal right here. And we'll pump that result out into the normal like so. All right, so if I were to jump up and out, and take a look at the angle here, you can see we are rotating very, very little. That is odd there. And that's because I put in the bound angle. All right, there we go. Cool. So now we are doing the same exact thing. Cool. So if you ever, or if you are comfortable point bops, and you want to see, you know, what the code is in VEX for that, you can always just click on this guy and say, view VEX VOP options and say, view VEX code. And usually, right down at the bottom, you'll find how to make the actual VEX on your own. All right. So that's pretty much all you actually need to write. Cool. So just a couple of ways to go about doing all that stuff. But that is what I wanted to show. Hopefully you guys like that. All right, thanks so much.