use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class BulletPhysics method updateTrigger.
@Override
public // TODO: update if detectGroups changed
boolean updateTrigger(EntityRef entity) {
LocationComponent location = entity.getComponent(LocationComponent.class);
PairCachingGhostObject triggerObj = entityTriggers.get(entity);
if (location == null) {
logger.warn("Trying to update or create trigger of entity that has no LocationComponent?! Entity: {}", entity);
return false;
}
if (triggerObj != null) {
float scale = location.getWorldScale();
if (Math.abs(triggerObj.getCollisionShape().getLocalScaling(new Vector3f()).x - scale) > BulletGlobals.SIMD_EPSILON) {
discreteDynamicsWorld.removeCollisionObject(triggerObj);
newTrigger(entity);
} else {
Quat4f worldRotation = VecMath.to(location.getWorldRotation());
Vector3f worldPosition = VecMath.to(location.getWorldPosition());
triggerObj.setWorldTransform(new Transform(new Matrix4f(worldRotation, worldPosition, 1.0f)));
}
return true;
} else {
newTrigger(entity);
return false;
}
}
use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class EntityMotionState method setWorldTransform.
@Override
public void setWorldTransform(Transform transform) {
LocationComponent loc = entity.getComponent(LocationComponent.class);
if (loc != null) {
loc.setWorldPosition(VecMath.from(transform.origin));
loc.setWorldRotation(VecMath.from(transform.getRotation(new javax.vecmath.Quat4f())));
}
}
use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class ReadWriteStorageManager method createPlayerStore.
private PlayerStoreBuilder createPlayerStore(Client client, EntityRef character) {
LocationComponent location = character.getComponent(LocationComponent.class);
Vector3f relevanceLocation;
if (location != null) {
relevanceLocation = location.getWorldPosition();
} else {
relevanceLocation = new Vector3f();
}
Long characterId;
if (character.exists()) {
characterId = character.getId();
} else {
characterId = null;
}
return new PlayerStoreBuilder(characterId, relevanceLocation);
}
use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class PojoEntityPool method create.
private EntityRef create(Prefab prefab, Vector3f position, Quat4f rotation, boolean sendLifecycleEvents) {
EntityBuilder builder = newBuilder(prefab);
builder.setSendLifecycleEvents(sendLifecycleEvents);
LocationComponent loc = builder.getComponent(LocationComponent.class);
if (loc == null && (position != null || rotation != null)) {
loc = new LocationComponent();
builder.addComponent(loc);
}
if (position != null) {
loc.setWorldPosition(position);
}
if (rotation != null) {
loc.setWorldRotation(rotation);
}
return builder.build();
}
use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class NetClient method sendNewChunks.
private void sendNewChunks(NetData.NetMessage.Builder message) {
if (!readyChunks.isEmpty()) {
chunkSendCounter += chunkSendRate * NET_TICK_RATE * networkSystem.getBandwidthPerClient();
if (chunkSendCounter > 1.0f) {
chunkSendCounter -= 1.0f;
Vector3i center = new Vector3i();
LocationComponent loc = getEntity().getComponent(ClientComponent.class).character.getComponent(LocationComponent.class);
if (loc != null) {
center.set(ChunkMath.calcChunkPos(new Vector3i(loc.getWorldPosition(), RoundingMode.HALF_UP)));
}
Vector3i pos = null;
int distance = Integer.MAX_VALUE;
for (Vector3i chunkPos : readyChunks.keySet()) {
int chunkDistance = chunkPos.distanceSquared(center);
if (pos == null || chunkDistance < distance) {
pos = chunkPos;
distance = chunkDistance;
}
}
Chunk chunk = readyChunks.remove(pos);
relevantChunks.add(pos);
message.addChunkInfo(chunk.encode());
}
} else {
chunkSendCounter = 1.0f;
}
}
Aggregations