private void CreateInternalGearScene() { this.speed = 0.05f; var radiusMax = InvoluteGearShape.RadiusMax(150, DiametralPitch, GearType.Internal); var shape = new InvoluteGearShape(150, DiametralPitch, radiusMax + 1.0f, this.PressureAngle, GearType.Internal); var gear = new Gear(shape, this.GetRandomNamedColor()); this.Gears.Add(gear); var axleRadius = InvoluteGearShape.RadiusMin(5, DiametralPitch, GearType.External) - 0.035f; var shape2 = new InvoluteGearShape(100, DiametralPitch, axleRadius, this.PressureAngle); var gear2 = new Gear(shape2, this.GetRandomNamedColor()); this.Gears.Add(gear2); gear.AddChild(gear2, 0.0f); var shape3 = new InvoluteGearShape(38, DiametralPitch, axleRadius, this.PressureAngle); var gear3 = new Gear(shape3, this.GetRandomNamedColor()); this.Gears.Add(gear3); gear2.AddChild(gear3, MathHelper.Pi + 0.5f); var shape4 = new InvoluteGearShape(5, DiametralPitch, axleRadius, this.PressureAngle); var gear4 = new Gear(shape4, this.GetRandomNamedColor()); this.Gears.Add(gear4); gear3.AddChild(gear4, 1.9f); }
public Gear(InvoluteGearShape shape, Color color) { this.Shape = shape; this.Children = new List <GearConnection>(0); //this.Visualization = new LineVisualization(shape, color); this.Visualization = new TriangleVisualization(shape, color); }
public LineVisualization(InvoluteGearShape shape, Color color) { this.Vertices = new VertexPositionColor[shape.Outline.Count + CirclePoints]; this.Indices = new short[(shape.Outline.Count + CirclePoints) * 2]; this.CreateLineList(color, shape.Outline, 0, 0); this.CreateLineList(color, CreateCircle(CirclePoints, shape.AxleRadius), shape.Outline.Count, shape.Outline.Count * 2); }
public TriangleVisualization(InvoluteGearShape shape, Color color) { var vertices = new List <VertexPositionColor>(); var indices = new List <int>(); var outline = shape.Outline; var ii = 0; for (var i = 0; i < outline.Count; i++) { var current = new Vector3(outline[i].X, outline[i].Y, 0); var next = new Vector3(outline[(i + 1) % outline.Count].X, outline[(i + 1) % outline.Count].Y, 0); var altCurrent = Vector3.Normalize(new Vector3(current.X, current.Y, 0)) * shape.AxleRadius; var altNext = Vector3.Normalize(new Vector3(next.X, next.Y, 0)) * shape.AxleRadius; { var a = new VertexPositionColor(current, color); var b = new VertexPositionColor(altCurrent, color); var c = new VertexPositionColor(altNext, color); vertices.Add(a); vertices.Add(b); vertices.Add(c); } { var a = new VertexPositionColor(current, color); var b = new VertexPositionColor(altNext, color); var c = new VertexPositionColor(next, color); vertices.Add(a); vertices.Add(b); vertices.Add(c); } if (shape.GearType == GearType.Internal) { indices.Add(ii++); indices.Add(ii++); indices.Add(ii++); indices.Add(ii++); indices.Add(ii++); indices.Add(ii++); } // To prevent counter clockwise faces from being culled we have to reverse the triangle order for external gears else { indices.Add(ii + 5); indices.Add(ii + 4); indices.Add(ii + 3); indices.Add(ii + 2); indices.Add(ii + 1); indices.Add(ii + 0); ii += 6; } } this.Vertices = vertices.ToArray(); this.Indices = indices.ToArray(); }