public bool HitTest(ref BoundingRect Rect, bool IncludeControlPoints) { foreach (Joint lp in Joints) { GeoPoint2D p; if (lp.StartCluster == this) { p = lp.curve.StartPoint; } else { p = lp.curve.EndPoint; } if (p > Rect) { return(false); } } return(true); }
/// <summary> /// Intersection with another. /// </summary> /// <param name="Other">The other polygon.</param> /// <param name="IntersectionPts">Output. The intersection points.</param> public bool Crosses(C2DPolyBase Other, List <C2DPoint> IntersectionPts) { if (!BoundingRect.Overlaps(Other.BoundingRect)) { return(false); } List <C2DPoint> IntPtsTemp = new List <C2DPoint>(); List <int> Index1 = new List <int>(); List <int> Index2 = new List <int>(); Lines.GetIntersections(Other.Lines, IntPtsTemp, Index1, Index2, BoundingRect, Other.BoundingRect); bool bResult = IntPtsTemp.Count > 0; IntersectionPts.InsertRange(0, IntPtsTemp); return(bResult); }
/// <summary> /// Overrides <see cref="CADability.GeoObject.IGeoObjectImpl.HitTest (Projection, BoundingRect, bool)"/> /// </summary> /// <param name="projection"></param> /// <param name="rect"></param> /// <param name="onlyInside"></param> /// <returns></returns> public override bool HitTest(Projection projection, BoundingRect rect, bool onlyInside) { CompoundShape cs = compoundShape.Project(plane, projection.ProjectionPlane); if (onlyInside) { return(cs.GetExtent() <= rect); } else { if (base.Count > 0) { // LinienSchraffur oder so return(base.HitTest(projection, rect, onlyInside)); } else { // SolidSchraffur return(cs.HitTest(ref rect)); } } }
/// <summary> /// Overrides <see cref="CADability.Actions.Action.OnMouseUp (MouseEventArgs, IView)"/> /// </summary> /// <param name="e"></param> /// <param name="vw"></param> public override void OnMouseUp(MouseEventArgs e, IView vw) { OnMouseMove(e, vw); // damit wird Invalidate... aufgerufen switch (Mode) { case 0: Mode = 1; SecondPoint = FirstPoint; break; case 1: Mode = -1; BoundingRect mm = BoundingRect.EmptyBoundingRect; mm.MinMax(vw.Projection.PointWorld2D(FirstPoint)); mm.MinMax(vw.Projection.PointWorld2D(SecondPoint)); base.RemoveThisAction(); // damit werden auch die PaintHandler abgemeldet // und es gibt noch ungültige Bereiche im Active. D.h. es wird gelöscht. vw.ZoomToRect(mm); break; } }
bool IOctTreeInsertable.HitTest(Projection projection, BoundingRect rect, bool onlyInside) { // kommt dran bei GetObjectsCloseTo if (onlyInside) { return(false); } else { ClipRect clr = new ClipRect(ref rect); // eine Linie machen, die bestimmt über das rechteck hinaus geht GeoPoint2D sp2d = projection.ProjectUnscaled(start); GeoVector2D dir2d = projection.ProjectUnscaled(dir); double max = 0.0; max = Math.Max(max, sp2d | rect.GetLowerLeft()); max = Math.Max(max, sp2d | rect.GetLowerRight()); max = Math.Max(max, sp2d | rect.GetUpperLeft()); max = Math.Max(max, sp2d | rect.GetUpperRight()); GeoPoint2D ep2d = sp2d + max * dir2d; return(clr.LineHitTest(sp2d, ep2d)); } }
/// <summary> /// Overrides <see cref="CADability.GeoObject.ISurfaceImpl.SameGeometry (BoundingRect, ISurface, BoundingRect, double, out ModOp2D)"/> /// </summary> /// <param name="thisBounds"></param> /// <param name="other"></param> /// <param name="otherBounds"></param> /// <param name="precision"></param> /// <param name="firstToSecond"></param> /// <returns></returns> public override bool SameGeometry(BoundingRect thisBounds, ISurface other, BoundingRect otherBounds, double precision, out ModOp2D firstToSecond) { if (other is HelicalSurface) { firstToSecond = ModOp2D.Null; HelicalSurface srother = other as HelicalSurface; bool reverse; if (!Curves.SameGeometry(BasisCurve, srother.BasisCurve, precision, out reverse)) { return(false); } if ((Location | srother.Location) > precision) { return(false); } if (Math.Abs(pitch - srother.pitch) > precision) { return(false); } GeoPoint2D uv1 = new GeoPoint2D(curveStartParameter, 0.0); GeoPoint p1 = PointAt(uv1); GeoPoint2D uv2 = srother.PositionOf(p1); GeoPoint p2 = srother.PointAt(uv2); if ((p1 | p2) > precision) { return(false); } uv1 = new GeoPoint2D(curveEndParameter, 0.0); p1 = PointAt(uv1); uv2 = srother.PositionOf(p1); p2 = srother.PointAt(uv2); if ((p1 | p2) > precision) { return(false); } firstToSecond = ModOp2D.Translate(uv2 - uv1); return(true); } return(base.SameGeometry(thisBounds, other, otherBounds, precision, out firstToSecond)); }
void OnRepaint(IView View, IPaintTo3D paintTo3D) { BoundingRect ext; if (layoutPatch.Area == null) { ext = new BoundingRect(0.0, 0.0, layoutView.Layout.PaperWidth, layoutView.Layout.PaperHeight); } else { ext = layoutPatch.Area.Extent; } LayoutView lv = View as LayoutView; if (lv != null) { GeoPoint2D clipll = lv.layoutToScreen * ext.GetLowerLeft(); GeoPoint2D clipur = lv.layoutToScreen * ext.GetUpperRight(); paintTo3D.SetColor(Color.LightGray); paintTo3D.FillRect2D(clipll.PointF, clipur.PointF); } }
public override void Update(GameTime gameTime) { if (!Active) { return; } // If we click on the enemy object play the assosiated sound effect // and hide it if (InputEngine.IsMouseLeftClick()) { if (BoundingRect.Contains(InputEngine.MousePosition)) { SoundEffect sndFx; if (AudioManager.SoundEffects.TryGetValue(ImageName, out sndFx)) { sndFx.CreateInstance().Play(); } Active = false; } } base.Update(gameTime); }
/// <summary> /// Overrides <see cref="CADability.Curve2D.GeneralCurve2D.HitTest (ref BoundingRect, bool)"/> /// </summary> /// <param name="Rect"></param> /// <param name="IncludeControlPoints"></param> /// <returns></returns> public override bool HitTest(ref BoundingRect Rect, bool IncludeControlPoints) { ClipRect clr = new ClipRect(ref Rect); if (clr.ArcHitTest(center, radius, 0, new GeoPoint2D(center.x + radius, center.y), new GeoPoint2D(center.x, center.y + radius))) { return(true); } if (clr.ArcHitTest(center, radius, 1, new GeoPoint2D(center.x, center.y + radius), new GeoPoint2D(center.x - radius, center.y))) { return(true); } if (clr.ArcHitTest(center, radius, 2, new GeoPoint2D(center.x - radius, center.y), new GeoPoint2D(center.x, center.y - radius))) { return(true); } if (clr.ArcHitTest(center, radius, 3, new GeoPoint2D(center.x, center.y - radius), new GeoPoint2D(center.x + radius, center.y))) { return(true); } return(false); }
GeoPoint extendedPole; // when there is no pole, the definition area is a annulus (circular ring). extendedPole is the point at (0,0) /// <summary> /// </summary> /// <param name="periodicSurface"></param> /// <param name="vmin"></param> /// <param name="vmax"></param> public NonPeriodicSurface(ISurface periodicSurface, BoundingRect bounds) { this.periodicSurface = periodicSurface; this.periodicBounds = bounds; bool uperiodic; if (periodicSurface.IsUPeriodic && periodicSurface.IsVPeriodic) { if (bounds.Width / periodicSurface.UPeriod < bounds.Height / periodicSurface.VPeriod) { periodicBounds.Bottom = 0.0; periodicBounds.Top = periodicSurface.VPeriod; uperiodic = false; } else { periodicBounds.Left = 0.0; periodicBounds.Right = periodicSurface.UPeriod; uperiodic = true; } } else if (periodicSurface.IsUPeriodic) { periodicBounds.Left = 0.0; periodicBounds.Right = periodicSurface.UPeriod; uperiodic = true; } else if (periodicSurface.IsVPeriodic) { periodicBounds.Bottom = 0.0; periodicBounds.Top = periodicSurface.VPeriod; uperiodic = false; } else { uperiodic = false; // must be assigned } Init(uperiodic); }
public override void Draw(SpriteBatch spriteBatch) { if (TextureAtlas == null) { switch (State) { case ButtonState.None: spriteBatch.FillRectangle(BoundingRect, Color.Red); break; case ButtonState.Hovered: spriteBatch.FillRectangle(BoundingRect, Color.Green); break; case ButtonState.Pressed: spriteBatch.FillRectangle(BoundingRect, Color.Blue); break; case ButtonState.Clicking: spriteBatch.FillRectangle(BoundingRect, Color.Wheat); break; default: throw new ArgumentOutOfRangeException(); } } else { DrawAtlas(spriteBatch); } if (!string.IsNullOrEmpty(Text) && Font != null) { spriteBatch.DrawString(Font, Text, BoundingRect.ToRectangle(), Color.Black, TextAlignment.Center); } base.Draw(spriteBatch); }
private void Add(Node currentNode, BoundingRect rect, T data) { var children = currentNode.Children; int emptyPosition = -1; for (int i = 0; i < children.Length; i++) { if (children[i] == null) { emptyPosition = i; break; } if (children[i].Contains(rect)) { this.Add(children[i], rect, data); currentNode.Depth = Math.Max(children[i].Depth, currentNode.Depth); currentNode.Balance(); return; } } // if no child already contains that point // We need to expand to contain it currentNode.BoundingBox = BoundingRect.Union(currentNode.BoundingBox, rect); // check to see if there is a place we can just store it quickly if (emptyPosition >= 0) { children[emptyPosition] = new Node() { Depth = 0, BoundingBox = rect, Children = new Node[this.ChildLength], Data = data }; currentNode.Depth = Math.Max(currentNode.Depth, 1); } else { // if there is no place to store it we need to force a merge into a child that does not contain it } currentNode.Balance(); }
/// <summary> /// Creates a random shape. /// </summary> /// <param name="cBoundary">The boundary.</param> /// <param name="nMinPoints">The minimum points.</param> /// <param name="nMaxPoints">The maximum points.</param> public bool CreateRandom(C2DRect cBoundary, int nMinPoints, int nMaxPoints) { C2DPolygon Poly = new C2DPolygon(); if (!Poly.CreateRandom(cBoundary, nMinPoints, nMaxPoints)) { return(false); } CRandomNumber rCenOnRight = new CRandomNumber(0, 1); this.Set(Poly); for (int i = 0; i < Lines.Count; i++) { C2DLineBase pLine = Lines[i]; bool bCenOnRight = (rCenOnRight.GetInt() > 0); double dLength = pLine.GetLength(); CRandomNumber Radius = new CRandomNumber(dLength, dLength * 3); C2DArc pNew = new C2DArc(pLine.GetPointFrom(), pLine.GetPointTo(), Radius.Get(), bCenOnRight, !bCenOnRight); if (!this.Crosses(pNew)) { Lines[i] = pNew; pNew.GetBoundingRect(LineRects[i]); BoundingRect.ExpandToInclude(LineRects[i]); } } // this.MakeLineRects(); // this.MakeBoundingRect(); return(true); }
/// <summary> /// Overrides <see cref="CADability.GeoObject.ISurfaceImpl.Make3dCurve (ICurve2D)"/> /// </summary> /// <param name="curve2d"></param> /// <returns></returns> public override ICurve Make3dCurve(ICurve2D curve2d) { if (curve2d is Curve2DAspect) { ICurve res = (curve2d as Curve2DAspect).Get3DCurve(this); if (res != null) { return(res); } } if (curve2d is ProjectedCurve pc) { if (pc.Surface is OffsetSurface) { BoundingRect otherBounds = new BoundingRect(PositionOf(pc.Surface.PointAt(pc.StartPoint)), PositionOf(pc.Surface.PointAt(pc.EndPoint))); if (pc.Surface.SameGeometry(pc.GetExtent(), this, otherBounds, Precision.eps, out ModOp2D notneeded)) { return(pc.Curve3DFromParams); // if trimmed or reversed still returns the correct 3d curve (but trimmed and/or reversed) } } } return(base.Make3dCurve(curve2d)); }
public CurveGraph(ICurve2D[] curves, double maxGap) { // aus den ICurve2D wird eine Clusterliste erzeugt (Start- und Endpunkte) this.maxGap = maxGap; BoundingRect ext = BoundingRect.EmptyBoundingRect; for (int i = 0; i < curves.Length; ++i) { ext.MinMax(curves[i].GetExtent()); } // clusterSize = (ext.Width + ext.Height) * 1e-8; clusterSize = maxGap; clusterTree = new QuadTree(ext); clusterTree.MaxDeepth = 8; clusterTree.MaxListLen = 3; clusterSet = new UntypedSet(); for (int i = 0; i < curves.Length; ++i) { if (curves[i].Length > clusterSize) { Insert(curves[i]); } } }
public override void Update(float dt) { foreach (Entity goalEntity in _goalEntities) { TransformComponent goalTransformComp = goalEntity.GetComponent <TransformComponent>(); BoundingRect goalAABB = new BoundingRect(goalTransformComp.Position.X - Constants.Pong.GOAL_WIDTH / 2, goalTransformComp.Position.Y - Constants.Pong.PLAYFIELD_HEIGHT / 2, Constants.Pong.GOAL_WIDTH, Constants.Pong.PLAYFIELD_HEIGHT); foreach (Entity ballEntity in _ballEntities) { TransformComponent ballTransformComp = ballEntity.GetComponent <TransformComponent>(); BallComponent ballComp = ballEntity.GetComponent <BallComponent>(); BoundingRect ballAABB = new BoundingRect(ballTransformComp.Position - ballComp.Bounds / 2, ballTransformComp.Position + ballComp.Bounds / 2); if (ballAABB.Intersects(goalAABB)) { Vector2 goalNormal = goalTransformComp.Position - ballTransformComp.Position; goalNormal.Normalize(); Vector2 ballEdge = ballTransformComp.Position + ballComp.Bounds * -goalNormal; Vector2 goalEdge = goalTransformComp.Position + new Vector2(Constants.Pong.GOAL_WIDTH, Constants.Pong.GOAL_HEIGHT) * goalNormal; Vector2 goalPosition = (ballEdge + goalEdge) / 2; EventManager.Instance.QueueEvent(new GoalEvent(ballEntity, goalEntity, goalPosition)); } } } }
public bool Contains(float x, float y) { if (!BoundingRect.Contains(x, y)) { return(false); } int numPoints = points.Length; bool contains = false; for (int i = 0; i < numPoints; i++) { Vector2 p = points[i]; Vector2 p1 = points[(i + 1) % numPoints]; if ((p.Y <= y && y < p1.Y || p1.Y <= y && y < p.Y) && x < (p1.X - p.X) / (p1.Y - p.Y) * (y - p.Y) + p.X) { contains = !contains; } } return(contains); }
public BlurWithPainter() { //m_rbuf2 = new ReferenceImage(); m_shape_bounds = new RectD(); m_shadow_ctrl = new PolygonEditWidget(4); this.FlattenCurveChecked = true; this.BlurMethod = BlurMethod.RecursiveBlur; this.BlurRadius = 15; Font svgFont = SvgFontStore.LoadFont("svg-LiberationSansFont", 300); m_pathVxs = svgFont.GetGlyph('a').originalVxs;// typeFaceForLargeA.GetGlyphForCharacter('a'); Affine shape_mtx = Affine.NewMatix(AffinePlan.Translate(150, 100)); m_pathVxs = shape_mtx.TransformToVxs(m_pathVxs); var curveFlattener = new CurveFlattener(); m_path_2 = new VertexStoreSnap(curveFlattener.MakeVxs(m_pathVxs)); BoundingRect.GetBoundingRect(m_path_2, ref m_shape_bounds); m_shadow_ctrl.SetXN(0, m_shape_bounds.Left); m_shadow_ctrl.SetYN(0, m_shape_bounds.Bottom); m_shadow_ctrl.SetXN(1, m_shape_bounds.Right); m_shadow_ctrl.SetYN(1, m_shape_bounds.Bottom); m_shadow_ctrl.SetXN(2, m_shape_bounds.Right); m_shadow_ctrl.SetYN(2, m_shape_bounds.Top); m_shadow_ctrl.SetXN(3, m_shape_bounds.Left); m_shadow_ctrl.SetYN(3, m_shape_bounds.Top); m_shadow_ctrl.LineColor = ColorRGBAf.MakeColorRGBA(0f, 0.3f, 0.5f, 0.3f); }
private Cluster FindCluster(ICurve2D curve, GeoPoint2D p, bool RemovePoint) { // Findet einen Cluster, der den Punkt p und die Kurve curve enthält BoundingRect clip = new BoundingRect(p, clusterSize, clusterSize); ICollection col = clusterTree.GetObjectsFromRect(clip); foreach (Cluster cl in col) { if (cl.HitTest(ref clip, false)) { for (int i = 0; i < cl.Joints.Count; ++i) { if ((cl.Joints[i]).curve == curve) { if (RemovePoint) { cl.Joints.RemoveAt(i); } return(cl); } } } } return(null); }
public virtual bool ContainsPointOnScreen(Point point, Camera camera) { return(BoundingRect.Contains(point.Transform(camera.GetMatrix().Invert()))); }
static SimpleFontAtlasBuilder CreateAggSubPixelRenderingTextureFont( Typeface typeface, float sizeInPoint, HintTechnique hintTech, IEnumerable <ushort> glyphIndexIter) { ////read type face from file //Typeface typeface; //using (var fs = new FileStream(fontfile, FileMode.Open, FileAccess.Read)) //{ // var reader = new OpenFontReader(); // //1. read typeface from font file // typeface = reader.Read(fs); //} //sample: create sample msdf texture //------------------------------------------------------------- var builder = new GlyphPathBuilder(typeface); builder.SetHintTechnique(hintTech); //------------------------------------------------------------- var atlasBuilder = new SimpleFontAtlasBuilder(); atlasBuilder.SetAtlasInfo(TextureKind.AggSubPixel, sizeInPoint); VertexStorePool vxsPool = new VertexStorePool(); //create agg cavnas foreach (ushort gindex in glyphIndexIter) { //build glyph builder.BuildFromGlyphIndex(gindex, sizeInPoint); var txToVxs = new GlyphTranslatorToVxs(); builder.ReadShapes(txToVxs); // //create new one var glyphVxs = new VertexStore(); txToVxs.WriteOutput(glyphVxs, vxsPool); //find bound //-------------------------------------------- //GlyphImage glyphImg = new GlyphImage() RectD bounds = new Agg.RectD(); BoundingRect.GetBoundingRect(new VertexStoreSnap(glyphVxs), ref bounds); //-------------------------------------------- int w = (int)System.Math.Ceiling(bounds.Width); int h = (int)System.Math.Ceiling(bounds.Height); if (w < 5) { w = 5; } if (h < 5) { h = 5; } //translate to positive quadrant double dx = (bounds.Left < 0) ? -bounds.Left : 0; double dy = (bounds.Bottom < 0) ? -bounds.Bottom : 0; w = w * 4; if (dx != 0 || dy != 0) { Agg.Transform.Affine transformMat = Agg.Transform.Affine.NewTranslation(dx, dy); VertexStore vxs2 = new VertexStore(); glyphVxs.TranslateToNewVxs(dx, dy, vxs2); glyphVxs = vxs2; } //-------------------------------------------- //create glyph img ActualImage img = new Agg.ActualImage(w, h, PixelFormat.ARGB32); ImageGraphics2D imgCanvas2d = new Agg.ImageGraphics2D(img); AggCanvasPainter painter = new Agg.AggCanvasPainter(imgCanvas2d); //we use white glyph on black bg for this texture painter.Clear(Color.Black); //fill with black painter.FillColor = Color.White; painter.StrokeColor = Color.White; //-------------------------------------------- painter.UseSubPixelRendering = true; //-------------------------------------------- //-------------------------------------------- painter.Fill(glyphVxs); //-------------------------------------------- var glyphImage = new GlyphImage(w, h); glyphImage.TextureOffsetX = dx; glyphImage.TextureOffsetY = dy; glyphImage.SetImageBuffer(ActualImage.GetBuffer2(img), false); //copy data from agg canvas to glyph image atlasBuilder.AddGlyph(gindex, glyphImage); //int[] buffer = glyphImage.GetImageBuffer(); //using (var bmp = new System.Drawing.Bitmap(glyphImage.Width, glyphImage.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) //{ // var bmpdata = bmp.LockBits(new System.Drawing.Rectangle(0, 0, glyphImage.Width, glyphImage.Height), // System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat); // System.Runtime.InteropServices.Marshal.Copy(buffer, 0, bmpdata.Scan0, buffer.Length); // bmp.UnlockBits(bmpdata); // bmp.Save("d:\\WImageTest\\a001_subpix_xn2_" + gindex + ".png"); //} } //var glyphImg2 = atlasBuilder.BuildSingleImage(); //using (var bmp = new System.Drawing.Bitmap(glyphImg2.Width, glyphImg2.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) //{ // var bmpdata = bmp.LockBits(new System.Drawing.Rectangle(0, 0, glyphImg2.Width, glyphImg2.Height), // System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat); // int[] intBuffer = glyphImg2.GetImageBuffer(); // System.Runtime.InteropServices.Marshal.Copy(intBuffer, 0, bmpdata.Scan0, intBuffer.Length); // bmp.UnlockBits(bmpdata); // bmp.Save("d:\\WImageTest\\a_total.png"); //} //atlasBuilder.SaveFontInfo("d:\\WImageTest\\a_info.xml"); return(atlasBuilder); }
public void RenderChar(char testChar, HintTechnique hint) { builder.SetHintTechnique(hint); #if DEBUG GlyphBoneJoint.dbugTotalId = 0;//reset builder.dbugAlwaysDoCurveAnalysis = true; #endif _infoView.Clear(); _latestHint = hint; _testChar = testChar; //---------------------------------------------------- // builder.Build(testChar, _sizeInPoint); var txToVxs1 = new GlyphTranslatorToVxs(); builder.GlyphDynamicEdgeOffset = this.GlyphEdgeOffset; builder.ReadShapes(txToVxs1); #if DEBUG var ps = txToVxs1.dbugGetPathWriter(); _infoView.ShowOrgBorderInfo(ps.Vxs); #endif PixelFarm.Drawing.VertexStore vxs = new PixelFarm.Drawing.VertexStore(); txToVxs1.WriteOutput(vxs); //---------------------------------------------------- //---------------------------------------------------- painter.UseSubPixelLcdEffect = this.UseLcdTechnique; //5. use PixelFarm's Agg to render to bitmap... //5.1 clear background painter.Clear(PixelFarm.Drawing.Color.White); RectD bounds = new RectD(); BoundingRect.GetBoundingRect(new PixelFarm.Drawing.VertexStoreSnap(vxs), ref bounds); //---------------------------------------------------- float scale = _typeface.CalculateScaleToPixelFromPointSize(_sizeInPoint); _pxscale = scale; this._infoView.PxScale = scale; var left2 = 0; int floor_1 = (int)left2; float diff = left2 - floor_1; //---------------------------------------------------- if (OffsetMinorX) { MinorOffsetInfo = left2.ToString() + " =>" + floor_1 + ",diff=" + diff; } else { MinorOffsetInfo = left2.ToString(); } //5. use PixelFarm's Agg to render to bitmap... //5.1 clear background painter.Clear(PixelFarm.Drawing.Color.White); if (FillBackGround) { //5.2 painter.FillColor = PixelFarm.Drawing.Color.Black; float xpos = 5;// - diff; if (OffsetMinorX) { xpos -= diff; } painter.SetOrigin(xpos, 10); painter.Fill(vxs); } if (DrawBorder) { //5.4 painter.StrokeColor = PixelFarm.Drawing.Color.Green; //user can specific border width here... //5.5 painter.Draw(vxs); //-------------- int markOnVertexNo = _infoView.DebugMarkVertexCommand; double x, y; vxs.GetVertex(markOnVertexNo, out x, out y); painter.FillRect(x, y, 4, 4, PixelFarm.Drawing.Color.Red); //-------------- _infoView.ShowFlatternBorderInfo(vxs); //-------------- } #if DEBUG builder.dbugAlwaysDoCurveAnalysis = false; #endif if (ShowTess) { RenderTessTesult(); } //if (DrawDynamicOutline) //{ // GlyphDynamicOutline dynamicOutline = builder.LatestGlyphFitOutline; // WalkDynamicOutline(painter, dynamicOutline, scale, DrawRegenerateOutline); //} }
/// <summary> /// Overrides <see cref="CADability.GeoObject.IGeoObjectImpl.HitTest (Projection, BoundingRect, bool)"/> /// </summary> /// <param name="projection"></param> /// <param name="rect"></param> /// <param name="onlyInside"></param> /// <returns></returns> public override bool HitTest(Projection projection, BoundingRect rect, bool onlyInside) { // egal ob onlyInside, da nur ein Punkt getestet wird return(projection.ProjectUnscaled(location) <= rect); }
/// <summary> /// Overrides <see cref="CADability.GeoObject.IGeoObjectImpl.GetExtent (Projection, ExtentPrecision)"/> /// </summary> /// <param name="projection"></param> /// <param name="extentPrecision"></param> /// <returns></returns> public override BoundingRect GetExtent(Projection projection, ExtentPrecision extentPrecision) { BoundingRect res = new BoundingRect(projection.Project(location)); return(res); }
void processCollision(Entity ballEntity) { TransformComponent transformComp = ballEntity.GetComponent <TransformComponent>(); BallComponent ballComp = ballEntity.GetComponent <BallComponent>(); // Wrap ball angle while (ballComp.Direction < 0) { ballComp.Direction += 2 * MathHelper.Pi; } while (ballComp.Direction > 2 * MathHelper.Pi) { ballComp.Direction -= 2 * MathHelper.Pi; } BoundingRect ballAABB = new BoundingRect(transformComp.Position - ballComp.Bounds / 2, transformComp.Position + ballComp.Bounds / 2); // Paddles foreach (Entity paddleEntity in _paddleEntities) { PaddleComponent paddleComp = paddleEntity.GetComponent <PaddleComponent>(); TransformComponent paddleTransformComp = paddleEntity.GetComponent <TransformComponent>(); BoundingRect paddleAABB = new BoundingRect(paddleTransformComp.Position - paddleComp.Bounds / 2, paddleTransformComp.Position + paddleComp.Bounds / 2); if (ballAABB.Intersects(paddleAABB)) { if (!paddleComp.IgnoreCollisions) { { Vector2 ballEdge = transformComp.Position + ballComp.Bounds * -paddleComp.Normal; Vector2 paddleEdge = paddleTransformComp.Position + paddleComp.Bounds * paddleComp.Normal; Vector2 bouncePosition = (ballEdge + paddleEdge) / 2; EventManager.Instance.QueueEvent(new BallBounceEvent(ballEntity, paddleEntity, bouncePosition)); } // Determine alpha of ball relative to the paddle's heigh float relativeY = transformComp.Position.Y - paddleTransformComp.Position.Y; float alpha = (relativeY + (paddleComp.Bounds.Y / 2)) / paddleComp.Bounds.Y; alpha = MathHelper.Clamp(alpha, 0, 1); // Determine new direction float newDir = MathHelper.Lerp(Constants.Pong.PADDLE_BOUNCE_MIN, Constants.Pong.PADDLE_BOUNCE_MAX, alpha); newDir = MathHelper.ToRadians(newDir); // Set ball direction if (paddleComp.Normal.X > 0) { ballComp.Direction = newDir; } else if (paddleComp.Normal.X < 0) { ballComp.Direction = MathHelper.Pi - newDir; } // Make sure ball does not get stuck inside paddle paddleComp.IgnoreCollisions = true; } } else { paddleComp.IgnoreCollisions = false; } } // Edges foreach (Entity edgeEntity in _edgeEntities) { EdgeComponent edgeComp = edgeEntity.GetComponent <EdgeComponent>(); TransformComponent edgeTransformComp = edgeEntity.GetComponent <TransformComponent>(); BoundingRect edgeAABB = new BoundingRect(edgeTransformComp.Position.X - Constants.Pong.PLAYFIELD_WIDTH / 2, edgeTransformComp.Position.Y - Constants.Pong.EDGE_HEIGHT / 2, Constants.Pong.EDGE_WIDTH, Constants.Pong.EDGE_HEIGHT); if (ballAABB.Intersects(edgeAABB)) { { Vector2 ballEdge = transformComp.Position + ballComp.Bounds * -edgeComp.Normal; Vector2 edgeEdge = edgeTransformComp.Position + new Vector2(Constants.Pong.EDGE_WIDTH, Constants.Pong.EDGE_HEIGHT) * edgeComp.Normal; Vector2 bouncePosition = (ballEdge + edgeEdge) / 2; EventManager.Instance.QueueEvent(new BallBounceEvent(ballEntity, edgeEntity, bouncePosition)); } // Determine directional vector of ball Vector2 ballDirection = new Vector2((float)Math.Cos(ballComp.Direction), (float)Math.Sin(ballComp.Direction)); // Determine reflection vector of ball Vector2 ballReflectionDir = getReflectionVector(ballDirection, edgeComp.Normal); // Set angle of new directional vector ballComp.Direction = (float)Math.Atan2(ballReflectionDir.Y, ballReflectionDir.X); } } }
public static Rect ToRect(this BoundingRect rect) { return(new Rect(rect.X, rect.Y, rect.W, rect.H)); }
internal bool Contains(BoundingRect rect) { return(this.BoundingBox.Contains(rect)); }
public virtual void DrawOutline(SpriteBatch sb, Color color, Camera camera) { Utility.Utility.DrawOutline(sb, BoundingRect.Transform(camera.GetMatrix()), color); }
public static void PlaceAndScaleLogos(Dictionary <FactionValue, GameObject> logos, StarmapRenderer renderer) { var boundingRects = new Dictionary <FactionValue, BoundingRect>(); foreach (var starNode in renderer.starmap.VisisbleSystem) { var faction = starNode.System.OwnerValue; if (!logos.ContainsKey(faction)) { continue; } BoundingRect boundingRect; if (boundingRects.ContainsKey(faction)) { boundingRect = boundingRects[faction]; } else { boundingRect = new BoundingRect(); boundingRects.Add(faction, boundingRect); } boundingRect.MinX = Mathf.Min(boundingRect.MinX, starNode.NormalizedPosition.x); boundingRect.MaxX = Mathf.Max(boundingRect.MaxX, starNode.NormalizedPosition.x); boundingRect.MinY = Mathf.Min(boundingRect.MinY, starNode.NormalizedPosition.y); boundingRect.MaxY = Mathf.Max(boundingRect.MaxY, starNode.NormalizedPosition.y); } foreach (var faction in logos.Keys) { if (!boundingRects.ContainsKey(faction)) { continue; } var logo = logos[faction]; var boundingRect = boundingRects[faction]; // ReSharper disable once CompareOfFloatsByEqualityOperator if (boundingRect.MinX == float.MaxValue) { // there were no star systems logo.SetActive(false); continue; } logo.SetActive(true); // position is in the middle of the boundingRect var x = (boundingRect.MaxX + boundingRect.MinX) / 2f; var y = (boundingRect.MaxY + boundingRect.MinY) / 2f; var normalizedPos = new Vector2(x, y); logo.transform.position = StarmapRenderer.NormalizeToMapSpace(normalizedPos); // scale is based off of the width/height of the boundingRect var topRight = StarmapRenderer.NormalizeToMapSpace(new Vector2(boundingRect.MaxX, boundingRect.MaxY)); var bottomLeft = StarmapRenderer.NormalizeToMapSpace(new Vector2(boundingRect.MinX, boundingRect.MinY)); var width = topRight.x - bottomLeft.x; var height = topRight.y - bottomLeft.y; var scale = Mathf.Min(Mathf.Min(width, height) * Main.Settings.LogoScalar, Main.Settings.LogoMaxSize); logo.transform.localScale = new Vector3(scale, scale); } }
internal BoundingRect Union(BoundingRect rect) { return(Union(this, rect)); }