doing some stuff

This commit is contained in:
zyb3rwolfi 2025-10-07 13:08:23 +01:00
parent ced63735a5
commit 72512fb632
2 changed files with 22 additions and 17 deletions

View File

@ -57,7 +57,6 @@ namespace TheLabs
// Create and compile our shader program from the shader source files // Create and compile our shader program from the shader source files
_shader = new Shader("Shaders/shader.vert", "Shaders/shader.frag"); _shader = new Shader("Shaders/shader.vert", "Shaders/shader.frag");
// Create a cube // Create a cube
_cube = new Cube();
_circle = new Circle(); _circle = new Circle();
_cylinder = new Cylinder(); _cylinder = new Cylinder();
// Use the shader program. This is similar to "activating" the shader program. // Use the shader program. This is similar to "activating" the shader program.
@ -73,10 +72,7 @@ namespace TheLabs
// Clear the color buffer and the depth buffer // Clear the color buffer and the depth buffer
GL.Clear(ClearBufferMask.DepthBufferBit | ClearBufferMask.ColorBufferBit); GL.Clear(ClearBufferMask.DepthBufferBit | ClearBufferMask.ColorBufferBit);
// Update the rotation
// Create the model, view, and projection matrices // Create the model, view, and projection matrices
Matrix4 model = Matrix4.CreateRotationY(_rotation) * Matrix4.CreateRotationX(_rotation * 0.5f);
Matrix4 view = Matrix4.CreateTranslation(0.0f, 0.0f, -3.0f); Matrix4 view = Matrix4.CreateTranslation(0.0f, 0.0f, -3.0f);
Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView( Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView(
MathHelper.DegreesToRadians(45f), MathHelper.DegreesToRadians(45f),
@ -84,20 +80,16 @@ namespace TheLabs
0.1f, 0.1f,
100.0f 100.0f
); );
// Set the matrices in the shader
int modelLoc = GL.GetUniformLocation(_shader.Handle, "model");
int viewLoc = GL.GetUniformLocation(_shader.Handle, "view");
int projLoc = GL.GetUniformLocation(_shader.Handle, "projection");
// Send the matrices to the shader
GL.UniformMatrix4(modelLoc, false, ref model);
GL.UniformMatrix4(viewLoc, false, ref view);
GL.UniformMatrix4(projLoc, false, ref projection);
// Draw the cube // Draw the cube
//_cube.Draw(_shader, model); for (int i = 0; i < 3; i++)
{
_cube = new Cube();
_cube.Position = new Vector3(0.5f, 0.5f * i * 0.5f, 0.0f);
_cube.Draw(_shader, view, projection, _rotation);
}
//_circle.Draw(_shader, model); //_circle.Draw(_shader, model);
_cylinder.Draw(_shader, model); //_cylinder.Draw(_shader, model);
SwapBuffers(); SwapBuffers();
GL.GetError(); GL.GetError();
} }

View File

@ -12,6 +12,7 @@ public class Cube
private int _vbo; private int _vbo;
private int _ebo; private int _ebo;
private int _vertexCount; private int _vertexCount;
public Vector3 Position = Vector3.Zero;
private readonly float[] _cubevertices = private readonly float[] _cubevertices =
{ {
@ -95,9 +96,21 @@ public class Cube
GL.BindVertexArray(0); GL.BindVertexArray(0);
} }
public void Draw(Shader shader, Matrix4 matrix4)
public void Draw(Shader shader, Matrix4 view, Matrix4 projection, float rotation)
{ {
shader.SetMatrix4("model", matrix4); // Create the model matrix with rotation and translation
Matrix4 model = Matrix4.CreateRotationY(rotation) * Matrix4.CreateRotationX(rotation * 0.5f) * Matrix4.CreateTranslation(Position);
// Set the matrices in the shader
int modelLoc = GL.GetUniformLocation(shader.Handle, "model");
int viewLoc = GL.GetUniformLocation(shader.Handle, "view");
int projLoc = GL.GetUniformLocation(shader.Handle, "projection");
// Send the matrices to the shader
GL.UniformMatrix4(modelLoc, false, ref model);
GL.UniformMatrix4(viewLoc, false, ref view);
GL.UniformMatrix4(projLoc, false, ref projection);
GL.BindVertexArray(_vao); GL.BindVertexArray(_vao);
GL.DrawElements(PrimitiveType.Triangles, _cubeIndices.Length, DrawElementsType.UnsignedInt, 0); GL.DrawElements(PrimitiveType.Triangles, _cubeIndices.Length, DrawElementsType.UnsignedInt, 0);