/// <summary> /// Performs a 3-dimensional rotation on the cuboid and returns a new axis-aligned cuboid resulting from this rotation. Not sure it it makes any sense to use this for other rotations than 90 degree intervals. /// </summary> public Cuboidi RotatedCopy(IVec3 vec, Vec3d origin) { return(RotatedCopy(vec.XAsInt, vec.YAsInt, vec.ZAsInt, origin)); }
public bool RayIntersectsWithCuboid(Cuboidd selectionBox, ref BlockFacing hitOnBlockFace, ref Vec3d hitPosition) { if (selectionBox == null) { return(false); } double w = selectionBox.X2 - selectionBox.X1; double h = selectionBox.Y2 - selectionBox.Y1; double l = selectionBox.Z2 - selectionBox.Z1; for (int i = 0; i < BlockFacing.NumberOfFaces; i++) { BlockFacing blockSideFacing = BlockFacing.ALLFACES[i]; Vec3i planeNormal = blockSideFacing.Normali; // Dot product of 2 vectors // If they are parallel the dot product is 1 // At 90 degrees the dot product is 0 double demon = planeNormal.X * ray.dir.X + planeNormal.Y * ray.dir.Y + planeNormal.Z * ray.dir.Z; // Does intersect this plane somewhere (only negative because we are not interested in the ray leaving a face, negative because the ray points into the cube, the plane normal points away from the cube) if (demon < -0.00001) { Vec3d planeCenterPosition = blockSideFacing.PlaneCenter .ToVec3d() .Mul(w, h, l) .Add(selectionBox.X1, selectionBox.Y1, selectionBox.Z1) ; Vec3d pt = Vec3d.Sub(planeCenterPosition, ray.origin); double t = (pt.X * planeNormal.X + pt.Y * planeNormal.Y + pt.Z * planeNormal.Z) / demon; if (t >= 0) { hitPosition = new Vec3d(ray.origin.X + ray.dir.X * t, ray.origin.Y + ray.dir.Y * t, ray.origin.Z + ray.dir.Z * t); lastExitedBlockFacePos = Vec3d.Sub(hitPosition, planeCenterPosition); // Does intersect this plane within the block if (Math.Abs(lastExitedBlockFacePos.X) <= w / 2 && Math.Abs(lastExitedBlockFacePos.Y) <= h / 2 && Math.Abs(lastExitedBlockFacePos.Z) <= l / 2) { hitOnBlockFace = blockSideFacing; return(true); } } } } return(false); }
public bool Contains(Vec3d pos) { return(pos.X >= MinX && pos.X < MaxX && pos.Y >= MinY && pos.Y < MaxY && pos.Z >= MinZ && pos.Z < MaxZ); }
public double Dot(Vec3d a) { return(X * a.X + Y * a.Y + Z * a.Z); }
public Vec3d SubCopy(Vec3d sub) { return(new Vec3d(X - sub.X, Y - sub.Y, Z - sub.Z)); }
public Vec3d AddCopy(Vec3d a) { return(new Vec3d(X + a.X, Y + a.Y, Z + a.Z)); }
public void Cross(Vec3d a, Vec4d b) { X = a.Y * b.Z - a.Z * b.Y; Y = a.Z * b.X - a.X * b.Z; Z = a.X * b.Y - a.Y * b.X; }