Archived

This topic is now archived and is closed to further replies.

leaves

This topic is 5110 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok i am a beginner in OpenGL but im trying to create a couple of leaves flying around first i created a function for creating a leaf then called it several times. what i want to do now is that every leaf flies around in diffrent directions and undependable on other leaves!? i tried to change every round the glTranslate but it didnt work maybe some kind of AI is needed thx in advance

Share this post


Link to post
Share on other sites
What you need to do is create a class/struct representing a leaf. This will contain information specific to each leaf.

In pseudocode (plus real STL code):
class Leaf{
position;
velocity;
colour;
Leaf(){
position = randomVector();
velocity = randomVector();
colour = randomColour();
}
};

void makeLeaves(int numberOfLeaves, std::vector<Leaf> leaves){
for each leaf {
Leaf l;
leaves.push_back(l);
}
}

void updateLeaves(std::vector<Leaf> leaves){
std::vector<Leaf>::iterator currentLeaf = leaves.begin();
while (currentLeaf != leaves.end()){
currentLeaf->updatePositionAndVelocity();
currentLeaf++;
}
}

void drawLeaves(std::vector<Leaf> leaves){
std::vector<Leaf>::iterator currentLeaf = leaves.begin();
while (currentLeaf != leaves.end()){
currentLeaf->draw();
currentLeaf++;
}
}


Enigma

Share this post


Link to post
Share on other sites