Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

re. Using Vectors Issue could anyone help ?

Status
Not open for further replies.

DGEN

Programmer
Oct 29, 2004
17
GB
Hi all
I am a bit of a learner in C++ what i need to know is how to read a vector without having to put a number in square braces.

I am making a program using an engine called Irrlicht to develop the application (RPG Builder 3D) and I use the mouse pointer to select a node (model) and repaint it but i only want it to paint the nodes[] vector and not anything else

IMeshSceneNode<Vector>* Nodes;

For (i=1024*4*3 ; i<1024 ; i++)
{
nodes.PushBack(i); //etc etc
}

for example (this is not the official code but it is simular)

so there are over 900 nodes in total nodes[900] - how do i get the program to look for the nodes[] Vector without me having to specify a node for it to check

if ( SelectedSceneNode == nodes[#] && SelectedSceneNode != Models[#]){ a += 1;} for example

if it is possible can you help me please.

Cheers
 
1. Use CODE tag to present your snippets (see Process TGML link on the form). Please, don't present unofficial code like this above: it's not the C++ and it's not some reasonable pseudocode.
2. Is it std::vector using issue? If so:
Code:
vector<NodeClass> nodes;
...
for (...)
{
   nodes.push_back(Node class object reference/* not an index!*/);
}
and so on. Why to read a vector without having to put a number in square braces?

Try to reformulate your true problem, please.
I'm afraid nobody can help you in that woolly style context.
 
Hi again

Ok I appologise for being so vague earlier below is the official code for the sections that i stated

Code:
 if (selectedSceneNode != 0 && selectedSceneNode != nodes[900])
{
selectedSceneNode->setMaterialTexture( 0, driver->getTexture(TilePic[T]) );
}

where i have selectedSceneNode != nodes[900] this is the code that i would like help on i do not want to have to put a number in here something like selectedSceneNode == nodes[#]

is there a possibility of doing something with this

also is it something to do with the below code that features earlier in the solution

Code:
IAnimatedMesh* mesh = smgr->getMesh("Objects/floor.dmf");
vector<IAnimatedMeshSceneNode*> nodes; 

// Creating five of them: 
for (int Boxes = -Ammountofblocks*Ammountofblocks*1024*3; Boxes < 1024*Ammountofblocks*Ammountofblocks; Boxes+=1024) 
{ 
   nodes.push_back(smgr->addAnimatedMeshSceneNode(mesh)); 
} 

// Initialise the created nodes 

for (size_t i = 0; i < nodes.size(); ++i) 

{ 
 if (AblocksLine >= Ammountofblocks*1024) {Ablocksdown +=  1024;AblocksLine =-Ammountofblocks*1024;}
      nodes[i]->setMaterialFlag(EMF_LIGHTING, false); 
      nodes[i]->setMaterialTexture( 0, driver->getTexture(TilePic[T]));

      nodes[i]->setPosition(vector3df(AblocksLine,0,Ablocksdown)); 
  nodes[i]->setMaterialFlag(EMF_FOG_ENABLE,true);
AblocksLine +=1024;
//nodes[i]->setDebugDataVisible(true);
Tempy[i]=Ablocksdown ;
Tempx[i]=AblocksLine-1024;

//ISceneNode* selectedSceneNode = smgr->getSceneCollisionManager()->getSceneNodeFromScreenCoordinatesBB(getPosition()); 

}
 
I'm still not sure exactly what you're asking, but if you don't want to specify a number in the braces, you can use an iterator. Ex:
Code:
vector<int> nums;

for ( int i = 0; i < 10; ++i )
{
   nums.push_back(i);
}

for ( vector<int>::iterator it = nums.begin(); it != nums.end(); ++it )
{
   cout << *it << endl;
}
 
Hi again

Ok what you are saying is for me to use an iterator when i first place the nodes into my scene is this correct?

will this then allow me to not need to enter a number into the if statement later where the array is mentioned?

so i would be able to use the vector and get the software to know that i am looking at the array as a group and not just a single node. could it be possible to elaborate on this a bit as i dont really understand what it is this code will do, though i will try it anyway.

Thank you for your help

Cheers
 
Use push_back() to add new elements to the end of the vector. Then you can use an iterator to read through all the elements of the vector and/or change existing element values.
If you want to treat the vector as one big array, you can do this:
Code:
void SomeFunction( node*  pNodes )
{
   // Do whatever you want with pNodes.
}

int main()
{
   vector<node> nodes;
   ...
   SomeFunction( nodes[0] );  // Pass the whole array to the function.
   ...
}
 
Oops, I forgot to take the address of nodes[0] when passing to the function:
Code:
SomeFunction( &nodes[0] );
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top