I have a C++ script with a struct object 'Particle' , with x, y ,z position stored. I create several particle objects with unique ID's. How do I get the position of a particle by ID? Something like: particle.getPosByID(int ID);
My code is as follows:
struct Particle {
Vector position { 0.0f, 0.0f, 0.0f };
Vector velocity { 0.0f, 0.0f, 0.0f };
Vector acceleration { 0.0f, 0.0f, 0.0f};
Vector color { 1.0f, 0.0f, 0.0f }; // RED
int ID = 0;}
I've tried within the struct:
float getPosX(int ID)
{
return this->position.x;
}
with:float ix = particles->getPosX(5);
but no luck. Any ideas? Would I need a class with getters? If so, how do I go about that? Struct has been good and easy to use so far...
Thanks!
EDITED
Vector is a struct:
struct Vector
{
float x, y, z;}
Particles are stored using an array:
const int MaxParticles = 5;
Particle particles[MaxParticles];
Particles? - NathanOliverVectorimplemented? Could you please add it to the problem? - Sumit Jha