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
doing some stuff
This commit is contained in:
parent
ced63735a5
commit
72512fb632
@ -57,7 +57,6 @@ namespace TheLabs
|
||||
// Create and compile our shader program from the shader source files
|
||||
_shader = new Shader("Shaders/shader.vert", "Shaders/shader.frag");
|
||||
// Create a cube
|
||||
_cube = new Cube();
|
||||
_circle = new Circle();
|
||||
_cylinder = new Cylinder();
|
||||
// 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
|
||||
GL.Clear(ClearBufferMask.DepthBufferBit | ClearBufferMask.ColorBufferBit);
|
||||
|
||||
// Update the rotation
|
||||
|
||||
// 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 projection = Matrix4.CreatePerspectiveFieldOfView(
|
||||
MathHelper.DegreesToRadians(45f),
|
||||
@ -84,20 +80,16 @@ namespace TheLabs
|
||||
0.1f,
|
||||
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
|
||||
//_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);
|
||||
_cylinder.Draw(_shader, model);
|
||||
//_cylinder.Draw(_shader, model);
|
||||
SwapBuffers();
|
||||
GL.GetError();
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@ public class Cube
|
||||
private int _vbo;
|
||||
private int _ebo;
|
||||
private int _vertexCount;
|
||||
public Vector3 Position = Vector3.Zero;
|
||||
|
||||
private readonly float[] _cubevertices =
|
||||
{
|
||||
@ -94,10 +95,22 @@ public class Cube
|
||||
|
||||
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.DrawElements(PrimitiveType.Triangles, _cubeIndices.Length, DrawElementsType.UnsignedInt, 0);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user