From cf8eb3f5fd4f8902e555786b6ab17c93662da1be Mon Sep 17 00:00:00 2001 From: Zyb3rWolfi Date: Thu, 13 Nov 2025 17:13:54 +0000 Subject: [PATCH] added bus --- TheRepo/TheLabs/MyExampleWindow.cs | 32 ++++------- TheRepo/TheLabs/Program.cs | 2 +- TheRepo/TheLabs/RenderObject.cs | 1 + TheRepo/TheLabs/Shapes/Bus.cs | 90 ++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 21 deletions(-) create mode 100644 TheRepo/TheLabs/Shapes/Bus.cs diff --git a/TheRepo/TheLabs/MyExampleWindow.cs b/TheRepo/TheLabs/MyExampleWindow.cs index 28cebc2..ff4a03d 100644 --- a/TheRepo/TheLabs/MyExampleWindow.cs +++ b/TheRepo/TheLabs/MyExampleWindow.cs @@ -31,6 +31,7 @@ namespace TheLabs private RenderObject _cubeObject2; private RenderObject _circleObject; private RenderObject _cylinderObject; + private Bus _bus; private Vector3 _cameraPosition = new Vector3(0.0f, 0.0f, -3.0f); private Vector3 _cameraFront = new Vector3(0.0f, 0.0f, -1.0f); @@ -65,23 +66,16 @@ namespace TheLabs GL.ClearColor(0.2f, 0.3f, 0.3f, 1.0f); GL.Enable(EnableCap.DepthTest); _camera = new Camera(_cameraPosition, _cameraFront, _cameraUp); + CursorState = CursorState.Grabbed; + _shader = new Shader("Shaders/shader.vert", "Shaders/shader.frag"); - _cubeMesh = ShapeFactory.CreateTexturedCube(); - _circleMesh = ShapeFactory.CreateTexturedCircle(); - _cylinderMesh = ShapeFactory.CreateTexturedCylinder(); - _cubeTexture = new Texture("Textures/stone.jpg"); + _cubeTexture = new Texture("Textures/placeholder.png"); _cubeTexture2 = new Texture("Textures/placeholder.png"); - _cubeObject = new RenderObject(_cubeMesh, _shader, _cubeTexture); - _cubeObject2 = new RenderObject(_cubeMesh, _shader, _cubeTexture2); - _circleObject = new RenderObject(_circleMesh, _shader, _cubeTexture); - _cylinderObject = new RenderObject(_cylinderMesh, _shader, _cubeTexture2); - _cylinderObject.Position = new Vector3(-2.5f, 0.0f, 0.0f); - _cubeObject.Position = new Vector3(-1.5f, 0.0f, 0.0f); - _cubeObject2.Position = new Vector3(1.5f, 0.0f, 0.0f); - _circleObject.Position = new Vector3(2.5f, 0.0f, 0.0f); - _cubeObject.Scale = new Vector3(0.5f, 0.5f, 0.5f); - _cubeObject2.Scale = new Vector3(0.5f, 0.5f, 0.5f); + + _bus = new Bus(_cubeTexture, _shader); + + } @@ -93,8 +87,8 @@ namespace TheLabs base.OnRenderFrame(e); // Clear the color buffer and the depth buffer GL.Clear(ClearBufferMask.DepthBufferBit | ClearBufferMask.ColorBufferBit); - _cubeObject.Rotation = Quaternion.FromEulerAngles(_rotation * 0.5f, _rotation, 0); // - _cubeObject2.Rotation = Quaternion.FromEulerAngles(-_rotation * 0.5f, -_rotation, 0); + //_cubeObject.Rotation = Quaternion.FromEulerAngles(_rotation * 0.5f, _rotation, 0); // + //_cubeObject2.Rotation = Quaternion.FromEulerAngles(-_rotation * 0.5f, -_rotation, 0); // --- Set up Camera --- Matrix4 view = _camera.LookAt(); @@ -112,10 +106,8 @@ namespace TheLabs 100.0f ); - _cubeObject.Draw(view, projection); - _cubeObject2.Draw(view, projection); - _circleObject.Draw(view, projection); - _cylinderObject.Draw(view, projection); + // --- Draw Scene Objects --- + _bus.DrawBus(view, projection); SwapBuffers(); } diff --git a/TheRepo/TheLabs/Program.cs b/TheRepo/TheLabs/Program.cs index f620bba..d190a72 100644 --- a/TheRepo/TheLabs/Program.cs +++ b/TheRepo/TheLabs/Program.cs @@ -10,7 +10,7 @@ namespace TheLabs { var nativeWindowSettings = new NativeWindowSettings { - Size = new Vector2i(800, 600), + Size = new Vector2i(1920, 1080), Title = "My OpenTK Example Program" }; MyVector myVector = new MyVector(30, 40, 0); diff --git a/TheRepo/TheLabs/RenderObject.cs b/TheRepo/TheLabs/RenderObject.cs index 1ef5d38..21ae1fc 100644 --- a/TheRepo/TheLabs/RenderObject.cs +++ b/TheRepo/TheLabs/RenderObject.cs @@ -11,6 +11,7 @@ public class RenderObject public Texture Texture; public Vector3 Position = Vector3.Zero; + public Matrix4 Transform = Matrix4.Identity; public Quaternion Rotation = Quaternion.Identity; public Vector3 Scale = Vector3.One; diff --git a/TheRepo/TheLabs/Shapes/Bus.cs b/TheRepo/TheLabs/Shapes/Bus.cs new file mode 100644 index 0000000..9cc40f5 --- /dev/null +++ b/TheRepo/TheLabs/Shapes/Bus.cs @@ -0,0 +1,90 @@ +using LearnOpenTK.Common; +using OpenTK.Mathematics; + +namespace TheLabs.Shapes; + +public class Bus +{ + private Mesh _wheelMesh; + private RenderObject _wheelObject; + + private Texture _wheelTexture; + private Shader _wheelShader; + private Texture _bodyTexture; + + public Bus(Texture texture, Shader shader) + { + _wheelTexture = new Texture("Textures/rubber.jpg"); + _wheelShader = shader; + + _bodyTexture = new Texture("Textures/rust.png"); + } + + public void DrawWheel(Matrix4 view, Matrix4 projection, Vector3 position) + { + Matrix4 localTransform = Matrix4.Identity; + //Matrix4 comboTransform = localTransform * _wheelObject.Transform; + + _wheelMesh = ShapeFactory.CreateTexturedCylinder(); + _wheelObject = new RenderObject(_wheelMesh, _wheelShader, _wheelTexture); + + // Front Left Wheel + _wheelObject.Position = new Vector3(position); + _wheelObject.Scale = new Vector3(0.3f, 0.1f, 0.2f); + _wheelObject.Rotation = Quaternion.FromAxisAngle(Vector3.UnitX, MathHelper.DegreesToRadians(90.0f)); + + _wheelObject.Draw(view, projection); + + } + + public void drawBody(Matrix4 view, Matrix4 projection) + { + Mesh bodyMesh = ShapeFactory.CreateTexturedCube(); + RenderObject bodyObject = new RenderObject(bodyMesh, _wheelShader, _bodyTexture); + + bodyObject.Position = new Vector3(0.0f, 0.0f, 0.0f); + bodyObject.Scale = new Vector3(1.5f, 0.5f, 0.5f); + + bodyObject.Draw(view, projection); + } + + private void drawRoof(Matrix4 view, Matrix4 projection) + { + Mesh roofMesh = ShapeFactory.CreateTexturedCylinder(); + RenderObject roofObject = new RenderObject(roofMesh, _wheelShader, _bodyTexture); + + roofObject.Position = new Vector3(0.0f, 0.25f, 0.0f); + roofObject.Scale = new Vector3(0.5f, 1.5f, .25f); + + roofObject.Rotation = Quaternion.FromAxisAngle(Vector3.UnitY, MathHelper.DegreesToRadians(90.0f)); + roofObject.Rotation *= Quaternion.FromAxisAngle(Vector3.UnitX, MathHelper.DegreesToRadians(90.0f)); + + + + roofObject.Draw(view, projection); + } + + public void DrawBus(Matrix4 view, Matrix4 projection) + { + // Drawing 4 wheels + float xOffset = 0.4f; // Reduced to bring wheels closer to the body + float zOffset = 0.28f; // Reduced to bring front and back wheels closer + float yOffset = -0.3f; // Adjusted to ensure wheels touch the body + + // Drawing 4 wheels + for (int i = 0; i < 4; i++) + { + float xPosition = (i % 2 == 0) ? -xOffset : xOffset; // Left or Right + float zPosition = (i < 2) ? zOffset : -zOffset; // Front or Back + + DrawWheel(view, projection, new Vector3(xPosition, yOffset, zPosition)); + } + + // Drawing the body + drawBody(view, projection); + // Drawing the roof + drawRoof(view, projection); + } + + +} \ No newline at end of file