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);
}
}
}
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);
}
}
}
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);
}
}
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();
}
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());
}
}
}
Aggregations