use of gnu.trove.iterator.TFloatIterator in project Terasology by MovingBlocks.
the class OpenGLMesh method buildMesh.
private void buildMesh(MeshData newData) {
this.data = newData;
List<TFloatIterator> parts = Lists.newArrayList();
TIntList partSizes = new TIntArrayList();
int vertexCount = newData.getVertices().size() / VERTEX_SIZE;
int vertexSize = VERTEX_SIZE;
parts.add(newData.getVertices().iterator());
partSizes.add(VERTEX_SIZE);
if (newData.getTexCoord0() != null && newData.getTexCoord0().size() / TEX_COORD_0_SIZE == vertexCount) {
parts.add(newData.getTexCoord0().iterator());
partSizes.add(TEX_COORD_0_SIZE);
texCoord0Offset = vertexSize * FLOAT_SIZE;
vertexSize += TEX_COORD_0_SIZE;
hasTexCoord0 = true;
}
if (newData.getTexCoord1() != null && newData.getTexCoord1().size() / TEX_COORD_1_SIZE == vertexCount) {
parts.add(newData.getTexCoord1().iterator());
partSizes.add(TEX_COORD_1_SIZE);
texCoord1Offset = vertexSize * FLOAT_SIZE;
vertexSize += TEX_COORD_1_SIZE;
hasTexCoord1 = true;
}
if (newData.getNormals() != null && newData.getNormals().size() / NORMAL_SIZE == vertexCount) {
parts.add(newData.getNormals().iterator());
partSizes.add(NORMAL_SIZE);
normalOffset = vertexSize * FLOAT_SIZE;
vertexSize += NORMAL_SIZE;
hasNormal = true;
}
if (newData.getColors() != null && newData.getColors().size() / COLOR_SIZE == vertexCount) {
parts.add(newData.getColors().iterator());
partSizes.add(COLOR_SIZE);
colorOffset = vertexSize * FLOAT_SIZE;
vertexSize += COLOR_SIZE;
hasColor = true;
}
stride = vertexSize * FLOAT_SIZE;
indexCount = newData.getIndices().size();
createVertexBuffer(parts, partSizes, vertexCount, vertexSize);
createIndexBuffer(newData.getIndices());
aabb = AABB.createEncompasing(newData.getVertices());
}
use of gnu.trove.iterator.TFloatIterator in project Terasology by MovingBlocks.
the class HealthAuthoritySystem method calculateTotal.
private int calculateTotal(int base, TFloatList multipliers, TIntList modifiers) {
// For now, add all modifiers and multiply by all multipliers. Negative modifiers cap to zero, but negative
// multipliers remain (so damage can be flipped to healing)
float total = base;
TIntIterator modifierIter = modifiers.iterator();
while (modifierIter.hasNext()) {
total += modifierIter.next();
}
total = Math.max(0, total);
if (total == 0) {
return 0;
}
TFloatIterator multiplierIter = multipliers.iterator();
while (multiplierIter.hasNext()) {
total *= multiplierIter.next();
}
return TeraMath.floorToInt(total);
}
use of gnu.trove.iterator.TFloatIterator in project Terasology by MovingBlocks.
the class AbstractValueModifiableEvent method getResultValue.
public float getResultValue() {
// For now, add all modifiers and multiply by all multipliers. Negative modifiers cap to zero, but negative
// multipliers remain.
float result = baseValue;
TFloatIterator modifierIter = modifiers.iterator();
while (modifierIter.hasNext()) {
result += modifierIter.next();
}
result = Math.max(0, result);
TFloatIterator multiplierIter = multipliers.iterator();
while (multiplierIter.hasNext()) {
result *= multiplierIter.next();
}
final TFloatIterator postModifierIter = postModifiers.iterator();
while (postModifierIter.hasNext()) {
result += postModifierIter.next();
}
return result;
}
use of gnu.trove.iterator.TFloatIterator in project Terasology by MovingBlocks.
the class OpenGLMesh method createVertexBuffer.
private void createVertexBuffer(List<TFloatIterator> parts, TIntList partSizes, int vertexCount, int vertexSize) {
FloatBuffer vertexBuffer = BufferUtils.createFloatBuffer(vertexSize * vertexCount);
for (int v = 0; v < vertexCount; ++v) {
for (int partIndex = 0; partIndex < parts.size(); ++partIndex) {
TFloatIterator part = parts.get(partIndex);
for (int i = 0; i < partSizes.get(partIndex); ++i) {
vertexBuffer.put(part.next());
}
}
}
vertexBuffer.flip();
if (disposalAction.vboVertexBuffer == 0) {
disposalAction.vboVertexBuffer = disposalAction.bufferPool.get(getUrn().toString());
}
VertexBufferObjectUtil.bufferVboData(disposalAction.vboVertexBuffer, vertexBuffer, GL15.GL_STATIC_DRAW);
vertexBuffer.flip();
}
use of gnu.trove.iterator.TFloatIterator 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