Jump to content
  • Advertisement
Sign in to follow this  
ChristianFrantz

checking adjacent cubes

This topic is 2113 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

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

Share this post


Link to post
Share on other sites
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.

Edited by Tispe

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!