/** * Get the orientation of the camera. * @return the orientation direction, a quaternion. */ public Quat4f getOrientation() { return new Quat4f(viewingDirection, viewingAngle); }
@Override public Quat4f copy(Quat4f value) { if (value != null) { return new Quat4f(value); } return null; } }
public static Quat4f completeQuat4f(float x, float y, float z) { float t = 1.0f - (x * x) - (y * y) - (z * z); float w = 0; if (t > 0.0f) { w = (float) -Math.sqrt(t); } Quat4f result = new Quat4f(x, y, z, w); result.normalize(); return result; }
/** * Set the collision box for the block * * @param offset The offset to the block's center * @param shape The shape of collision box */ public void setCollision(Vector3f offset, CollisionShape shape) { collisionShape = shape; collisionOffset = offset; bounds = shape.getAABB(new Transform(offset, new Quat4f(0, 0, 0, 1), 1.0f)); }
public static Quat4f correctQuat4f(Quat4f rot) { Quat4f result = new Quat4f(CORRECTION_QUATERNION); result.mul(rot); return result; }
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; }
@Override public Quat4f deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { if (json.isJsonArray()) { JsonArray array = json.getAsJsonArray(); if (array.size() == 4) { return new Quat4f(array.get(0).getAsFloat(), array.get(1).getAsFloat(), array.get(2).getAsFloat(), array.get(3).getAsFloat()); } } return null; } }
public Quat4f getRotation() { LocationComponent location = getCharacterEntity().getComponent(LocationComponent.class); if (location == null) { return new Quat4f(Quat4f.IDENTITY); } return location.getWorldRotation(); }
public Quat4f getQuat4f() { Quat4f rotation = new Quat4f(yaw.getRadians(), pitch.getRadians(), roll.getRadians()); rotation.normalize(); return rotation; }
private void mountCamera() { ClientComponent clientComponent = localPlayer.getClientEntity().getComponent(ClientComponent.class); EntityRef targetEntityForCamera = GazeAuthoritySystem.getGazeEntityForCharacter(clientComponent.character); LocationComponent cameraLocation = clientComponent.camera.getComponent(LocationComponent.class); // if the camera already has a location, use that as the relative position of the camera if (cameraLocation != null) { Location.attachChild(targetEntityForCamera, clientComponent.camera, cameraLocation.getLocalPosition(), new Quat4f(Quat4f.IDENTITY)); } else { Location.attachChild(targetEntityForCamera, clientComponent.camera, Vector3f.zero(), new Quat4f(Quat4f.IDENTITY)); } } }
@Override public void generate(BlockManager blockManager, CoreChunk view, Random rand, int posX, int posY, int posZ) { Vector3f position = new Vector3f(0f, 0f, 0f); Matrix4f rotation = new Matrix4f(new Quat4f(new Vector3f(0f, 0f, 1f), (float) Math.PI / 2f), Vector3f.ZERO, 1.0f); float angleOffset = rand.nextFloat(-MAX_ANGLE_OFFSET, MAX_ANGLE_OFFSET); Block bark = blockManager.getBlock(barkType); Block leaf = blockManager.getBlock(leafType); recursiveGenerator.recurse(view, rand, posX, posY, posZ, angleOffset, new CharSequenceIterator(initialAxiom), position, rotation, bark, leaf, 0, this); }
public Quat4f getViewRotation() { ClientComponent clientComponent = getClientEntity().getComponent(ClientComponent.class); if (clientComponent == null) { return new Quat4f(Quat4f.IDENTITY); } LocationComponent location = clientComponent.camera.getComponent(LocationComponent.class); if (location == null) { return getRotation(); } return location.getWorldRotation(); }
public Vector3f getLocalPosition() { Vector3f pos = new Vector3f(objectSpacePos); if (parent != null) { pos.sub(parent.getObjectPosition()); Quat4f inverseParentRot = new Quat4f(); inverseParentRot.inverse(parent.getObjectRotation()); inverseParentRot.rotate(pos, pos); } return pos; }
@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)); } }
@ReceiveEvent public void ensureGazeContainerEntitiesCreated(OnActivatedComponent event, EntityRef entityRef, GazeMountPointComponent gazeMountPointComponent, LocationComponent locationComponent) { if (!gazeMountPointComponent.gazeEntity.exists()) { gazeMountPointComponent.gazeEntity = createGazeEntity(); entityRef.saveComponent(gazeMountPointComponent); } gazeMountPointComponent.translate.y = config.getPlayer().getEyeHeight(); Location.attachChild(entityRef, gazeMountPointComponent.gazeEntity, gazeMountPointComponent.translate, new Quat4f(Quat4f.IDENTITY)); }
private EntityRef createAndAttachVisualEntity(EntityBuilder entityBuilder, EntityRef characterEntity) { entityBuilder.setPersistent(false); entityBuilder.setOwner(characterEntity); entityBuilder.addOrSaveComponent(new LocationComponent()); EntityRef visualCharacterEntity = entityBuilder.build(); Location.attachChild(characterEntity, visualCharacterEntity, new Vector3f(), new Quat4f(0, 0, 0, 1)); return visualCharacterEntity; }
@Override public Quat4f deserialize(PersistedData data, DeserializationContext context) { if (data.isArray()) { PersistedDataArray dataArray = data.getAsArray(); if (dataArray.isNumberArray() && dataArray.size() > 3) { TFloatList floats = dataArray.getAsFloatArray(); return new Quat4f(floats.get(0), floats.get(1), floats.get(2), floats.get(3)); } } return null; } }
public void setWorldPosition(Vector3f value) { this.position.set(value); LocationComponent parentLoc = parent.getComponent(LocationComponent.class); if (parentLoc != null) { this.position.sub(parentLoc.getWorldPosition()); this.position.scale(1f / parentLoc.getWorldScale()); Quat4f rot = new Quat4f(0, 0, 0, 1); rot.inverse(parentLoc.getWorldRotation()); rot.rotate(this.position, this.position); } }