use of org.terasology.physics.components.shapes.SphereShapeComponent in project Terasology by MovingBlocks.
the class PlayerFactory method getHeightOf.
private float getHeightOf(ComponentContainer prefab) {
BoxShapeComponent box = prefab.getComponent(BoxShapeComponent.class);
if (box != null) {
return box.extents.getY();
}
CylinderShapeComponent cylinder = prefab.getComponent(CylinderShapeComponent.class);
if (cylinder != null) {
return cylinder.height;
}
CapsuleShapeComponent capsule = prefab.getComponent(CapsuleShapeComponent.class);
if (capsule != null) {
return capsule.height;
}
SphereShapeComponent sphere = prefab.getComponent(SphereShapeComponent.class);
if (sphere != null) {
return sphere.radius * 2.0f;
}
HullShapeComponent hull = prefab.getComponent(HullShapeComponent.class);
if (hull != null) {
AABB aabb = hull.sourceMesh.getAABB();
return aabb.maxY() - aabb.minY();
}
logger.warn("entity {} does not have any known extent specification - using default", prefab);
return 1.0f;
}
use of org.terasology.physics.components.shapes.SphereShapeComponent in project Terasology by MovingBlocks.
the class BulletPhysics method getShapeFor.
/**
* Returns the shape belonging to the given entity. It currently knows 4
* different shapes: Sphere, Capsule, Cylinder or arbitrary.
* The shape is determined based on the shape component of the given entity.
* If the entity has somehow got multiple shapes, only one is picked. The
* order of priority is: Sphere, Capsule, Cylinder, arbitrary.
* <br><br>
* TODO: Flyweight this (take scale as parameter)
*
* @param entity the entity to get the shape of.
* @return the shape of the entity, ready to be used by Bullet.
*/
private ConvexShape getShapeFor(EntityRef entity) {
BoxShapeComponent box = entity.getComponent(BoxShapeComponent.class);
if (box != null) {
Vector3f halfExtents = new Vector3f(VecMath.to(box.extents));
halfExtents.scale(0.5f);
return new BoxShape(halfExtents);
}
SphereShapeComponent sphere = entity.getComponent(SphereShapeComponent.class);
if (sphere != null) {
return new SphereShape(sphere.radius);
}
CapsuleShapeComponent capsule = entity.getComponent(CapsuleShapeComponent.class);
if (capsule != null) {
return new CapsuleShape(capsule.radius, capsule.height);
}
CylinderShapeComponent cylinder = entity.getComponent(CylinderShapeComponent.class);
if (cylinder != null) {
return new CylinderShape(new Vector3f(cylinder.radius, 0.5f * cylinder.height, cylinder.radius));
}
HullShapeComponent hull = entity.getComponent(HullShapeComponent.class);
if (hull != null) {
ObjectArrayList<Vector3f> verts = new ObjectArrayList<>();
TFloatIterator iterator = hull.sourceMesh.getVertices().iterator();
while (iterator.hasNext()) {
Vector3f newVert = new Vector3f();
newVert.x = iterator.next();
newVert.y = iterator.next();
newVert.z = iterator.next();
verts.add(newVert);
}
return new ConvexHullShape(verts);
}
CharacterMovementComponent characterMovementComponent = entity.getComponent(CharacterMovementComponent.class);
if (characterMovementComponent != null) {
return new CapsuleShape(characterMovementComponent.radius, characterMovementComponent.height);
}
logger.error("Creating physics object that requires a ShapeComponent or CharacterMovementComponent, but has neither. Entity: {}", entity);
throw new IllegalArgumentException("Creating physics object that requires a ShapeComponent or CharacterMovementComponent, but has neither. Entity: " + entity);
}
Aggregations