Translation notice
This page was translated with machine translation and may contain inaccuracies. If you can help improve it, please open an issue or submit a pull request.
introduction
Display entities are one of the technical entities of Minecraft, and their role is mainly reflected in the visual aspect. These entities have no collision boxes, do not have any autonomous behavior, and can only be generated through technical means. If you don't specify NBT when generating, nothing will be displayed. Developers of vanilla technology can use the regular fields of the display entity to display some common content, such as normal-shaped blocks, items, and text. However, it would be a bit monotonous if only the display entity is used to display these regular contents.
The transformation field that displays the entity is a more complex field in the entity format. It uses matrix form or decomposition form to represent the rendering transformation of the entity, thereby creating some special effects.
matrix form
When using matrix form, the data type of the field transformation is a list. There are 16 elements in the list, and these elements are single-precision floating point numbers. This list is used to represent a
Basic transformation forms include translation, rotation, scaling (mirror), and shearing. All transformations are based on the actual coordinates of the entity.
Pan
Assume that any point on the display entity
Then the translation matrix
rotate
There are three ways of rotation, namely around
So there is
Convert it to an affine matrix and get
In the same way, around
around
Zoom
Assume that any point on the display entity
Then the scaling matrix
like
mirror
For a scaling matrix, in particular, if
\
If you display any point on the entity
in
cut
The shear transformation moves all points on the entity in a certain direction. The distance of any point on the straight line passing through the origin in that direction changes linearly with the distance between the straight line and the origin, which makes the image tilt. A shear transformation occurs in a plane composed of two orthogonal coordinate axes, with shearing in one direction and no transformation in the other direction. There are six pairs of orthogonal relationships between coordinate axes in the three-dimensional coordinate system, so there are six elementary shear transformations.
As shown in the figure, when the image is sheared in one direction, it actually has a shearing angle with the other direction.
but
In the same way, the matrices required for the other six shear transformations can be derived. When the direction of the shear transformation is
The shear matrices described above only transform in one direction and form a certain shear angle with the other direction. If multiple different shear transformations are applied at the same time and the elements are filled in using the above rules, the shear matrix can be recorded as
If the shear transformation in a certain direction is not used, the corresponding position in the matrix will be
Combined transformation
One transformation may not suffice, and sometimes multiple transformations need to be applied simultaneously to represent complex transformations. For a finite number of affine transformations
Note that matrix multiplication follows the operation rules from right to left and does not support commutative law, but supports associative law, so there is
make
The matrices used in tagtransformation are all combined transformation matrices.
Application examples
Modify a block to display the NBT data of the entity so that it flows around the
Therefore, command should be
data merge entity @e[type=block_display,limit=1] {transformation:[-0.35f,-0.71f,0.61f,0.0f,0.87f,0.0f,0.5f,0.0f,-0.35f,0.71f,0.61f,0.0f,0.0f,0.0f,0.0f,1.0f]}Decomposed form
for these
The block array in the formula
The transformation field in decomposed form is a block array
In the formula:
say
Taking the transposed matrix on the left and right sides of the equal sign in the above equation, we get
Because of the square matrix
Transform the above formula:
phalanx
find out
Step 1:
From the characteristic equation
Step 2:
For each eigenvalue
Step 3:
If the obtained eigenvectors are not orthogonal to each other, then for the eigenvectors
Step 4:
If the vector obtained
For the right singular vector matrix
In the same way, the right singular vector matrix can be obtained. The calculation steps are the same as the above steps for calculating the left singular vector matrix, where
In this way, the right singular vector matrix can be directly obtained without performing diagonalization calculations.
The results of matrix singular value decomposition have geometric meaning, wheretransformation is a composite tag:
right_rotation:The model performs rotation transformation before scaling transformation, that is, the first rotation transformation. Related to V in singular value decomposition. There are two available data forms: axial angle form and quaternion form. You can use axial angle form when writing, but when storing data, it will always be converted into quaternion form.
scale:The scaling transformation of the model, related to ∑ in singular value decomposition. Use three-dimensional vectors.
left_rotation:The rotation transformation after the model is scaled and transformed, that is, rotated again, is related to U in singular value decomposition. There are also two expression methods: axis-angle form and quaternion form. You can use axial angle form when writing, but when storing data, it will always be converted into quaternion form.
translation:The translation transformation T of the model. Corresponds to the elements in the first three rows of the last column of the matrix form. Use three-dimensional vectors.
For the two fields right_rotationandleft_rotation, there are two data forms representing rotation: axis angle form and quaternion form. These two data forms are introduced below:
axial angle
Angular rotation can be understood as: a vector
For the convenience of analysis, the vector
Will
So we can get
for vectors
In fact, in the vector

Now consider the vector
Depend on
Know
so get
When using axial angle to represent rotation, the fields right_rotationandleft_rotation are composite tags:
angle:The angle of rotation around the axis, that is, the θ angle, in the angle system.
axis:An ordered array of three elements used to define the rotation axis vector uu. Generally it can be written as a unit vector.
Quaternion form
When using quaternion form to represent rotation, the fields right_rotationandleft_rotation types are lists, and the data format is:
(list element)An element in a quaternion
All quaternions can be written in the following form:
in
For the rotation axis and vector in the axis-angle formula, it can be written in the form of pure quaternions, such as
If
Notice that the quaternion q above has the following properties:
This is a unit quaternion. Quaternions generally used for rotation transformation are unit quaternions. \emphasize{Non-unit quaternions will cause the model to be scaled while rotating}. So the vector rotation expressed in quaternion form is
make
In the formula:
As a result, the rotation formula expressed in quaternion form is obtained:
in
In the formula:
For a rendering transformation, let the quaternion used for its initial rotation be
Perform the first rotation and get
Then applying the scaling transformation, we get
Under the combined action of the initial rotation and scaling transformation, the relative position of each point in the model will change. Only when rotating the quaternion for the first time
Finally, a translation transformation is applied to determine the final position of the model to obtain the point
Application examples
Use block to display entity to display a glass. Requirement: Generate this display entity so that the diagonal line of the glass body is equal to
The diagonal line of the body in the model starts from
Calculate the angle of rotation: convert
The axis of rotation is perpendicular to the vector before and after rotation, we have
convert it into unitsleft_rotation is:
left_rotation:{angle: 54.74f, axis: [-0.71f, 0.0f, 0.71f]}Compute rotated quaternion again
The model does not require initial rotation, scaling and translation, sotransformation field in decomposed form is:
transformation:{right_rotation: [0.0f, 0.0f, 0.0f, 1.0f], scale: [1.0f, 1.0f, 1.0f], left_rotation: [-0.33f, 0.0f, 0.33f, 0.89f], translation: [1.0f, 1.0f, 1.0f]}The commands required to generate this display entity are:
summon block_display ~ ~ ~ {block_state:{Name:"minecraft:glass"},transformation:{right_rotation:[0.0f,0.0f,0.0f,1.0f],scale:[1.0f,1.0f,1.0f],left_rotation:[-0.33f,0.0f,0.33f,0.89f],translation:[1.0f,1.0f,1.0f]}}The value of the field left_rotationhas been defined. The rotation animation is completed by interpolation and can be defined byright_rotation. The quantity to be determined is still the rotation angle.
byright_rotation is
right_rotation: {angle: 90, axis: [0.58f, 0.58f, 0.58f]}Convert to quaternion form
right_rotation:[0.41f,0.41f,0.41f,0.71f]Same reason
right_rotation:[0.58f,0.58f,0.58f,0.0f]}right_rotation:[0.41f,0.41f,0.41f,-0.71f]}right_rotation:[0.0f,0.0f,0.0f,1.0f]}In order to smoothly transition the rotation angle of the model to
data merge entity @n[type=block_display] {transformation:{right_rotation:[0.41f,0.41f,0.41f,0.71f]},interpolation_duration:20}After the command is executed, apply the command block circuit or function plan so that after 20gt, when the defined interpolation animation ends, the rotation angle of the model begins to smoothly transition to
data merge entity @n[type=block_display] {transformation:{right_rotation:[0.58f,0.58f,0.58f,0.0f]},interpolation_duration:20}After 20gt, a smooth transition begins to
data merge entity @n[type=block_display] {transformation:{right_rotation:[0.41f,0.41f,0.41f,-0.71f]},interpolation_duration:20}After 20gt, a smooth transition begins to
data merge entity @n[type=block_display] {transformation:{right_rotation:[0.0f,0.0f,0.0f,1.0f]},interpolation_duration:20}After 20gt, a smooth transition begins to90.mcfunction, 180.mcfunction, 270.mcfunction, and 0.mcfunctioncan be created in the directorydata\minecraft\function\animation. For example, the content of function90.mcfunction could look like this:
data merge entity @n[type=block_display] {transformation:{right_rotation:[0.41f,0.41f,0.41f,0.71f]},interpolation_duration:20}
schedule function minecraft:animation/180 20tReferences
[1] https://zh.minecraft.wiki/w/展示实体
[2] https://krasjet.github.io/quaternion/quaternion.pdf
[3] https://blog.csdn.net/YiYeZhiNian/article/details/106750302
[4] https://zhuanlan.zhihu.com/p/45404840
[5] https://zhuanlan.zhihu.com/p/183973440
