2025-11-11 15:35:10 +00:00

42 lines
1.2 KiB
C#

using LearnOpenTK.Common;
using OpenTK.Graphics.OpenGL4;
using OpenTK.Mathematics;
namespace TheLabs;
public class RenderObject
{
public Mesh Mesh;
public Shader Shader;
public Texture Texture;
public Vector3 Position = Vector3.Zero;
public Quaternion Rotation = Quaternion.Identity;
public Vector3 Scale = Vector3.One;
public RenderObject(Mesh mesh, Shader shader, Texture texture)
{
Mesh = mesh;
Shader = shader;
Texture = texture;
}
public void Draw(Matrix4 view, Matrix4 projection)
{
// 1. Activate Shader
Shader.Use();
Shader.SetInt("uTexture", 0);
// 2. Bind Texture
Texture.Use(); // Assumes you have a Texture class
// 3. Calculate Model Matrix
Matrix4 model = Matrix4.CreateScale(Scale) * Matrix4.CreateFromQuaternion(Rotation) * Matrix4.CreateTranslation(Position);
// 4. Set Uniforms
Shader.SetMatrix4("model", model);
Shader.SetMatrix4("view", view);
Shader.SetMatrix4("projection", projection);
// 5. Tell the Mesh to draw itself
Mesh.Draw();
}
}