gpt4 book ai didi

c# - 如何旋转 Vector2?

转载 作者:行者123 更新时间:2023-11-30 19:20:39 24 4
gpt4 key购买 nike


我正在尝试旋转 Vector2 但没有任何效果。
我尝试了以下 -> 没有用:

x' = cos(angle)*x - sin(angle)*y & y' = sin(angle)*x + cos(angle)*y

我试过使用旋转矩阵 -> 没用

我做错了什么? :/

angle = MathHelper.Pi;
direction.X = (int)((direction.X) * Math.Cos(angle) - direction.Y * Math.Sin(angle));
direction.Y = (int)((direction.X) * Math.Sin(angle) + direction.Y * Math.Cos(angle));

float angle = MathHelper.PiOver2;
Vector2 dir = new Vector2(direction.X, direction.Y);
Vector2.Transform(dir, Matrix.CreateRotationX(angle));
direction = new Point((int)dir.X, (int)dir.Y);

最佳答案

Vector2.Transform()返回结果而不是就地应用更改。

var transformed = Vector2.Transform(dir, Matrix.CreateRotationX(angle));
direction = new Point((int) dir.X, (int) dir.Y);

关于c# - 如何旋转 Vector2?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5510512/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com