public void DrawLine(List <Transform> trans) { List <Vector2> pos = new List <Vector2>(); for (int i = 0; i < trans.Count; i++) { pos.Add(trans[i].position); } for (int i = 0; i < pos.Count; i++) { Vector2 t = pos[i]; int j = i; while ((j > 0) && (pos[j - 1].x > t.x)) { pos[j] = pos[j - 1]; --j; } pos[j] = t; } if (currentLight.LineIndex == -1) { currentLight.LineIndex = lineManger.AddLine(pos); } else { lineManger.Draw(currentLight.LineIndex, pos); } }
/// <summary> /// Gerar um Bitmap com plano cartesiano /// </summary> /// <returns></returns> private Bitmap GetBitmapwWhitCartesian() { DrawLine drawLine = new DrawLine(); //Desenhar Linha horizontal drawLine.Draw(new Point2D(-(pictureBox1.Width / 2), 0), new Point2D((pictureBox1.Width / 2), 0), Color.Red); //Desenhar Linha Vertical drawLine.Draw(new Point2D(0, -(pictureBox1.Height / 2)), new Point2D(0, (pictureBox1.Height / 2)), Color.Red); return(drawLine.bitmap); }
public static void DrawTriangle(Triangle t, Bitmap actualBitmap, Color color) { DrawLine drawline = new DrawLine(); drawline.bitmap = actualBitmap; // Draw 1 linha drawline.Draw(new Point2D(t.FirstPoint.X, t.FirstPoint.Y), new Point2D(t.SecondPoint.X, t.SecondPoint.Y), color); // Draw 2 linha drawline.Draw(new Point2D(t.SecondPoint.X, t.SecondPoint.Y), new Point2D(t.ThirdPoint.X, t.ThirdPoint.Y), color); // Draw 3 linha drawline.Draw(new Point2D(t.ThirdPoint.X, t.ThirdPoint.Y), new Point2D(t.FirstPoint.X, t.FirstPoint.Y), color); }
public void CastLandingPosition() { if (!_isCast) { _frAudio.Cast(); _isCast = true; _timeOfCast = Time.time; } float fractionOfJourney = _extendingRate / _distToFinalPoint; _landingPad.transform.position = Vector3.Lerp(_landingPad.transform.position, _finalPoint.transform.position, fractionOfJourney); _verticleParticles.Play(); _horizontalParticles.Play(); _groundLight.enabled = true; _drawLine.Draw(_landingPad.transform.position); CheckForLOS(); SlowTimeAbility(); if (_timeOfCast + 2f < Time.time) { _extendingRate = 1f; } }
void MyDrawTriangle(Texture2D tex) { float x1 = p1.x, y1 = p1.y; float x2 = p2.x, y2 = p2.y; float x3 = p3.x, y3 = p3.y; // 令 y1 ≥ y2 ≥ y3 if (y2 <= y3) { MyUtility.Swap(ref y2, ref y3); MyUtility.Swap(ref x2, ref x3); } if (y1 <= y2) { MyUtility.Swap(ref y2, ref y1); MyUtility.Swap(ref x2, ref x1); } if (y2 < y3) { MyUtility.Swap(ref y2, ref y3); MyUtility.Swap(ref x2, ref x3); } // 令 y2 == y3 && x2 < x3 if (y2 == y3 && x2 > x3) { MyUtility.Swap(ref y2, ref y3); MyUtility.Swap(ref x2, ref x3); } // 令 y1 == y2 && x2 < x1 if (y2 == y1 && x2 > x1) { MyUtility.Swap(ref y2, ref y1); MyUtility.Swap(ref x2, ref x1); } var A = new MyVector3(x1, y1); var B = new MyVector3(x2, y2); var C = new MyVector3(x3, y3); // 直线AC y - y1 = m * (x - x1), m = (y1-y3)/(x1-x3) float M_x = (y2 - y1) / ((y1 - y3) / (x1 - x3)) + x1; MyVector3 M = new MyVector3(M_x, y2); var Left = B.x < M.x ? B : M; var Right = B.x < M.x ? M : B; DrawTriangleInner(tex, A, Left, Right, -1); DrawTriangleInner(tex, C, Left, Right, +1); // 最后画BM DrawLine.Draw(tex, (int)B.x, (int)B.y, (int)M.x, (int)M.y, triangleColor, DrawLine.LineType.Line); // 4个顶点 MyUtility.DrawPoint(tex, (int)A.x, (int)A.y, Color.red); MyUtility.DrawPoint(tex, (int)B.x, (int)B.y, Color.green); MyUtility.DrawPoint(tex, (int)C.x, (int)C.y, Color.blue); MyUtility.DrawPoint(tex, (int)M.x, (int)M.y, Color.yellow); }
public override void OnInspectorGUI() { DrawDefaultInspector(); drawline = target as DrawLine; if (GUILayout.Button("Draw!")) { drawline.Draw(drawline.start, drawline.end); } }
void MyDrawTriangleOutLine(Texture2D tex) { int x1 = (int)p1.x, y1 = (int)p1.y; int x2 = (int)p2.x, y2 = (int)p2.y; int x3 = (int)p3.x, y3 = (int)p3.y; DrawLine.Draw(tex, x1, y1, x2, y2, outLineColor, DrawLine.LineType.Line); DrawLine.Draw(tex, x2, y2, x3, y3, outLineColor, DrawLine.LineType.Line); DrawLine.Draw(tex, x3, y3, x1, y1, outLineColor, DrawLine.LineType.Line); }
/// <summary> /// Desenhar uma linha em um dos octantes /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click_1(object sender, EventArgs e) { DrawLine drawLine = new DrawLine(); drawLine.bitmap = mBitmap; try { Point2D startPoint = new Point2D(double.Parse(px1.Text), double.Parse(py1.Text)); Point2D endPoint = new Point2D(double.Parse(px2.Text), double.Parse(py2.Text)); drawLine.Draw(startPoint, endPoint, Color.Blue); } catch (Exception ex) { Console.WriteLine(ex.Message); } UpdateView(); }
public void MyDraw(Texture2D tex) { if (Points == null || Points.Length < 1) { return; } switch (type) { case BizierCurveType.Quad_th_BizierCurve: Quad_th_BizierCurve(tex); break; case BizierCurveType.MyNth_BizierCurve: MyNth_BizierCurve(tex); break; case BizierCurveType.Nth_BizierCurve: Nth_BizierCurve(tex); break; default: break; } // debug int n = Points.Length; MyUtility.DrawPoint(tex, (int)Points[0].x, (int)Points[0].y, Color.red); for (int i = 0, j = 1; j < n; i++, j++) { var pre = Points[i]; var cur = Points[j]; int x0 = (int)pre.x, y0 = (int)pre.y; int x1 = (int)cur.x, y1 = (int)cur.y; DrawLine.Draw(tex, x0, y0, x1, y1, Color.white, DrawLine.LineType.Bresenham); MyUtility.DrawPoint(tex, x1, y1, Color.red); } }
// https://www.jasondavies.com/animated-bezier/ void Quad_th_BizierCurve(Texture2D tex, float t = 0) { /* t 在[0, 1] * n = 2 -> B1(t) = P0 + (P1 - p0)t, 从P0起点沿P0->P1直线方向移动, 当t = 1时到达P1 * n = 3 -> B2(t) = (1-t)²*P0 + (1-t)*t*P1 + t²*P2 */ if (Points == null || Points.Length < 3) { return; } if (t >= 1) { return; } MyVector2 p1 = Points[0]; MyVector2 p2 = Points[1]; MyVector2 p3 = Points[2]; int x1 = (int)p1.x, y1 = (int)p1.y; int x2 = (int)p2.x, y2 = (int)p2.y; int x3 = (int)p3.x, y3 = (int)p3.y; DrawLine.Draw(tex, x1, y1, x2, y2, Color.white, DrawLine.LineType.Bresenham); DrawLine.Draw(tex, x2, y2, x3, y3, Color.white, DrawLine.LineType.Bresenham); MyUtility.DrawPoint(tex, x1, y1, Color.red); MyUtility.DrawPoint(tex, x2, y2, Color.green); MyUtility.DrawPoint(tex, x3, y3, Color.blue); // p' = (1-t)*p0 + t*p1 var pa = (1 - t) * p1 + t * p2; var pb = (1 - t) * p2 + t * p3; var o = (1 - t) * pa + t * pb; tex.SetPixel((int)o.x, (int)o.y, Color.red); Quad_th_BizierCurve(tex, t + 0.01f); }