Jump to content

View more

Image of the Day

#ld38 #screenshotsaturday Mimosa Fizz action gif #2 https://t.co/TUzdppvfUL
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Drawing Ball Path using XNA

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 Bonchenko   Members   

105
Like
0Likes
Like

Posted 14 May 2012 - 10:48 PM

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](http://www.golf-simu.../images/ms4.jpg)

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
  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);
	    }

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

Thanks in advance

#2 Digitalfragment   Members   

1487
Like
1Likes
Like

Posted 14 May 2012 - 11:46 PM

List<VertexPositionColor> has a ToArray() function that will convert it to type VertexPositionColor[]




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]; 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.



#3 Bonchenko   Members   

105
Like
0Likes
Like

Posted 15 May 2012 - 01:25 AM

Whoa, thanks for the hint. That solves the problem




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.