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
Fixed some bugs
This commit is contained in:
parent
72512fb632
commit
82bc46fbb3
@ -71,8 +71,8 @@ namespace TheLabs
|
||||
base.OnRenderFrame(e);
|
||||
// Clear the color buffer and the depth buffer
|
||||
GL.Clear(ClearBufferMask.DepthBufferBit | ClearBufferMask.ColorBufferBit);
|
||||
|
||||
// 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),
|
||||
@ -82,14 +82,10 @@ namespace TheLabs
|
||||
);
|
||||
|
||||
// Draw the cube
|
||||
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);
|
||||
//_cube = new Cube();
|
||||
//_cube.Draw(_shader, view, projection, _rotation);
|
||||
//_circle.Draw(_shader, view, projection, model);
|
||||
//_cylinder.Draw(_shader, model, view, projection);
|
||||
SwapBuffers();
|
||||
GL.GetError();
|
||||
}
|
||||
|
||||
@ -9,22 +9,19 @@ public class Circle
|
||||
// Vertex Array Object, Vertex Buffer Object, Element Buffer Object
|
||||
private int _vao;
|
||||
private int _vbo;
|
||||
private int _ebo;
|
||||
private int _vertexCount;
|
||||
|
||||
private readonly float[] _vertices =
|
||||
{
|
||||
|
||||
|
||||
};
|
||||
private int _maxVert = 100;
|
||||
public Circle(float z = 0f, int segments = 100, Vector4? color = null)
|
||||
{
|
||||
Vector4 col = color ?? new Vector4(0f, 0f, 1f, 1f);
|
||||
for (int i = 0; i <= segments; i++)
|
||||
{
|
||||
|
||||
float angle = i * 2.0f * MathF.PI / _maxVert;
|
||||
float angle = i * 2.0f * MathF.PI / segments;
|
||||
float x = 0.5f * MathF.Cos(angle);
|
||||
float y = 0.5f * MathF.Sin(angle);
|
||||
|
||||
@ -71,9 +68,19 @@ public class Circle
|
||||
{
|
||||
return _vertices;
|
||||
}
|
||||
public void Draw(Shader shader, Matrix4 matrix4)
|
||||
public void Draw(Shader shader, Matrix4 view, Matrix4 projection, Matrix4 model)
|
||||
{
|
||||
shader.SetMatrix4("model", matrix4);
|
||||
//shader.SetMatrix4("model", matrix4);
|
||||
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);
|
||||
|
||||
shader.Use();
|
||||
GL.BindVertexArray(_vao);
|
||||
GL.DrawArrays(PrimitiveType.TriangleFan, 0, _vertices.Length / 7);
|
||||
|
||||
@ -82,7 +89,6 @@ public class Circle
|
||||
public void Dispose()
|
||||
{
|
||||
GL.DeleteBuffer(_vbo);
|
||||
GL.DeleteBuffer(_ebo);
|
||||
GL.DeleteVertexArray(_vao);
|
||||
}
|
||||
}
|
||||
@ -31,7 +31,7 @@ public class Cylinder
|
||||
_vertexCount = _indices.Length;
|
||||
_topCircle = new Circle(0.5f, 100, new Vector4(1f, 1f, 0f, 1f));
|
||||
_bottomCircle = new Circle(-0.5f, 100, new Vector4(1f, 0f, 0f, 1f));
|
||||
GenerateCylinder(101);
|
||||
GenerateCylinder(100);
|
||||
|
||||
}
|
||||
|
||||
@ -105,14 +105,23 @@ public class Cylinder
|
||||
GL.BindVertexArray(0);
|
||||
}
|
||||
|
||||
public void Draw(Shader shader, Matrix4 matrix4)
|
||||
public void Draw(Shader shader, Matrix4 model, Matrix4 view, Matrix4 projection)
|
||||
{
|
||||
shader.SetMatrix4("model", matrix4);
|
||||
shader.SetMatrix4("model", model);
|
||||
// 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, _indices.Length, DrawElementsType.UnsignedInt, 0);
|
||||
_topCircle.Draw(shader, matrix4);
|
||||
_bottomCircle.Draw(shader, matrix4);
|
||||
_topCircle.Draw(shader, view, projection, model);
|
||||
_bottomCircle.Draw(shader, view, projection, model);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user