#region usings using System.Collections.Generic; using OpenTK.Graphics.OpenGL4; using SM.Base.Scene; using SM.Base.Window; using SM.OGL.Mesh; #endregion namespace SM.Base.Drawing { /// /// Contains general basis systems for drawing objects. /// public abstract class DrawingBasis : IShowItem, IModelItem { /// /// The camera, that was used last time the object was rendered. /// public GenericCamera LastDrawingCamera { get; private set; } /// /// The material it should use. /// public Material Material { get; set; } = new Material(); /// /// Transformation for the textures. /// public TextureTransformation TextureTransform { get; set; } = new TextureTransformation(); /// /// This allows custom shaders to add own arguments. /// public ShaderArguments ShaderArguments => Material.ShaderArguments; /// /// This can force a shader to render the object with the specified mesh type. /// public PrimitiveType? ForcedMeshType { get; set; } /// /// The mesh it should use. /// public GenericMesh Mesh { get; set; } = SMRenderer.DefaultMesh; /// public object Parent { get; set; } /// public string Name { get; set; } = "Unnamed draw object"; /// public ICollection Flags { get; set; } /// /// This value determents if the object should draw something. /// public bool Active { get; set; } = true; /// public bool RenderActive { get; set; } = true; /// public void Draw(DrawContext context) { context.Material = Material; context.Mesh = Mesh; DrawContext(ref context); } /// public virtual void OnAdded(object sender) { } /// public virtual void OnRemoved(object sender) { } /// /// Draws the context, that was given to them. /// /// protected virtual void DrawContext(ref DrawContext context) { context.ForcedType = ForcedMeshType; context.TextureMatrix *= TextureTransform.GetMatrix(); context.LastObject = this; LastDrawingCamera = context.UseCamera; } } /// /// Contains general basis systems for drawing objects. /// /// The transformation type public abstract class DrawingBasis : DrawingBasis, IShowTransformItem where TTransformation : GenericTransformation, new() { /// /// The current transformation. /// public TTransformation Transform { get; set; } = new TTransformation(); /// protected override void DrawContext(ref DrawContext context) { base.DrawContext(ref context); Transform.LastMaster = context.ModelMatrix; context.ModelMatrix = Transform.InWorldSpace; } } }