/// <summary> /// Return a list of points forming a circle. /// onPlane, X = Vertical, Y = Horizontal, Z = the other /// </summary> /// <param name="sides">The more sides the smoother the circle will appear</param> /// <param name="colour">The colour e.g. Color.White or Color.Red</param> public VertexPositionColor[] GetCircle(float radius, int sides, Color colour, Vector3 centre, string onPlane) { int points = sides + 1; VertexPositionColor[] pointList = new VertexPositionColor[points]; // This function creates a circle so the maxArc is always 2PI (360 degrees) float maxArc = 2 * (float)Math.PI; // in Radians float fStep = maxArc / (float)sides; float fAngle = 0; for (int i = 0; i < sides; i++) { if (onPlane == "X") { // X plane Vertical forward pointList[i] = new VertexPositionColor( new Vector3(centre.X, ((float)Math.Sin(fAngle) * radius) + centre.Y, ((float)Math.Cos(fAngle) * radius) + centre.Z), colour); } else if (onPlane == "Y") { // Y plane Horizontal pointList[i] = new VertexPositionColor( new Vector3(((float)Math.Sin(fAngle) * radius) + centre.X, centre.Y, ((float)Math.Cos(fAngle) * radius) + centre.Z), colour); } else { // Z plane Vertical side pointList[i] = new VertexPositionColor( new Vector3(((float)Math.Sin(fAngle) * radius) + centre.X, ((float)Math.Cos(fAngle) * radius) + centre.Y, centre.Z), colour); } // Move the point round by a segment of the circle fAngle += fStep; } // Make sure the circle is complete the last point is the same as the first pointList[sides] = pointList[0]; return(pointList); }
/// <summary> /// Return a list of points forming a vertical cylinder with only one edge /// </summary> /// <param name="radius">Radius</param> /// <param name="hight">Height</param> /// <param name="sides">The sides of the top and bottom circles /// the more sides the smoother the circles will appear</param> /// <param name="colour">The colour e.g. Color.White or Color.Red</param> public VertexPositionColor[] GetCylinder(float radius, float height, int sides, Color colour) { // 2 circles and a line down one side int points = (sides + 1) * 2; VertexPositionColor[] pointList = new VertexPositionColor[points]; VertexPositionColor[] circleList = GetCircle(1.0f, sides, Color.Red, Vector3.Zero, "Y"); for (int i = 0; i < circleList.Length; i++) { // Add the top and bottom circles at the same time pointList[i] = circleList[i]; pointList[i + circleList.Length] = circleList[i]; pointList[i + circleList.Length].Position.Y += height; } // Make sure the circle is complete the last point is the same as the first return(pointList); }