This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
cw4:tutorials:rotation_conversion [2021/01/09 14:02] – created Karsten75 | cw4:tutorials:rotation_conversion [2025/02/14 14:57] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | < | ||
+ | < | ||
+ | |||
====== Converting between different kinds of rotation ====== | ====== Converting between different kinds of rotation ====== | ||
- | Many objects in CW4 have a rotation which can either be obtained or set through 4RPL commands. This includes the rotation of the camera, units and the individual objects custom | + | Many objects in CW4 have a rotation which can either be obtained or set through 4RPL commands. This includes the rotation of the camera, units and the individual objects custom |
This page will show you how the different types of rotations in this game work and how to convert between them | This page will show you how the different types of rotations in this game work and how to convert between them | ||
+ | |||
+ | ---- | ||
===== Radians and degrees ===== | ===== Radians and degrees ===== | ||
- | {{ : | + | {{ : |
The trigonometry functions of 4RPL such as sin, cos, tan, atan2, etc. all use or return radian values, but other parts of the game use degrees, which is why you'll have to convert between them. | The trigonometry functions of 4RPL such as sin, cos, tan, atan2, etc. all use or return radian values, but other parts of the game use degrees, which is why you'll have to convert between them. | ||
Line 22: | Line 27: | ||
< | < | ||
</ | </ | ||
+ | |||
+ | ---- | ||
===== The difference between Unity rotation and mathematical rotation ===== | ===== The difference between Unity rotation and mathematical rotation ===== | ||
- | **TLDR; | + | **TLDR; |
- | Even though units are normally locked to the grid, the game allows us to rotate them by any amount. Lets try to give a unit a Y rotation of 30°, which should make them point slightly up and to the right, just like the image above here. | + | Even though units are normally locked to the grid, the game allows us to rotate them by any amount. Lets try to give a unit a Y rotation of 30°, which should make them point slightly up and to the right, just like the image of the section |
<code 4rpl> | <code 4rpl> | ||
Line 34: | Line 41: | ||
</ | </ | ||
- | What we see when we run this however, is that the unit faces //down //and to the right instead, we only get the result we originally expected when we use the //negative //value -30°. This means that rotations along the Y-axis is inverted. It turns out the the same is true for the X-axis. The Z axis on the other hand is fine and works as we would expect. | + | What we see when we run this however, is that the unit faces //down //and to the right instead, we only get the result we originally expected when we use the //negative //value -30°. This means that rotations along the Y-axis is inverted. |
- | {{: | + | {{: |
- | So, if you work out some kind of angle within the map' | + | It turns out the the same is true for the X-axis (rotating by a negative value will make units face upwards instead of downwards). The Z axis on the other hand is not inverted and works as we would expect. |
+ | |||
+ | So, if you use conventional math to calculate a rotation | ||
+ | |||
+ | This way of calculating rotations is tied to the engine, and therefore used in any and all game objects that can have some kind of rotation. That includes units, their individual component objects and notably, the camera. | ||
+ | |||
+ | ---- | ||
===== Camera rotation ===== | ===== Camera rotation ===== | ||
Line 47: | Line 60: | ||
To account for this, we'll have to turn our angle 90° to the right before setting the camera. Similarly, when we want to convert the angle back into something that works in the map's coordinate system, you'll have to turn 90° left first. Below are some functions made for converting from and to camera orientation. | To account for this, we'll have to turn our angle 90° to the right before setting the camera. Similarly, when we want to convert the angle back into something that works in the map's coordinate system, you'll have to turn 90° left first. Below are some functions made for converting from and to camera orientation. | ||
+ | |||
+ | ---- | ||
===== Converting rotations using 4RPL ===== | ===== Converting rotations using 4RPL ===== | ||
Line 67: | Line 82: | ||
deg2rad * | deg2rad * | ||
</ | </ | ||
+ | |||
+ | < | ||