Tag: vector

XNA从播放器中查找最近的矢量

我有一个向量列表和一个PlayerVector我只想知道如何在我的列表中找到最接近我的PlayerVector的Vector。 这是我的变量: List Positions; Vector2 Player; 变量已经声明了所有,我只需要一个简单的代码来搜索我的播放器最近的位置。 有没有一个简单的方法?

从c ++到C#的3D矢量结构

我正在尝试将我的引擎中的一些function从c ++移植到C#。 我使用非托管c ++编译我的引擎作为dll,并且只在C#包装器中使用extern“C”函数。 我有各种函数,可以获取并返回Vector3df 。 这被定义为 typedef Vector3d Vector3df; 而f32实际上是一个float 。 该类本身只有一些名为xy和z的成员以及许多方法。 我可以用C#重写整个课程,这不是问题,但无论如何,2可以匹配吗? 我们来举例说明以下函数: extern “C” void SetColor(Vector3df color) extern “C” Vector3df GetColor() 我希望在C#中有这样的东西: [DllImport(“Engine.dll”, EntryPoint = “SetColor”, CallingConvention = CallingConvention.Cdecl)] static extern void SetColor(Vector3df color); [DllImport(“Engine.dll”, EntryPoint = “GetColor”, CallingConvention = CallingConvention.Cdecl)] static extern Vector3df GetColor(); 无论如何,我可以使代码类似于这项工作吗? 请注意,我绝不是C#guru。我在编组方面失败了。 我主要是为了制作我的游戏的地图编辑器而不必学习Qt或wxWidgets。 谢谢!

如何在C#中获取矢量类型?

我想在我正在编写的C#应用​​程序中使用Vectors,然后单独使用Vector3。 如果没有自己编写Vector类型,最好的方法是什么?

c#等价于c ++ vector或deque

我几乎可以肯定这应该是重复但我搜索了一段时间,但找不到答案。 我应该在C#中使用什么来有效地替换C ++ vector和deque。 也就是说,我需要一种能够高效地支持直接索引的结构,并且还支持以有效的方式从一端或两端(取决于向量或双端情况)删除。 在java中,我通常使用ArrayList至少用于向量,但对于C#,我发现这个源声明: ArrayList resizes dynamically. As elements are added, it grows in capacity to accommodate them. It is most often used in older C# programs. ArrayList resizes dynamically. As elements are added, it grows in capacity to accommodate them. It is most often used in older C# programs. 。 那么新的方法是什么? 再次,我该如何处理deque案件?

两个矢量2D之间的角度

我正在尝试计算两个向量之间的角度。 我试过这个,但它总是返回零: public double GetAngle(Vector2 a, Vector2 b) { double angle = Math.Atan2(bY, bX) – Math.Atan2(aY, aX); return angle; } GetAngle(new Vector2(1,1), new Vector2(50,50));

给定边界框和一条线(两个点),确定该线是否与框相交

给定一个边界框,定义如bounds.min.(x/y/z) , bounds.max.(x/y/z) ,以及3D空间中的两个点(表示为Vector3对象),如何确定是否由两点组成的线与边界框相交?

基于鼠标瞄准Unity3d

我正在制作炮弹射击游戏。 这是一个简短的代码,我在计算瞄准方向。 Vector3 mousePos = Input.mousePosition; mousePos.z = thisTransform.position.z – camTransform.position.z; mousePos = mainCamera.ScreenToWorldPoint (mousePos); Vector3 force = mousePos – thisTransform.position; force.z = force.magnitude; 这适用于球和角度(0,0,0)。 但是当角度改变时,我无法向正确的方向射击。 假设球和相机在右侧看45度,相同的代码不起作用。 当前代码假定两者都是角度(0,0,0)。 所以在上面提到的情况下,投掷方向总是错误的。 我想把球扔向任何方向。 但假设它为0角并相应地投掷。

将角度转换为矢量

我正在做一些游戏编程。 FWIW我正在使用XNA,但我怀疑这是否相关。 我想将度数转换为幅度为1的方向向量(即X和Y)。 我的起源(0,0)位于左上角。 所以我想要0度转换为[0,-1] 我认为最好的方法是采用我的North / Up定义并使用矩阵旋转它,但这似乎不起作用。 这是守则…… public class Conversion { public static Vector2 GetDirectionVectorFromDegrees(float Degrees) { Vector2 North= new Vector2(0, -1); float Radians = MathHelper.ToRadians(Degrees); var RotationMatrix = Matrix.CreateRotationZ(Radians); return Vector2.Transform(North, RotationMatrix); } } ……这是我的unit testing…… [TestFixture] public class Turning_Tests { [Test] public void Degrees0_Tests() { Vector2 result = Conversion.GetDirectionVectorFromDegrees(0); Assert.AreEqual(0, result.X); […]

将矢量/数组从非托管C ++传递到C#

我想从非托管C ++传递大约100 – 10,000点到C#。 C ++端看起来像这样: __declspec(dllexport) void detect_targets( char * , int , /* More arguments */ ) { std::vector id_x_y_z; // Now what’s the best way to pass this vector to C# } 现在我的C#端看起来像这样: using System; using System.Runtime.InteropServices; class HelloCpp { [DllImport(“detector.dll”)] public static unsafe extern void detect_targets( string fn , /* More […]