public RHBoundingBox PrinterBoundingBox() { RHBoundingBox b = new RHBoundingBox(); b.Add(ps.BedLeft, ps.BedFront, -0.0 * ps.PrintAreaHeight); b.Add(ps.BedLeft + ps.PrintAreaWidth, ps.BedFront + ps.PrintAreaDepth, 1.0 * ps.PrintAreaHeight); return(b); }
public RHBoundingBox ObjectsBoundingBox() { RHBoundingBox b = new RHBoundingBox(); foreach (PrintModel model in Main.main.objectPlacement.ListObjects(false)) { b.Add(model.bbox.minPoint); b.Add(model.bbox.maxPoint); } if (b.minPoint == null) { return(PrinterBoundingBox()); } return(b); }
public RHBoundingBox ObjectsBoundingBox() { RHBoundingBox b = new RHBoundingBox(); foreach (PrintModel model in ProjectManager.Instance.CurrentProject.ModelList) // Main.main.objectPlacement.ListObjects(false)) { b.Add(model.bbox.minPoint); b.Add(model.bbox.maxPoint); } if (b.minPoint == null) { return(PrinterBoundingBox()); } return(b); }
private void includePoint(RHVector3 v) { float x, y, z; Vector4 v4 = v.asVector4(); x = Vector4.Dot(trans.Column0, v4); y = Vector4.Dot(trans.Column1, v4); z = Vector4.Dot(trans.Column2, v4); bbox.Add(new RHVector3(x, y, z)); }
public void FitBoundingBox(RHBoundingBox box) { float bedRadius = (float)(1.5 * Math.Sqrt((ps.PrintAreaDepth * ps.PrintAreaDepth + ps.PrintAreaHeight * ps.PrintAreaHeight + ps.PrintAreaWidth * ps.PrintAreaWidth) * 0.25)); RHVector3 shift = new RHVector3(-ps.BedLeft - 0.5 * ps.PrintAreaWidth, -ps.BedFront - 0.5 * ps.PrintAreaDepth, -0.5 * ps.PrintAreaHeight); viewCenter = box.Center.asVector3(); distance = defaultDistance; int loops = 5; while (loops > 0) { loops--; angle = 15.0 * Math.PI / 180; double ratio = (double)control.gl.Width / (double)control.gl.Height; Vector3 camPos = CameraPosition; Matrix4 lookAt = Matrix4.LookAt(camPos.X, camPos.Y, camPos.Z, viewCenter.X, viewCenter.Y, viewCenter.Z, 0, 0, 1.0f); Matrix4 persp; Vector3 dir = new Vector3(); Vector3.Subtract(ref viewCenter, ref camPos, out dir); dir.Normalize(); float dist; Vector3.Dot(ref dir, ref camPos, out dist); dist = -dist; float nearDist = Math.Max(1, dist - bedRadius); float farDist = Math.Max(bedRadius * 2, dist + bedRadius); float nearHeight = 2.0f * (float)Math.Tan(angle) * dist; if (control.toolParallelProjection.Checked) { persp = Matrix4.CreateOrthographic(nearHeight * (float)ratio, nearHeight, nearDist, farDist); loops = 0; } else { persp = Matrix4.CreatePerspectiveFieldOfView((float)(angle * 2.0), (float)ratio, nearDist, farDist); } Matrix4 trans = Matrix4.Mult(lookAt, persp); RHVector3 min = new RHVector3(0, 0, 0); RHVector3 max = new RHVector3(0, 0, 0); Vector4 pos; RHBoundingBox bb = new RHBoundingBox(); pos = Vector4.Transform(box.minPoint.asVector4(), trans); bb.Add(new RHVector3(pos)); pos = Vector4.Transform(box.maxPoint.asVector4(), trans); bb.Add(new RHVector3(pos)); Vector4 pnt = new Vector4((float)box.xMin, (float)box.yMax, (float)box.zMin, 1); pos = Vector4.Transform(pnt, trans); bb.Add(new RHVector3(pos)); pnt = new Vector4((float)box.xMin, (float)box.yMax, (float)box.zMin, 1); pos = Vector4.Transform(pnt, trans); bb.Add(new RHVector3(pos)); pnt = new Vector4((float)box.xMax, (float)box.yMax, (float)box.zMin, 1); pos = Vector4.Transform(pnt, trans); bb.Add(new RHVector3(pos)); pnt = new Vector4((float)box.xMin, (float)box.yMax, (float)box.zMax, 1); pos = Vector4.Transform(pnt, trans); bb.Add(new RHVector3(pos)); pnt = new Vector4((float)box.xMin, (float)box.yMin, (float)box.zMax, 1); pos = Vector4.Transform(pnt, trans); bb.Add(new RHVector3(pos)); pnt = new Vector4((float)box.xMax, (float)box.yMin, (float)box.zMax, 1); pos = Vector4.Transform(pnt, trans); bb.Add(new RHVector3(pos)); double fac = Math.Max(Math.Abs(bb.xMin), Math.Abs(bb.xMax)); fac = Math.Max(fac, Math.Abs(bb.yMin)); fac = Math.Max(fac, Math.Abs(bb.yMax)); distance *= fac * 1.03; if (distance < 1) { angle = Math.Atan(distance * Math.Tan(15.0 * Math.PI / 180.0)); } } }