mirror of
https://github.com/UOH-CS-Level5/551455-graphics-programming-2526-the-repo-Zyb3rWolfi.git
synced 2025-11-29 00:43:08 +00:00
45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
using OpenTK.Mathematics;
|
|
using System.Collections.Generic;
|
|
|
|
namespace TheLabs;
|
|
|
|
public class SceneNode
|
|
{
|
|
public RenderObject? RenderObject;
|
|
|
|
public List<SceneNode> Children = new List<SceneNode>();
|
|
|
|
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, Lighting light)
|
|
{
|
|
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, light);
|
|
}
|
|
|
|
foreach (var child in Children)
|
|
{
|
|
child.Draw(view, projection, globalTransform, light);
|
|
}
|
|
}
|
|
} |