use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.
the class CharacterMovementSystemUtility method setToExtrapolateState.
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);
}
use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.
the class CharacterSystem method onAttackRequest.
@ReceiveEvent(components = LocationComponent.class, netFilter = RegisterMode.AUTHORITY)
public void onAttackRequest(AttackRequest event, EntityRef character, CharacterComponent characterComponent) {
// if an item is used, make sure this entity is allowed to attack with it
if (event.getItem().exists()) {
if (!character.equals(event.getItem().getOwner())) {
return;
}
}
OnItemUseEvent onItemUseEvent = new OnItemUseEvent();
character.send(onItemUseEvent);
if (!onItemUseEvent.isConsumed()) {
EntityRef gazeEntity = GazeAuthoritySystem.getGazeEntityForCharacter(character);
LocationComponent gazeLocation = gazeEntity.getComponent(LocationComponent.class);
Vector3f direction = gazeLocation.getWorldDirection();
Vector3f originPos = gazeLocation.getWorldPosition();
HitResult result = physics.rayTrace(originPos, direction, characterComponent.interactionRange, Sets.newHashSet(character), DEFAULTPHYSICSFILTER);
if (result.isHit()) {
result.getEntity().send(new AttackEvent(character, event.getItem()));
}
}
}
use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.
the class CharacterSystem method isDistanceToLarge.
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;
}
use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.
the class KinematicCharacterMover method extractResidualMovement.
private Vector3f extractResidualMovement(Vector3f hitNormal, Vector3f direction, float normalMag) {
float movementLength = direction.length();
if (movementLength > physics.getEpsilon()) {
direction.normalize();
Vector3f reflectDir = Vector3fUtil.reflect(direction, hitNormal, new Vector3f());
reflectDir.normalize();
Vector3f perpendicularDir = Vector3fUtil.getPerpendicularComponent(reflectDir, hitNormal, new Vector3f());
if (normalMag != 0.0f) {
Vector3f perpComponent = new Vector3f(perpendicularDir);
perpComponent.scale(normalMag * movementLength);
direction.set(perpComponent);
}
}
return direction;
}
use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.
the class KinematicCharacterMover method followToParent.
private void followToParent(final CharacterStateEvent state, EntityRef entity) {
LocationComponent locationComponent = entity.getComponent(LocationComponent.class);
if (!locationComponent.getParent().equals(EntityRef.NULL)) {
Vector3f velocity = new Vector3f(locationComponent.getWorldPosition());
velocity.sub(state.getPosition());
state.getVelocity().set(velocity);
state.getPosition().set(locationComponent.getWorldPosition());
}
}
Aggregations