Converting this small chunck to c++

Alright this is from a tutorial I did a long time ago in C#.

1
2
3
4
5
6
7
8
9
10
11
12
foreach (GameObject ball in cannonBalls)
{
    if (!ball.alive)
    {
        ball.alive = true;
        ball.position = cannon.position - ball.center;
        ball.velocity = new Vector2(
            (float)Math.Cos(cannon.rotation),
            (float)Math.Sin(cannon.rotation)) * 5.0f;
        return;
    }
}


I'm just wondering how I can make the velocity = the cos and sin angle how it does in this c# example.

So main thing I'm trying to figure out how to do is something in the lines of Vector2(..) but in C#

Cheers,
Myth.
Do you mean something like this?
1
2
3
4
5
6
7
8
9
struct Vector2
{
    double x,y;
    Vector2 ( double X, double Y ) : x ( X ), y ( Y ) {}
};

//...

ball.velocity = Vector2 ( cos ( cannon.rotation ), sin ( cannon.rotation ) * 5.0 );
Awesome - thanks bazzy.
Topic archived. No new replies allowed.