using OpenTK.Mathematics; using System.Collections.Generic; namespace TheLabs; public class SceneNode { public RenderObject? RenderObject; public List Children = new List(); public Vector3 Position = Vector3.Zero; public Quaternion Rotation = Quaternion.Identity; public Vector3 Scale = Vector3.One; public SceneNode(RenderObject? renderObject = null) { RenderObject = renderObject; } public void AddChild(SceneNode child) { Children.Add(child); } public void Draw(Matrix4 view, Matrix4 projection, Matrix4 parentTransform) { Matrix4 localTransform = Matrix4.CreateScale(Scale) * Matrix4.CreateFromQuaternion(Rotation) * Matrix4.CreateTranslation(Position); Matrix4 globalTransform = localTransform * parentTransform; if (RenderObject != null) { RenderObject.Position = Vector3.Zero; RenderObject.Rotation = Quaternion.Identity; RenderObject.Scale = Vector3.One; RenderObject.Draw(view, projection); } foreach (var child in Children) { child.Draw(view, projection, globalTransform); } } }