use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.
the class Region3i method createFromCenterExtents.
/**
* Create a region with center point and x,y,z coordinate extents size
* @param center the center point of region
* @param extents the extents size of each side of region
* @return a new region base on the center point and extents size
*/
public static Region3i createFromCenterExtents(BaseVector3f center, BaseVector3f extents) {
Vector3f min = new Vector3f(center.x() - extents.x(), center.y() - extents.y(), center.z() - extents.z());
Vector3f max = new Vector3f(center.x() + extents.x(), center.y() + extents.y(), center.z() + extents.z());
max.x = max.x - Math.ulp(max.x);
max.y = max.y - Math.ulp(max.y);
max.z = max.z - Math.ulp(max.z);
return createFromMinMax(new Vector3i(min), new Vector3i(max));
}
use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.
the class Region3i method max.
/**
* @return The largest vector in the region
*/
public Vector3i max() {
Vector3i max = new Vector3i(min);
max.add(size);
max.sub(1, 1, 1);
return max;
}
use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.
the class ChunkMonitorDisplay method mouseToChunkPos.
private Vector3i mouseToChunkPos(Point p) {
Preconditions.checkNotNull(p, "The parameter 'p' must not be null");
int x = (p.x - centerOffsetX - offsetX) / chunkSize;
int z = (p.y - centerOffsetY - offsetY) / chunkSize;
return new Vector3i(x - 1, renderY, z);
}
use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.
the class ObjMeshFormat method processData.
private MeshData processData(List<Vector3f> rawVertices, List<Vector3f> rawNormals, List<Vector2f> rawTexCoords, List<Vector3i[]> rawIndices) throws IOException {
MeshData result = new MeshData();
TFloatList vertices = result.getVertices();
TFloatList texCoord0 = result.getTexCoord0();
TFloatList normals = result.getNormals();
TIntList indices = result.getIndices();
int vertCount = 0;
for (Vector3i[] face : rawIndices) {
for (Vector3i indexSet : face) {
if (indexSet.x > rawVertices.size()) {
throw new IOException("Vertex index out of range: " + indexSet.x);
}
Vector3f vertex = rawVertices.get(indexSet.x - 1);
vertices.add(vertex.x);
vertices.add(vertex.y);
vertices.add(vertex.z);
if (indexSet.y != -1) {
if (indexSet.y > rawTexCoords.size()) {
throw new IOException("TexCoord index out of range: " + indexSet.y);
}
Vector2f texCoord = rawTexCoords.get(indexSet.y - 1);
texCoord0.add(texCoord.x);
texCoord0.add(1 - texCoord.y);
}
if (indexSet.z != -1) {
if (indexSet.z > rawNormals.size()) {
throw new IOException("Normal index out of range: " + indexSet.z);
}
Vector3f normal = rawNormals.get(indexSet.z - 1);
normals.add(normal.x);
normals.add(normal.y);
normals.add(normal.z);
}
}
for (int i = 0; i < face.length - 2; ++i) {
indices.add(vertCount);
indices.add(vertCount + i + 1);
indices.add(vertCount + i + 2);
}
vertCount += face.length;
}
return result;
}
use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.
the class CharacterSoundSystem method onFootstep.
@ReceiveEvent
public void onFootstep(FootstepEvent event, EntityRef entity, LocationComponent locationComponent, CharacterSoundComponent characterSounds) {
List<StaticSound> footstepSounds = characterSounds.footstepSounds;
// Check if the block the character is standing on has footstep sounds
Vector3i blockPos = new Vector3i(locationComponent.getLocalPosition());
// The block *below* the character's feet is interesting to us
blockPos.y--;
Block block = worldProvider.getBlock(blockPos);
if (block != null) {
if (block.getSounds() == null) {
logger.error("Block '{}' has no sounds", block.getURI());
} else if (!block.getSounds().getStepSounds().isEmpty()) {
footstepSounds = block.getSounds().getStepSounds();
}
}
if (footstepSounds.size() > 0 && characterSounds.lastSoundTime + MIN_TIME < time.getGameTimeInMs()) {
StaticSound sound = random.nextItem(footstepSounds);
entity.send(new PlaySoundEvent(entity, sound, characterSounds.footstepVolume));
characterSounds.lastSoundTime = time.getGameTimeInMs();
entity.saveComponent(characterSounds);
}
}
Aggregations