• Advertisement
Sign in to follow this  

[XNA] Drawing a spline of arbitrary length.

This topic is 2778 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi folks,

I'm trying to figure out a good way of drawing a spline of arbitrary length.

Currently I generate all the indices at load time:


static readonly ushort[] splineIndices = GenerateSplineIndices();

private static ushort[] GenerateSplineIndices()
{
ushort[] indices = new ushort[MAXINDICES];
int j = 0;

for (ushort i = 0; i < MAXINDICES / 2; ++i)
{
indices[j++] = i;
indices[j++] = (ushort)(i + 1);
}

return indices;
}



The indices are then chopped to fit the size of the spline as follows:


public void DrawSpline(Vector3[] interpolatedPoints, Color color)
{
ushort[] indices = new ushort[interpolatedPoints.Length * 2];
int numIndices = indices.Length - 1;

for (int i = 0; i < numIndices; ++i)
{
indices = splineIndices;
}

indices[numIndices] = indices[numIndices - 1];

DrawWireShape(interpolatedPoints, indices, color);
}



Currently I am not happy that I have to copy each value over to a new array each time I wish to draw the spline.

Unfortunately this has to be case because I must have a degenerate index at the end of the array in order to stop the end point linking up with the next shape drawn.

Can anyone suggest where improvements could be made and how I could avoid this?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement