/** * The default constructor will set the location to calculate the * distances from to {0, 0, 0}. */ public DistanceComparator() { origin = new Vector3f(); }
/** * Add a new "position" and "velocity" to the map. * @param sequenceNumber the sequenceNumber of the CharacterStateEvent. * @param position the position of the event. * @param velocity the velocity of the event. */ public void add(int sequenceNumber, Vector3f position, Vector3f velocity) { Vector3f[] data = new Vector3f[2]; data[0] = new Vector3f(position); data[1] = new Vector3f(velocity); idToData.put(sequenceNumber, data); }
/** * Creates a new AABB from the given minimum and maximum points, both inclusive. * * @param min The minimum of the AABB. * @param max The maximum of the AABB. * @return The created AABB. */ public static AABB createMinMax(Vector3f min, Vector3f max) { return new AABB(new Vector3f(min), new Vector3f(max)); }
private Vector3f getQuantizedMainLightDirection(float stepSize) { float mainLightAngle = (float) Math.floor((double) backdropProvider.getSunPositionAngle() * stepSize) / stepSize + 0.0001f; Vector3f mainLightDirection = new Vector3f(0.0f, (float) Math.cos(mainLightAngle), (float) Math.sin(mainLightAngle)); // When the sun goes under the horizon we flip the vector, to provide the moon direction, and viceversa. if (mainLightDirection.y < 0.0f) { mainLightDirection.scale(-1.0f); } return mainLightDirection; } }
/** * @return The distance from the center to the max node */ public Vector3f getExtents() { Vector3f dimensions = new Vector3f(max); dimensions.sub(min); dimensions.scale(HALVING_FACTOR); return dimensions; }
public Vector3f getCenter() { Vector3f dimensions = new Vector3f(max); dimensions.add(min); dimensions.scale(HALVING_FACTOR); return dimensions; }
public Vector3f getInstigatorLocation() { LocationComponent loc = instigator.getComponent(LocationComponent.class); if (loc != null) { return loc.getWorldPosition(); } return new Vector3f(); } }
protected boolean checkDistance(Vector3f soundPosition) { Vector3f distance = new Vector3f(soundPosition); distance.sub(listenerPosition); return distance.lengthSquared() < MAX_DISTANCE_SQUARED; }
private boolean vectorsAreAboutEqual(Vector3f v1, Vector3f v2) { Vector3f delta = new Vector3f(); delta.add(v1); delta.sub(v2); float epsilon = 0.0001f; float deltaSquared = delta.lengthSquared(); return deltaSquared < epsilon; }
@Command(shortDescription = "Teleport all users to location", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION) public String teleportAllPlayersToLocation(@CommandParam("x") float x, @CommandParam("y") float y, @CommandParam("z") float z) { for (EntityRef clientEntity : entityManager.getEntitiesWith(ClientComponent.class)) { ClientComponent clientComp = clientEntity.getComponent(ClientComponent.class); if (clientComp != null) { clientComp.character.send(new CharacterTeleportEvent(new Vector3f(x, y, z))); } } return "All possible players teleported"; }
@Command(value = "pushCharacter", shortDescription = "Pushes you in the direction (x, y, z)", runOnServer = true) public String pushCharacterCommand(@Sender EntityRef sender, @CommandParam("x") float x, @CommandParam("y") float y, @CommandParam("z") float z) { ClientComponent clientComponent = sender.getComponent(ClientComponent.class); clientComponent.character.send(new CharacterImpulseEvent(new Vector3f(x, y, z))); return "Pushing character with " + x + " " + y + " " + z; }
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; }
@ReceiveEvent(components = {CharacterMovementComponent.class, LocationComponent.class, AliveCharacterComponent.class}) public void onTeleport(CharacterTeleportEvent event, EntityRef entity) { CircularBuffer<CharacterStateEvent> stateBuffer = characterStates.get(entity); CharacterStateEvent lastState = stateBuffer.getLast(); CharacterStateEvent newState = new CharacterStateEvent(lastState); newState.setPosition(new Vector3f(event.getTargetPosition())); newState.setTime(time.getGameTimeInMs()); stateBuffer.add(newState); characterMovementSystemUtility.setToState(entity, newState); }
@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 void setToExtrapolateState(EntityRef entity, CharacterStateEvent state, long time) { float t = (time - state.getTime()) * 0.0001f; Vector3f newPos = new Vector3f(state.getVelocity()); newPos.scale(t); newPos.add(state.getPosition()); extrapolateLocationComponent(entity, state, newPos); extrapolateCharacterMovementComponent(entity, state); setPhysicsLocation(entity, newPos); }
@Override public Vector3f deserialize(PersistedData data, DeserializationContext context) { if (data.isArray()) { PersistedDataArray dataArray = data.getAsArray(); if (dataArray.isNumberArray() && dataArray.size() > 2) { TFloatList floats = dataArray.getAsFloatArray(); return new Vector3f(floats.get(0), floats.get(1), floats.get(2)); } } return null; } }
@Test public void testParentScalesWorldLocation() { LocationComponent parent = giveParent(); loc.setLocalPosition(pos1); parent.setLocalScale(2.0f); assertEquals(new Vector3f(2, 4, 6), loc.getWorldPosition()); }
@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 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)); }