首页 > 解决方案 > 将 2 个数组值添加到一个向量中 c++

问题描述

我有 2 个名为 movePositionsX 和 movePositionY 的数组,就像这样

int movePositionsX[5] = { 1080 , 720 , 160 , 240 , 640};
int movePositionsY[5] = { 720 , 360 , 520, 860 , 164};

我有一个随机获取两个数组上的随机位置之一,我想将它们都放入 1 vector2 我该怎么做?

这是向量2

vector<int> combine;

到目前为止我有这段代码,但它给出了一个错误'没有匹配的函数调用 std::vector::insert(, int&, int&, float&)'

circleObjectArray[i].setPosition(Interpolate(circleObjectArray[i].getPosition(),combine.insert(combine.end,movePositionsX[rand() % 5], movePositionsY[rand() % 5], factor));

这是我的插值函数

Vector2f Interpolate(
const Vector2f pointA,
const Vector2f pointB,
float factor
) {
if( factor > 1.f )
    factor = 1.f;

else if( factor < 0.f )
    factor = 0.f;

return pointA + (pointB - pointA) * factor;
}

如何将数组的两个值组合成 1 个 vector2 以在此函数中使用它?

谢谢你的时间:D

标签: c++arraysvector

解决方案


推荐阅读