How to rotate, scale, and translate a matrix all at once in C#?

后端 未结 4 2069
难免孤独
难免孤独 2020-12-31 19:39

Okay, this is something that should be a simple matrix question, but my understanding of matrices is somewhat limited. Here\'s the scenario: I have a 1px by 1px sprite tha

4条回答
  •  -上瘾入骨i
    2020-12-31 19:51

    I just went through the pain of learning matrix transformation, but using XNA.

    I found these articles to be very helpful in understanding what happens. The method calls are very similar in XNA and the theory behind it all should apply to you, even with SlimDX.

    From glancing at your code, I think you should be translating at the start, to the origin, and then translating again at the end, to the final position, though I'm still a little bit of a newbie at this as well.

    The order I would do it in is:

    • Translate to origin
    • Scale
    • Rotate
    • Translate to desired location

    The reason for translating to the origin first is that rotations are based from the origin. Therefore to rotate something about a certain point, place that point on the origin before rotating.

提交回复
热议问题