use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class BulletPhysics method newTrigger.
// *******************Private helper methods**************************\\
/**
* Creates a new trigger.
*
* @param entity the entity to create a trigger for.
*/
private boolean newTrigger(EntityRef entity) {
LocationComponent location = entity.getComponent(LocationComponent.class);
TriggerComponent trigger = entity.getComponent(TriggerComponent.class);
btCollisionShape shape = getShapeFor(entity);
if (shape != null && location != null && trigger != null) {
float scale = location.getWorldScale();
shape.setLocalScaling(new Vector3f(scale, scale, scale));
List<CollisionGroup> detectGroups = Lists.newArrayList(trigger.detectGroups);
CollisionGroup collisionGroup = trigger.collisionGroup;
btPairCachingGhostObject triggerObj = createCollider(location.getWorldPosition(new Vector3f()), shape, collisionGroup.getFlag(), combineGroups(detectGroups), btCollisionObject.CollisionFlags.CF_NO_CONTACT_RESPONSE);
triggerObj.userData = entity;
btPairCachingGhostObject oldTrigger = entityTriggers.put(entity, triggerObj);
if (oldTrigger != null) {
logger.warn("Creating a trigger for an entity that already has a trigger. " + "Multiple trigger pre entity are not supported. Removing old one. Entity: {}", entity);
removeCollider(oldTrigger);
return false;
} else {
return true;
}
} else {
logger.warn("Trying to create trigger for entity without ShapeComponent or without LocationComponent " + "or without TriggerComponent. Entity: {}", entity);
return false;
}
}
use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class EntityMotionState method setWorldTransform.
@Override
public void setWorldTransform(Matrix4f transform) {
LocationComponent loc = entity.getComponent(LocationComponent.class);
if (loc != null) {
rot.setFromNormalized(transform);
rot.normalize();
transform.getTranslation(position);
loc.setWorldRotation(rot);
loc.setWorldPosition(position);
}
}
use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class FloatingTextRenderer method render.
private void render(Iterable<EntityRef> floatingTextEntities) {
Vector3fc cameraPosition = camera.getPosition();
Matrix4f model = new Matrix4f();
Matrix4f modelView = new Matrix4f();
Vector3f worldPos = new Vector3f();
for (EntityRef entity : floatingTextEntities) {
FloatingTextComponent floatingText = entity.getComponent(FloatingTextComponent.class);
LocationComponent location = entity.getComponent(LocationComponent.class);
if (location == null) {
logger.warn("location component is not defined can't render text: {}", floatingText.text);
continue;
}
location.getWorldPosition(worldPos);
if (!worldProvider.isBlockRelevant(worldPos) || !worldPos.isFinite()) {
continue;
}
String[] linesOfText = floatingText.text.split("\n");
Color baseColor = floatingText.textColor;
Color shadowColor = floatingText.textShadowColor;
boolean underline = false;
int textWidth = 0;
for (String singleLine : linesOfText) {
if (font.getWidth(singleLine) > textWidth) {
textWidth = font.getWidth(singleLine);
}
}
FontMeshBuilder meshBuilder = new FontMeshBuilder(underlineMaterial);
Map<Material, Mesh> meshMap = entityMeshCache.get(entity);
if (meshMap == null) {
meshMap = meshBuilder.createTextMesh(font, Arrays.asList(linesOfText), textWidth, HorizontalAlign.CENTER, baseColor, shadowColor, underline);
entityMeshCache.put(entity, meshMap);
}
if (floatingText.isOverlay) {
glDisable(GL_DEPTH_TEST);
}
float scale = METER_PER_PIXEL * floatingText.scale;
model.setTranslation(worldPos.sub(cameraPosition));
modelView.set(camera.getViewMatrix()).mul(model).m00(1.0f).m10(0.0f).m20(0.0f).m01(0.0f).m11(1.0f).m21(0.0f).m02(0.0f).m12(0.0f).m22(1.0f);
modelView.scale(scale, -scale, scale);
modelView.translate(-textWidth / 2.0f, 0.0f, 0.0f);
for (Map.Entry<Material, Mesh> meshMapEntry : meshMap.entrySet()) {
Mesh mesh = meshMapEntry.getValue();
Material material = meshMapEntry.getKey();
material.enable();
material.bindTextures();
material.setFloat4("croppingBoundaries", Float.MIN_VALUE, Float.MAX_VALUE, Float.MIN_VALUE, Float.MAX_VALUE);
material.setMatrix4("modelViewMatrix", modelView);
material.setMatrix4("projectionMatrix", camera.getProjectionMatrix());
material.setFloat2("offset", 0.0f, 0.0f);
material.setFloat("alpha", 1.0f);
mesh.render();
}
// Revert to default state
if (floatingText.isOverlay) {
glEnable(GL_DEPTH_TEST);
}
}
}
use of org.terasology.engine.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 boneEntity = entityManager.create(loc);
skeleton.boneEntities.put(bone.getName(), boneEntity);
}
}
for (Bone bone : skeleton.mesh.getBones()) {
EntityRef boneEntity = skeleton.boneEntities.get(bone.getName());
EntityRef parent = (bone.getParent() != null) ? skeleton.boneEntities.get(bone.getParent().getName()) : entity;
Location.attachChild(parent, boneEntity);
}
for (Bone bone : skeleton.mesh.getBones()) {
EntityRef boneEntity = skeleton.boneEntities.get(bone.getName());
LocationComponent loc = boneEntity.getComponent(LocationComponent.class);
loc.setLocalPosition(bone.getLocalPosition());
loc.setLocalRotation(bone.getLocalRotation());
loc.setLocalScale(bone.getLocalScale().x);
boneEntity.saveComponent(loc);
if (bone.getParent() == null) {
skeleton.rootBone = boneEntity;
}
}
entity.saveComponent(skeleton);
}
use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class EntityBasedRenderableChunk method hasMesh.
@Override
public boolean hasMesh() {
ChunkMeshComponent mesh = entity.getComponent(ChunkMeshComponent.class);
LocationComponent location = entity.getComponent(LocationComponent.class);
return mesh != null && location != null && mesh.mesh != null;
}
Aggregations