use of org.terasology.engine.network.ClientComponent in project Terasology by MovingBlocks.
the class CameraClientSystem method ensureCameraEntityCreated.
private void ensureCameraEntityCreated() {
if (!localPlayer.getCameraEntity().exists()) {
ClientComponent clientComponent = localPlayer.getClientEntity().getComponent(ClientComponent.class);
// create the camera from the prefab
EntityBuilder builder = entityManager.newBuilder("engine:camera");
builder.setPersistent(false);
clientComponent.camera = builder.build();
// Ensure that the camera isn't destroyed by the purgeWorld command.
clientComponent.camera.setScope(EntityScope.GLOBAL);
localPlayer.getClientEntity().saveComponent(clientComponent);
}
}
use of org.terasology.engine.network.ClientComponent in project Terasology by MovingBlocks.
the class CameraClientSystem method mountCamera.
private void mountCamera() {
ClientComponent clientComponent = localPlayer.getClientEntity().getComponent(ClientComponent.class);
EntityRef targetEntityForCamera = GazeAuthoritySystem.getGazeEntityForCharacter(clientComponent.character);
// TODO: why is the camera setup differently
LocationComponent cameraLocation = clientComponent.camera.getComponent(LocationComponent.class);
// if the camera already has a location, use that as the relative position of the camera
if (cameraLocation != null) {
Location.attachChild(targetEntityForCamera, clientComponent.camera, cameraLocation.getLocalPosition(), new Quaternionf());
} else {
Location.attachChild(targetEntityForCamera, clientComponent.camera, new Vector3f(0, 0, 0), new Quaternionf());
}
}
use of org.terasology.engine.network.ClientComponent in project Terasology by MovingBlocks.
the class LocalPlayer method getViewPosition.
/**
* position of camera if one is present else use {@link #getPosition(Vector3f)}
*
* @param dest will hold the result
* @return dest
*/
public Vector3f getViewPosition(Vector3f dest) {
ClientComponent clientComponent = getClientEntity().getComponent(ClientComponent.class);
LocationComponent location = clientComponent.camera.getComponent(LocationComponent.class);
return location.getWorldPosition(dest);
}
use of org.terasology.engine.network.ClientComponent in project Terasology by MovingBlocks.
the class LocalPlayer method getViewRotation.
/**
* orientation of camera if one is present else use {@link #getPosition(Vector3f)}
*
* @param dest will hold the result
* @return dest
*/
public Quaternionf getViewRotation(Quaternionf dest) {
ClientComponent clientComponent = getClientEntity().getComponent(ClientComponent.class);
LocationComponent location = clientComponent.camera.getComponent(LocationComponent.class);
return location.getWorldRotation(dest);
}
use of org.terasology.engine.network.ClientComponent in project Terasology by MovingBlocks.
the class LocalPlayer method setClientEntity.
// TODO: As per Immortius answer in Pull Request #1088,
// TODO: there appears to be situations in which LocalPlayer is instantiated
// TODO: but the client entity is -not- set, i.e. in the headless server.
// TODO: However, it's unclear why the headless server needs a LocalPlayer,
// TODO: instance. If that can be avoided the code in the following method
// TODO: might be more rightfully placed in the LocalPlayer constructor.
public void setClientEntity(EntityRef entity) {
this.clientEntity = entity;
ClientComponent clientComp = entity.getComponent(ClientComponent.class);
if (clientComp != null) {
clientComp.local = true;
entity.saveComponent(clientComp);
}
}
Aggregations