Cocos2d-x 计算两个点之间的距离
在 Cocos2d-x 中,可以使用 'Vec2' 类来表示二维坐标点,并且提供了一个静态方法 'distance' 来计算两个点之间的距离。以下是一个示例代码:
#include "cocos2d.h"
USING_NS_CC;
int main(int argc, char** argv)
{
// 创建两个点
Vec2 point1(0, 0);
Vec2 point2(3, 4);
// 计算两个点之间的距离
float distance = Vec2::distance(point1, point2);
// 输出距离
printf("Distance between point1 and point2: %.2f\n", distance);
return 0;
}
在上述代码中,我们首先创建了两个点 'point1' 和 'point2',然后使用 'Vec2::distance' 方法计算了这两个点之间的距离,并将结果保存在 'distance' 变量中。最后,我们使用 'printf' 函数输出了这个距离值。
原文地址: https://www.cveoy.top/t/topic/zcW 著作权归作者所有。请勿转载和采集!