/** * Get the orientation of the camera. * @return the orientation direction, a quaternion. */ public Quat4f getOrientation() { return new Quat4f(viewingDirection, viewingAngle); }
private Quat4f[] quad4fArrayFromFloat16ArrayData(float[] inverseBindMatrixArray) { Quat4f[] rotationArray = new Quat4f[inverseBindMatrixArray.length / 16]; for (int i = 0; i < inverseBindMatrixArray.length / 16; ++i) { int offset = i * 16; Matrix4f matrix4f = new Matrix4f(Arrays.copyOfRange(inverseBindMatrixArray, offset, offset + 16)); Quat4f rotation = new Quat4f(); rotation.set(matrix4f); rotationArray[i] = rotation; } return rotationArray; }
public static Vector3f correctOffset(Vector3f offset) { return CORRECTION_QUATERNION.rotate(offset, new Vector3f()); }
Vector3f cameraPosition = worldRenderer.getActiveCamera().getPosition(); Quat4f worldRot = new Quat4f(); Vector3f worldPos = new Vector3f(); Quat4f inverseWorldRot = new Quat4f(); inverseWorldRot.inverse(worldRot); location.getWorldPosition(worldPos); float worldScale = location.getWorldScale(); Vector3f pos = boneLocation.getWorldPosition(); pos.sub(worldPos); inverseWorldRot.rotate(pos, pos); bonePositions.add(pos); Quat4f rot = new Quat4f(inverseWorldRot); rot.mul(boneLocation.getWorldRotation()); boneRotations.add(rot); } else { logger.warn("Unable to resolve bone \"{}\"", bone.getName()); bonePositions.add(new Vector3f()); boneRotations.add(new Quat4f());
Quat4f rotation = new Quat4f(TeraMath.DEG_TO_RAD * state.getYaw(), 0, 0); tmp = new Vector3f(0.0f, 0.0f, -1.0f); rotation.rotate(tmp, tmp); float angleToClimbDirection = tmp.angle(climbDir3f); float pitchAmount = state.isGrounded() ? 45f : 90f; float pitch = input.getPitch() > 30f ? pitchAmount : -pitchAmount; rotation = new Quat4f(TeraMath.DEG_TO_RAD * state.getYaw(), TeraMath.DEG_TO_RAD * pitch, 0); rotation.rotate(desiredVelocity, desiredVelocity); float rollAmount = state.isGrounded() ? 45f : 90f; tmp = new Vector3f(); rotation.rotate(climbDir3f, tmp); float leftOrRight = tmp.x; float plusOrMinus = (leftOrRight < 0f ? -1.0f : 1.0f) * (climbDir3i.x != 0 ? -1.0f : 1.0f); if (jumpOrCrouchActive) { rotation = new Quat4f(TeraMath.DEG_TO_RAD * state.getYaw(), 0, 0); } else { rotation = new Quat4f(TeraMath.DEG_TO_RAD * input.getYaw(), 0f, TeraMath.DEG_TO_RAD * rollAmount * plusOrMinus ); rotation.rotate(desiredVelocity, desiredVelocity); rotation = new Quat4f(TeraMath.DEG_TO_RAD * state.getYaw(), 0, 0); rotation.rotate(desiredVelocity, desiredVelocity); clearMovementToDirection = false;
public Quat4f getWorldRotation(Quat4f output) { output.set(rotation); LocationComponent parentLoc = parent.getComponent(LocationComponent.class); while (parentLoc != null) { output.mul(parentLoc.rotation, output); parentLoc = parentLoc.parent.getComponent(LocationComponent.class); } return output; }
public void setLocalRotation(Quat4f newQuat) { rotation.set(newQuat); }
private void updateSkeleton(SkeletalMeshComponent skeletalMeshComp, MeshAnimationFrame frameA, MeshAnimationFrame frameB, float interpolationVal) { for (int i = 0; i < skeletalMeshComp.animation.getBoneCount(); ++i) { EntityRef boneEntity = skeletalMeshComp.boneEntities.get(skeletalMeshComp.animation.getBoneName(i)); if (boneEntity == null) { continue; } LocationComponent boneLoc = boneEntity.getComponent(LocationComponent.class); if (boneLoc != null) { Vector3f newPos = BaseVector3f.lerp(frameA.getPosition(i), frameB.getPosition(i), interpolationVal); boneLoc.setLocalPosition(newPos); Quat4f newRot = BaseQuat4f.interpolate(frameA.getRotation(i), frameB.getRotation(i), interpolationVal); newRot.normalize(); boneLoc.setLocalRotation(newRot); boneEntity.saveComponent(boneLoc); } } }
dir.set(Direction.FORWARD.getVector3f()); Quat4f rotation = Quat4f.shortestArcQuat(Direction.FORWARD.getVector3f(), dir);
@SuppressWarnings(value = "SuspiciousNameCombination") private void updateRotation(CharacterMovementComponent movementComp, CharacterStateEvent result, CharacterMoveInputEvent input) { if (movementComp.faceMovementDirection && result.getVelocity().lengthSquared() > 0.01f) { float yaw = (float) Math.atan2(result.getVelocity().x, result.getVelocity().z); result.getRotation().set(new Vector3f(0, 1, 0), yaw); } else { result.getRotation().set(new Quat4f(TeraMath.DEG_TO_RAD * input.getYaw(), 0, 0)); } }
public Vector3f getLocalDirection() { Vector3f result = Direction.FORWARD.getVector3f(); getLocalRotation().rotate(result, result); return result; }
case WALKING: if (!config.getRendering().isVrSupport()) { viewRotation = new Quat4f(TeraMath.DEG_TO_RAD * lookYaw, 0, 0); playerCamera.setOrientation(viewRotation); playerCamera.getOrientation().rotate(relMove, relMove); break; case CLIMBING: default: if (!config.getRendering().isVrSupport()) { viewRotation = new Quat4f(TeraMath.DEG_TO_RAD * lookYaw, TeraMath.DEG_TO_RAD * lookPitch, 0); playerCamera.setOrientation(viewRotation); playerCamera.getOrientation().rotate(relMove, relMove); relMove.y += relativeMovement.y; break;
public Bone(int index, String name, Vector3f position, Quat4f rotation) { this.index = index; this.name = name; this.objectSpacePos.set(position); this.rotation.set(rotation); }