manual->convertToMesh("BladesOfGrass");
for
loops:for(int i=0;i<50;i++) { for(int j=0;j<50;j++) {
for
loops, create a nameless entity and a nameless scene node:Ogre::Entity * ent = mSceneMgr->createEntity("BladesOfGrass"); Ogre::SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(i*3,-10,j*3)); node->attachObject(ent);
for
loops:} }
In step 1, we used a new function from a manual object which converts the manual object into a mesh we can instantiate using the createEntity()
function of the scene manager. To be able to use the new entity, we need a name that will be used later as a parameter for the createEntity()
function. We used BladesOfGrass
as a descriptive name. We want several instances of our grass, so we created two for
loops in step 2, each running 50 times. Step 3 added the body of the for
loop. In the body we first created a new entity using the mesh name we just created. An observant reader might notice that we didn't use the createEntity()function
with two parameters one for the entity type and one for the name we want this entity to have. This time, we only gave the entity type as a parameter, not a name. But didn't we have to always give a name to an entity because each entity needs a unique name? This is still true; the function we called is just a helper function, which only needs an entity type name because it generates a unique name and then calls the function we always called. It just saves us the trouble of appending the for
loop variables to a generic name like BladesOfGrassEntity
. We used the same kind of function for scene node creation.
3.144.30.75