本文整理了Java中com.badlogic.gdx.math.MathUtils.floor()
方法的一些代码示例,展示了MathUtils.floor()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MathUtils.floor()
方法的具体详情如下:
包路径:com.badlogic.gdx.math.MathUtils
类名称:MathUtils
方法名:floor
[英]Returns the largest integer less than or equal to the specified float. This method will only properly floor floats from -(2^14) to (Float.MAX_VALUE - 2^14).
[中]返回小于或等于指定浮点的最大整数。此方法只能正确地将地板浮动从-(2^14)调整到(Float.MAX_VALUE-2^14)。
代码示例来源:origin: mstojcevich/Radix
@Override
public int getChunkPosition(float value) {
int subtraction = MathUtils.floor(value) & (CHUNK_SIZE-1);
return MathUtils.floor(value - subtraction);
}
代码示例来源:origin: SquidPony/SquidLib
protected int translateX(int screenX) {
return MathUtils.floor((screenX + offsetX) / cellWidth);
}
代码示例来源:origin: SquidPony/SquidLib
protected int translateY(int screenY) {
return MathUtils.floor((screenY + offsetY) / cellHeight);
}
代码示例来源:origin: SquidPony/SquidLib
/**
* Converts the provided color into a three dimensional coordinate point for
* use in the Bresenham algorithms.
*
* @param color
* @return
*/
private Coord3D scolorToCoord3D(SColor color) {
return new Coord3D(MathUtils.floor(color.r * 255), MathUtils.floor(color.g * 255), MathUtils.floor(color.b * 255));
}
代码示例来源:origin: mstojcevich/Radix
/**
* Performs a scalar product on this vector
* @param f Scale factor
* @return {@code this}
*/
public Vec3i scale(float f) {
set(MathUtils.floor(x * f), MathUtils.floor(y * f), MathUtils.floor(z * f));
return this;
}
代码示例来源:origin: mstojcevich/Radix
@Override
public void reset() {
plotted = 0;
index.x = MathUtils.floor((pos.x - off.x) / size.x);
index.y = MathUtils.floor((pos.y - off.y) / size.y);
index.z = MathUtils.floor((pos.z - off.z) / size.z);
float ax = index.x * size.x + off.x;
float ay = index.y * size.y + off.y;
float az = index.z * size.z + off.z;
max.x = (sign.x > 0) ? ax + size.x - pos.x : pos.x - ax;
max.y = (sign.y > 0) ? ay + size.y - pos.y : pos.y - ay;
max.z = (sign.z > 0) ? az + size.z - pos.z : pos.z - az;
max.set(max.x / dir.x, max.y / dir.y, max.z / dir.z);
}
代码示例来源:origin: mstojcevich/Radix
@Override
public void renderSouth(int atlasIndex, float x1, float y1, float x2, float y2, float z, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
int zi = MathUtils.floor(z);
int xi = MathUtils.floor(x1);
int yi = MathUtils.floor(y1);
IWorld world = RadixClient.getInstance().getWorld();
IChunk chunk = world.getChunk(xi, zi);
short meta = 0;
try {
meta = chunk.getMeta(xi & (world.getChunkSize() - 1), yi, zi & (world.getChunkSize() - 1));
} catch (CoordinatesOutOfBoundsException e) {
e.printStackTrace();
}
super.renderSouth(atlasIndex, x1, y1, x2, y1 + getHeight(meta), z, lightLevel, pcld, builder);
}
代码示例来源:origin: mstojcevich/Radix
@Override
public void renderEast(int atlasIndex, float z1, float y1, float z2, float y2, float x, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
int zi = MathUtils.floor(z1);
int xi = MathUtils.floor(x - 1);
int yi = MathUtils.floor(y1);
IWorld world = RadixClient.getInstance().getWorld();
IChunk chunk = world.getChunk(xi, zi);
short meta = 0;
try {
meta = chunk.getMeta(xi & (world.getChunkSize() - 1), yi, zi & (world.getChunkSize() - 1));
} catch (CoordinatesOutOfBoundsException e) {
e.printStackTrace();
}
super.renderEast(atlasIndex, z1, y1, z2, y1 + getHeight(meta), x, lightLevel, pcld, builder);
}
代码示例来源:origin: mstojcevich/Radix
@Override
public void renderTop(int atlasIndex, float x1, float z1, float x2, float z2, float y, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
int zi = MathUtils.floor(z1);
int xi = MathUtils.floor(x1);
int yi = MathUtils.floor(y - 1);
IWorld world = RadixClient.getInstance().getWorld();
IChunk chunk = world.getChunk(xi, zi);
short meta = 0;
try {
meta = chunk.getMeta(xi & (world.getChunkSize()-1), yi, zi & (world.getChunkSize()-1));
} catch (CoordinatesOutOfBoundsException e) {
e.printStackTrace();
}
super.renderTop(atlasIndex, x1, z1, x2, z2, y - (1 - getHeight(meta)), lightLevel, pcld, builder);
}
代码示例来源:origin: mstojcevich/Radix
@Override
public void renderNorth(int atlasIndex, float x1, float y1, float x2, float y2, float z, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
int zi = MathUtils.floor(z - 1);
int xi = MathUtils.floor(x1);
int yi = MathUtils.floor(y1);
IWorld world = RadixClient.getInstance().getWorld();
IChunk chunk = world.getChunk(xi, zi);
short meta = 0;
try {
meta = chunk.getMeta(xi & (world.getChunkSize() - 1), yi, zi & (world.getChunkSize() - 1));
} catch (CoordinatesOutOfBoundsException e) {
e.printStackTrace();
}
super.renderNorth(atlasIndex, x1, y1, x2, y1 + getHeight(meta), z, lightLevel, pcld, builder);
}
代码示例来源:origin: mstojcevich/Radix
@Override
public void renderWest(int atlasIndex, float z1, float y1, float z2, float y2, float x, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
int zi = MathUtils.floor(z1);
int xi = MathUtils.floor(x);
int yi = MathUtils.floor(y1);
IWorld world = RadixClient.getInstance().getWorld();
IChunk chunk = world.getChunk(xi, zi);
short meta = 0;
try {
meta = chunk.getMeta(xi & (world.getChunkSize() - 1), yi, zi & (world.getChunkSize() - 1));
} catch (CoordinatesOutOfBoundsException e) {
e.printStackTrace();
}
super.renderWest(atlasIndex, z1, y1, z2, y1 + getHeight(meta), x, lightLevel, pcld, builder);
}
代码示例来源:origin: mstojcevich/Radix
public int getBlockInHead(IWorld world) {
int x = MathUtils.floor(getPosition().getX());
int z = MathUtils.floor(getPosition().getZ());
int y = MathUtils.floor(getPosition().getY() + HEIGHT);
IChunk chunk = world.getChunk(x, z);
if (chunk != null) {
if (y >= world.getHeight()) return 0;
try {
return chunk.getBlockId(x & (world.getChunkSize() - 1), y, z & (world.getChunkSize() - 1));
} catch (BlockStorage.CoordinatesOutOfBoundsException e) {
e.printStackTrace();
return 0;
}
} else {
return 0;
}
}
代码示例来源:origin: mstojcevich/Radix
public boolean checkCollision(Vector3 pos) {
if (pos.y >= RadixClient.getInstance().getWorld().getHeight() || pos.y <0)
return false;
int x = MathUtils.floor(pos.x);
int y = MathUtils.floor(pos.y);
int z = MathUtils.floor(pos.z);
IChunk chunk = game.getWorld().getChunk(x, z);
if (chunk == null)
return true;
int cx = x & (game.getWorld().getChunkSize() - 1);
int cz = z & (game.getWorld().getChunkSize() - 1);
try {
Block block = chunk.getBlock(cx, y, cz);
return block != null && block.isSolid() && block.calculateBoundingBox(chunk, cx, y, cz).contains(pos);
} catch (CoordinatesOutOfBoundsException ex) {
ex.printStackTrace();
return true;
}
}
代码示例来源:origin: mstojcevich/Radix
@Override
public void run() {
try {
while (!game.isDone()) {
if (game.getPlayer() != null && game.getWorld() != null && !game.isRemote()) {
int viewDistance = game.getSettingsManager().getVisualSettings().getViewDistance();
EntityPosition playerPos = game.getPlayer().getPosition();
if (currentChunk == null) {
game.getWorld().loadChunks(playerPos, viewDistance);
currentChunk = game.getWorld().getChunk(MathUtils.floor(playerPos.getX()), MathUtils.floor(playerPos.getZ()));
} else {
if (Math.abs((int) currentChunk.getStartPosition().x - game.getPlayer().getPosition().getX()) > game.getWorld().getChunkSize() || Math.abs((int) currentChunk.getStartPosition().z - game.getPlayer().getPosition().getZ()) > game.getWorld().getChunkSize()) {
currentChunk = game.getWorld().getChunk(MathUtils.floor(playerPos.getX()), MathUtils.floor(playerPos.getZ()));
game.getWorld().loadChunks(playerPos, viewDistance);
}
}
}
Thread.sleep(1000);
}
} catch (Exception e) {
RadixClient.getInstance().handleCriticalException(e);
}
}
代码示例来源:origin: mstojcevich/Radix
public boolean checkDeltaCollision(LivingEntity e, float deltaX, float deltaY, float deltaZ) {
BoundingBox curBB = e.calculateBoundingBox();
BoundingBox newBB = new BoundingBox(curBB.min.cpy().add(deltaX, deltaY, deltaZ), curBB.max.cpy().add(deltaX, deltaY, deltaZ));
boolean collideSuccess = false;
int x = MathUtils.floor(e.getPosition().x);
int y = MathUtils.floor(e.getPosition().y);
int z = MathUtils.floor(e.getPosition().z);
IChunk chunk = game.getWorld().getChunk(x, z);
if (chunk == null)
return true;
int cx = x & (game.getWorld().getChunkSize() - 1);
int cz = z & (game.getWorld().getChunkSize() - 1);
try {
Block block = chunk.getBlock(cx, y, cz);
for (Vector3 corner : getCorners(newBB)) {
collideSuccess = collideSuccess || checkCollision(corner);
}
return collideSuccess ||
(block != null && block.isSolid()
&& block.calculateBoundingBox(chunk, cx, y, cz).intersects(newBB));
} catch(CoordinatesOutOfBoundsException ex) {
ex.printStackTrace();
return true;
}
}
代码示例来源:origin: mstojcevich/Radix
if (yVelocity <0) {// falling down and failed because we hit the ground
int x = MathUtils.floor(getPosition().getX());
int y = MathUtils.floor(getPosition().getY());
int z = MathUtils.floor(getPosition().getZ());
int cx = x & (RadixClient.getInstance().getWorld().getChunkSize() - 1);
int cz = z & (RadixClient.getInstance().getWorld().getChunkSize() - 1);
代码示例来源:origin: mstojcevich/Radix
public int getBlockInFeet(IWorld world) {
int x = MathUtils.floor(getPosition().getX());
int y = MathUtils.floor(getPosition().getY());
int z = MathUtils.floor(getPosition().getZ());
IChunk chunk = world.getChunk(x, z);
if (chunk != null && y
int cz = z & (world.getChunkSize() - 1);
try {
int id = chunk.getBlockId(cx, y, cz);
Block block = RadixAPI.instance.getBlock(id);
if (block == null) return 0;
BoundingBox blockBox = block.calculateBoundingBox(chunk, cx, y, cz);
float halfWidth = width / 2f;
Vector3 bottomBackLeft = getPosition().cpy().add(-halfWidth, 0, -halfWidth);
Vector3 bottomBackRight = bottomBackLeft.cpy().add(width, 0, 0);
Vector3 bottomFrOntRight= bottomBackRight.cpy().add(0, 0, width);
Vector3 bottomFrOntLeft= bottomBackLeft.cpy().add(width, 0, 0);
boolean inFeet = blockBox.contains(bottomBackLeft) || blockBox.contains(bottomBackRight) || blockBox.contains(bottomFrontLeft) || blockBox.contains(bottomFrontRight);
return inFeet ? id : 0;
} catch (BlockStorage.CoordinatesOutOfBoundsException ex) {
ex.printStackTrace();
return 0;
}
} else {
return 0;
}
}
代码示例来源:origin: yichen0831/Bomberman_libGdx
public void createBomb(Player player, float x, float y) {
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyDef.BodyType.KinematicBody;
bodyDef.position.set(MathUtils.floor(x) + 0.5f, MathUtils.floor(y) + 0.5f);
代码示例来源:origin: yichen0831/Bomberman_libGdx
public Entity createRemoteBomb(Player player, float x, float y) {
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyDef.BodyType.KinematicBody;
bodyDef.position.set(MathUtils.floor(x) + 0.5f, MathUtils.floor(y) + 0.5f);
代码示例来源:origin: yichen0831/Bomberman_libGdx
public void createPowerUp(float x, float y) {
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyDef.BodyType.DynamicBody;
bodyDef.position.set(MathUtils.floor(x) + 0.5f, MathUtils.floor(y) + 0.5f);