public Vector3f sub(Vector3f v) { return sub(v.x, v.y, v.z); }
public Vector3f sub(Vector3f v) { return sub(v.x, v.y, v.z); }
public Vector3f sub(double x, double y, double z) { return sub((float) x, (float) y, (float) z); }
public Vector3f sub(double x, double y, double z) { return sub((float) x, (float) y, (float) z); }
public BoundingBox grow(float x, float y, float z) { return new BoundingBox(start.sub(x, y, z), end.add(x, y, z)); } }
private static boolean checkForOverlap(Vector3f p0, Vector3f v0, Vector3f p1, Vector3f v1) { final Vector3f p10 = p1.sub(p0); if (!isZero(p10.cross(v0))) { return false; } float t = getNonNaN(p10.div(v0)); if (t >= 0 && t <= 1) { return true; } t = getNonNaN(p0.sub(p1).div(v1)); return t >= 0 && t <= 1; }
private Triangle[] subdivide() { final Vector3f e0 = v1.sub(v0).div(2); final Vector3f va = v0.add(e0); final Vector3f e1 = v2.sub(v1).div(2); final Vector3f vb = v1.add(e1); final Vector3f e2 = v0.sub(v2).div(2); final Vector3f vc = v2.add(e2); return new Triangle[]{ new Triangle(v0, va, vc), new Triangle(va, v1, vb), new Triangle(vc, vb, v2), new Triangle(va, vb, vc) }; } }
default boolean isOnGround() { Vector3i blockPosition = getPosition().sub(0f, 0.1f, 0f).toInt(); if (blockPosition.getY() < 0) { return false; } int chunkX = blockPosition.getX() >> 4; int chunkZ = blockPosition.getZ() >> 4; int chunkInX = blockPosition.getX() & 0x0f; int chunkInZ = blockPosition.getZ() & 0x0f; Optional<Chunk> chunkOptional = getLevel().getChunkIfLoaded(chunkX, chunkZ); return chunkOptional.isPresent() && chunkOptional.get().getBlock(chunkInX, blockPosition.getY(), chunkInZ).getBlockState().getBlockType() != BlockTypes.AIR; }
@Override public void handle(McpeMovePlayer packet) { Health health = ensureAndGet(Health.class); if (!spawned || health.isDead()) { return; } // TODO: We may do well to perform basic anti-cheat Vector3f originalPosition = getPosition(); Vector3f newPosition = packet.getPosition().sub(0, 1.62, 0); // Reject moves that are obviously too fast. (>=100 blocks) if (newPosition.distanceSquared(newPosition) >= 10000) { setPosition(originalPosition); setRotation(packet.getRotation()); return; } setPosition(newPosition); setRotation(packet.getRotation()); // If we haven't moved in the X or Z axis, don't update viewable entities or try updating chunks - they haven't changed. if (hasSubstantiallyMoved(originalPosition, newPosition)) { updateViewableEntities(); sendNewChunks().exceptionally(throwable -> { LOGGER.error("Unable to send chunks", throwable); disconnect("Internal server error"); return null; }); } }
final Vector3f v00 = p01.sub(p00); final Vector3f v01 = p02.sub(p01); final Vector3f v10 = p11.sub(p10); final Vector3f v11 = p12.sub(p11); final Matrix3f m0 = new Matrix3f( v00.getX(), v01.getX(), v10.getX(), return null; final Vector3f v02 = p00.sub(p02); final Vector3f v12 = p10.sub(p12); if (isZero(v00.cross(v10)) && checkForOverlap(p00, v00, p10, v10)) { return new Vector2i(0, 0);
/** * Creates a "look at" matrix for the given eye point. * * @param eye The position of the camera * @param at The point that the camera is looking at * @param up The "up" vector * @return A rotational transform that corresponds to a camera looking at the given point */ public static Matrix4f createLookAt(Vector3f eye, Vector3f at, Vector3f up) { final Vector3f f = at.sub(eye).normalize(); final Vector3f s = f.cross(up).normalize(); final Vector3f u = s.cross(f); final Matrix4f mat = new Matrix4f( s.getX(), s.getY(), s.getZ(), 0, u.getX(), u.getY(), u.getZ(), 0, -f.getX(), -f.getY(), -f.getZ(), 0, 0, 0, 0, 1); return mat.translate(eye.negate()); }
/** * Creates a "look at" matrix for the given eye point. * * @param eye The position of the camera * @param at The point that the camera is looking at * @param up The "up" vector * @return A rotational transform that corresponds to a camera looking at the given point */ public static Matrix4f createLookAt(Vector3f eye, Vector3f at, Vector3f up) { final Vector3f f = at.sub(eye).normalize(); final Vector3f s = f.cross(up).normalize(); final Vector3f u = s.cross(f); final Matrix4f mat = new Matrix4f( s.getX(), s.getY(), s.getZ(), 0, u.getX(), u.getY(), u.getZ(), 0, -f.getX(), -f.getY(), -f.getZ(), 0, 0, 0, 0, 1); return mat.translate(eye.negate()); }
/** * Creates a "look at" matrix for the given eye point. * * @param size The size of the matrix, minimum of 4 * @param eye The position of the camera * @param at The point that the camera is looking at * @param up The "up" vector * @return A rotational transform that corresponds to a camera looking at the given point */ public static MatrixNf createLookAt(int size, Vector3f eye, Vector3f at, Vector3f up) { if (size < 4) { throw new IllegalArgumentException("Minimum matrix size is 4"); } final Vector3f f = at.sub(eye).normalize(); up = up.normalize(); final Vector3f s = f.cross(up).normalize(); final Vector3f u = s.cross(f).normalize(); final MatrixNf mat = new MatrixNf(size); mat.set(0, 0, s.getX()); mat.set(0, 1, s.getY()); mat.set(0, 2, s.getZ()); mat.set(1, 0, u.getX()); mat.set(1, 1, u.getY()); mat.set(1, 2, u.getZ()); mat.set(2, 0, -f.getX()); mat.set(2, 1, -f.getY()); mat.set(2, 2, -f.getZ()); return mat.translate(eye.mul(-1).toVectorN()); }
/** * Creates a "look at" matrix for the given eye point. * * @param size The size of the matrix, minimum of 4 * @param eye The position of the camera * @param at The point that the camera is looking at * @param up The "up" vector * @return A rotational transform that corresponds to a camera looking at the given point */ public static MatrixNf createLookAt(int size, Vector3f eye, Vector3f at, Vector3f up) { if (size < 4) { throw new IllegalArgumentException("Minimum matrix size is 4"); } final Vector3f f = at.sub(eye).normalize(); up = up.normalize(); final Vector3f s = f.cross(up).normalize(); final Vector3f u = s.cross(f).normalize(); final MatrixNf mat = new MatrixNf(size); mat.set(0, 0, s.getX()); mat.set(0, 1, s.getY()); mat.set(0, 2, s.getZ()); mat.set(1, 0, u.getX()); mat.set(1, 1, u.getY()); mat.set(1, 2, u.getZ()); mat.set(2, 0, -f.getX()); mat.set(2, 1, -f.getY()); mat.set(2, 2, -f.getZ()); return mat.translate(eye.mul(-1).toVectorN()); }
radius * sinPhi * TrigMath.cos(radTheta)); addVector(positions, p.sub(0, halfHeight, 0)); addVector(normals, p.normalize());
@Override public void run(Entity entity) { Physics physics = entity.ensureAndGet(Physics.class); if (entity.getMotion().lengthSquared() > 0) { boolean onGroundPreviously = entity.isOnGround(); entity.setPositionFromSystem(entity.getPosition().add(entity.getMotion())); boolean onGroundNow = entity.isOnGround(); if (!onGroundPreviously && onGroundNow) { entity.setPositionFromSystem(new Vector3f(entity.getPosition().getX(), entity.getPosition().getFloorY(), entity.getPosition().getZ())); entity.setMotion(Vector3f.ZERO); } else { entity.setMotion(entity.getMotion().mul(1f - physics.getDrag())); if (!onGroundNow) { entity.setMotion(entity.getMotion().sub(0, physics.getGravity(), 0)); } } } } }