简体   繁体   English

C#的Vector3是否有标准的C ++等价物?

[英]Is there a standard C++ equivalent of C#'s Vector3?

Just wondering if C++ has a standard equivalent of the Vector2/3/4 (structures I think?) in C#? 只是想知道C ++在C#中是否有标准的Vector2 / 3/4(我认为的结构?)?

Edit: For clarification a XNA C# Vector2/3/4 "structures" (I'm not entirely sure what they are) basically hold 2, 3, or 4 float values like a struct in C++ defined as: 编辑:为了澄清一个XNA C#Vector2 / 3/4“结构”(我不完全确定它们是什么)基本上保存2,3或4个浮点值,如C ++中的结构定义为:

struct Vector3
{
    float x, y, z;
};

I've been basically using just that code in C++, but I was hoping for a standard alternative and was unable to find one. 我基本上一直在使用C ++中的代码,但我希望有一个标准的替代方案而无法找到它。

The Vector3 struct in C# is from XNA, not the base class libraries. C#中的Vector3结构来自XNA,而不是基类库。

The equivelent in C++ would be to use XMFLOAT3 . C ++中的equivelent将使用XMFLOAT3

Nothing standard that I know of, but here's some code to get you started 没有什么标准我知道,但这里有一些代码可以帮助你入门

http://www.flipcode.com/archives/Faster_Vector_Math_Using_Templates.shtml http://www.flipcode.com/archives/Faster_Vector_Math_Using_Templates.shtml

If you are using C++/CLI and targeting Windows and .NET, you can use Vector2, etc. 如果您使用的是C ++ / CLI并且目标是Windows和.NET,则可以使用Vector2等。

Though there's no equivalent to Vector3 in standard C++, there are several linear algebra libraries that have one. 虽然在标准 C ++中没有与Vector3相同的东西,但有几个线性代数库都有一个。 Some that are very small and fast: 一些非常小而快:

A valarray<complex<T>> could be used like a Vector2 in many cases. 在许多情况下, valarray<complex<T>>可以像Vector2一样使用。 For Vector3/4 I know no standard equivalent. 对于Vector3/4我知道没有标准的等价物。

I don't believe that there are any "canned" objects in C++ which are equivalent. 我不相信C ++中有任何“罐装”对象是等价的。 The STL vector is not the same thing. STL vector不是一回事。 That is essentially a dynamic array for storage of any value types whereas the vector that you're referring to is class with added member functionality, typically seen used in XNA graphic applications (in my experience at least). 这本质上是一个用于存储任何值类型的动态数组,而您引用的向量是具有添加成员功能的类,通常在XNA图形应用程序中使用(至少在我的经验中)。 You are on to something with your recognition of the fact that Vector2/3/4 are data structures. 您认识到Vector2 / 3/4是数据结构这一事实。 You could very easily store the values of the W, X, Y, Z components in your own structure, but the added member functions provided with the Vector2/3/4 object would need to be added by you. 您可以非常轻松地将W,X,Y,Z组件的值存储在您自己的结构中,但是需要添加随Vector2 / 3/4对象提供的添加的成员函数。

There are also several C++ 3D graphics libraries similar to XNA, such as Ogre3D , Irrlicht , and others. 还有一些类似于XNA的C ++ 3D图形库,例如Ogre3DIrrlicht等。 Might be a bit of an overkill if you only need the Vector3 structure though. 如果你只需要Vector3结构,可能会有点矫枉过正。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM