/** * Get a new AABB which have a new location base on the offset * @param offset The offset between the current AABB and the new AABB * @return the new AABB */ public AABB move(Vector3f offset) { Vector3f newMin = new Vector3f(min); newMin.add(offset); Vector3f newMax = new Vector3f(max); newMax.add(offset); return new AABB(newMin, newMax); }
public Vector3f getCenter() { Vector3f dimensions = new Vector3f(max); dimensions.add(min); dimensions.scale(HALVING_FACTOR); return dimensions; }
/** * Transforms the point {@code v} into the space represented by this transform. The result is placed * back into {@code v}. * @param v The point to transform. */ public void transform(Vector3f v) { getBasis().transform(v); v.add(origin); } }
/** * @return the portion of direction that is perpendicular to normal */ public static Vector3f getPerpendicularComponent(Vector3f direction, Vector3f normal, Vector3f out) { Vector3f perpendicular = getParallelComponent(direction, normal, out); perpendicular.scale(-1); perpendicular.add(direction); return perpendicular; }
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; }
/** * @return The reflection of direction against normal */ public static Vector3f reflect(Vector3f direction, Vector3f normal, Vector3f out) { out.set(normal); out.scale(-2.0f * direction.dot(normal)); out.add(direction); return out; }
/** * @return The position at the center of the region */ public Vector3f center() { Vector3f result = min.toVector3f(); Vector3f halfSize = size.toVector3f(); halfSize.scale(0.5f); result.add(halfSize); return result; }
@Override public void update(final VelocityAffectorComponent component, final ParticleData particleData, final Random random, final float delta ) { particleData.position.add( particleData.velocity.x() * delta, particleData.velocity.y() * delta, particleData.velocity.z() * delta ); } }
@Override public void update(final AccelerationAffectorComponent component, final ParticleData particleData, final Random random, final float delta ) { particleData.velocity.add( component.acceleration.x() * delta, component.acceleration.y() * delta, component.acceleration.z() * delta ); } }
public List<Vector3f> getVertexPositions(List<Vector3f> bonePositions, List<Quat4f> boneRotations) { List<Vector3f> results = Lists.newArrayListWithCapacity(getVertexCount()); for (int i = 0; i < vertexStartWeights.size(); ++i) { Vector3f vertexPos = new Vector3f(); for (int weightIndexOffset = 0; weightIndexOffset < vertexWeightCounts.get(i); ++weightIndexOffset) { int weightIndex = vertexStartWeights.get(i) + weightIndexOffset; BoneWeight weight = weights.get(weightIndex); Vector3f current = boneRotations.get(weight.getBoneIndex()).rotate(weight.getPosition(), new Vector3f()); current.add(bonePositions.get(weight.getBoneIndex())); current.scale(weight.getBias()); vertexPos.add(current); } results.add(vertexPos); } return results; }
@Override public AABB getAABB() { if (aabb == null) { Vector3f min = getChunkWorldOffset().toVector3f(); Vector3f max = ChunkConstants.CHUNK_SIZE.toVector3f(); max.add(min); aabb = AABB.createMinMax(min, max); } return aabb; }
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(); }
/** * Creates a new AABB with the given center and extents. * * @param center The center of the AABB. * @param extent The extent of the AABB. * @return The created AABB. */ public static AABB createCenterExtent(Vector3f center, Vector3f extent) { Vector3f min = new Vector3f(center); min.sub(extent); Vector3f max = new Vector3f(center); max.add(extent); return new AABB(min, max); }
public List<Vector3f> getVertexNormals(List<Vector3f> bonePositions, List<Quat4f> boneRotations) { List<Vector3f> results = Lists.newArrayListWithCapacity(getVertexCount()); for (int i = 0; i < vertexStartWeights.size(); ++i) { Vector3f vertexNorm = new Vector3f(); for (int weightIndexOffset = 0; weightIndexOffset < vertexWeightCounts.get(i); ++weightIndexOffset) { int weightIndex = vertexStartWeights.get(i) + weightIndexOffset; BoneWeight weight = weights.get(weightIndex); Vector3f current = boneRotations.get(weight.getBoneIndex()).rotate(weight.getNormal(), new Vector3f()); current.scale(weight.getBias()); vertexNorm.add(current); } results.add(vertexNorm); } return results; }
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; }
private void emitParticle(final ParticleEmitterComponent particleEmitter) { int index = particleEmitter.particlePool.reviveParticle(); particleEmitter.particlePool.loadTemporaryDataFrom(index, ParticleDataMask.ALL.toInt()); particleEmitter.generatorFunctionMap.forEach( (component, generator) -> generator.onEmission(component, particleEmitter.particlePool.temporaryParticleData, random) ); particleEmitter.particlePool.temporaryParticleData.position.add( particleEmitter.locationComponent.getWorldPosition() ); particleEmitter.particlePool.storeTemporaryDataAt(index, ParticleDataMask.ALL.toInt()); }
public Vector3f getWorldPosition(Vector3f output) { output.set(position); LocationComponent parentLoc = parent.getComponent(LocationComponent.class); while (parentLoc != null) { output.scale(parentLoc.scale); parentLoc.getLocalRotation().rotate(output, output); output.add(parentLoc.position); parentLoc = parentLoc.parent.getComponent(LocationComponent.class); } return output; }
@ReceiveEvent(components = {CharacterMovementComponent.class, LocationComponent.class, AliveCharacterComponent.class}) public void onImpulse(CharacterImpulseEvent event, EntityRef entity) { Vector3f impulse = event.getDirection(); CircularBuffer<CharacterStateEvent> stateBuffer = characterStates.get(entity); CharacterStateEvent lastState = stateBuffer.getLast(); CharacterStateEvent newState = new CharacterStateEvent(lastState); newState.setVelocity(impulse.add(newState.getVelocity())); newState.setTime(time.getGameTimeInMs()); newState.setGrounded(false); stateBuffer.add(newState); characterMovementSystemUtility.setToState(entity, newState); }
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); }
private void checkCollision(final ParticlePool pool, final int offset) { final Vector3f vel = new Vector3f(); final Vector3f halfVelDir = new Vector3f(); final Vector3f curr = new Vector3f(); for (int i = offset; i < pool.livingParticles(); i += PHYSICS_SKIP_NR) { int i3 = i * 3; curr.set(pool.position[i3 + 0], pool.position[i3 + 1], pool.position[i3 + 2]); vel.set(pool.velocity[i3 + 0], pool.velocity[i3 + 1], pool.velocity[i3 + 2]); halfVelDir.scale(0).add(vel).normalize().scale(0.5f); curr.sub(halfVelDir); float dist = (vel.length() + 0.5f) * movingAvgDelta * PHYSICS_SKIP_NR * 1.5f; vel.normalize(); HitResult hitResult = physics.rayTrace(curr, vel, dist, StandardCollisionGroup.WORLD); if (hitResult.isHit()) { pool.energy[i] = 0; } } }