public bool Project2DLine(Vector PointIn3DSpace1, Vector PointIn3DSpace2, out QPoint ProjectedPointIn2D1, out QPoint ProjectedPointIn2D2) { ProjectedPointIn2D1 = QPoint.Empty; ProjectedPointIn2D2 = QPoint.Empty; Vector v1 = orientToCamera(ref PointIn3DSpace1); Vector v2 = orientToCamera(ref PointIn3DSpace2); if (v1.X < FRONT_CLIP_PLANE) { if (v2.X < FRONT_CLIP_PLANE) { return(false); } clipToFrontPlane(ref v1, ref v2); } else if (v2.X < FRONT_CLIP_PLANE) { if (v1.X < FRONT_CLIP_PLANE) { return(false); } clipToFrontPlane(ref v2, ref v1); } project(ref v1, ref ProjectedPointIn2D1); project(ref v2, ref ProjectedPointIn2D2); return(lineClip(ref ProjectedPointIn2D1, ref ProjectedPointIn2D2)); }
private ClipCode GetClipCode(QPoint P) { ClipCode code; code = ClipCode.Inside; if (P.X < minPoint.X) { code |= ClipCode.Left; } else if (P.X > maxPoint.X) { code |= ClipCode.Right; } if (P.Y < minPoint.Y) { code |= ClipCode.Bottom; } else if (P.Y > maxPoint.Y) { code |= ClipCode.Top; } return(code); }
public float DistanceTo(QPoint Other) { var x = this.X - Other.X; var y = this.Y - Other.Y; return((float)Math.Sqrt(x * x + y * y)); }
public void DrawString(string Text, QPoint Location, QPen Pen, QFont Font) { #if WPF PendingText.Add(new Tuple <string, QPoint, QPen, QFont, bool>(Text, Location, Pen, Font, false)); #else DrawingTarget.DrawString(Text, Font.Font, Pen.Brush, Location.X, Location.Y); #endif }
public void DrawStringCentered(string Text, QPoint Location, QPen Pen, QFont Font) { #if WPF PendingText.Add(new Tuple <string, QPoint, QPen, QFont, bool>(Text, Location, Pen, Font, true)); #else var size = MeasureText(Text, Font); DrawingTarget.DrawString(Text, Font.Font, Pen.Brush, Location.X - size.Width / 2, Location.Y - size.Height / 2); #endif }
public QCommand(CommandCode Code, bool Shift, bool Control, bool Alt, QPoint Point, double Data = 0, string String = "") { this.Shift = Shift; this.Control = Control; this.Alt = Alt; this.String = String; this.Data = Data; this.CommandCode = Code; this.Point = Point; }
public void Overwrite(QPoint P) { #if DEBUG if (base.Equals(QPoint.Empty)) { throw new Exception(); } #endif this.X = P.X; this.Y = P.Y; }
private CelestialBody findClosestBody(QPoint Point, List <CelestialBody> RenderLocations, int NumLocations) { CelestialBody closest = null; float minDist = 300f; for (int i = 0; i < NumLocations; i++) { if (RenderLocations[i].RenderPoint.DistanceTo(Point) < minDist) { closest = RenderLocations[i]; minDist = RenderLocations[i].RenderPoint.DistanceTo(Point); } } return(closest); }
protected override void SetupLayout() { this.rect = this.screenSize.GetRectangleDockedBottomRight(new QSize(355, 190), 20); const float LEFT_MARGIN = 10; titleLoc = rect.TopLeft + new QPoint(LEFT_MARGIN, 10); float x = rect.Left + LEFT_MARGIN; float y = rect.Top + 40; float margin = 10; rects[0] = new QRectangle(x, y, YEAR_WIDTH, BOX_HEIGHT); x += YEAR_WIDTH + margin; rects[1] = new QRectangle(x, y, NUM_WIDTH, BOX_HEIGHT); x += NUM_WIDTH + margin; rects[2] = new QRectangle(x, y, NUM_WIDTH, BOX_HEIGHT); x += NUM_WIDTH + margin; rects[3] = new QRectangle(x, y, NUM_WIDTH, BOX_HEIGHT); x += NUM_WIDTH + margin; rects[4] = new QRectangle(x, y, NUM_WIDTH, BOX_HEIGHT); x += NUM_WIDTH + margin; rects[5] = new QRectangle(x, y, NUM_WIDTH, BOX_HEIGHT); x += NUM_WIDTH + margin; rects[6] = new QRectangle(x, y, NUM_WIDTH, BOX_HEIGHT); QPoint offset = new QPoint(-2, 3); slash1 = rects[0].TopRight + offset; slash2 = rects[1].TopRight + offset; colon1 = rects[3].TopRight + offset; colon2 = rects[4].TopRight + offset; localLoc = new QPoint(rects[6].Center.X - 1, rects[6].Bottom - 5); help1Loc = new QPoint(rect.Left + LEFT_MARGIN, rect.Bottom - 100); help2Loc = new QPoint(rect.Left + LEFT_MARGIN, rect.Bottom - 76); help3Loc = new QPoint(rect.Left + LEFT_MARGIN, rect.Bottom - 52); help4Loc = new QPoint(rect.Left + LEFT_MARGIN, rect.Bottom - 28); }
protected override void SetupLayout() { this.rect = this.screenSize.GetRectangleDockedBottomRight(new QSize(340, 230), 20); const float LEFT_MARGIN = 10; titleLoc = rect.TopLeft + new QPoint(LEFT_MARGIN, 10); findTextBorder = new QRectangle(rect.TopLeft + new QPoint(LEFT_MARGIN, 40), new QSize(rect.Width - LEFT_MARGIN * 2, 30)); findTextPoint = findTextBorder.Location + new QPoint(4, 2); hintRectangle = new QRectangle(rect.Left + LEFT_MARGIN, findTextPoint.Y + 40, findTextBorder.Width, 40); help1Loc = new QPoint(rect.Left + LEFT_MARGIN, rect.Bottom - 100); help2Loc = new QPoint(help1Loc.X, help1Loc.Y + 24); help3Loc = new QPoint(help2Loc.X, help2Loc.Y + 24); help4Loc = new QPoint(help3Loc.X, help3Loc.Y + 30); }
protected void drawArrow(QPoint Location, QSize Size, double Angle) { const double arrowAngle = 0.8; var tip = new QPoint(Location.X + Size.Width * Math.Cos(Angle), Location.Y - Size.Height * Math.Sin(Angle)); renderer.DrawLine(LinePen, tip, Location); var leftFin = new QPoint(tip.X + sizeVSmall.Width * Math.Cos(Angle + Math.PI * arrowAngle), tip.Y - sizeVSmall.Height * Math.Sin(Angle + Math.PI * arrowAngle)); renderer.DrawLine(LinePen, tip, leftFin); var rightFin = new QPoint(tip.X + sizeVSmall.Width * Math.Cos(Angle - Math.PI * arrowAngle), tip.Y - sizeVSmall.Height * Math.Sin(Angle - Math.PI * arrowAngle)); renderer.DrawLine(LinePen, tip, rightFin); }
public void Render() { if (locked || --messageCountdown > 0) { if (messageSize == QSize.Empty) { messageSize = renderer.MeasureText(message, renderer.ExtraLargeFont); this.screenSize = QSize.Empty; } if (renderer.ScreenSize != this.screenSize) { rect = new QRectangle((renderer.ScreenSize.Width - messageSize.Width) / 2, renderer.ScreenSize.Height - 100, messageSize.Width, messageSize.Height); this.screenSize = renderer.ScreenSize; textLocation = new QPoint(rect.X + rect.Width / 40, rect.Y + 1); } renderer.FillRectangle(rect, fillPen, borderPen); renderer.DrawString(message, textLocation, forePen, renderer.ExtraLargeFont); } }
protected override void SetupLayout() { this.rect = this.screenSize.GetRectangleDockedBottomRight(new QSize(400, 195), 20); const float LEFT_MARGIN = 10; titleLoc = rect.TopLeft + new QPoint(LEFT_MARGIN, 10); float x = rect.Left + LEFT_MARGIN; float y = rect.Top + 40; float margin = 3; rects[0] = new QRectangle(x, y, NUM_WIDTH, BOX_HEIGHT); x += NUM_WIDTH + margin; rects[1] = new QRectangle(x, y, NUM_WIDTH, BOX_HEIGHT); x += NUM_WIDTH + margin; rects[2] = new QRectangle(x, y, NUM_WIDTH, BOX_HEIGHT); x += NUM_WIDTH + margin; rects[3] = new QRectangle(x, y, CHAR_WIDTH, BOX_HEIGHT); x += CHAR_WIDTH + margin * 4; rects[4] = new QRectangle(x, y, NUM_WIDTH, BOX_HEIGHT); x += NUM_WIDTH + margin; rects[5] = new QRectangle(x, y, NUM_WIDTH, BOX_HEIGHT); x += NUM_WIDTH + margin; rects[6] = new QRectangle(x, y, NUM_WIDTH, BOX_HEIGHT); x += NUM_WIDTH + margin; rects[7] = new QRectangle(x, y, CHAR_WIDTH, BOX_HEIGHT); latLoc = rects[0].BottomLeft + new QPoint(70, 2); lngLoc = rects[4].BottomLeft + new QPoint(70, 2); help1Loc = new QPoint(rect.Left + LEFT_MARGIN, rect.Bottom - 76); help2Loc = new QPoint(rect.Left + LEFT_MARGIN, rect.Bottom - 52); help3Loc = new QPoint(rect.Left + LEFT_MARGIN, rect.Bottom - 28); }
public override void Render() { var top = dataSource.CameraUp.__GetTranslationRelativeToReferenceAsXAxis(dataSource.CameraView); var angle = Math.PI - Math.Atan2(top.Z, top.Y); QPoint adjCenter = new QPoint(center.X - Math.Cos(angle) * 40, center.Y + Math.Sin(angle) * 40); drawArrow(adjCenter, smallArrowSize, angle); angle -= MathEx.HALF_PI; var xOffset = Math.Cos(angle) * innerSize.Width; var yOffset = -Math.Sin(angle) * innerSize.Height; renderer.DrawLine(BackPen, new QPoint(center.X - xOffset, center.Y - yOffset), new QPoint(center.X + xOffset, center.Y + yOffset)); var angleDegrees = angle.NormalizeAngleNegativePiToPi().ToDegreesFromRadians(); var angleString = (angleDegrees >= 0.0 ? "L" : "R") + String.Format("{0:000.0}°", Math.Abs(angleDegrees)); renderer.DrawStringCentered(angleString, textCenter, TextPen, renderer.SmallFont); }
public bool Project2DPoint(Vector PointIn3DSpace, bool FailIfOffscreen, out QPoint ProjectedPointIn2D) { ProjectedPointIn2D = QPoint.Empty; Vector v = orientToCamera(ref PointIn3DSpace); if (v.X < FRONT_CLIP_PLANE) { return(false); } project(ref v, ref ProjectedPointIn2D); if (!FailIfOffscreen || (ProjectedPointIn2D.X >= minPoint.X && ProjectedPointIn2D.X <= maxPoint.X && ProjectedPointIn2D.Y >= minPoint.Y && ProjectedPointIn2D.Y < maxPoint.Y)) { return(true); } return(false); }
private void orthographicProject(ref Vector VectorIn3DSpace, ref QPoint P) { double inc = VectorIn3DSpace.Inclination; P.Overwrite(halfScreenSize.Width - Zoom * Math.Cos(inc) * Math.Sin(VectorIn3DSpace.Azimuth), halfScreenSize.Height - Zoom * Math.Sin(inc)); }
public void DrawCircle(QPoint Center, float Radius, QPen Pen) { DrawingTarget.DrawCircle(Pen, Center, Radius); }
private void cyclindricalProject(ref Vector VectorIn3DSpace, ref QPoint P) { P.Overwrite(halfScreenSize.Width - VectorIn3DSpace.Azimuth * Zoom, halfScreenSize.Height - VectorIn3DSpace.Inclination * Zoom); }
private void stereographicProject(ref Vector VectorIn3DSpace, ref QPoint P) { P.Overwrite(halfScreenSize.Width - Zoom * VectorIn3DSpace.Y / VectorIn3DSpace.X, halfScreenSize.Height - Zoom * VectorIn3DSpace.Z / VectorIn3DSpace.X); }
public static QRectangle GetRectangleCenteredOn(QPoint Center, QSize Size) { return(new QRectangle(Center.X - Size.Width / 2, Center.Y - Size.Height / 2, Size.Width, Size.Height)); }
public static void FillRectangle(this WriteableBitmap bmp, QPen Pen, QPoint Point, QSize Size) { bmp.FillRectangle(Pen, (int)Point.X, (int)Point.Y, (int)(Point.X + Size.Width), (int)(Point.Y + Size.Height)); }
public void SetupForProjection(Camera Camera) { Position = Camera.Position; PositionNearlyLocked = Camera.PositionNearlyLocked; ViewMode = Camera.ViewMode; var camView = Camera.View; var camUp = Camera.Up; BodyWithCamera = Camera.BodyWithCamera; BodyBeingViewed = Camera.BodyBeingViewed; halfScreenSize = new QSize(ScreenSize.Width / 2, ScreenSize.Height / 2); minPoint = new QPoint(0, 0); maxPoint = new QPoint(screenSize.Width, screenSize.Height); switch (ProjectionMode) { case SolarMax.ProjectionMode.Cylindrical: project = cyclindricalProject; Zoom = (float)Camera.Zoom; break; case SolarMax.ProjectionMode.Stereographic: project = stereographicProject; Zoom = (float)Camera.Zoom * 0.8f; break; case SolarMax.ProjectionMode.Orthographic: project = orthographicProject; Zoom = (float)Camera.Zoom * 0.9f; break; } // Get Camera Rotation var camAz = Quaternion.GetRotationQuaternion(Vector.UnitZ, -camView.Azimuth); var camInc = Quaternion.GetRotationQuaternion(Vector.UnitY, camView.Inclination); var trans = camInc * camAz; Vector upTrans; if (camView.AngleDiffAbs(camUp) > MathEx.EPSILON) { upTrans = trans.RotateVectorFast(camUp); } else if (camView.AngleDiffAbs(Vector.UnitX) > MathEx.EPSILON) { upTrans = trans.RotateVectorFast(Vector.UnitZ); } else { upTrans = trans.RotateVectorFast(Vector.UnitX); } var camRot = Quaternion.GetRotationQuaternion(Vector.UnitX, Math.Atan2(upTrans.Y, upTrans.Z)); var transWRotate = camRot * trans; // Get Panning Rotation var az = Quaternion.GetRotationQuaternion(Vector.UnitZ, panAzimuth); panAzimuth = 0; var inc = Quaternion.GetRotationQuaternion(Vector.UnitY, panInclination); panInclination = 0; var rot = Quaternion.GetRotationQuaternion(Vector.UnitX, panRotate); panRotate = 0; pan.SetTarget(az * inc * rot * pan.Target, false); pan.Track(); // Combine projectionQ = pan.Actual * transWRotate; PanView = projectionQ.Conjugate.RotateVectorFast(Vector.UnitX); PanUp = projectionQ.Conjugate.RotateVectorFast(Vector.UnitZ); }
public static void DrawLine(this WriteableBitmap bmp, QPen Pen, QPoint P1, QPoint P2) { bmp.DrawLine(Pen, (int)P1.X, (int)P1.Y, (int)P2.X, (int)P2.Y); }
public bool Equals(QPoint P) { return(this == P); }
static QPoint() { Empty = new QPoint(0f, 0f); }
public void FillRectangle(QPoint Location, QSize Size, QPen FillPen, QPen BorderPen) { this.FillRectangle(Location, Size, FillPen); DrawingTarget.DrawRectangle(BorderPen, Location, Size); }
// Cohen–Sutherland clipping algorithm private bool lineClip(ref QPoint P1, ref QPoint P2) { ClipCode cc1 = GetClipCode(P1); ClipCode cc2 = GetClipCode(P2); while (true) { if ((cc1 | cc2) == ClipCode.Inside) { return(true); } else if ((cc1 & cc2) != ClipCode.Inside) { return(false); } else { QPoint p; // failed both tests, so calculate the line segment to clip // from an outside point to an intersection with clip edge // At least one endpoint is outside the clip rectangle; pick it. ClipCode cc = (cc1 != ClipCode.Inside) ? cc1 : cc2; // Now find the intersection point; // use formulas y = y0 + slope * (x - x0), x = x0 + (1 / slope) * (y - y0) if ((cc & ClipCode.Top) != ClipCode.Inside) { p = new QPoint(P1.X + (P2.X - P1.X) * (maxPoint.Y - P1.Y) / (P2.Y - P1.Y), maxPoint.Y); } else if ((cc & ClipCode.Bottom) != ClipCode.Inside) { p = new QPoint(P1.X + (P2.X - P1.X) * (minPoint.Y - P1.Y) / (P2.Y - P1.Y), minPoint.Y); } else if ((cc & ClipCode.Right) != ClipCode.Inside) { p = new QPoint(maxPoint.X, P1.Y + (P2.Y - P1.Y) * (maxPoint.X - P1.X) / (P2.X - P1.X)); } else // point must be to left { p = new QPoint(minPoint.X, P1.Y + (P2.Y - P1.Y) * (minPoint.X - P1.X) / (P2.X - P1.X)); } if (cc.Equals(cc1)) { P1.Overwrite(p); cc1 = GetClipCode(P1); } else { P2.Overwrite(p); cc2 = GetClipCode(P2); } } } }
public void FillRectangle(QPoint Location, QSize Size, QPen Pen) { DrawingTarget.FillRectangle(Pen, Location, Size); }
private void setupGeometry() { drawCenter = new QPoint(center.X, Location.Y + Size.Height * 0.7); arcRect = QRectangle.GetRectangleCenteredOn(drawCenter, innerSize); textPoint = new QPoint(center.X, Location.Y + Size.Height * 0.8); }
public QRectangle(QPoint Location, QSize Size) : this(Location.X, Location.Y, Size.Width, Size.Height) { }