Skip to main content
GameDev.net gamedev.net
🔒 Locked

STL vector

Started by MagTDK May 26, 2002 at 1:16 PM 3 replies 200+ views
Original Post
MagTDK
MagTDK
I need some help on how to use a stl vector with a type that contains another stl vector. In my code below I have have two questions that I'm confused with.
        
struct Vertex
{

	float X, Y, Z;
	float U, V;

};


struct Frame
{

	std::vector<Vertex> VertexList;

};


// declared in my class header

std::vector<Frame>  Frames;

//////////////////////////////////////////////////////////////////////////////

m_Frames // contains a list of frames and vertices


m_Faces // contains vertex and texture coord indices that make up face


m_TextureCoord // contains texture coord

//////////////////////////////////////////////////////////////////////////////


void CMesh::VertexList()

	Vertex	TempVert;

	// for each frame

	for (int i = 0; i < NumFrames; i++) {

		// for each face

		for (int j = 0; j < NumFaces; j++) {

			// for each vertex

			for (int k = 0; k < 3; k++) {

				// copy over to TempVert

				TempVert.X = m_Frames[i].Vertex[m_Faces[j].VertexIndex[k]].X;
				TempVert.Z = m_Frames[i].Vertex[m_Faces[j].VertexIndex[k]].Y;
				TempVert.Y = m_Frames[i].Vertex[m_Faces[j].VertexIndex[k]].Z;

				// copy texture coordinates over.

				TempVert.U = m_TextureCoord[m_Faces[j].TextureIndex[k]].U;
				TempVert.V = m_TextureCoord[m_Faces[j].TextureIndex[k]].V;

				// set vertex color

				TempVert.Color = D3DCOLOR_XRGB (255, 255, 255);

				// *** after i copy over the vertex data into TempVert, i want to use the vector 

				// *** push_back method to add the vertex to this m_Frames list

				????????.push_back(TempVert);	// This is were I'm confused


			}

		}

		// *** after i have collected all the vertices for this frame, I want to add the list of 

		// *** vertices to this frame

		??????.push_back(?????????);	// This is were I'm confused

	}

}
    
[edited by - MagTDK on May 26, 2002 2:59:01 PM]
MagTDK
MagTDK

hehe...I really screwed that up I typed that in from memory because I''m not at my computer were I have the actual code. I think it''s fixed now, thanks for pointing out those errors. Can you have another look at it.
Indeterminatus
Indeterminatus
Hey, just a suggestion. If you don''t know how many entries you definitely need, i''ll recommend you not to use a vector, but a list or bsp-tree instead. they are still available in the stl, but work faster in this respect...

yours,

Indeterminatus

--si tacuisses, philosophus mansisses--
Indeterminatus--si tacuisses, philosophus mansisses--

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.