Jump to content
  • Advertisement

Archived

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

uber_n00b

Quick question about if's

This topic is 5284 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 this question specifically concerns DigiBen''s Octree class (gametutorials.com octree2 program). In his program when he creates a new node, the function looks like this:
oid COctree::CreateNewNode(CPoly *pPoly, vector<bool> pList, int numberOfVerts,
					  	    CVector3 vCenter,	 float width,        int triangleCount, int nodeID)
{
	if(triangleCount)		
	{
		CPoly *pNodeVertices = new CPoly [triangleCount];
		int index = 0;
		for(int i = 0; i < numberOfVerts; i++)
		{
			if(pList[i])	
			{
				pNodeVertices[index] = pPoly[i];
				index++;
			}
		}
		m_pOctreeNodes[nodeID] = new COctree;
		CVector3 vNodeCenter = GetNewNodeCenter(vCenter, width, nodeID);
		g_CurrentSubdivision++;
		m_pOctreeNodes[nodeID]->CreateNode(pNodeVertices, triangleCount, vNodeCenter, width / 2);
		g_CurrentSubdivision--;
		delete [] pNodeVertices;
	}
}
What does the first if statement actually prove true for? It seems a bit weird to me because I would have thought it only returns true for triangleCount = 1, but he seems to act like it works for values above 1 as well. triangleCount is the intended amount of triangles to put into one node.

Share this post


Link to post
Share on other sites
Advertisement
In C++, every non-zero value evaluates to true (including negitives). So if(triangleCount) will return true if it isn''t 0.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!