Rotate a mesh at a certain point

Uhm… you aren’t understanding what we mean by “origin”.

A mesh is just a list of vertices, denoted by an X, Y, and Z value. (Sometimes, a custom vertex structure will include other things, like normals, UV coordinates, etc).

Let’s say you have a very simple quad in 2D space, given by the following coordinates:

0,0
1,0
1,1
0,1

The “origin” is at (0,0). It always is. The center of the quad is at (0.5,0.5).

If you apply a rotation to this quad, it is going to pivot around the lower left corner located at (0,0). This is not a rotation around the center of the object.

If we want to rotate around the center of the quad, at (0.5, 0.5), then you first have to do a translation by (-0.5,-0.5), then apply a rotation.

Notice that we put the center of the quad at the origin.

Now, you may be frustrated and wondering, “Why does it work this way?”

Because mathematics. The same mathematical operation is applied to every single point on the mesh. If you do a 90 degree counter clockwise rotation on a unit vector of (1,0), the pivot point is always based off of the origin at (0,0) and the result will be (0,1) because… we’re doing (cos(90), sin(90))

Matrices are wonderful little things people invented which really help us compact all this stuff. A matrix will store all of the accrued rotations, translations, and scales you apply to a vertex, and the accrued values keep the order of your operations correct. This is mostly done on way back on the engine side, particularly with API’s like DirectX11 and OpenGL, but you can get a matrix “transform” within blueprints and apply it to an object.

Anyways, long story short, the origin is always at 0,0,0. It never moves. You always rotate around the origin. Usually we perform a translation on an object so that its on the origin, perform a rotation, then apply the inverse translation. It doesn’t matter if the object is a single point, a static mesh, a mesh component, etc.