public Vector3f getLocalDirection() { Vector3f result = Direction.FORWARD.getVector3f(); getLocalRotation().rotate(result, result); return result; }
public static Direction inDirection(Vector3f dir) { return inDirection(dir.x, dir.y, dir.z); }
@Test public void testRotateMixed() { Rotation rotation = Rotation.rotate(Yaw.CLOCKWISE_180, Pitch.CLOCKWISE_90, Roll.CLOCKWISE_90); Quat4f rot = rotation.getQuat4f(); Vector3f dir = rot.rotate(Side.FRONT.toDirection().getVector3f(), new Vector3f()); assertEquals(Direction.inDirection(dir).toSide(), rotation.rotate(Side.FRONT)); }
@Test public void right() { Direction dir = Direction.inHorizontalDirection((float) -1, (float) 0); assertEquals(Direction.RIGHT, dir); }
@Test public void testRotateSidePitch() { Rotation rotation = Rotation.rotate(Pitch.CLOCKWISE_90); Quat4f rot = rotation.getQuat4f(); Vector3f dir = rot.rotate(Side.FRONT.toDirection().getVector3f(), new Vector3f()); assertEquals(Direction.inDirection(dir).toSide(), rotation.rotate(Side.FRONT)); assertEquals(Side.TOP, Rotation.rotate(Pitch.CLOCKWISE_90).rotate(Side.FRONT)); assertEquals(Side.RIGHT, Rotation.rotate(Pitch.CLOCKWISE_90).rotate(Side.RIGHT)); }
@Test public void forward() { Direction dir = Direction.inHorizontalDirection((float) 0, (float) 1); assertEquals(Direction.FORWARD, dir); }
@Test public void testRotateSideYaw() { Rotation rotation = Rotation.rotate(Yaw.CLOCKWISE_90); Quat4f rot = rotation.getQuat4f(); Vector3f dir = rot.rotate(Side.FRONT.toDirection().getVector3f(), new Vector3f()); assertEquals(Direction.inDirection(dir).toSide(), rotation.rotate(Side.FRONT)); assertEquals(Side.LEFT, Rotation.rotate(Yaw.CLOCKWISE_90).rotate(Side.FRONT)); assertEquals(Side.TOP, Rotation.rotate(Yaw.CLOCKWISE_90).rotate(Side.TOP)); }
@Test public void down() { Direction dir = Direction.inDirection(0, -1, 0); assertEquals(Direction.DOWN, dir); }
public Vector3f getWorldDirection() { Vector3f result = Direction.FORWARD.getVector3f(); getWorldRotation().rotate(result, result); return result; }
@Test public void backward() { Direction dir = Direction.inHorizontalDirection((float) 0, (float) -1); assertEquals(Direction.BACKWARD, dir); } }
@Test public void testRotateSideRoll() { Rotation rotation = Rotation.rotate(Roll.CLOCKWISE_90); Quat4f rot = rotation.getQuat4f(); Vector3f dir = rot.rotate(Side.TOP.toDirection().getVector3f(), new Vector3f()); assertEquals(Direction.inDirection(dir).toSide(), rotation.rotate(Side.TOP)); assertEquals(Side.LEFT, Rotation.rotate(Roll.CLOCKWISE_90).rotate(Side.TOP)); assertEquals(Side.FRONT, Rotation.rotate(Roll.CLOCKWISE_90).rotate(Side.FRONT)); }
@Test public void up() { Direction dir = Direction.inDirection(0, 1, 0); assertEquals(Direction.UP, dir); }
public Vector3f getViewDirection() { Quat4f rot = getViewRotation(); // TODO: Put a generator for direction vectors in a util class somewhere // And just put quaternion -> vector somewhere too Vector3f dir = Direction.FORWARD.getVector3f(); return rot.rotate(dir, dir); }
@Test public void left() { Direction dir = Direction.inHorizontalDirection((float) 1, (float) 0); assertEquals(Direction.LEFT, dir); }
@Test public void backward() { Direction dir = Direction.inDirection(0, 0, -1); assertEquals(Direction.BACKWARD, dir); } }
@Override public void updateListener(Vector3f position, Quat4f orientation, Vector3f velocity) { AL10.alListener3f(AL10.AL_VELOCITY, velocity.x, velocity.y, velocity.z); OpenALException.checkState("Setting listener velocity"); Vector3f dir = orientation.rotate(Direction.FORWARD.getVector3f(), new Vector3f()); Vector3f up = orientation.rotate(Direction.UP.getVector3f(), new Vector3f()); FloatBuffer listenerOri = BufferUtils.createFloatBuffer(6).put(new float[] {dir.x, dir.y, dir.z, up.x, up.y, up.z}); listenerOri.flip(); AL10.alListener(AL10.AL_ORIENTATION, listenerOri); OpenALException.checkState("Setting listener orientation"); this.listenerPosition.set(position); AL10.alListener3f(AL10.AL_POSITION, position.x, position.y, position.z); OpenALException.checkState("Setting listener position"); }
@Test public void left() { Direction dir = Direction.inDirection(1, 0, 0); assertEquals(Direction.LEFT, dir); }
dir.normalize(); } else { dir.set(Direction.FORWARD.getVector3f()); Quat4f rotation = Quat4f.shortestArcQuat(Direction.FORWARD.getVector3f(), dir);
@Test public void right() { Direction dir = Direction.inDirection(-1, 0, 0); assertEquals(Direction.RIGHT, dir); }
private void updateCamera(CharacterMovementComponent charMovementComp, Vector3f position, Quat4f rotation) { playerCamera.getPosition().set(position); Vector3f viewDir = Direction.FORWARD.getVector3f(); rotation.rotate(viewDir, playerCamera.getViewingDirection()); float stepDelta = charMovementComp.footstepDelta - lastStepDelta; if (stepDelta < 0) { stepDelta += 1; } bobFactor += stepDelta; lastStepDelta = charMovementComp.footstepDelta; if (playerCamera.isBobbingAllowed()) { if (config.getRendering().isCameraBobbing()) { ((PerspectiveCamera) playerCamera).setBobbingRotationOffsetFactor(calcBobbingOffset(0.0f, 0.01f, 2.5f)); ((PerspectiveCamera) playerCamera).setBobbingVerticalOffsetFactor(calcBobbingOffset((float) java.lang.Math.PI / 4f, 0.025f, 3f)); } else { ((PerspectiveCamera) playerCamera).setBobbingRotationOffsetFactor(0.0f); ((PerspectiveCamera) playerCamera).setBobbingVerticalOffsetFactor(0.0f); } } if (charMovementComp.mode == MovementMode.GHOSTING) { playerCamera.extendFov(24); } else { playerCamera.resetFov(); } }