/// <summary> /// overrides the <see cref="CustomEntity.OnDraw"/>method. /// </summary> /// <param name="Device"></param> protected override void OnDraw(OpenGlDevice Device) { if (Device == null) { return; } if (Device.RenderKind == RenderKind.SnapBuffer) { } if (!visible) { return; } if (Device.RenderKind != RenderKind.SnapBuffer) { base.OnDraw(Device); } if (!Device.ForegroundDrawEnable) { if (MarkerVisible) { ShowMarker(); } DrawSkeleton(); } if (Device.RenderKind == RenderKind.SnapBuffer) { ShowMarker(); } }
/// <summary> /// internal. /// </summary> internal static void MeshdrawTriangles2d(OpenGlDevice Device, List <IndexType> Indices, xyf[] Points, xyf[] Texture) { float dir = 1; for (int i = 0; i < Indices.Count; i += 3) { xy A = new xy(Points[Indices[i + 1]].x - Points[Indices[i]].x, Points[Indices[i + 1]].y - Points[Indices[i]].y); xy B = new xy(Points[Indices[i + 2]].x - Points[Indices[i]].x, Points[Indices[i + 2]].y - Points[Indices[i]].y); double F = A & B; if (System.Math.Abs(F) > 0.0001) { if (F < 0) { dir = 1; } else { dir = -1; } break; } } int ID = MeshVertices.Count; for (int i = 0; i < Indices.Count; i++) { MeshIndices.Add((IndexType)(Indices[i] + ID)); } if (MeshVertices.Count + Points.Length > IndexType.MaxValue) { int CT = (MeshVertices.Count + Points.Length); MeshIndices = new List <IndexType>(); Renew(); throw new Exception("Points count to large " + CT.ToString()); } for (int i = 0; i < Points.Length; i++) { MeshVertices.Add(Device.ModelMatrix * new xyz(Points[i].x, Points[i].y, 0).toXYZF()); } xyzf NP = Device.ModelMatrix * new xyzf(0, 0, 0); xyzf N = Device.ModelMatrix * new xyzf(0, 0, dir) - NP; for (int i = 0; i < Points.Length; i++) { MeshNormals.Add(N); } if (Texture != null) { MeshTextureCoords.AddRange(Texture); } MeshMode = PolygonMode.Fill; if (Entity.Compiling) { if (Device.RenderKind == RenderKind.SnapBuffer) { MeshCreator.Renew(); } } }
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); }
/// <summary> /// override this method by drawing his (compiled) progs. /// </summary> /// <param name="Device"></param> protected override void OnDraw(OpenGlDevice Device) { for (int i = 0; i < Progs.Count; i++) { Progs[i]._Ondraw(Device); } }
/// <summary> /// compiles the <see cref="DrawAction"/> draw and returns a meshContainer. /// The <b>progs</b> of this is a list of <see cref="Mesh"/>. /// This method is called from <see cref="Entity.Compile(OpenGlDevice)"/>. /// </summary> /// <param name="Device"><see cref="OpenGlDevice"/> in which will be drawn.</param> /// <param name="Draw">the <see cref="DrawAction"/>, which is used to produce a <see cref="MeshContainer"/></param> /// <returns></returns> public static MeshContainer Compile(OpenGlDevice Device, DrawAction Draw) { Device.PushMatrix(); MeshListCurrent = new MeshContainer(); bool Compiling = Entity.Compiling; if (Compiling) { MeshCreator.Push(); } bool SaveCompiling = Entity.Compiling; Entity.Compiling = true; RenderKind SaveRenderKind = Device.RenderKind; Device.RenderKind = RenderKind.Render; MeshIndices.Clear(); Draw(Device); Renew(); Entity.Compiling = SaveCompiling; Device.RenderKind = SaveRenderKind; Device.PopMatrix(); MeshContainer Result = MeshListCurrent; if (Compiling) { MeshCreator.Pop(); } return(Result); }
void RekursiveDraw(Assimp.Node node, OpenGlDevice Device) { if ((node.HasMeshes)) { foreach (var index in node.MeshIndices) { D3DMesh mesh = (Meshes[index] as D3DMesh); xyzf b = new xyzf(0, 0, 0); CpuSkinningEvaluator.CachedMeshData MD = SkinninEvaluator.GetEntry(mesh); SkinninEvaluator.GetTransformedVertexPosition(node, mesh, 0, out b); if (mesh.Material.Translucent < 1) { TransparentMeshes.Add(new TransParencyItem(mesh, MD._cachedPositions, MD._cachedNormals)); continue; } xyzf[] SavePos = mesh.Position; xyzf[] SaveNormals = mesh.Normals; mesh.Position = MD._cachedPositions; mesh.Normals = MD._cachedNormals; mesh.Paint(Device); mesh.Position = SavePos; mesh.Normals = SaveNormals; } } for (int i = 0; i < node.Children.Count; i++) { RekursiveDraw(node.Children[i], Device); } }
/// <summary> /// overrides the <see cref="Entity.OnForegroundDraw(OpenGlDevice)"/> method. /// </summary> /// <param name="Device"></param> public override void OnForegroundDraw(OpenGlDevice Device) { Matrix P = Device.ProjectionMatrix; Device.ProjectionMatrix = ForegroundMatrix(); float pw = Device.PenWidth; Device.PenWidth = PenWidth; Color C = Device.Emission; Device.Emission = Color; Device.drawLine(new xyz(A.x, A.Y, Device.ViewPort.Width / 2), new xyz(A.x, B.Y, Device.ViewPort.Width / 2)); Device.drawLine(new xyz(A.x, B.Y, Device.ViewPort.Width / 2), new xyz(B.x, B.Y, Device.ViewPort.Width / 2)); Device.drawLine(new xyz(B.x, B.Y, Device.ViewPort.Width / 2), new xyz(B.x, A.Y, Device.ViewPort.Width / 2)); Device.drawLine(new xyz(B.x, A.Y, Device.ViewPort.Width / 2), new xyz(A.x, A.Y, Device.ViewPort.Width / 2)); Device.PenWidth = pw; Device.Emission = C; Device.ProjectionMatrix = P; }
/// <summary> /// overrides the <see cref="OnDraw(OpenGlDevice)"/> method. /// </summary> /// <param name="Device"></param> protected override void OnDraw(OpenGlDevice Device) { TransparentMeshes.Clear(); if (HasAnimations) { RekursiveDraw(this._Scene.RootNode, Device); } else { foreach (D3DMesh M in Meshes) { if (M.Material.Translucent < 1) { TransparentMeshes.Add(new TransParencyItem(M, null, null)); } else { M.Paint(Device); } } } TransparencyDraw(Device); base.OnDraw(Device); }
/// <summary> /// is the most important method of this class. You have to override this Method. /// To call method you have to call <see cref="Entity.Paint(OpenGlDevice)"/> or you add <b>this</b> to the /// <see cref="Entity.Children"/> of an entity and call the paint method of any <b>parent</b> ancestor. /// </summary> /// <param name="Device">the <see cref="OpenGlDevice" /> in which will be drawn.</param> protected virtual void OnDraw(OpenGlDevice Device) { if (Draw != null) { Draw(this, Device); } }
private void BIASUpdate(Field sender, object UpdateObject) { OpenGlDevice Device = UpdateObject as OpenGlDevice; float b = (float)(3 / Device.FarClipping / 10); sender.SetValue(b); }
/// <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); } }
private void LighCountUpdate(Field sender, object UpdateObject) { OpenGlDevice Device = UpdateObject as OpenGlDevice; // sender.SetValue(Device.Lights.Count); sender.SetValue(1); }
/// <summary> /// a consturctor with device, from, to and duration. /// Rem: SpeedInUnitsPerMilliSec is set to 1. /// </summary> /// <param name="Device">the device in which the animator works.</param> /// <param name="from">from value</param> /// <param name="to">tovalue</param> /// <param name="Duration">duration</param> public LinearAnimator(OpenGlDevice Device, float from, float to, long Duration) : base(Device) { this.FromValue = from; this.ToValue = to; this.Duration = Duration; }
/// <summary> /// is a very useful method. If you have a complicated background and a simple object, before the background you can use /// this method by drawing the simple object in the foreground. See also <see cref="OpenGlDevice.ForegroundDrawEnable"/>. /// </summary> /// <param name="Device">is the used device.</param> public virtual void OnForegroundDraw(OpenGlDevice Device) { if (ForegroundDraw != null) { ForegroundDraw(this, Device); } }
/// <summary> /// overrides the <see cref="CustomEntity.Draw"/> method. /// </summary> /// <param name="Device"></param> protected override void OnDraw(OpenGlDevice Device) { for (int i = 0; i < Curvextruders.Count; i++) { for (int j = 0; j < Curvextruders[i].Count; j++) { Curvextruders[i][j].Paint(Device); if (Device.RenderKind == RenderKind.SnapBuffer) { SnappItem SI = Selector.StoredSnapItems[Selector.StoredSnapItems.Count - 1]; SI.OfObject = this; } } } if (ShowUpPlane) { DrawUpPlane(Device); } if (ShowDownPlane) { DrawDownPlane(Device); } base.OnDraw(Device); }
/// <summary> /// overrides the <see cref="Surface.OnDraw(OpenGlDevice)"/> method. /// </summary> /// <param name="Device"></param> protected override void OnDraw(OpenGlDevice Device) { //if ((BoundedCurves == null) || (BoundedCurves.Count == 0)) // Device.drawSphere(Center, Radius, UResolution, VResolution); //else base.OnDraw(Device); }
/// <summary> /// a consturctor with device, from, to and SpeedInUnitsPerMilliSec. /// </summary> /// <param name="Device">the device in which the animator works.</param> /// <param name="from">from value</param> /// <param name="to">to value</param> /// <param name="SpeedInUnitsPerMilliSec"></param> public LinearAnimator(OpenGlDevice Device, float from, float to, float SpeedInUnitsPerMilliSec) : base(Device) { this.FromValue = from; this.ToValue = to; this.SpeedInUnitsPerMilliSec = SpeedInUnitsPerMilliSec; }
/// <summary> /// a call invoke the <see cref="Field.Update"/> of every var. /// </summary> public virtual void UpDateAllVars() { foreach (var item in Vars.Values) { (item as Field).Update(); OpenGlDevice.CheckError(); } }
void internDraw(OpenGlDevice Device) { Entity Save = CurrentEntity; CurrentEntity = this; OnDraw(Device); CurrentEntity = Save; }
/// <summary> /// loged in the object. See also <see cref="OpenGlDevice.EventServer"/> /// </summary> /// <param name="Device">is the used device.</param> /// <param name="EventPosition">is the position in the eventserver, where the object is positioned.</param> public virtual void OnLogin(OpenGlDevice Device, int EventPosition) { SetDevice(Device, EventPosition); if (LogIn != null) { LogIn(this, new EventArgs()); } }
/// <summary> /// internal. /// </summary> internal static void MeshPaintEntity(OpenGlDevice Device, Entity Entity) { MeshCreator.Renew(); Entity._Ondraw(Device); for (int i = 0; i < Entity.Children.Count; i++) { MeshPaintEntity(Device, Entity.Children[i]); } }
void CompileDraw(OpenGlDevice Device) { OnDraw(Device);// Paint(Device); ////if (Draw != null) Draw(this, Device); for (int i = 0; i < Children.Count; i++) { Children[i].Paint(Device); } }
/// <summary> /// overrides the <see cref="CustomEntity.OnDraw(OpenGlDevice)"/> method by calling /// the <see cref="Entity.Paint(OpenGlDevice)"/> method of every <see cref="Face.Surface"/>. /// </summary> /// <param name="Device">the <see cref="OpenGlDevice"/> in which will be drawn.</param> protected override void OnDraw(OpenGlDevice Device) { for (int i = 0; i < FaceList.Count; i++) { // (FaceList[i] as Face).Surface.CompileEnable = false; (FaceList[i] as Face).Surface.Paint(Device); } base.OnDraw(Device); }
private void drawLetter(Font F, byte b, String s, xyz Start, int iD, OpenGlDevice Device) { if (F.Compiled[b] == null) { CompileChar = b; CompileFont = F; MeshCreator.Push(); bool SaveRegSnap = Selector.RegisterSnap; Selector.RegisterSnap = false; F.Compiled[b] = MeshCreator.Compile(this, Compiledraw); Selector.RegisterSnap = SaveRegSnap; MeshCreator.Pop(); } if (F.Compiled[b] == null) { throw new Exception("Compile error of " + (char)(b)); } if (RenderKind == RenderKind.SnapBuffer) { Object Handle = null; if ((RenderKind == RenderKind.SnapBuffer)) { Handle = Selector.RegisterSnapItem(new TextSnappItem(F, s, iD, Start, ModelMatrix * new xyz(0, 0, 0))); if (F.GlyphInfo[b].BlackBoxY < 0.1) // blank { drawBox(new xyz(0, 0, 0), new xyz(F.GlyphInfo[b].Deltax, 1, 1)); } else { drawBox(new xyz(0, 0, 0), new xyz(F.GlyphInfo[b].Deltax, F.GlyphInfo[b].BlackBoxY, 1)); } if ((RenderKind == RenderKind.SnapBuffer)) { Selector.UnRegisterSnapItem(Handle); } } return; } if (Entity.Compiling) { MeshContainer M = F.Compiled[b] as MeshContainer; for (int i = 0; i < M.Progs.Count; i++) { Mesh E = (M.Progs[i] as Mesh).Clone() as Mesh; E.Transform(ModelMatrix); MeshCreator.MeshListCurrent.Progs.Add(E); } return; } F.Compiled[b].Paint(this); }
/// <summary> /// sets the value of the field. It works only when the shader is <see cref="OGLShader.Using"/> true is. /// </summary> /// <param name="value">the new value</param> /// <returns>true when the shader is using and the field has a handle >=0.</returns> public bool SetValue(Drawing3d.Matrix value) { if (!(Owner.Using) || (handle < 0)) { return(false); } float[] M = value.ToFloat(); GL.UniformMatrix4(handle, 1, false, ref M[0]); OpenGlDevice.CheckError(); return(true); }
/// <summary> /// override <see cref="CustomEntity.Draw"/> method. /// </summary> /// <param name="Device"></param> protected override void OnDraw(OpenGlDevice Device) { Color Save = Device.Diffuse; xAxis.Paint(Device); yAxis.Paint(Device); zAxis.Paint(Device); Device.Diffuse = Save; base.OnDraw(Device); }
/// <summary> /// is the main method of this object. See also <see cref="Entity.CompileDraw(OpenGlDevice)"/>. /// </summary> /// <param name="Device">Device in which it willl be compiled.</param> /// <param name="Draw">a event, which holds the drawings.</param> public static MeshContainer CreateMeshes(OpenGlDevice Device, DrawAction Draw) { // sollte nur von compilesnapbuffer aufgerufen werden !!!! und erstellt die triangles bool Compiling = Entity.Compiling; if (Compiling) { MeshCreator.Push(); } bool SaveCompiling = Entity.Compiling; // Entity.Compiling = true; // Checken braucht es wegen line snap if (Selector.StoredSnapItems.Count == 0) { Selector.StoredSnapItems.Add(null); // braucht es nicht } MeshListCurrent = new MeshContainer(); // braucht es nicht MeshIndices.Clear(); // braucht es wahrscheinlich nicht RenderKind R = Device.RenderKind;// wieder heraus Draw(Device); Renew(); Device.RenderKind = R; Entity.Compiling = SaveCompiling; MeshContainer Result = MeshListCurrent; // MeshListCurrent.MySnapItem = new MeshSnapItem(MeshListCurrent); Device.RenderKind = RenderKind.SnapBuffer; TriangleList TL = new TriangleList(); for (int i = 0; i < MeshListCurrent.Progs.Count; i++) { if (MeshListCurrent.Progs[i] is Mesh) { Mesh M = MeshListCurrent.Progs[i] as Mesh; M.getTriangles(TL); } } TriangleArrays TA = TL.ToArrays(); Device.RenderKind = R; if (Compiling) { MeshCreator.Pop(); } return(Result); }
private void ShadowEnablepdate(Field sender, object UpdateObject) { OpenGlDevice Device = UpdateObject as OpenGlDevice; if (Device.Shadow) { sender.SetValue((int)1); } else { sender.SetValue((int)0); } }
private void ClippingPlaneUpdate(Field sender, object UpdateObject) { OpenGlDevice Device = UpdateObject as OpenGlDevice; float[] CP = Device.getClippingPlanes(); sender.SetValue(CP.Length, CP); Field E = getvar("ClippingPlaneEnabled[0]"); if (E != null) { E.Update(); } }
private void Light0EnabledUpdate(Field sender, object UpdateObject) { OpenGlDevice Device = UpdateObject as OpenGlDevice; if (Device.LightEnabled) { sender.SetValue((int)1); } else { sender.SetValue((int)0); } }