简体   繁体   English

Vector2在C ++中是否等效?

[英]Vector2 equivalent in c++?

Hi I'm porting my game from c#/xna to c++/cocos2d-x and I was trying to find an equivalent to Vector2. 嗨,我正在将我的游戏从c#/ xna移植到c ++ / cocos2d-x,我试图找到与Vector2等效的游戏。 I did find a couple such as b2Vec2, I'm just not sure which one I should use because I need it to be cross platform and not bound to a specific operating system. 我确实找到了一对,例如b2Vec2,但我不确定应该使用哪个,因为我需要它是跨平台的并且不绑定到特定的操作系统。

The class you're looking for is the poorly-named* CCPoint class. 您要查找的类是名称不佳的CCPoint类。 Cocos2d-x is a direct port of the API of Cocos2d, which was designed for Objective C. And since Objective C doesn't have operator overloading, neither does Cocos2d-x, even though it's written in C++ where operator overloading exists. Cocos2d-x是为目标C设计的Cocos2d API的直接端口。由于目标C没有运算符重载,即使Cocos2d-x也没有用运算符重载的C ++编写,也没有。 So you have to use free-functions to do vector operations . 因此,您必须使用自由函数进行矢量运算

*: In case you're wondering why it is poorly named, "vector" covers the concept of "point" (a position within a space) and "direction" (a direction in a space). *:如果您想知道为什么它的名字不好,“矢量”涵盖了“点”(空间中的位置)和“方向”(空间中的方向)的概念。 A vector can be either of these. 向量可以是任何一个。 Adding vectors has a specific meaning geometrically, as does subtracting them, multiplying them, taking the length, etc. Adding a point to another point is nonsense, geometrically. 向量的添加在几何上具有特定的含义,将它们相减,相乘,取长度等也是如此。在几何上,将一个点添加到另一个点是无意义的。 You can only add vector directions , not positions. 您只能添加矢量方向 ,而不能添加位置。 You can transform positions into another space, but you don't do that by adding one position to another. 您可以将位置变换到另一个空间,但不能通过将一个位置添加到另一个空间来实现。

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

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