English 中文(简体)
2. 围绕核心矢量点对物体进行轮换
原标题:Rotation of an object around a central vector2 point

我首先要谈谈这一点,我不是在数人附近。 在另一个问题中发现的代码I似乎有些发挥作用......但造成目标I的位置在大圈中轮换,大多在屏幕上。

该法典:

public void Update(GameTime gameTime)
{
    Location = RotateAboutOrigin(Center, Origin, 0.01f);
}

public Vector2 RotateAboutOrigin(Vector2 point, Vector2 origin, float rotation)
{
    var u = point - origin; //point relative to origin  

    if (u == Vector2.Zero)
         return point;

    var a = (float)Math.Atan2(u.Y, u.X); //angle relative to origin  
    a += rotation; //rotate  

    //u is now the new point relative to origin  
    u = u.Length() * new Vector2((float)Math.Cos(a), (float)Math.Sin(a));
    return u + origin;
} 

位置由在中央矢量周围任意位置的 mo点确定。

在我点击时,中心是物体I所在地的(主人)中心。 它只是区分案文的高度和宽度。

起源是矢量2 ,我正试图轮流。 它固定在384 384处。


As best I can tell, it s getting the distance between the two vectors and then using atan2 to determine the angle. The rest afterward is a mystery to me. I m aware that I should learn what everything does, and I do intend to when I go to college(only a decade late) starting in the spring. I ve tried reading up on them, but I m lost. Any help would be appreciated.

而且,如果你对贵方建议的地点有好的三点,我将乐于阅读。

最佳回答

这里可以选择:

public Vector2 RotateAboutOrigin(Vector2 point, Vector2 origin, float rotation)
{
    return Vector2.Transform(point - origin, Matrix.CreateRotationZ(rotation)) + origin;
} 

它的确是“向世界过渡,轮流,然后又转回”轨道。

This rotates point around origin by rotation radians regardless of where origin is relative to the world origin. The trig happens in the CreateRotationZ() built in function. To see how it applies the trig, reflect that method in the framework.

Edit: 固定变量名称

问题回答

使用矩阵比较容易,尽管基本理论可能难以理解,但你并不真正需要知道所有使用这种理论(尽管在巨头和所有方面)。

1. 传承媒介:

Vector2.Transform(PosComponent.Direction, Matrix.CreateRotationZ(-0.1f))

在<代码>PosComponent.Direction 是我的矢量,-0.1f 是它想要由(在rad而不是学位)轮流使用的数量。

Since you want to rotate a vector around something other than the origin you ll need to move the vector first, then rotate, then move it back. That s basically what you re code above is doing, except to get the angle and do the rotation it s using trig.

Do do a rotation:

  1. You get the point relative to the origin (as in your code),
  2. then rotate either
    • using trig to get the angle, manipulate it then recalculate the vector (as in your code),
    • or using matricies (as in my code).
  3. Finally move the vector back (as in your code).

这个问题和我的回答在理解三点时可能有一些用处:。 鉴于角角,在环绕上点的位置?





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签