Saa*_*aad 5 java vector minecraft
我的球场和偏航都搞砸了.我有垫子的俯仰和偏航,但是梁的俯仰和偏航都搞砸了.如何计算垫的俯仰和偏航的法向量?我尝试了从stackoverflow的数学垃圾负载,但到目前为止他们都失败了.
这就是当我习惯于垫的俯仰和偏航以及计算方向向量时会发生的情况:

我接下来尝试做的是将横梁的俯仰和偏航从横梁的俯仰和偏航中分开并将它们分别计算出来.这大部分都有效,但是偏航仍然完全搞砸了.
我用来计算横梁的偏航和俯仰的方向向量是我的工具用来为暴徒做的:
public static Vec3d getVectorForRotation3d(float pitch, float yaw) {
float f = MathHelper.cos(-yaw * 0.017453292F - (float) Math.PI);
float f1 = MathHelper.sin(-yaw * 0.017453292F - (float) Math.PI);
float f2 = -MathHelper.cos(-pitch * 0.017453292F);
float f3 = MathHelper.sin(-pitch * 0.017453292F);
return new Vec3d((double) (f1 * f2), (double) f3, (double) (f * f2));
}
Run Code Online (Sandbox Code Playgroud)
但是那显然失败了,所以最后,我尝试了以下使用pad的音调:
double pitch = ((te.getPadPitch() + 90) * Math.PI) / 180;
double yaw = ((te.getPadYaw() + 90) * Math.PI) / 180;
double x = Math.sin(pitch) * Math.cos(yaw);
double y = Math.sin(pitch) * Math.sin(yaw);
double z = Math.cos(pitch);
Vec3d lookvec = new Vec3d(x, y, z);
Run Code Online (Sandbox Code Playgroud)
俯仰和偏航都是以玩家头部旋转的方式计算的.当我在垫子上使用它们时,垫子的俯仰和偏转是100%正确的,但是当我在梁上使用它们时会弄乱.这些都使用GL功能
虽然俯仰和偏航不尊重运动员的头部定位系统,但它适用于垫子.
例如,这是这张照片中镜子的偏航,它对于它的当前值是完美的
并且垫子像这样旋转:
GlStateManager.rotate(te.getPadYaw(), 0, 0, 1);
GlStateManager.rotate(te.getPadPitch(), 1, 0, 0);
Run Code Online (Sandbox Code Playgroud)
这条线是这样绘制的:
public static void drawConnection(BlockPos pos1, BlockPos pos2, Color color) {
GlStateManager.pushMatrix();
GL11.glLineWidth(1);
GlStateManager.disableTexture2D();
GlStateManager.color(color.getRed(), color.getGreen(), color.getBlue(), 0.7f);
GlStateManager.translate(0.5, 0.7, 0.5);
VertexBuffer vb = Tessellator.getInstance().getBuffer();
vb.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION);
vb.pos(pos2.getX() - pos1.getX(), pos2.getY() - pos1.getY(), pos2.getZ() - pos1.getZ()).endVertex();
vb.pos(0, 0, 0).endVertex();
Tessellator.getInstance().draw();
GlStateManager.enableTexture2D();
GlStateManager.popMatrix();
}
Run Code Online (Sandbox Code Playgroud)
我正在获得pos1和pos2,因为[当前,最近]:
double pitch = ((te.getPadPitch() + 90) * Math.PI) / 180;
double yaw = ((te.getPadYaw() + 90) * Math.PI) / 180;
double x = Math.sin(pitch) * Math.cos(yaw);
double y = Math.sin(pitch) * Math.sin(yaw);
double z = Math.cos(pitch);
Vec3d lookvec = new Vec3d(x, y, z);
Vec3d centervec = new Vec3d(te.getPos().getX() + 0.5, te.getPos().getY() + 0.8, te.getPos().getZ() + 0.5);
Vec3d startvec = centervec.add(lookvec);
Vec3d end = startvec.add(new Vec3d(lookvec.xCoord * 30, lookvec.yCoord * 30, lookvec.zCoord * 30));
RayTraceResult result = te.getWorld().rayTraceBlocks(startvec, end, true, false, true);
Utils.drawConnection(te.getPos(), result.getBlockPos(), Color.RED);
Run Code Online (Sandbox Code Playgroud)
如何从打击垫的俯仰和偏航中正确计算法向量或垂直于打击垫的矢量?
我在这一点上不知所措,因为我几乎尝试了我在google上找到的所有东西,但没有运气.
编辑:我被告知,不应该有必要分割光束的音高和偏离音高和俯仰偏航,我同意但是我不能让它工作.为什么光束绘制数学与pad数学不同?
小智 1
我不确定这是否是你的问题,但对我来说,当我处理它们时,MC 返回了一些混乱的偏航位置,这就是我解决这个问题的方法
if (Yaw < -180.0) Yaw += 360;
else if (Yaw > 180) Yaw -= 360;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
369 次 |
| 最近记录: |