public float calculateYOffset(AxisAlignedBB other, float offset) { //Y if (other.max.X > min.X && other.min.X < max.X && other.max.Z > min.Z && other.min.Z < max.Z) { if (offset > 0.0D && other.max.Y <= min.Y) { float d1 = min.Y - other.max.Y; if (d1 < offset) { offset = d1; } } else if (offset < 0.0D && other.min.Y >= this.max.Y) { float d0 = max.Y - other.min.Y; if (d0 > offset) { offset = d0; } } } return(offset); }
public float calculateXOffset(AxisAlignedBB other, float offset) { //X if (other.max.Y > min.Y && other.min.Y < max.Y && other.max.Z > min.Z && other.min.Z < max.Z) { if (offset > 0.0D && other.max.X <= min.X) { float d1 = min.X - other.max.X; if (d1 < offset) { offset = d1; } } else if (offset < 0.0D && other.min.X >= max.X) { float d0 = max.X - other.min.X; if (d0 > offset) { offset = d0; } } } return(offset); }
public List <AxisAlignedBB> getBlockCollisionBoxes(AxisAlignedBB box) { List <AxisAlignedBB> blocks = new List <AxisAlignedBB>(); var bb = box.union(box); for (int x = (int)bb.min.X, maxX = (int)bb.max.X; x < maxX; x++) { for (int y = (int)bb.min.Y, maxY = (int)bb.max.Y; y < maxY; y++) { for (int z = (int)bb.min.Z, maxZ = (int)bb.max.Z; z < maxZ; z++) { var pos = new BlockPos(x, y, z); var block = Game.INSTANCE.world.getBlock(pos); if (block == EnumBlock.AIR) { continue; } blocks.Add( ModelManager.getModelForBlock(block, getMetadata(pos)).boundingBox.offset(pos.vector)); } } } return(blocks); }
private Chunk(ChunkCache cache) { chunkPos = cache.chunkPos; boundingBox = new AxisAlignedBB(Vector3.Zero, Vector3.One * 16 + Vector3.UnitY * 240).offset(chunkPos.vector); chunkBlocks = cache.chunkBlocks; }
public Chunk(BlockPos chunkPos) { this.chunkPos = chunkPos; boundingBox = new AxisAlignedBB(Vector3.Zero, Vector3.One * 16 + Vector3.UnitY * 240).offset(chunkPos.vector); chunkBlocks = new short[16, 256, 16]; }
public EntityPlayerSP(Vector3 pos) : base(pos) { camera = new Camera(); camera.pos = pos; boundingBox = new AxisAlignedBB(new Vector3(-0.3f, 0, -0.3f), new Vector3(0.3f, 1.65f, 0.3f)).offset(lastPos = pos); hotbar = new ItemStack[9]; }
public AxisAlignedBB union(AxisAlignedBB other) { var minX = (int)Math.Floor(MathUtil.Min(min.X, max.X, other.min.X, other.max.X)); var minY = (int)Math.Floor(MathUtil.Min(min.Y, max.Y, other.min.Y, other.max.Y)); var minZ = (int)Math.Floor(MathUtil.Min(min.Z, max.Z, other.min.Z, other.max.Z)); var maxX = (int)Math.Ceiling(MathUtil.Max(min.X, max.X, other.min.X, other.max.X)); var maxY = (int)Math.Ceiling(MathUtil.Max(min.Y, max.Y, other.min.Y, other.max.Y)); var maxZ = (int)Math.Ceiling(MathUtil.Max(min.Z, max.Z, other.min.Z, other.max.Z)); return(new AxisAlignedBB(minX, minY, minZ, maxX, maxY, maxZ)); }
public virtual void Move() { var bb_o = boundingBox.union(boundingBox.offset(motion)); List <AxisAlignedBB> list = Game.INSTANCE.world.getBlockCollisionBoxes(bb_o); var m_orig = motion; for (int i = 0; i < list.Count; i++) { var blockBB = list[i]; motion.Y = blockBB.calculateYOffset(boundingBox, motion.Y); } boundingBox = boundingBox.offset(motion * Vector3.UnitY); for (int i = 0; i < list.Count; i++) { var blockBB = list[i]; motion.X = blockBB.calculateXOffset(boundingBox, motion.X); } boundingBox = boundingBox.offset(motion * Vector3.UnitX); for (int i = 0; i < list.Count; i++) { var blockBB = list[i]; motion.Z = blockBB.calculateZOffset(boundingBox, motion.Z); } boundingBox = boundingBox.offset(motion * Vector3.UnitZ); setPositionToBB(); onGround = Math.Abs(m_orig.Y - motion.Y) > 0.00001f && m_orig.Y < 0.0D; if (Math.Abs(m_orig.X - motion.X) > 0.00001f) { motion.X = 0; } if (Math.Abs(m_orig.Z - motion.Z) > 0.00001f) { motion.Z = 0; } if (onGround && motion.Y < 0) { motion.Y = 0; } }
public List <AxisAlignedBB> getIntersectingEntitiesBBs(AxisAlignedBB with) { List <AxisAlignedBB> bbs = new List <AxisAlignedBB>(); for (int i = 0; i < _entities.Count; i++) { var bb = _entities[i].getBoundingBox(); if (bb.intersectsWith(with)) { bbs.Add(bb); } } return(bbs); }
public bool intersectsWith(AxisAlignedBB other) { return((min.X < other.max.X && max.X > other.min.X) && (min.Y < other.max.Y && max.Y > other.min.Y) && (min.Z < other.max.Z && max.Z > other.min.Z)); }
public static bool rayIntersectsBB(Vector3 /*ray*/ origin, Vector3 /*ray*/ direction, AxisAlignedBB bb, out Vector3 hitPosition, out Vector3 hitNormal) { direction = direction.Normalized(); hitNormal = Vector3.One.Normalized(); hitPosition = Vector3.Zero; float tmin, tmax, tymin, tymax, tzmin, tzmax; var invrd = direction; invrd.X = 1.0f / invrd.X; invrd.Y = 1.0f / invrd.Y; invrd.Z = 1.0f / invrd.Z; if (invrd.X >= 0.0f) { tmin = (bb.min.X - origin.X) * invrd.X; tmax = (bb.max.X - origin.X) * invrd.X; } else { tmin = (bb.max.X - origin.X) * invrd.X; tmax = (bb.min.X - origin.X) * invrd.X; } if (invrd.Y >= 0.0f) { tymin = (bb.min.Y - origin.Y) * invrd.Y; tymax = (bb.max.Y - origin.Y) * invrd.Y; } else { tymin = (bb.max.Y - origin.Y) * invrd.Y; tymax = (bb.min.Y - origin.Y) * invrd.Y; } if ((tmin > tymax) || (tymin > tmax)) { return(false); } if (tymin > tmin) { tmin = tymin; } if (tymax < tmax) { tmax = tymax; } if (invrd.Z >= 0.0f) { tzmin = (bb.min.Z - origin.Z) * invrd.Z; tzmax = (bb.max.Z - origin.Z) * invrd.Z; } else { tzmin = (bb.max.Z - origin.Z) * invrd.Z; tzmax = (bb.min.Z - origin.Z) * invrd.Z; } if ((tmin > tzmax) || (tzmin > tmax)) { return(false); } if (tzmin > tmin) { tmin = tzmin; } if (tzmax < tmax) { tmax = tzmax; } if (tmin < 0) { tmin = tmax; } if (tmax < 0) { return(false); } float t = tmin; hitPosition = origin + t * direction; Vector3 AABBCenter = (bb.min + bb.max) * 0.5f; Vector3 dir = hitPosition - AABBCenter; Vector3 width = bb.max - bb.min; width.X = Math.Abs(width.X); width.Y = Math.Abs(width.Y); width.Z = Math.Abs(width.Z); Vector3 ratio = Vector3.One; ratio.X = Math.Abs(dir.X / width.X); ratio.Y = Math.Abs(dir.Y / width.Y); ratio.Z = Math.Abs(dir.Z / width.Z); hitNormal = Vector3.Zero; int maxDir = 0; // x if (ratio.X >= ratio.Y && ratio.X >= ratio.Z) { // x is the greatest maxDir = 0; } else if (ratio.Y >= ratio.X && ratio.Y >= ratio.Z) { // y is the greatest maxDir = 1; } else if (ratio.Z >= ratio.X && ratio.Z >= ratio.Y) { // z is the greatest maxDir = 2; } if (dir[maxDir] > 0) { hitNormal[maxDir] = 1.0f; } else { hitNormal[maxDir] = -1.0f; } return(true); }
protected Entity(Vector3 pos) { this.pos = pos; boundingBox = AxisAlignedBB.BLOCK_FULL.offset(Vector3.One * -0.5f).offset(pos); }