Texture GetPatternTexture(OpenGlDevice Device) { Texture Save = Device.texture; if (Pattern == null) { return(null); } Rectangled R = new Rectangled(Pattern.PatternX, Pattern.PatternY, Pattern.PatternWidth, Pattern.PatternHeight); FBO FrameBuffer = new FBO(); FrameBuffer.BackGround = System.Drawing.Color.Transparent; Device.PushMatrix(); xyz RU = new xyz(R.Width, R.Height, 0); xyz RD = new xyz(R.X, R.Y, 0); Point _RU = Device.ToScr(RU); Point _RD = Device.ToScr(RD); FrameBuffer.Init((int)(_RU.X - _RD.X), (int)(_RD.Y - _RU.Y)); FrameBuffer.EnableWriting(); Pattern.Paint(Device); Device.PopMatrix(); FrameBuffer.DisableWriting(); Texture result = FrameBuffer.Texture; Device.texture = Save; result.WorldWidth = R.Width; result.WorldHeight = R.Height; result.Translation = new xy(R.X, R.Y); FrameBuffer.Dispose(true); return(result); }
void ReCalculateBuffer() { Rectangled R = DefinitionDomain; U_Coeff = new double[100][]; double Step = (float)R.Width / 100f; for (int i = 0; i < 100; i++) { U_Coeff[i] = Utils.CoeffSpline(UKnots, ControlPoints.GetLength(0), UDegree, UPeriodicity, R.Left + i * Step); } V_Coeff = new double[100][]; Step = (float)R.Height / 100f; for (int i = 0; i < 100; i++) { V_Coeff[i] = Utils.CoeffSpline(VKnots, ControlPoints.GetLength(1), VDegree, VPeriodicity, R.Bottom + i * Step); } }
/// <summary> /// a construcor which have a <see cref="Rectangled"/> and a <see cref="OpenGlDevice"/>. See also <see cref="OpenGlDevice"/> /// </summary> /// <param name="Rectangle"></param> /// <param name="Device"></param> public CtrlRectangle(Rectangled Rectangle, OpenGlDevice Device) : base(Device) { _A = new xy(Rectangle.X, Rectangle.Y); _B = new xy(Rectangle.X + Rectangle.Width, Rectangle.Y + Rectangle.Height); }
/// <summary> /// overrides the <see cref="Surface.CheckPeriodic"/> method and set the <see cref="Surface.UPeriodicity"/> and the <see cref="Surface.VPeriodicity"/>. /// </summary> protected override void CheckPeriodic() { double Fac = 0.000001; Rectangled R = DefinitionDomain; try { if (Value(R.X, R.Y).dist(Value(R.X + R.Width, R.Y)) < 20 * Fac) { UPeriodicity = R.Width; } else { UPeriodicity = 1000000; } } catch (Exception) { } if (Value(R.X + R.Width, R.Y).dist(Value(R.X + R.Width, R.Y + R.Height)) < 20 * Fac) { VPeriodicity = R.Height; } else { VPeriodicity = 1000000; } if (Value(R.X, R.Y).dist(Value(R.X + R.Width / 4, R.Y)) < 20 * Fac) { DownPol = new Pol(true, R.Y); } else { DownPol = new Pol(false, -1); } if (Value(R.X, R.Y + R.Height).dist(Value(R.X + R.Width / 4, R.Y)) < 20 * Fac) { UpPol = new Pol(true, R.Y + R.Height); } else { UpPol = new Pol(false, -1); } if (Value(R.X, R.Y).dist(Value(R.X, R.Y + R.Height)) < 20 * Fac) { LeftPol = new Pol(true, R.Y); } else { LeftPol = new Pol(false, -1); } if (Value(R.X + R.Width, R.Y).dist(Value(R.X + R.Width, R.Y + R.Height)) < 20 * Fac) { RightPol = new Pol(true, R.X + R.Width); } else { RightPol = new Pol(false, -1); } if (UpPol.Enable & DownPol.Enable & LeftPol.Enable & RightPol.Enable) { } }
/// <summary> /// Calculates the value of the <see cref="BSplineSurface"/>. /// </summary> /// <param name="u">Parameter u.</param> /// <param name="v">Parameter v.</param> /// <returns>The Evaluation of the bspline.</returns> public override xyz Value(double u, double v) { try { if (UKnots == null) { UKnots = Utils.StandardKnots(ControlPoints.GetLength(0), UDegree); } if (VKnots == null) { VKnots = Utils.StandardKnots(ControlPoints.GetLength(1), VDegree); } Rectangled R = DefinitionDomain; xyz Result = new xyz(0, 0, 0); int UCount = ControlPoints.GetLength(0); int VCount = ControlPoints.GetLength(1); double[] UCoeff = Utils.CoeffSpline(UKnots, UCount, UDegree, UPeriodicity, v); double[] VCoeff = Utils.CoeffSpline(VKnots, VCount, VDegree, VPeriodicity, u); int FirstUCoeffNonZero = 0; for (int i = 0; i < UCoeff.Length; i++) { if (UCoeff[i] != 0) { FirstUCoeffNonZero = i; break; } } int FirstVCoeffNonZero = 0; for (int i = 0; i < VCoeff.Length; i++) { if (VCoeff[i] != 0) { FirstVCoeffNonZero = i; break; } } int UntilU = Math.Min(FirstUCoeffNonZero + UDegree, UCoeff.Length - 1); int UntilV = Math.Min(FirstVCoeffNonZero + VDegree, VCoeff.Length - 1); for (int i = 0; i < UCoeff.Length; i++) { for (int k = 0; k < VCoeff.Length; k++) { Result = Result + ControlPoints[i, k] * (UCoeff[i] * VCoeff[k]); } } if (ZHeight(u, v) != 0) { return(Base.Absolut(Result + Normal(u, v) * ZHeight(u, v))); } else { return(Base.Absolut(Result)); } } catch (Exception) { if ((ControlPoints.GetLength(0) + UDegree + 1) != UKnots.Length) { System.Windows.Forms.MessageBox.Show("the definition of the UKnots is wrong. . It must be UKnots.Length=ControlPoints.GetLength(0) + UDegree + 1"); } else if ((ControlPoints.GetLength(1) + VDegree + 1) != VKnots.Length) { System.Windows.Forms.MessageBox.Show("the definition of the VKnots is wrong. It must be VKnots.Length=ControlPoints.GetLength(1) + VDegree + 1"); } return(new xyz(0, 0, 0)); } }
void RefreshVertices() { Position = new xyzf[(UResolution + 1) * (VResolution + 1)]; Normals = new xyzf[(UResolution + 1) * (VResolution + 1)]; Rectangled R = new Rectangled(0, 0, 1, 1); double xStep = (float)1 / (float)(UResolution); double yStep = (float)1 / (float)(VResolution); xyzf _Point = new xyzf(0, 0, 0); xyzf _Normal = new xyzf(0, 0, 0); float ustep = (float)(Width / (float)UResolution); float vstep = (float)(Height / (float)VResolution); for (int u = 0; u < UResolution + 1; u++) { int URow = u * (VResolution + 1); for (int v = 0; v < VResolution + 1; v++) { Position[URow + v] = new xyzf((float)Origin.x + u * ustep, (float)Origin.y + v * vstep, (float)Origin.z); } } for (int u = 0; u < UResolution + 1; u++) { int URow = u * (VResolution + 1); for (int v = 0; v < VResolution + 1; v++) { Normals[URow + v] = new xyzf(0, 0, 1); } } TextureCoords = new xyf[(UResolution + 1) * (VResolution + 1)]; ustep = (float)(1 / (float)UResolution); vstep = (float)(1 / (float)VResolution); for (int u = 0; u < UResolution + 1; u++) { int URow = u * (VResolution + 1); for (int v = 0; v < VResolution + 1; v++) { TextureCoords[URow + v] = new xyf(u * ustep, v * vstep); } } if (UseQuads) { Indices = new int[UResolution * VResolution * 4]; int ID = 0; for (int u = 0; u < UResolution; u++) { int URow = u * (VResolution + 1); for (int v = 0; v < VResolution; v++) { Indices[ID] = u * (VResolution + 1) + v; Indices[ID + 1] = u * (VResolution + 1) + v + 1; Indices[ID + 2] = (u + 1) * (VResolution + 1) + v + 1; Indices[ID + 3] = (u + 1) * (VResolution + 1) + v; ID += 4; } } TriangleIndices = getTriangleIndices(); } else { Indices = getTriangleIndices(); } }