Search in sources :

Example 41 with LocationComponent

use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.

the class SkeletonRenderer method renderBone.

private void renderBone(EntityRef boneEntity, Vector3f centerPos) {
    LocationComponent loc = boneEntity.getComponent(LocationComponent.class);
    if (loc == null) {
        return;
    }
    LocationComponent parentLoc = loc.getParent().getComponent(LocationComponent.class);
    if (parentLoc != null) {
        Vector3f worldPosA = loc.getWorldPosition();
        worldPosA.sub(centerPos);
        Vector3f worldPosB = parentLoc.getWorldPosition();
        worldPosB.sub(centerPos);
        glBegin(GL11.GL_LINES);
        glVertex3f(worldPosA.x, worldPosA.y, worldPosA.z);
        glVertex3f(worldPosB.x, worldPosB.y, worldPosB.z);
        glEnd();
        for (EntityRef child : loc.getChildren()) {
            renderBone(child, centerPos);
        }
    }
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) BaseVector3f(org.terasology.math.geom.BaseVector3f) LocationComponent(org.terasology.logic.location.LocationComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 42 with LocationComponent

use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.

the class SkeletonRenderer method updateSkeleton.

private void updateSkeleton(SkeletalMeshComponent skeletalMeshComp, MeshAnimationFrame frameA, MeshAnimationFrame frameB, float interpolationVal) {
    for (int i = 0; i < skeletalMeshComp.animation.getBoneCount(); ++i) {
        EntityRef boneEntity = skeletalMeshComp.boneEntities.get(skeletalMeshComp.animation.getBoneName(i));
        if (boneEntity == null) {
            continue;
        }
        LocationComponent boneLoc = boneEntity.getComponent(LocationComponent.class);
        if (boneLoc != null) {
            Vector3f newPos = BaseVector3f.lerp(frameA.getPosition(i), frameB.getPosition(i), interpolationVal);
            boneLoc.setLocalPosition(newPos);
            Quat4f newRot = BaseQuat4f.interpolate(frameA.getRotation(i), frameB.getRotation(i), interpolationVal);
            newRot.normalize();
            boneLoc.setLocalRotation(newRot);
            boneEntity.saveComponent(boneLoc);
        }
    }
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) BaseVector3f(org.terasology.math.geom.BaseVector3f) EntityRef(org.terasology.entitySystem.entity.EntityRef) LocationComponent(org.terasology.logic.location.LocationComponent) BaseQuat4f(org.terasology.math.geom.BaseQuat4f) Quat4f(org.terasology.math.geom.Quat4f)

Example 43 with LocationComponent

use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.

the class SkeletonRenderer method newSkeleton.

@ReceiveEvent(components = { SkeletalMeshComponent.class, LocationComponent.class })
public void newSkeleton(OnActivatedComponent event, EntityRef entity) {
    SkeletalMeshComponent skeleton = entity.getComponent(SkeletalMeshComponent.class);
    if (skeleton.mesh == null) {
        return;
    }
    if (skeleton.boneEntities == null) {
        skeleton.boneEntities = Maps.newHashMap();
        for (Bone bone : skeleton.mesh.getBones()) {
            LocationComponent loc = new LocationComponent();
            EntityRef parent = (bone.getParent() != null) ? skeleton.boneEntities.get(bone.getParent().getName()) : entity;
            EntityRef boneEntity = entityManager.create(loc);
            Location.attachChild(parent, boneEntity);
            loc.setLocalPosition(bone.getLocalPosition());
            loc.setLocalRotation(bone.getLocalRotation());
            if (bone.getParent() == null) {
                skeleton.rootBone = boneEntity;
            }
            skeleton.boneEntities.put(bone.getName(), boneEntity);
        }
        entity.saveComponent(skeleton);
    }
}
Also used : Bone(org.terasology.rendering.assets.skeletalmesh.Bone) LocationComponent(org.terasology.logic.location.LocationComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 44 with LocationComponent

use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.

the class SkeletonRenderer method renderBoneOrientation.

private void renderBoneOrientation(EntityRef boneEntity) {
    LocationComponent loc = boneEntity.getComponent(LocationComponent.class);
    if (loc == null) {
        return;
    }
    glPushMatrix();
    Vector3f worldPosA = loc.getWorldPosition();
    Quat4f worldRot = loc.getWorldRotation();
    Vector3f offset = new Vector3f(0, 0, 0.1f);
    worldRot.rotate(offset, offset);
    offset.add(worldPosA);
    glBegin(GL11.GL_LINES);
    glVertex3f(worldPosA.x, worldPosA.y, worldPosA.z);
    glVertex3f(offset.x, offset.y, offset.z);
    glEnd();
    loc.getChildren().forEach(this::renderBoneOrientation);
    glPopMatrix();
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) BaseVector3f(org.terasology.math.geom.BaseVector3f) LocationComponent(org.terasology.logic.location.LocationComponent) BaseQuat4f(org.terasology.math.geom.BaseQuat4f) Quat4f(org.terasology.math.geom.Quat4f)

Example 45 with LocationComponent

use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.

the class BlockEntitySystem method defaultDropsHandling.

@ReceiveEvent(priority = EventPriority.PRIORITY_TRIVIAL)
public void defaultDropsHandling(CreateBlockDropsEvent event, EntityRef entity, ActAsBlockComponent blockComponent) {
    if (blockComponent.block != null) {
        if (entity.hasComponent(BlockRegionComponent.class)) {
            BlockRegionComponent blockRegion = entity.getComponent(BlockRegionComponent.class);
            if (blockComponent.dropBlocksInRegion) {
                // loop through all the blocks in this region and drop them
                for (Vector3i location : blockRegion.region) {
                    Block blockInWorld = worldProvider.getBlock(location);
                    commonDefaultDropsHandling(event, entity, location, blockInWorld.getBlockFamily().getArchetypeBlock());
                }
            } else {
                // just drop the ActAsBlock block
                Vector3i location = new Vector3i(blockRegion.region.center(), RoundingMode.HALF_UP);
                commonDefaultDropsHandling(event, entity, location, blockComponent.block.getArchetypeBlock());
            }
        } else if (entity.hasComponent(LocationComponent.class)) {
            LocationComponent locationComponent = entity.getComponent(LocationComponent.class);
            Vector3i location = new Vector3i(locationComponent.getWorldPosition(), RoundingMode.HALF_UP);
            commonDefaultDropsHandling(event, entity, location, blockComponent.block.getArchetypeBlock());
        }
    }
}
Also used : BlockRegionComponent(org.terasology.world.block.regions.BlockRegionComponent) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block) LocationComponent(org.terasology.logic.location.LocationComponent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Aggregations

LocationComponent (org.terasology.logic.location.LocationComponent)69 EntityRef (org.terasology.entitySystem.entity.EntityRef)40 Vector3f (org.terasology.math.geom.Vector3f)39 ClientComponent (org.terasology.network.ClientComponent)17 Quat4f (org.terasology.math.geom.Quat4f)16 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)11 Command (org.terasology.logic.console.commandSystem.annotations.Command)10 Vector3i (org.terasology.math.geom.Vector3i)10 BlockComponent (org.terasology.world.block.BlockComponent)7 CharacterTeleportEvent (org.terasology.logic.characters.CharacterTeleportEvent)6 BaseQuat4f (org.terasology.math.geom.BaseQuat4f)6 Vector3f (javax.vecmath.Vector3f)5 Component (org.terasology.entitySystem.Component)5 BaseVector3f (org.terasology.math.geom.BaseVector3f)5 MeshComponent (org.terasology.rendering.logic.MeshComponent)5 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)4 DisplayNameComponent (org.terasology.logic.common.DisplayNameComponent)4 Matrix4f (org.terasology.math.geom.Matrix4f)4 BlockFamily (org.terasology.world.block.family.BlockFamily)4 ConvexShape (com.bulletphysics.collision.shapes.ConvexShape)3