• Create Account

Need scary sound effects or creepy audio loops for your next horror-themed game? Check out Highscore Vol.3 - The Horror Edition in our marketplace. 50 sounds and 10 loops for only \$9.99!

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

7 replies to this topic

### #1burnt_casadilla  Members   -  Reputation: 370

Like
0Likes
Like

Posted 01 October 2013 - 10:27 PM

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

### #2Tispe  Members   -  Reputation: 684

Like
0Likes
Like

Posted 02 October 2013 - 12:29 AM

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, 02 October 2013 - 12:35 AM.

### #3burnt_casadilla  Members   -  Reputation: 370

Like
0Likes
Like

Posted 02 October 2013 - 12:33 AM

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

### #4Goran Milovanovic  Members   -  Reputation: 1092

Like
0Likes
Like

Posted 02 October 2013 - 12:48 AM

Why not just research Occlusion Culling, and implement that?

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

| Need a programmer?        ->   http://www.nilunder.com/protoblend   |

| Want to become one?       ->   http://www.nilunder.com/tutoring     |
| Game Dev video tutorials  ->   http://www.youtube.com/goranmilovano |
+---------------------------------------------------------------------+

### #5burnt_casadilla  Members   -  Reputation: 370

Like
0Likes
Like

Posted 02 October 2013 - 12:55 AM

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

### #6Tispe  Members   -  Reputation: 684

Like
0Likes
Like

Posted 02 October 2013 - 05:24 AM

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


### #7burnt_casadilla  Members   -  Reputation: 370

Like
0Likes
Like

Posted 02 October 2013 - 01:05 PM

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

### #8burnt_casadilla  Members   -  Reputation: 370

Like
0Likes
Like

Posted 02 October 2013 - 05:59 PM

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

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS