本文整理汇总了C#中System.Drawing.Drawing2D.Matrix.TransformPoints方法的典型用法代码示例。如果您正苦于以下问题:C# System.Drawing.Drawing2D.Matrix.TransformPoints方法的具体用法?C# System.Drawing.Drawing2D.Matrix.TransformPoints怎么用?C# System.Drawing.Drawing2D.Matrix.TransformPoints使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Drawing2D.Matrix
的用法示例。
在下文中一共展示了System.Drawing.Drawing2D.Matrix.TransformPoints方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCurrentPosteriorVector
private static Vector3D GetCurrentPosteriorVector(Vector3D imagePosterior, int sourceWidth, float adjustedSourceHeight, int rotation, float scaleX, float scaleY, bool flipX, bool flipY)
{
// figure out where the posterior direction went
using (var transform = new Matrix())
{
var points = new[] {new PointF(sourceWidth*imagePosterior.X, adjustedSourceHeight*imagePosterior.Y)};
transform.Rotate(rotation);
transform.Scale(scaleX*(flipY ? -1 : 1), scaleY*(flipX ? -1 : 1));
transform.TransformPoints(points);
return new Vector3D(points[0].X, points[0].Y, 0);
}
}
示例2: GetCursor
/// <summary>
/// Return cursor for command
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="zoomLevel"></param>
/// <returns>null if coordinates are not fine</returns>
public Cursor GetCursor(float x, float y, System.Drawing.Drawing2D.Matrix viewMatrix)
{
// transform x,y back to object coordinates to check for selection
System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
mat.Multiply(this.TransformationMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
mat.Multiply(this.Owner.DrawMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
mat.Multiply(viewMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
mat.Invert();
PointF tmpPoint = new PointF(x, y);
PointF[] points = new PointF[1];
points[0] = tmpPoint;
mat.TransformPoints(points);
tmpPoint = points[0];
// check if this item should be selected
float w = (float)this.WidthInPixels / this.Owner.ViewMatrix.Elements[0];
float h = (float)this.HeightInPixels / this.Owner.ViewMatrix.Elements[3];
// if starting coordinate fall inside this component rect
if (tmpPoint.X >= 0 && tmpPoint.X <= w && tmpPoint.Y >= 0 && tmpPoint.Y <= h)
{
return this.cursor;
}
else
{
return null;
}
}
示例3: BisectAngle
/// <summary>
/// Bisects the inner angle formed by <paramref name="point1"/> <paramref name="point2"/> <paramref name="point3"/>.
/// </summary>
/// <remarks>
/// <para>
/// Based largely on <see cref="ProtractorRoiCalloutLocationStrategy"/>.
/// </para>
/// <para>
/// The return value is a point within the angle such that the line segment
/// from this point to <paramref name="point2"/> has the specified <paramref name="magnitude"/> and bisects the angle
/// <paramref name="point1"/> <paramref name="point2"/> <paramref name="point3"/>.
/// </para>
/// </remarks>
private static PointF BisectAngle(PointF point1, PointF point2, PointF point3, float magnitude)
{
PointF[] points = new PointF[] {point1, point3};
using (Matrix2D rotation = new Matrix2D())
{
rotation.Rotate((float) (-Vector.SubtendedAngle(point1, point2, point3)/2 + 180));
rotation.Translate(-point2.X, -point2.Y);
rotation.TransformPoints(points);
}
Vector3D result = new Vector3D(points[0].X, points[0].Y, 0);
if (FloatComparer.AreEqual(result.Magnitude, 0F, 0.01F))
result = new Vector3D(-1, 0, 0);
result = result/result.Magnitude*magnitude;
return new PointF(point2.X - result.X, point2.Y - result.Y);
}
示例4: AddKeyPoint
/// <summary>
/// Add a key point into this polyline link.
/// </summary>
/// <param name="x">X coordinate of the key point.</param>
/// <param name="y">Y coordinate of the key point.</param>
/// <param name="rgObjs">GOM object collection.</param>
public void AddKeyPoint(float x, float y, GOM_Objects rgObjs)
{
if ( m_linkingStyle != GOM_Linking_Style.Polyline )
{
return;
}
System.Drawing.Drawing2D.Matrix matrix;
System.Drawing.PointF[] rgPts, rgAllPts;
System.Drawing.PointF startPt, endPt;
startPt = StartPointInCanvas(rgObjs);
endPt = EndPointInCanvas(rgObjs);
rgPts = new System.Drawing.PointF[2];
rgAllPts = new System.Drawing.PointF[m_keyPts.Count+2];
rgAllPts[0].X = startPt.X;
rgAllPts[0].Y = startPt.Y;
for(int i=0; i<m_keyPts.Count; i++)
{
rgAllPts[1+i].X = m_keyPts[i].x;
rgAllPts[1+i].Y = m_keyPts[i].y;
}
rgAllPts[rgAllPts.Length-1].X = endPt.X;
rgAllPts[rgAllPts.Length-1].Y = endPt.Y;
for(int i=0; i<(rgAllPts.Length-1); i++)
{
rgPts[0].X = rgAllPts[i+1].X;
rgPts[0].Y = rgAllPts[i+1].Y;
rgPts[1].X = x;
rgPts[1].Y = y;
matrix = new System.Drawing.Drawing2D.Matrix();
matrix.Translate(-rgAllPts[i].X, -rgAllPts[i].Y);
matrix.TransformPoints(rgPts);
float angle = (float)(System.Math.Atan2(rgAllPts[i+1].Y - rgAllPts[i].Y, rgAllPts[i+1].X - rgAllPts[i].X) / System.Math.PI) * 180;
matrix.Reset();
matrix.Rotate(-angle);
matrix.TransformPoints(rgPts);
if ((Math.Abs(rgPts[1].Y) < 2) && (-2 < rgPts[1].X) && (rgPts[1].X < rgPts[0].X + 2))
{
GOM_Point point = new GOM_Point();
point.x = x;
point.y = y;
m_keyPts.Insert(i, point);
return;
}
}
}
示例5: CanBeSelected
/// <summary>
/// Check if this command can be selected and return true in case it can
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
public bool CanBeSelected(float x, float y, System.Drawing.Drawing2D.Matrix viewMatrix)
{
// transform x,y back to object coordinates to check for selection
System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
mat.Multiply(this.TransformationMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
mat.Multiply(this.Owner.DrawMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
mat.Multiply(viewMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
mat.Invert();
PointF tmpPoint = new PointF(x, y);
PointF[] points = new PointF[1];
points[0] = tmpPoint;
mat.TransformPoints(points);
tmpPoint = points[0];
// check if this item should be selected
//float tmpX = LocationInPixelsX * zoomLevel;
//float tmpY = LocationInPixelsY * zoomLevel;
//float w = widthInPixels; //** zoomLevel;
//float h = heightInPixels; //* zoomLevel;
float w = (float)this.WidthInPixels / this.Owner.ViewMatrix.Elements[0];
float h = (float)this.HeightInPixels / this.Owner.ViewMatrix.Elements[3];
// if starting coordinate fall inside this component rect
if (tmpPoint.X >= 0 && tmpPoint.X <= w && tmpPoint.Y >= 0 && tmpPoint.Y <= h)
{
return true;
}
else
{
return false;
}
}
示例6: TestMatrix2
public void TestMatrix2()
{
System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
mat.Rotate(30);
mat.Translate(-20, 20);
var at = new AffineCoordinateTransformation2D(mat);
var atInv = at.Inverse();
var p0 = new double[] { 50d, 50d };
var pt = at.Transform(p0);
at.Invert();
var p1 = at.Transform(pt);
NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(p1[0] - p0[0]), 0.01d);
NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(p1[1] - p0[1]), 0.01d);
var p2 = atInv.Transform(pt);
NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(p2[0] - p0[0]), 0.01d);
NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(p2[1] - p0[1]), 0.01d);
System.Drawing.PointF[] pts = new System.Drawing.PointF[] { new System.Drawing.PointF(50, 50) };
mat.TransformPoints(pts);
System.Diagnostics.Debug.WriteLine(string.Format("POINT ({0} {1})", pts[0].X, pts[0].Y));
System.Drawing.PointF ptt = pts[0];
System.Drawing.PointF[] ptts = new System.Drawing.PointF[] { new System.Drawing.PointF(ptt.X, ptt.Y) };
System.Drawing.Drawing2D.Matrix inv = mat.Clone();
inv.Invert();
inv.TransformPoints(ptts);
NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(ptts[0].X - 50f), 0.01);
NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(ptts[0].Y - 50f), 0.01);
}
示例7: Draw2dTextures
public void Draw2dTextures(Draw2dData[] todraw, int textureid, float angle)
{
GL.PushAttrib(AttribMask.ColorBufferBit);
GL.BindTexture(TextureTarget.Texture2D, textureid);
GL.Enable(EnableCap.Texture2D);
GL.Disable(EnableCap.DepthTest);
VertexPositionTexture[] vertices;
ushort[] indices;
if (todraw.Length >= draw2dtexturesMAX)
{
vertices = new VertexPositionTexture[todraw.Length * 4];
indices = new ushort[todraw.Length * 4];
}
else
{
if (draw2dtexturesVertices == null)
{
draw2dtexturesVertices = new VertexPositionTexture[draw2dtexturesMAX * 4];
draw2dtexturesIndices = new ushort[draw2dtexturesMAX * 4];
}
vertices = draw2dtexturesVertices;
indices = draw2dtexturesIndices;
}
ushort i = 0;
foreach (Draw2dData v in todraw)
{
RectangleF rect;
if (v.inAtlasId == null)
{
rect = new RectangleF(0, 0, 1, 1);
}
else
{
rect = TextureAtlas.TextureCoords2d(v.inAtlasId.Value, d_Terrain.texturesPacked);
}
float x2 = v.x1 + v.width;
float y2 = v.y1 + v.height;
PointF[] pnts = new PointF[4] {
new PointF(x2, y2),
new PointF(x2,v.y1),
new PointF(v.x1,v.y1),
new PointF(v.x1,y2)};
if (angle != 0)
{
System.Drawing.Drawing2D.Matrix mx=new System.Drawing.Drawing2D.Matrix();
mx.RotateAt(angle, new PointF(v.x1+v.width/2,v.y1+v.height/2));
mx.TransformPoints(pnts);
}
vertices[i] = new VertexPositionTexture(pnts[0].X, pnts[0].Y, 0, rect.Right, rect.Bottom, v.color);
vertices[i + 1] = new VertexPositionTexture(pnts[1].X, pnts[1].Y, 0, rect.Right, rect.Top, v.color);
vertices[i + 2] = new VertexPositionTexture(pnts[2].X, pnts[2].Y, 0, rect.Left, rect.Top, v.color);
vertices[i + 3] = new VertexPositionTexture(pnts[3].X, pnts[3].Y, 0, rect.Left, rect.Bottom, v.color);
indices[i] = i;
indices[i + 1] = (ushort)(i + 1);
indices[i + 2] = (ushort)(i + 2);
indices[i + 3] = (ushort)(i + 3);
i += 4;
}
GL.EnableClientState(ArrayCap.TextureCoordArray);
GL.EnableClientState(ArrayCap.VertexArray);
GL.EnableClientState(ArrayCap.ColorArray);
unsafe
{
fixed (VertexPositionTexture* p = vertices)
{
GL.VertexPointer(3, VertexPointerType.Float, StrideOfVertices, (IntPtr)(0 + (byte*)p));
GL.TexCoordPointer(2, TexCoordPointerType.Float, StrideOfVertices, (IntPtr)(12 + (byte*)p));
GL.ColorPointer(4, ColorPointerType.UnsignedByte, StrideOfVertices, (IntPtr)(20 + (byte*)p));
GL.DrawElements(BeginMode.Quads, i, DrawElementsType.UnsignedShort, indices);
}
}
GL.DisableClientState(ArrayCap.TextureCoordArray);
GL.DisableClientState(ArrayCap.VertexArray);
GL.DisableClientState(ArrayCap.ColorArray);
GL.Enable(EnableCap.DepthTest);
GL.PopAttrib();
}
示例8: HardFit
private void HardFit()
{
/*
* Rotate the rectangle so that top-left is centered at the top with bot-right at the bottom center. This angle is BaseTheta
* Find the min/max x/y
* Use those and find the efficiency of that ellipse
* Rotate by PI/2/ANGLETRYCOUNT for PI/2 rad's (90 degs), running this same algorithm for each rotation
* Use the most efficient, using -(BaseTheta+Theta) as the rotation of the ellipse
*/
PointF[] Pts = (PointF[])mImgSec.PixelsUsed().SelectMany(p => new PointF[]{new PointF((float)p.X, (float)p.Y)});
System.Drawing.Drawing2D.Matrix BaseRotator = new System.Drawing.Drawing2D.Matrix(), StepRotate = new System.Drawing.Drawing2D.Matrix();
// |\ = ATan(Width/Height) so |\ |
// | \ | \ |
// | \ | \ |
// |___\ |___\| = -Atan(W/H)
float BaseTheta = (float)(-Math.Atan((double)mImgSec.Width / (double)mImgSec.Height));
BaseRotator.Rotate(BaseTheta);
StepRotate.Rotate((float)Math.PI / 2f / (float)ANGLETRYCOUNT);
BaseRotator.TransformPoints(Pts);
double BestFit = 0d,temp;
int BestChoice = -1;
SizeF BestDim = new SizeF(),tempDim;
for(int i = 0; i < ANGLETRYCOUNT - 1; i++, StepRotate.TransformPoints(Pts))
{
if((temp = GetFit(Pts, out tempDim)) > BestFit)
{BestChoice = i; BestFit = temp;BestDim = tempDim;}
}
mRotation = -(BaseTheta+BestChoice*Math.PI / 2d / (double)ANGLETRYCOUNT);
mEllWidth = BestDim.Width;
mEllHeight = BestDim.Height;
return;
}
示例9: GetDytqMap
/// <summary>
///获取低压台区网络图
/// </summary>
/// <param name="tqcode"></param>
/// <returns></returns>
public static Bitmap GetDytqMap(string tqcode ,int width,int height) {
int w = width;
int h = height;
Bitmap bp = new Bitmap(w, h);
Graphics g = Graphics.FromImage(bp);
IList<PS_xl> list = Ebada.Client.ClientHelper.PlatformSqlMap.GetList<PS_xl>("where linecode like '" + tqcode + "%' and linevol='0.4'");
RectangleF rf = RectangleF.Empty;
int bl = 10000;
Dictionary<PS_xl, IList<PS_gt>> gts = new Dictionary<PS_xl, IList<PS_gt>>();
List<PS_gtsb> gtsbs = new List<PS_gtsb>();
foreach (PS_xl xl in list) {
IList<PS_gt> gtlist = Client.ClientHelper.PlatformSqlMap.GetList<PS_gt>("where linecode ='" + xl.LineCode + "' order by gtcode");
if (gtlist.Count == 0) continue;
IList<PS_gtsb> gtsblist = Client.ClientHelper.PlatformSqlMap.GetList<PS_gtsb>(" where sbtype like '17%' and gtid in (select gtid from ps_gt where linecode ='" + xl.LineCode + "')");
gtsbs.AddRange(gtsblist);
IList<PS_gt> gtlist2 = new List<PS_gt>();
foreach (PS_gt gt in gtlist) {
if (gt.gtLat == 0 || gt.gtLon == 0) continue;
gtlist2.Add(gt);
if (rf.IsEmpty)
rf = new RectangleF((float)gt.gtLon*bl, (float)gt.gtLat*bl, 1f, 1f);
else
rf=RectangleF.Union(rf,new RectangleF((float)gt.gtLon*bl, (float)gt.gtLat*bl,1f,1f));
//rf..Inflate((float)gt.gtLon, (float)gt.gtLat);
}
gts.Add(xl, gtlist2);
}
DataTable gtbhtable = Ebada.Core.ConvertHelper.ToDataTable(gtsbs,typeof(PS_gtsb));
//g.TranslateTransform(-rf.X, -rf.Y);
rf.Inflate(3, 3);
System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix();
matrix.Translate(-rf.X, -rf.Y);
float f1=w / rf.Width;
float f2=h/rf.Height;
float scale = Math.Min(f1,f2);
matrix.Scale(scale, scale, System.Drawing.Drawing2D.MatrixOrder.Append);
if (f1 < f2)
matrix.Translate(0, (h - f1 * rf.Height) / 2, System.Drawing.Drawing2D.MatrixOrder.Append);
else
matrix.Translate((w - f2 * rf.Width) / 2, 0, System.Drawing.Drawing2D.MatrixOrder.Append);
List<PointF> plist = new List<PointF>();
g.Clear(Color.White);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
Font f = new Font("宋体", 9);
PointF p0 = Point.Empty;
Pen pen0 = new Pen(Color.Blue);
pen0.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
List<string> gt0list = new List<string>();//记录重叠杆塔
List<RectangleF> gtboxlist = new List<RectangleF>();
foreach (PS_xl xl in gts.Keys) {
plist.Clear();
foreach (PS_gt gt in gts[xl]) {
plist.Add(new PointF((float)gt.gtLon*bl, (float)gt.gtLat*bl));
}
if (plist.Count <2) continue;
PointF[] pts=plist.ToArray();
matrix.TransformPoints(pts);
for(int i=0;i<pts.Length;i++){
pts[i].Y = h - pts[i].Y;
}
g.DrawLines(Pens.Blue,pts );
bool b1 = Math.Abs(pts[0].X - pts[1].X) > Math.Abs(pts[0].Y - pts[1].Y);
Point offset = new Point(b1 ? 0 : 20, b1 ? 20 : 0);
int gtnum = 0;
for(int i=0;i<pts.Length;i++) {
PS_gt gt =gts[xl][i];
if (gt.gtLat==0.0m||gt.gtLon==0.0m) continue;
if (gt.gtJg == "是" && i==0) {
if (xl.ParentID.Length > 10) continue;//台区下干线除外
PointF pf0 = pts[i];
bool ret = false;
if (gt0list.Contains(xl.ParentID)) {
foreach (RectangleF rtf in gtboxlist) {
if (rtf.Contains(pf0)) { ret = true; break; }
}
} else {
gt0list.Add(xl.ParentID);
}
if (ret) continue;
RectangleF rtf0 = RectangleF.Empty;
rtf0.Location = pf0;
rtf0.Inflate(10, 10);
gtboxlist.Add(rtf0);
}
DataRow[] rows= gtbhtable.Select("gtid='" + gt.gtID + "'");
int n = 1;
foreach (DataRow row in rows) {
//.........这里部分代码省略.........
示例10: GraphicsView_MouseMove
private void GraphicsView_MouseMove(object sender, MouseEventArgs e)
{
if (movestart == null) return;
if (!TranslateFocus)
return;
System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix();
//m.Translate(Translate.X, Translate.Y, System.Drawing.Drawing2D.MatrixOrder.Append);
m.Scale(ZoomScale, ZoomScale, System.Drawing.Drawing2D.MatrixOrder.Append);
m.Invert();
Point movement = new Point(movestart.X - e.X, movestart.Y - e.Y);
movement.X = -movement.X;
movement.Y = -movement.Y;
Point[] t = new Point[] { movement };
m.TransformPoints(t);
movement = t[0];
Translate.X -= movestart.X - e.X;
Translate.Y -= movestart.Y - e.Y;
movestart = e.Location;
HighPrecisionDraw = false;
this.Refresh();
}
示例11: PointToObject
public System.Drawing.PointF PointToObject(System.Drawing.PointF pt)
{
System.Drawing.Drawing2D.Matrix matrix;
System.Drawing.RectangleF rc;
System.Drawing.PointF[] rgPts;
rc = this.BoundingBox;
rgPts = new System.Drawing.PointF[1];
rgPts[0].X = pt.X;
rgPts[0].Y = pt.Y;
matrix = new System.Drawing.Drawing2D.Matrix();
matrix.Translate(-this.xOffset, -this.yOffset);
matrix.TransformPoints(rgPts);
matrix.Reset();
matrix.Translate(-(rc.Left + rc.Right) / 2, -(rc.Top + rc.Bottom) / 2);
matrix.TransformPoints(rgPts);
matrix.Reset();
matrix.Rotate(-this.rotation);
matrix.TransformPoints(rgPts);
matrix.Reset();
matrix.Translate((rc.Left + rc.Right) / 2, (rc.Top + rc.Bottom) / 2);
matrix.TransformPoints(rgPts);
return rgPts[0];
}
示例12: Update
/// <summary>
/// Update function of map. Calls Bayes filtering and handles the rotation and translation of all map objects.
/// </summary>
private void Update(object sender, EventArgs e)
{
lock (robot.mapLock)
{
Bayes(true, preySensor, ref preyProbability);
Bayes(false, obstacleSensor, ref obstacleProbability);
bBayes = new Bitmap(bMap.Size.Width, bMap.Size.Height);
SetNewRovioPosition();
// Run AStar if there is a suitable destination and draw it on the map.
using (graphics = Graphics.FromImage(bBayes))
{
AStar astar = new AStar(finalMap.GetLength(0), finalMap.GetLength(1));
astar.Build(finalMap, new DPoint(destination.X, destination.Y), new DPoint((picBoxRovio.Location.X / 10) + (picBoxRovio.Width / 10 / 2), picBoxRovio.Location.Y / 10));
aStarPath = astar.path;
for (int i = 0; i < maxX; i++)
{
for (int j = 0; j < maxY; j++)
{
graphics.FillRectangle(new SolidBrush(DColor.FromArgb((int)(preyProbability[i, j] * 255), System.Drawing.Color.DarkRed)), new DRectangle(i * 10, j * 10, 10, 10));
graphics.FillRectangle(new SolidBrush(DColor.FromArgb((int)(obstacleProbability[i, j] * 255), System.Drawing.Color.DarkBlue)), new DRectangle(i * 10, j * 10, 10, 10));
if (astar.inPath[i, j])
graphics.FillRectangle(new SolidBrush(DColor.Red), new DRectangle(i * 10, j * 10, 10, 10));
}
}
}
picBoxBayes.Image = bBayes;
// Check which cells are within the viewing cone.
if (viewConePoints != null)
{
for (int i = 0; i < maxX; i++)
{
for (int j = 0; j < maxY; j++)
{
DPoint a = new DPoint(i * 10 + 1, j * 10 + 1); // Top left
DPoint b = new DPoint((i + 1) * 10 - 1, j * 10 + 1); // Top right
DPoint c = new DPoint(i * 10 + 1, (j + 1) * 10 - 1); // Bottom left
DPoint d = new DPoint((i + 1) * 10 - 1, (j + 1) * 10 - 1); // Bottom right
if (!(PointInPolygon(a, viewConePoints) || PointInPolygon(b, viewConePoints)
|| PointInPolygon(c, viewConePoints) || PointInPolygon(d, viewConePoints)))
{
isCellVisible[i, j] = false;
}
else
{
preySensor[i, j] = false;
obstacleSensor[i, j] = false;
isCellVisible[i, j] = true;
}
}
}
}
if (robot.GetType() == typeof(Rovio.PredatorMap))
{
if (robot.IsPreySeen())
{
FindRelativeLocation(picBoxPrey, robot.preyRectangle, robot.GetPreyDistance(), 1, 1);
try
{
preySensor[(int)((picBoxPrey.Location.X / 10) + 1.5), (int)((picBoxPrey.Location.Y / 10) + 1.5)] = true;
} catch { }
}
else
picBoxPrey.Hide();
if ((robot as Rovio.BaseArena).IsObstacleSeen())
{
// Find obstacle position relative to the Rovio's position.
FindRelativeLocation(picBoxObstacle, robot.obstacleRectangle, robot.GetObstacleDistance(), 40, 3);
try
{
int p = (int)((picBoxObstacle.Location.X / 10) + 0.5);
int q = (int)((picBoxObstacle.Location.Y / 10) + 0.5);
// Populate 3x3 area with the obstacle.
for (int i = -1; i <= 1; i++)
for (int j = -1; j <= 1; j++)
obstacleSensor[(int)((picBoxObstacle.Location.X / 10) + i), (int)((picBoxObstacle.Location.Y / 10) + j)] = true;
}
catch { }
}
else
picBoxObstacle.Hide();
}
// Rotate the Rovio icon to the angle that the robot physically faces.
System.Drawing.Drawing2D.Matrix matrixRovio = new System.Drawing.Drawing2D.Matrix();
matrixRovio.RotateAt((float)robot.cumulativeAngle, new System.Drawing.Point(picBoxRovio.Location.X + (picBoxRovio.Size.Width / 2), picBoxRovio.Location.Y + (picBoxRovio.Size.Height / 2)));
matrixRovio.Translate(0f, -0f);
DPoint[] rovioMovementPoints = {new DPoint(picBoxRovio.Location.X+(picBoxRovio.Size.Width/2), picBoxRovio.Location.Y + (picBoxRovio.Size.Height/2)),
new DPoint(picBoxRovio.Location.X+(picBoxRovio.Size.Width/2) - 69, picBoxRovio.Location.Y-150),
new DPoint(picBoxRovio.Location.X+(picBoxRovio.Size.Width/2) + 69, picBoxRovio.Location.Y-150)};
matrixRovio.TransformPoints(rovioMovementPoints);
//.........这里部分代码省略.........
示例13: SetNewRovioPosition
/// <summary>
/// Set the Rovio's position using linear interpolation.
/// </summary>
private void SetNewRovioPosition()
{
Vector2 oldP = new Vector2(picBoxRovio.Location.X, picBoxRovio.Location.Y);
Vector2 newP = new Vector2(0, -1);
// Find the angle of the Rovio on the perimeter of the arena.
newP = Vector2.Transform(-Vector2.UnitY, Matrix.CreateRotationZ(MathHelper.ToRadians((float)robot.cumulativeAngle)));
newP /= MathHelper.Max(Math.Abs(newP.X), Math.Abs(newP.Y));
newP += Vector2.One;
newP *= new Vector2(260, 300) * 0.5f;
// Translate into the arena from the perimeter.
using (matrix = new System.Drawing.Drawing2D.Matrix())
{
matrix.Translate((int)newP.X, (int)newP.Y);
matrix.RotateAt((float)robot.cumulativeAngle, new DPoint(0, 0));
matrix.Translate(0f, (float)(robot.GetWallDist() * 100));
DPoint[] newPos = { new DPoint(0, 0) };
matrix.TransformPoints(newPos);
if (newPos[0].X < -400 || newPos[0].X > 600)
newPos[0] = new DPoint(-100, -100);
// Compensate for the alcoves.
if (newPos[0].X < 30 && (newPos[0].Y < 100 || newPos[0].Y > 200))
newPos[0].X += 30;
else if (newP.X > 230 && (newPos[0].Y < 100 || newPos[0].Y > 200))
newPos[0].X -= 30;
newP = Vector2.Lerp(oldP, new Vector2(newPos[0].X, newPos[0].Y), 0.1f);
picBoxRovio.Location = new DPoint((int)newP.X, (int)newP.Y);
}
}
示例14: FindRelativeLocation
/// <summary>
/// Find location of PicBox relative to the Rovio.
/// </summary>
/// <param name="picBox">Picture box to check.</param>
/// <param name="rect">Rectangle of the picture box's object on screen</param>
/// <param name="distance">Distance to object</param>
/// <param name="multiplierOne">First multiplier to change X position by.</param>
/// <param name="multiplierTwo">Second multiplier to change X position by.</param>
private void FindRelativeLocation(PictureBox picBox, DRectangle rect, double distance, int multiplierOne, int multiplierTwo)
{
picBox.Location = new System.Drawing.Point(picBoxRovio.Location.X + rect.X + rect.Width, picBoxRovio.Location.Y - (int)(distance * 20 * 3));
double totalFOV = distance * 100 * 0.93;
double percentage = rect.X / (double)robot.cameraDimensions.X * 100;
double newX = percentage * (totalFOV / 100);
DPoint newPosition = new System.Drawing.Point(picBoxRovio.Location.X - ((int)totalFOV / 2) + (int)newX*2, picBox.Location.Y);
using (matrix = new System.Drawing.Drawing2D.Matrix())
{
matrix.RotateAt((float)robot.cumulativeAngle, new System.Drawing.Point(picBoxRovio.Location.X + (picBoxRovio.Size.Width / 2), picBoxRovio.Location.Y + (picBoxRovio.Size.Height / 2)));
matrix.Translate((float)-newX + 30f, -(float)(distance * multiplierOne * multiplierTwo));
DPoint[] aPoints = { newPosition };
matrix.TransformPoints(aPoints);
picBox.Location = aPoints[0];
}
}
示例15: rotatePoint
public void rotatePoint(PointF centerpoint, float angle, ref PointF dstpoint)
{
System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
mat.RotateAt(angle, centerpoint);
PointF[] arraypoints = new PointF[1];
arraypoints[0] = dstpoint;
mat.TransformPoints(arraypoints);
dstpoint = arraypoints[0];
}