Sign in to follow this  

Drawing Ball Path using XNA

This topic is 2072 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

hello, I am currently making a golf ball game using C# and XNA.
So far I have been able to make the ball fly, bounce, and roll, while displaying the position and velocity.
Now I want to be able to see the ball path (similar to images below), in order to check the whole ball movement.

![golf ball path]([url="http://www.golf-simulators.com/images/ms4.jpg"]http://www.golf-simu.../images/ms4.jpg[/url])

My code updates the ball position at a fixed time interval. I am thinking of:
1) using these position,
2) insert them to an array of VertexPositionColor[],
3) and draw them using GraphicsDevice.DrawUserPrimitives<VertexPositionColor>() method

but I have no luck so far, the VertexPositionColor is static array, while the amount of position data is always increasing.

I am thinking of using List<VertexPositionColor>, but the GraphicsDevice.DrawUserPrimitives<VertexPositionColor>() method refuse to take that as an input
[CODE]
protected override void Draw(GameTime gameTime) {
trail_vertice = new VertexPositionColor;
trail_vertice.Position = Position;
trail_vertice.Color = Color.Black;
trail_amount += 1;
trailList.Add(trail_vertice);

basicEffect.CurrentTechnique.Passes[0].Apply();
graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineStrip, trailList, 0, trail_amount);
}
[/CODE]

I do not need an advanced effect like using particle engine. Just a single line is enough. Any suggestion?

Thanks in advance

Share this post


Link to post
Share on other sites
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left][background=rgb(250, 251, 252)]List<VertexPositionColor> has a ToArray() function that will convert it to type VertexPositionColor[][/background][/left][/size][/font][/color]
[left]

[font="helvetica, arial, verdana, tahoma, sans-serif"][size="2"][color="#282828"]For the sake of speed though, i'd suggest keeping it as the array to begin with and just set it so its initailised with a predetermined maximum size, eg new VertexPositionColor[256]; [/color][/size][/font][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=1]If you go to add more verticies, and the array is full, then you can start treating it like a ring/circle buffer and forget the oldest points.[/size][/font][/color][/left]

Share this post


Link to post
Share on other sites

This topic is 2072 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this