Search in sources :

Example 61 with Vector3f

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);
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) BaseVector3f(org.terasology.math.geom.BaseVector3f)

Example 62 with Vector3f

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()));
        }
    }
}
Also used : HitResult(org.terasology.physics.HitResult) OnItemUseEvent(org.terasology.logic.characters.events.OnItemUseEvent) Vector3f(org.terasology.math.geom.Vector3f) EntityRef(org.terasology.entitySystem.entity.EntityRef) LocationComponent(org.terasology.logic.location.LocationComponent) AttackEvent(org.terasology.logic.characters.events.AttackEvent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 63 with Vector3f

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;
}
Also used : Vector3f(org.terasology.math.geom.Vector3f)

Example 64 with Vector3f

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;
}
Also used : Vector3f(org.terasology.math.geom.Vector3f)

Example 65 with Vector3f

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());
    }
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) LocationComponent(org.terasology.logic.location.LocationComponent)

Aggregations

Vector3f (org.terasology.math.geom.Vector3f)194 LocationComponent (org.terasology.logic.location.LocationComponent)45 EntityRef (org.terasology.entitySystem.entity.EntityRef)44 Quat4f (org.terasology.math.geom.Quat4f)33 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)26 Vector3i (org.terasology.math.geom.Vector3i)21 Test (org.junit.Test)20 ClientComponent (org.terasology.network.ClientComponent)15 Command (org.terasology.logic.console.commandSystem.annotations.Command)14 Matrix4f (org.terasology.math.geom.Matrix4f)13 BaseVector3f (org.terasology.math.geom.BaseVector3f)9 Block (org.terasology.world.block.Block)9 Vector2f (org.terasology.math.geom.Vector2f)8 HitResult (org.terasology.physics.HitResult)8 CharacterTeleportEvent (org.terasology.logic.characters.CharacterTeleportEvent)7 IOException (java.io.IOException)6 FloatBuffer (java.nio.FloatBuffer)6 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)5 AABB (org.terasology.math.AABB)5 ChunkMesh (org.terasology.rendering.primitives.ChunkMesh)5