private boolean lightIsRenderable(LightComponent lightComponent, Vector3f lightPositionRelativeToCamera) { // if lightRenderingDistance is 0.0, the light is always considered, no matter the distance. boolean lightIsRenderable = lightComponent.lightRenderingDistance == 0.0f || lightPositionRelativeToCamera.lengthSquared() < (lightComponent.lightRenderingDistance * lightComponent.lightRenderingDistance); // above: rendering distance must be higher than distance from the camera or the light is ignored // No matter what, we ignore lights that are not in the camera frustrum lightIsRenderable &= activeCamera.getViewFrustum().intersects(lightPositionRelativeToCamera, lightComponent.lightAttenuationRange); // TODO: (above) what about lights just off-frame? They might light up in-frame surfaces. return lightIsRenderable; }
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; }
private float score(Vector3i chunkPos) { Vector3f vec = chunkPos.toVector3f(); vec.sub(localPlayer.getPosition()); return vec.lengthSquared(); } }
private static float squaredDistanceToCamera(RenderableChunk chunk, Vector3f cameraPosition) { // For performance reasons, to avoid instantiating too many vectors in a frequently called method, // comments are in use instead of appropriately named vectors. Vector3f result = chunk.getPosition().toVector3f(); // chunk position in chunk coordinates result.add(CHUNK_CENTER_OFFSET); // chunk center in chunk coordinates result.x *= ChunkConstants.SIZE_X; // chunk center in world coordinates result.y *= ChunkConstants.SIZE_Y; result.z *= ChunkConstants.SIZE_Z; result.sub(cameraPosition); // camera to chunk vector return result.lengthSquared(); }
@Override public int compare(EntityRef o1, EntityRef o2) { LocationComponent loc1 = o1.getComponent(LocationComponent.class); LocationComponent loc2 = o2.getComponent(LocationComponent.class); if (loc1 == null && loc2 == null) { return 0; } else if (loc1 == null) { return 1; } else if (loc2 == null) { return -1; } loc1.getWorldPosition(temp); temp.sub(origin); float dis1 = temp.lengthSquared(); loc2.getWorldPosition(temp); temp.sub(origin); float dis2 = temp.lengthSquared(); if (dis1 < dis2) { return -1; } else if (dis2 < dis1) { return 1; } else { //dis1 == dis2 return 0; } }
private boolean isDistanceToLarge(LocationComponent characterLocation, LocationComponent targetLocation, float maxInteractionRange) { float maxInteractionRangeSquared = maxInteractionRange * maxInteractionRange; Vector3f positionDelta = new Vector3f(); positionDelta.add(characterLocation.getWorldPosition()); positionDelta.sub(targetLocation.getWorldPosition()); float interactionRangeSquared = positionDelta.lengthSquared(); // add a small epsilon to have rounding mistakes be in favor of the player: float epsilon = 0.00001f; return interactionRangeSquared > maxInteractionRangeSquared + epsilon; }
@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)); } }
Vector3f dir = new Vector3f(characterLocation.getWorldDirection()); dir.y = 0; if (dir.lengthSquared() > 0.001f) { dir.normalize(); } else {
Vector3f expectedMove = new Vector3f(targetPos); expectedMove.sub(position); if (expectedMove.lengthSquared() > physics.getEpsilon()) { expectedMove.normalize(); expectedMove.scale(actualDist); expectedMove.sub(position); extractResidualMovement(callback.getHitNormalWorld(), expectedMove); float sqrDist = expectedMove.lengthSquared(); if (sqrDist > physics.getEpsilon()) { expectedMove.normalize();
Vector3f dist = new Vector3f(worldPos); dist.sub(localPlayer.getPosition()); double distanceToPlayer = dist.lengthSquared();
Vector3f horizNormal = new Vector3f(callback.getHitNormalWorld().x, 0, callback.getHitNormalWorld().z); if (horizNormal.lengthSquared() > physics.getEpsilon()) { horizNormal.normalize(); if (lastHitNormal.dot(horizNormal) > physics.getEpsilon()) { newDir.scale(newHorizDir.length() / modHorizDir.length()); float sqrDist = newDir.lengthSquared(); if (sqrDist > physics.getEpsilon()) { newDir.normalize();
Vector3f dist = new Vector3f(worldPos); dist.sub(localPlayer.getPosition()); double distanceToPlayer = dist.lengthSquared();
Vector3f desiredVelocity = new Vector3f(input.getMovementDirection()); float lengthSquared = desiredVelocity.lengthSquared();