checking adjacent cubes

Started by
6 comments, last by ChristianFrantz 10 years, 6 months ago
I wasnt sure where to put this question. It's more of a design question than a code problem.

I have a list of cubes. The cubes are structs, with a World matrix that stores their positionand a bool isSolid that checks if it's solid it not.
My goal here is to nit draw any cubes where a six sides are adjacent by other cubes. I'm not worried about faces, just the cubes as a whole. If all cubes around the cube are solid,that cube isn't drawn.

How would i loop through my list of cubes to check if all the cubes around it are solid? This would require 6 if statements im assuming? Once i figure out which cubes should be solid and which aren't, i can store those cubes in another buffer and draw that buffer

If you see a post from me, you can safely assume its C# and XNA :)

Advertisement

Each cube could store 6 pointers, each pointer points to the nearest cube in 6 directions.

Search for cubes that are aligned with the new cube and update pointers for your new cube and the 6 other cubes.

Could you give some pseudocode for that? The idea makes sense, but how exactly am i checking the pointers against another cube?

If you see a post from me, you can safely assume its C# and XNA :)

Why not just research Occlusion Culling, and implement that?

+---------------------------------------------------------------------+

| Game Dev video tutorials -> http://www.youtube.com/goranmilovano | +---------------------------------------------------------------------+
I would rather just cull whole cubes first, and if i need to ill cull individual faces. Since i use hardware instancing, i don't think it will make too much of a difference. Ill be culling chunks too when i get to that point

If you see a post from me, you can safely assume its C# and XNA :)

You can brute search. I assume you have a huge container that manages all the cubes. If you spawn a new cube, traverse the "main" container and check every cube in relation to the new cube for all 6 directions.

Something like this:


Cube* pNewCube = new Cube(initstuff);

for(auto it = MyCubesContainer.begin(); it!=MyCubesContainer.end();it++){

	//Check if new cube and *it are on the same YZ plane
	if((*it)->Pos.y == pNewCube->Pos.y && (*it)->Pos.z == pNewCube->Pos.z){

		//Check if *it are closer to pNewCube top face then the current one
		if((*it)->Pos.x < pNewCube->pTop &&  (*it)->Pos.x > pNewCube->Pos.x){
			pNewCube->pTop = &(*it);					//*it is closer to the Top face then the current cube

			//also update *it's bottom to point to pNewCube

		}

		//Check if *it are closer to pNewCube bottom face then the current one
		if((*it)->Pos.x < pNewCube->pBottom &&  (*it)->Pos.x > pNewCube->Pos.x){
			pNewCube->pBottom = &(*it);					//*it is closer to the bottom face then the current cube

			//also update *it's top to point to pNewCube
		}

	}

	//Check for all planes
}

MyCubesContainer.push_back(pNewCube);
That seems pretty simple to do in c#. would it make sense to copy the cubes to a new list and draw the new list after I've checked all thecubes?

If you see a post from me, you can safely assume its C# and XNA :)

Turns out that you can get the six sides from the world matrix. I can set those sides based on location of the cube, check adjacency and voila I'm done

If you see a post from me, you can safely assume its C# and XNA :)

This topic is closed to new replies.

Advertisement