Draw a 2D Curve in XNA

Is there a way to generate a curve class and then draw that curve in 2D on the screen in XNA?

I want to basically randomly generate some terrain using a curve, and then draw it. Hoping that I can use this curve to detect a collision with the ground.

+4
source share
1 answer

It looks like you need the 2D equivalent of a height map. I would avoid making a true “curve” and just approach linear segments.

So basically you will have an array or list of numbers that represent the height of your area at evenly distributed points (horizontally). When you need the height between two points, you simply linearly interpolate between them.

To generate it , you can set several points in random order, and then do some form of smooth interpolation to set the rest. (It really depends on which curve you want.)

To do this , you can simply use the triangle strip. Each point of your height map will have two vertices associated with it - one at the bottom of the screen and the other at the height of that point on the height map.

To make collision detection - the easiest way is to make your objects the only point (it looks like you are making an artillery game like Scorched Earth) - just take the X-position of your object, get the Y-position of your landscape in this position X, if the position Y of your object is below the terrain, set it so that it is on the surface of the terrain.

What a rough guide, anyway :)

+4
source

Source: https://habr.com/ru/post/1316291/


All Articles