It is not possible to correctly calculate the normal / direction vector from pitch and yaw

enter image description here

My pitches and dots are ruined. I have a pitch and yaw of the court, but the rays and yaw are confused. How to calculate the normal vector for the pitch and yaw? I tried crappy math loading from stackoverflow, but they all failed so far.

What I first tried was adding 90 to the pitch, but the yaw remained tainted: enter image description here

And this is what happens when I used the pad pitch and yaw, just like to calculate the direction vector: enter image description here

What I tried to do next was to separate the beam pitch and yaw from the site and the yaw of the site and both of them separately. It basically worked, but the yaw was still completely messed up.

What I used to calculate the direction vector from yaw and ray pitch was used by minecraft for this for mobs:

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)); } 

But this failed, so finally I tried using the pad step:

  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); 

And it worked great for the yaw, but fell through the field enter image description here

pitch and yaw are calculated as the player’s head rotates. The pitch of the pitch and the yaw is 100% correct when I use them on the pitch itself, but the mess is when I use them on the beam. They both use GL functions.

Despite the fact that pitch and yaw do not take into account the orientation system of the player’s head, he works with the pad.

For example, this is the yaw of the mirror in this figure, and it is ideal for its current value. enter image description here And the panel will be rotated as follows:

  GlStateManager.rotate(te.getPadYaw(), 0, 0, 1); GlStateManager.rotate(te.getPadPitch(), 1, 0, 0); 

And the line is drawn as such:

  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(); } 

I get pos1 and pos2 like this [PRESENT, MOST RECENTLY]:

  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); 

How can I calculate a normal vector or a vector that is perpendicular to the pad correctly from the pitch and angle of the pad?

I am at a loss at this point, because almost everything I found on google found almost nothing.

EDIT: I was told that splitting the beam and yaw from the site and yaw should not be necessary, and I agreed, but I just can't get it to work differently. Why is the math of the beam different from the math of the pad?

+5
source share
1 answer

It’s somehow difficult for me to say this in a comment, so I put this in response. when i saw:

 double pitch = ((te.getPadPitch() + 90) * Math.PI) / 180; double yaw = ((te.getPadYaw() + 90) * Math.PI) / 180; double x = Math.sin(pitch) * Math.cos(yaw); \\Line 3 is HERE <--- double y = Math.sin(pitch) * Math.sin(yaw); double z = Math.cos(pitch); Vec3d lookvec = new Vec3d(x, y, z); 

Why did you use sin(pitch) and cos(yaw) ? cos() calculates your x, so why did you use sin(pitch) ? This makes sense for both y and z , but I think your math is a bit off or just a syntax error, or I'm completely wrong (which is probably most likely).

0
source

All Articles