XNA Creators Club Online
Page 1 of 1 (3 items)
Sort Posts: Previous Next

Rotation headache.

Last post 5/15/2008 7:17 PM by JohnWestMinor. 2 replies.
  • 5/15/2008 6:04 PM

    Rotation headache.

    Using the formulae
    x'=x\cos\theta-y\sin\theta\,y'=+x\sin\theta+y\cos\theta\,which I found on Wikipedia, I have written this:

    rotdist2 = new Vector4(
    rotdist.X * (float)Math.Cos(radian) - rotdist.Y * (float)Math.Sin(radian)
    , rotdist.Y * (float)Math.Cos(radian) + rotdist.X * (float)Math.Sin(radian)

    , rotdist.Z * (float)Math.Cos(radian) - rotdist.W * (float)Math.Sin(radian)
    , rotdist.Z * (float)Math.Cos(radian) + rotdist.W * (float)Math.Sin(radian)
    );


    However, when I try to rotate my points (X,Y) and (Z,W) (and the subsequent lines I'm drawing between them) it all goes crazy.

    Did I do the formula correct? I can't see how I didn't.
  • 5/15/2008 6:49 PM In reply to

    Re: Rotation headache.

    It looks like the last line:

    , rotdist.Z * (float)Math.Cos(radian) + rotdist.W * (float)Math.Sin(radian)

    should be:

    , rotdist.W * (float)Math.Cos(radian) + rotdist.Z * (float)Math.Sin(radian)

    But why are you packing these into a 4D Vector and writing out the rotations manually? It could just be something like:

    Vector2 point1, point2;

    Matrix rotMatrix = Matrix.CreateRotationZ(radians);

    point1 = Vector2.Transform(point1, rotMatrix);
    point2 = Vector2.Transform(point2, rotMatrix);

    Where Matrix.CreateRotationZ is building the same rotation you just described and is used to transform both points.

    Good luck!
  • 5/15/2008 7:17 PM In reply to

    Re: Rotation headache.

    Thanks, that fixed it. And I'm going to switch over to transformation matrices now, I just didn't know how to use them.
Page 1 of 1 (3 items) Previous Next