Tutorial: Finding center of rotation from initial and final positions Last edited 3 weeks ago2024-09-26 14:18:17 UTC

A little lesson in geometrical construction, to find the center of rotation between an object (initial position) and an image (final position). This will help you in building rotating doors that rotate to any final position (or as close to it as J.A.C.K./Hammer allows you).

Throughout this page the terms object (original position) and image (position after rotation) may be used to refer to an entity's initial and final positions, or in case of doors, the closed and open positions.
At the moment, this tutorial only cover cases where you know the degree of rotation in advance. An extension to cover an unknown amount may come later. Hint: it will involve some trigonometry.

Principle

Finding the center of rotation boils down to the following steps:
  1. Identify 2 reference points from an object, and the corresponding points on the image.
  2. Draw straight lines between the object and image for both points.
  3. Draw a perpendicular line for each of the lines at the midpoint (perpendicular bisector).
  4. The intersection of the perpendicular lines is the center of rotation.
Translating the concepts to J.A.C.K./Hammer is quite easy, and certainly easier than in real life using compasses and set squares:
Tip: Use the User posted image SKIP tool texture for your geometrical construction. This will be removed by compiler with no effect to the rest of level geometry, so it is safe to [accidentally] leave them in.

Examples

1. 90° rotation

Suppose we want to have following rotation:
User posted image
First we identify 2 points on the object (A and B), and the corresponding points on the rotated image (A' and B'):
User posted image
Now we switch to Block Creation Tool (Shift+B), select the Wedge primitive, and draw a selection that has the object-image point pair at the corners. Then we create the brush. Here's for A-A':
User posted image
User posted image
And here's for B-B':
User posted image
User posted image
Note: At this point, the lines shouldn't intersect. If they do, you made a mistake on identifying the points, or somehow flipped the image, which the game engine doesn't support. Try again. Hint: Labeling all points on the brush in order (e.g. clockwise) should help.
Now to draw the perpendicular lines. Select the wedge for A-A, clone it, rotate by 90 degrees (direction doesn't matter), and align the center handles (the "x" in the middle of the brush):
User posted image
User posted image
User posted image
User posted image
Now do the same for B-B':
User posted image
And would you look at that! Our perpendicular lines just so happen to intersect precisely to a point on the very first try! That point of intersection is the origin for this rotation!
User posted image
Let's commemorate our success by building our origin brush right there and then!
User posted image

2. 90° rotation (but the other way)

Let's do another 90° rotation, but now it goes the other way:
User posted image
Let's again start by identifying our points:
User posted image
Now we connect the points. Note that B-B' is perfectly horizontal so we'll be using the long straight edge instead of the diagonal edge.
Relevant edges highlighted redRelevant edges highlighted red
Now the perpendicular bisections (in green). Since the "x" handles are on grid this time, I've taken the liberty of aligning the rotated wedges to it directly.
The intersection of the bisectors are our center of rotation.
User posted image
This intersection also happens on grid, but this is not guaranteed for all cases:
User posted image

3. 45° rotation

User posted image
This is going to be a bit more complicated since none of the points on the image are on grid. What we can do instead is to align the whole brush to the top-right side, and imagine there's a point at the corner of the aligning bounds there:
User posted image
And since we know the angles are 45° we can transfer the imaginary point back to the object:
User posted image
As for the other point... none of the points on the other side of the image are on grid too... but the edge line connecting the two has its center very close to be on grid. That'll do.
User posted image
Now we'll do the usual thing. First connect corresponding points (relevant lines in red):
User posted image
Then the perpendicular bisectors (remember: rotate 90° and align the "x" handles):
User posted image
Our bisector lines aren't long enough to intersect, so we'll simply duplicate the wedges and align the ends.
Bisectors highlighted in redBisectors highlighted in red
Finally, the origin brush. The bisectors (highlighted red) are now intersecting off-grid, so we'll make do with this:
User posted image

Conclusion

Provided the angle of rotation is known beforehand, you'll now be able to place any kind of rotation where the final position would be where you want it to be (or close enough). Hope this helps realize some epic, crazy setups in your minds!

Comments

You must log in to post a comment. You can login or register a new account.