パーティクルシステムを作成しようとしていて、パーティクルオブジェクトを作成して後で使用するためにベクターに格納する必要があります。それを行う 機能は次のとおりです。オブジェクトを作成してベクトルに格納すると値が失われる
void spawnLoop(std::vector<Particle*> &particleVector){
for (int i=0; i < 5; i++) {
particleVector.emplace_back(new Particle(400.0, 400.0, 1.0, 1.0));
}
}
粒子クラスのコンストラクタは次のようになります。
Particle::Particle(float xPos= 400,float yPos= 400,float xVel= 0,float yVel= 0) {
float xPosition = xPos;
float yPosition = yPos;
float xVelocity = xVel;
float yVelocity = yVel;
bool dead = false;
std::cout<< "We have " << xPosition << " "<< yPosition << " "<< xVelocity << " "<< yVelocity << std::endl;
//This prints the values and they look correct
}
しかし、私は、私はそれを格納するために完了し、正確後にベクトルをループしようとした場合、それは私を与えます値は、1.81063e + 13となります。 私はそれをかなり研究してみましたが、それに対する解決策は見つかりませんでした。 EDIT:
void loopOver(std::vector<Particle*> const vec){
for (auto i = vec.begin(); i != vec.end(); i++){
std::cout << "avem " << (*i)->getXPos() << " " << (*i)->getYPos() << std::endl;
}
}
それはあなたに起こっていないのでしょうか? – StoryTeller
'std :: vector>'のように、 'std :: vector 'の使い方に疑問を持たせる必要があります。 'std :: vector ' –
UnholySheep
なぜそのベクトルにポインタを格納する必要がありますか?単にそこに普通の 'Particle'インスタンスを格納することはできませんか? – user0042