protected override void OnCreated() { base.OnCreated(); Box1.Name = "Box1"; Box2.Name = "Box2"; Sphere.Name = "Sphere"; Cone.Name = "Cone"; Torus.Name = "Torus"; xyArray A1 = new xyArray(); Loxy Li = new Loxy(); A1.data = new xy[] { new xy(0, 0), new xy(6, 0), new xy(6, 6), new xy(0, 6), new xy(0, 0) }; Li.Add(A1); A1 = new xyArray(); A1.data = new xy[] { new xy(2, 2), new xy(2, 4), new xy(4, 4), new xy(4, 2), new xy(2, 2) }; Li.Add(A1); Extrude = new DiscreteExtrude(Li, 4); Extrude.Refresh(); Extrude.Name = "Extruded"; Extrude = new DiscreteExtrude(Li, 4); Extrude.Refresh(); Extrude.Name = "Extruded"; Torus.Transformation = Matrix.Translation(new xyz(0, 0, 0.5)); // Outlook BackColor = Color.White; Cursor = D3DCursors.C1001; }
Loxy getLoxy(double UpDown, ref Base Base) { Loxy Result = new Loxy(); if ((Curvextruders != null) && (Curvextruders.Count > 0) && (Curvextruders[0].Count > 3)) { xyzArray A = new xyzArray(); for (int j = 0; j < Curvextruders[0].Count; j++) { A.Add(Curvextruders[0][j].Value(0, UpDown)); } xyz N = A.normal(); Base = Base.DoComplete(Curvextruders[0][0].Value(0, UpDown), N); for (int i = 0; i < Curvextruders.Count; i++) { xyArray _A = new xyArray(); Result.Add(_A); for (int j = 0; j < Curvextruders[i].Count; j++) { xy P = Base.Relativ(Curvextruders[i][j].Value(0, UpDown)).toXY(); _A.Add(P); } if (_A.Count > 0) { _A.Add(_A[0]); } } } return(Result); }
/// <summary> /// Gets an array of Resolution+1 interpolationpoints. /// <seealso cref="Resolution"/> <seealso cref="ToArray"/> /// </summary> /// <returns></returns> public xyArray ToXYArray() { xyArray Result = new xyArray(Resolution + 1); ToArray(Result, 0); return(Result); }
/// <summary> /// Gets the smaller rectangle, which contains the curve. /// </summary> /// <returns>A rectangle</returns> public virtual RectangleF GetMaxrect() { xyArray a = new xyArray(Resolution + 1); this.ToArray(a, 0); return(a.Maxrect); }
static CrossList CrossWithLine(xy A, xy B, CurveArray Array, EdgeLoop E) { xyArray xyArray = Array.getxyArray(); if (xyArray[xyArray.Count - 1].dist(xyArray[0]) > 0.0001) // 17.6 ausgeklammert?----------- { xyArray.Add(xyArray[0]); } CrossList CL = CrossWithLine(A, B, xyArray, E); for (int i = 0; i < CL.Count; i++) { Curve C = E[i].ParamCurve; CL[i].Param1 = Array.xyArrayIndexToCurveArrayIndex(CL[i].Param1); if (CL[i].Param1 == 4) { } int First = (int)CL[i].Param1; int Second = First + 1; if (Second >= Array.Count) { Second = 0; } CL[i].A = Array.Value(First); CL[i].B = Array.Value(Second); } return(CL); }
/// <summary> /// copies the backcound to the foreground. /// </summary> public void CopyFromBackGround() { // Draw the Texture from Backbuffer by a Polygon Rectangle for the full screen xyArray FP = new xyArray(); FP.data = new xy[] { new xy(0, 0), new xy(0, 1), new xy(1, 1), new xy(1, 0) }; Matrix P = ProjectionMatrix; GLShader S = Shader; RenderKind K = RenderKind; RenderKind = RenderKind.Render; Shader = BackGroundShader; Texture T = texture; texture = BackBuffer.Texture; PushMatrix(); ModelMatrix = Matrix.Translation(new xyz(0, 0, 1)); PolygonMode PM = PolygonMode; PolygonMode = PolygonMode.Fill; ProjectionMatrix = Bias; drawPolyLine(FP); ProjectionMatrix = P; PopMatrix(); // Save Back RenderKind = K; texture = T; this.Shader = S; PolygonMode = PM; }
/// <summary> /// internal. /// </summary> /// <param name="Device"></param> /// <param name="A"></param> public static void drawArrayLined(OpenGlDevice Device, xyArray A) { if (Entity.Compiling) { PolygonMode P = Device.PolygonMode; MeshCreator.MeshdrawLined(Device, A); Device.PolygonMode = P; return; } if (Device.RenderKind == RenderKind.SnapBuffer) { MeshCreator.MeshdrawLined(Device, A); return; } int MPosition = Device.Shader.Position.handle; if (MPosition >= 0) { GL.EnableVertexAttribArray(MPosition); xyf[] Array = (A.ToFloatArray()); GL.VertexAttribPointer(MPosition, 2, VertexAttribPointerType.Float, false, 0, ref Array[0].x); GL.DrawArrays(PrimitiveType.LineStrip, 0, Array.Length); GL.DisableVertexAttribArray(MPosition); } }
/// <summary> /// draws a 2d-polygon, which is stored in Array. See also <see cref="xyArray"/>. /// </summary> /// <param name="Array"><see cref="xyArray"/>.</param> public void drawPolyLine(xyArray Array) { Object Handle = null; if ((RenderKind == RenderKind.SnapBuffer)) { Handle = Selector.RegisterSnapItem(new PolyLineSnappItem(Array)); } if (PolygonMode == PolygonMode.Fill) { Loxy L = new Loxy(); L.Add(Array); drawFilledArray2d(this, L); if ((RenderKind == RenderKind.SnapBuffer)) { Selector.UnRegisterSnapItem(Handle); } if (PolygonMode == PolygonMode.Fill) { return; } } Primitives2d.drawArrayLined(this, Array); if ((RenderKind == RenderKind.SnapBuffer)) { Selector.UnRegisterSnapItem(Handle); } }
/// <summary> /// draws a 3d-polygon, which is stored in Array. See also <see cref="xyzArray"/> if the <see cref="OpenGlDevice.PolygonMode"/> = <b>Fill</b> and the array is planar then /// the polygon is drawn as filled polygon else as a lined polygon. /// </summary> /// <param name="Array"><see cref="xyzArray"/>hollds the array information</param> public void drawPolyLine(xyzArray Array) { Object Handle = null; if ((RenderKind == RenderKind.SnapBuffer)) { Handle = Selector.RegisterSnapItem(new PolyLineSnappItem3D(Array)); } if ((PolygonMode == PolygonMode.Fill) && (Array.Count > 2) && (Array.planar)) { Loxy L = new Loxy(); PushMatrix(); MulMatrix(Array.Base.ToMatrix()); xyArray A = Array.ToxyArray(); L.Add(A); drawFilledArray2d(this, L); PopMatrix(); if ((RenderKind == RenderKind.SnapBuffer)) { Selector.UnRegisterSnapItem(Handle); } if (PolygonMode == PolygonMode.Fill) { return; } } Primitives3d.drawArrayLined(this, Array); if ((RenderKind == RenderKind.SnapBuffer)) { Selector.UnRegisterSnapItem(Handle); } }
/// <summary> /// gets a <see cref="xyArray"/>. it is closed, if addEndPoint is true; /// </summary> /// <param name="addEndPoint">if is true the returned xyarray is closed by adding a point.</param> /// <returns>a <see cref="xyArray"/>.</returns> public xyArray getxyArrayClosed(bool addEndPoint) { int Resolution = 0; for (int i = 0; i < Count; i++) { Curve c = this[i]; Resolution = Resolution + c.Resolution; } Resolution++; xyArray xyarray = new xyArray(Resolution); int index = 0; for (int i = 0; i < Count; i++) { Curve c = this[i]; c.ToArray(xyarray, index); index = index + c.Resolution; } if (!addEndPoint) { xyarray.RemoveAt(xyarray.Count - 1); } return(xyarray); }
/// <summary> /// Converts a xyArray to an array of float points /// </summary> /// <param name="Array">the xyArray, which will be converted</param> /// <returns>Array of <see cref="xyf"/></returns> public static xyf[] ToxyfArray(xyArray Array) { xyf[] Result = new xyf[Array.Count]; for (int i = 0; i < Array.Count; i++) { Result[i] = new xyf((float)Array[i].x, (float)Array[i].y); } return(Result); }
/// <summary> /// Returns a leftside parallel xyArray to the curve, which has a distance of width. /// </summary> /// <param name="width">Distance of the parallel</param> /// <returns>a parallel <see cref="xyArray"/></returns> public virtual xyArray Parallel(double width) { xyArray result = new xyArray(Resolution + 1); for (int i = 0; i <= Resolution; i++) { double param = fromParam + i * (toParam - fromParam) / Resolution; result[i] = Value(param) + Derivation(param).normal().normalize() * width; } return(result); }
/// <summary> /// draws a rectangle withe edge points A and B. /// </summary> /// <param name="A">1. point of the rectangle.</param> /// <param name="B">2. point of the rectangle.</param> public void drawRectangle(xy A, xy B) { xyArray AR = new xyArray(5); AR[0] = A; AR[1] = new xy(A.x, B.y); AR[2] = B; AR[3] = new xy(B.x, A.y); AR[4] = A; drawPolyLine(AR); }
/// <summary> /// Calculates the length of a part of the curve, which is given from 0 to the value param. /// <seealso cref="LengthToParam"/> /// </summary> /// <param name="Param">Param until which the length is calculated</param> /// <returns>Returns the length of the curve</returns> public double ParamToLength(double Param) { if (Param >= toParam) { Param = toParam; } xyArray a = new xyArray(Resolution + 1); this.ToArray(a, 0); return(a.ParamToLength((Param - fromParam) * Resolution)); }
private void MakeClean() { Data = new xyArray(Resolution + 1); for (int i = 0; i <= Resolution; i++) { double t = fromParam + (toParam - fromParam) * i / (float)Resolution; xy p = Value(t); Data[i] = p; } Dirty = false; RMAx = Data.GetMaxrect(Matrix.identity); }
/// <summary> /// Converts a length to a param, which can be used in the method <see cref="Value"/>. /// <seealso cref="ParamToLength"/> /// </summary> /// <param name="le">A length.</param> /// <returns>A param for using in <see cref="Value"/>. Rem: if le is greater then the lenght of the curve a value -1 is returned.</returns> public double LengthToParam(double le) { //if ( le > CurveLength) return toParam; xyArray a = new xyArray(Resolution + 1); this.ToArray(a, 0); double r = a.LengthToParam(le); if (r < 0) { return(r); } return(fromParam + toParam * a.LengthToParam(le) / Resolution); }
/// <summary> /// internal. /// </summary> internal static void MeshdrawLined(OpenGlDevice Device, xyArray A) { int ID = MeshVertices.Count; for (int i = 0; i < A.Count; i++) { MeshIndices.Add((IndexType)(i + ID)); } for (int i = 0; i < A.Count; i++) { MeshVertices.Add(((Device.ModelMatrix * A[i].toXYZ()).toXYZF())); } MeshMode = PolygonMode.Line; }
/// <summary> /// draws a list of 2D curves. See also <see cref="CurveArray"/> /// </summary> /// <param name="CA"><see cref="CurveArray"/></param> public void drawPolyCurve(CurveArray CA) { xyArray A = CA.getxyArray(); Object Handle = null; if ((RenderKind == RenderKind.SnapBuffer)) { Handle = Selector.RegisterSnapItem(new PolyCurveSnappItem(CA)); } drawPolyLine(A); if ((RenderKind == RenderKind.SnapBuffer)) { Selector.UnRegisterSnapItem(Handle); } }
/// <summary> /// /// This method calculates the distance of a LineType to this Curve only in case, when the distance is /// smaller then MaxDist, otherwise <see cref="Utils.big"/> will be returned. /// You can imagine a cylinders with radius MaxDist around the Curve. If the line goes through the /// "curved" cylinder, then the distance will be calculated and returned. /// </summary> /// <param name="L">Line, which will be checked</param> /// <param name="MaxDist">Maximal distance</param> /// <param name="param">paramter fo the nearest point in the curve</param> /// <returns>distance</returns> public double Distance(LineType L, double MaxDist, out double param) { double lam; double result = Utils.big; xyArray a = new xyArray(Resolution + 1); this.ToArray(a, 0); double di = a.Distance(L, MaxDist, out param, out lam); if (!Utils.Less(MaxDist, di)) { param = this.fromParam + param * toParam / Resolution; result = di; } return(result); }
/// <summary> /// restricted the <see cref="Loxyz"/> to a <see cref="Loxy"/> by omitting the z-value. /// </summary> /// <returns>a <see cref="Loxy"/></returns> public Loxy ToLoxy() { Loxy result = new Loxy(); for (int i = 0; i < Count; i++) { xyArray A = new xyArray(this[i].Count); for (int j = 0; j < A.Count; j++) { A[j] = Base.Relativ(this[i][j]).toXY(); } result.Add(A); } return(result); }
public override Base GetBase() { Base B = Base.UnitBase; B.BaseO = Point; int id = -1; xyArray A = null; LineType ViewLine = Device.FromScr(Device.MousePos); xyz P = ModelMatrix * ViewLine.P; xyz Q = ModelMatrix * ViewLine.Q; ViewLine = new LineType(P, Q); for (int i = 1; i < Loca.Count; i++) { A = Loca[i].getxyArray(); A = ModelMatrix * A; double Dummy = -1; double di = A.Distance(ViewLine, Snapdist * 8, out Lam, out Dummy); if (di <= Snapdist) { id = i; // break; } } if (id >= 0) { if (id == 1) { } if (Lam >= 0) { double L = Lam; Lam = Loca[id].xyArrayIndexToCurveArrayIndex(Lam); xyz D = Loca[id].Direction(Lam).toXYZ(); B = Base.DoComplete(A.Value(L).toXYZ(), D, new xyz(0, 0, 1) & D); } } else { B = ModelMatrix.toBase(); B.BaseO = Point; } return(B); }
/// <summary> /// Get a <see cref="CrossList"/>, which contains the crossing points with /// another curve?. The parameter param1 and param2 in <see cref="CrossItem"/> are converted to /// a curve parameter. /// </summary> /// <param name="Curve"></param> /// <returns></returns> public CrossList GetCrossList(Curve Curve) { xyArray xyArray1 = new xyArray(this.Resolution + 1); xyArray xyArray2 = new xyArray(Curve.Resolution + 1); this.ToArray(xyArray1, 0); Curve.ToArray(xyArray2, 0); CrossList Result = xyArray1.getCrossList(xyArray2, true); for (int i = 0; i < Result.Count; i++) { CrossItem C = Result[i]; C.Param1 = C.Param1 / this.Resolution; C.Param2 = C.Param2 / Curve.Resolution; } return(Result); }
protected internal override xyz Cross(LineType ViewLine) { //if (PolygonMode == PolygonMode.Line) // Path = PrimId; //else // Path = -1; xyArray A = null; if (Path >= 0) { A = PolyPoly[Path]; double Dummy = -1; double di = A.Distance(ViewLine, 2 * Snapdist, out Lam, out Dummy); if (di < 2 * Snapdist) { return(PolyPoly[Path].Value(Lam).toXYZ()); } else { Lam = -1; } } else { for (int i = 0; i < PolyPoly.Count; i++) { A = PolyPoly[i]; double Dummy = -1; double di = A.Distance(ViewLine, 2 * Snapdist, out Lam, out Dummy); if (di <= 2 * Snapdist) { // Path = i; return(PolyPoly[i].Value(Lam).toXYZ()); } //else // Path = -1; } } xyz Result = new xyz(0, 0, 0); double LineLam = -1; new Plane(new xyz(0, 0, 0), new xyz(0, 0, 1)).Cross(ViewLine, out LineLam, out Result); return(Result); }
void SetCurveArray() { Matrix M = StandardBase.ToMatrix();// xyz K = B.BaseO + B.BaseX * P.x + B.BaseY * P.y; _CurveArray = new xyzArray(); if ((Direction.length() == 0) || (Curve == null)) { return; } xyArray xyA = Curve.ToXYArray(); for (int i = 0; i < xyA.Count; i++) { _CurveArray.Add(xyA[i].toXYZ()); } CurveArray = M * _CurveArray; }
protected override void OnCreated() { base.OnCreated(); Navigating = false; MarkeredRect.LiveTransform = true; MarkeredRect.Creating = false; for (int i = 0; i < StarCount; i++) { xyArray Star = xyArray.CreateStar(new xy(getRandom(), getRandom()), 6 + (int)(R.NextDouble() * 6), 2, 5); Stars.Add(Star); byte[] CO = new byte[3]; R.NextBytes(CO); Colors.Add(Color.FromArgb(255, CO[0], CO[1], CO[2])); } LightEnabled = false; }
/// <summary> /// Crosses the Curve with an other curve by crossing the interpolating polygonarray. /// <seealso cref="Cross(Curve,double, double , out double , out double)"/> /// </summary> /// <param name="Curve">The other Curve</param> /// <param name="lam">Parameter to evaluate with the value method ( this.value(lam))</param> /// <param name="mue">>Parameter to evaluate with the value method of Curve ( Curve.value(mue))</param> /// <returns>True if there is a crosspoint else false.</returns> public bool Cross(Curve Curve, out double lam, out double mue) { lam = 0; mue = 0; xyArray A = new xyArray(Resolution + 1); ToArray(A, 0); xyArray B = new xyArray(Curve.Resolution + 1); ; Curve.ToArray(B, 0); A.RemoveZeros(); B.RemoveZeros(); for (int i = 0; i < A.Count - 1; i++) { LineType2d L1 = new LineType2d(A[i], A[i + 1] - A[i]); if (!L1.Direction.Equals(new xy(0, 0))) { for (int j = 0; j < B.Count - 1; j++) { LineType2d L2 = new LineType2d(B[j], B[j + 1] - B[j]); bool solution = L1.Cross(L2, out lam, out mue); if (solution) { if ((lam >= -0.000001) && (lam <= 1.000001) && (mue >= -0.00001) && (mue <= 1.000001)) { solution = L1.Cross(L2, out lam, out mue); lam = (i + lam) / (float)Resolution; mue = (j + mue) / (float)Curve.Resolution; return(true); } } } } } lam = -1; mue = -1; return(false); }
/// <summary> /// Converts a xyzArray to a xyArray relative to the base if it is planar, else the z-coord is omitted. /// </summary> /// <returns>The lifted xyzArray</returns> public xyArray ToxyArray() { xyArray result = new xyArray(Count); if (planar) { for (int i = 0; i < Count; i++) { result[i] = this.Base.Relativ(this[i]).toXY(); } } else { for (int i = 0; i < Count; i++) { result[i] = new xy(this[i].x, this[i].y); } } return(result); }
/// <summary> /// Returns a <see cref="Drawing3d.xyArray"/> by calling the <see cref="Curve.ToArray"/>-method of the /// curves. /// </summary> /// <returns></returns> public xyArray getxyArray() { int Resolution = 0; for (int i = 0; i < Count; i++) { Curve c = this[i]; Resolution = Resolution + c.Resolution; } xyArray xyarray = new xyArray(Resolution + 1); int index = 0; for (int i = 0; i < Count; i++) { Curve c = this[i]; c.ToArray(xyarray, index); index = index + c.Resolution; } return(xyarray); }
/// <summary> /// This method fills values, calculated by the function Value in an array, starting at index. /// </summary> /// <param name="xyArray">Array for storing the values of the curve</param> /// <param name="index">startindex, from which the values are stored</param> /// <remarks>The array must be initialized until index + resolution + 1</remarks> public virtual void ToArray(xyArray xyArray, int index) { if (Dirty || (Data == null)) { MakeClean(); Data.data.CopyTo(xyArray.data, index); } else if (Data.data.Length > xyArray.data.Length) { xyArray.data = new xy[Data.data.Length]; MakeClean(); Data.data.CopyTo(xyArray.data, index); } else { Data.data.CopyTo(xyArray.data, index); } }
/// <summary> /// draws a 2D curve. /// </summary> /// <param name="C"><see cref="Curve"/></param> public void drawCurve(Curve C) { xyArray A = C.ToXYArray(); PolygonMode save = PolygonMode; if (A.Count == 2) { PolygonMode = PolygonMode.Line; } Object Handle = null; if ((RenderKind == RenderKind.SnapBuffer)) { Handle = Selector.RegisterSnapItem(new CurveSnappItem(C)); } drawPolyLine(A); if ((RenderKind == RenderKind.SnapBuffer)) { Selector.UnRegisterSnapItem(Handle); } PolygonMode = save; }