views:

137

answers:

1

Hi,

I am very new to Windows Phone 7. I am writing a sample game in which I want to move the Image randomly.

While discussing with one of my friend, he told me to use Bezier path. I search in the net to understand Bezier path concept. It looks like it will suit for my solution. But I did not found any sample code which will do this.

Please help me to find sample.

+1  A: 

A Bezier path is a valid solution to your problem, but might I suggest using a Catmull-Rom spline instead. It is far eaiser to implement, not least of all because XNA already includes a function for generating such a spline. It is also easier to use (each control point is also a point on the spline).

The function in question is Vector2.CatmullRom (there are also versions for Vector3 and for floats in MathHelper). You specify four points. The middle two of which are valid for your spline. If you need more than two points, simply cycle the inputs as you move (second becomes first, third becomes second, and so on). The amount argument species the position that you want, along the path.

The Catmull-Rom spline is described here on Wikipedia.

And here is an interactive demo showing how the spline works.

Andrew Russell