75 lines
2.6 KiB
C#

using LearnOpenTK.Common;
using OpenTK.Mathematics;
namespace TheLabs.Shapes;
public class Bus
{
public SceneNode MainNode;
private Mesh _wheelMesh;
private Mesh _bodyMesh;
private Mesh _roofMesh;
public Bus(Texture wheelTexture,Texture bodyTexture, Shader shader)
{
_wheelMesh = ShapeFactory.CreateTexturedCylinder();
_bodyMesh = ShapeFactory.CreateTexturedCube();
_roofMesh = ShapeFactory.CreateTexturedCylinder();
MainNode = new SceneNode();
// Building the body
var bodyObj = new RenderObject(_bodyMesh, shader, bodyTexture);
var bodyNode = new SceneNode(bodyObj);
bodyNode.Scale = new Vector3(1.5f, 0.5f, 0.5f);
bodyNode.Scale = new Vector3(0.0f, 0.0f, 0.0f);
MainNode.AddChild(bodyNode);
// Building the body
var roofObj = new RenderObject(_roofMesh, shader, bodyTexture);
var roofNode = new SceneNode(roofObj);
roofNode.Position = new Vector3(0.0f, 0.25f, 0.0f);
roofNode.Scale = new Vector3(0.5f, 1.5f, .25f);
roofNode.Rotation = Quaternion.FromAxisAngle(Vector3.UnitY, MathHelper.DegreesToRadians(90.0f));
roofNode.Rotation *= Quaternion.FromAxisAngle(Vector3.UnitX, MathHelper.DegreesToRadians(90.0f));
MainNode.AddChild(roofNode);
// Building the 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
Vector3[] wheelPositions =
{
new Vector3(-xOffset, yOffset, zOffset), // Front Left
new Vector3(xOffset, yOffset, zOffset), // Front Right
new Vector3(-xOffset, yOffset, -zOffset), // Back Left
new Vector3(xOffset, yOffset, -zOffset) // Back Right
};
foreach (var pos in wheelPositions)
{
//var wheelObj = new RenderObject(_wheelMesh, shader, wheelTexture);
var wheelNode = new SceneNode(wheelObj);
wheelNode.Position = pos; // Relative to the MainNode!
wheelNode.Scale = new Vector3(0.3f, 0.1f, 0.2f);
// Rotate cylinder to act like a wheel
wheelNode.Rotation = Quaternion.FromAxisAngle(Vector3.UnitX, MathHelper.DegreesToRadians(90.0f));
MainNode.AddChild(wheelNode);
}
}
public void Draw(Matrix4 view, Matrix4 projection)
{
//MainNode.Draw(view, projection, Matrix4.Identity);
}
}