Vector3 到四元数

问题描述 投票:0回答:1

我正在尝试将标准化的玩家方向向量转换为旋转四元数。我正在使用 Quaternionf (JOML)

ItemDisplay leftArm = (ItemDisplay) player.getWorld().spawnEntity(player.getEyeLocation().add(0,0,0), EntityType.ITEM_DISPLAY);
ItemStack head = new ItemStack(Material.PLAYER_HEAD);
SkullMeta headMeta = (SkullMeta) head.getItemMeta();
headMeta.setOwningPlayer(player);
headMeta.setCustomModelData(3);
head.setItemMeta(headMeta);
leftArm.setItemStack(head);
leftArm.setItemDisplayTransform(ItemDisplay.ItemDisplayTransform.THIRDPERSON_RIGHTHAND);
leftArm.setViewRange(0.6f);

在重复的 bukkit 中运行

Transformation transformation3 = leftArm.getTransformation();

transformation3.getLeftRotation().rotationXYZ((float)Math.toRadians(player.getLocation().getDirection().getX()),
                            (float)Math.toRadians(player.getLocation().getDirection().getY()),
                            (float)Math.toRadians(player.getLocation().getDirection().getZ()));
leftArm.setTransformation(transformation3);

我尝试使用rotationXYZ和上面的参数,但是旋转似乎非常不正确。

java minecraft quaternions
1个回答
0
投票

看到代码后,我有以下建议,还请提供更多代码来满足为 dbuge 重现此错误的最低要求。

Transformation transformation3 = leftArm.getTransformation();

float xRotation = (float) Math.toRadians(Math.toDegrees(player.getLocation().getDirection().getX()));
float yRotation = (float) Math.toRadians(Math.toDegrees(player.getLocation().getDirection().getY()));
float zRotation = (float) Math.toRadians(Math.toDegrees(player.getLocation().getDirection().getZ()));

transformation3.getLeftRotation().rotationXYZ(xRotation, yRotation, zRotation);

这里我们使用 Math.toDegrees 将方向向量分量转换为度数。然后,我们使用 Math.toRadians 将度数转换为弧度。然后将其传递给rotationXYZ。

上述技巧可能有效,也可能无效,在这种情况下,我们需要您提供更多信息。

© www.soinside.com 2019 - 2024. All rights reserved.