Register    Login    Forum    Search    FAQ

Board index » Everything




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: does this look right?
 Post Posted: March 15th, 2017, 2:52 pm 
 

Joined: November 30th, 2013, 7:40 pm
Posts: 599
Location: Merville, British Columbia Canada
Hey folks, I'm doing some 3D work and I am setting up collision planes in a partitioned world. Each cell holds a list of triangles from the world, which is a giant room with vertical walls. I am using this algorithm to place triangles in the cells. It works 95% of the time but seems to miss some. I made sure that the cell size is larger than any triangle (save for the ceiling). I am using this but it seems to miss the odd one ?.. any suggestions ?
The cells are an array based on the x and z axis, as y is irrelevant in this case
Code:
void AddPlane(Utilities::Plane* plane)
   {
      
      // ?? hmm.. adding one plane to possible 3 cells, i think
      // i have to do this in order to make sure
      // we can intersect that plane, no matter how
      // little of it is in the cell

      // get indices of plane points
      size_t index[3];
      size_t cSize = (size_t)m_cellSize;
      size_t row1 =  (size_t)plane->pt0.z / cSize;
      size_t col1 = (size_t)plane->pt0.x / cSize;

      size_t row2 = (size_t)plane->pt1.z / cSize;
      size_t col2 = (size_t)plane->pt1.x / cSize;

      size_t row3 = (size_t)plane->pt2.z / cSize;
      size_t col3 = (size_t)plane->pt2.x / cSize;

      index[0] = row1 * m_columns + col1;
      index[1] = row2 * m_columns + col2;
      index[2] = row3 * m_columns + col3;
      for (size_t i = 0; i < 3; i++)
      {
         
            
            
            auto& it = std::find_if(m_cells[index[i]].m_planes.begin(),
               m_cells[index[i]].m_planes.end(), [plane](Utilities::Plane& p)
            {
               return plane->index == p.index;
                      //index set when reading in data from .obj file
            });
                      // not in cell's plane list so add it
            if(it == m_cells[index[i]].m_planes.end())
               m_cells[index[i]].m_planes.push_back(*plane);
         }
         
      
   }

_________________
Curiosity killed the cat, satisfaction brought him back


Top 
 Profile  
Reply with quote  
 Post Posted: March 15th, 2017, 6:09 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2826
Location: Oklahoma, United States
So let me see if I understand what you are doing.

First you calculate which cell each vertex of a triangle...( I understand it only takes 3 points to define a plane ). Then you loop through the three possible cells the triangle ( plane ) could be in.

Even though a plane can be defined by three points, a plane is usually going to have four boundaries I would imagine that if the plane's vertex 0 is in cell 20 and vertex 1 is in cell 20 + columns + 1 and vertex 2 is in cell 20 + columns, the fourth unspecified vertex would be in cell 21.

So perhaps collision misses because of this missing fourth cell from calculations.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post Posted: March 15th, 2017, 8:59 pm 
 

Joined: November 30th, 2013, 7:40 pm
Posts: 599
Location: Merville, British Columbia Canada
I have solved the issue, All the triangles are getting placed properly, the error was in the collision detection. I went with AABB edge checking against the plane instead of a line going in the direction of velocity.. and it works great now.
What i've done is placed the planes in cells (around a max of 8 or so in each cell), get the cell the ammo/player or entity is in and check only those planes in that cell for collision. It's fast and works good.
The collision correction is a bit wonky, but working on that.
Peace Out

_________________
Curiosity killed the cat, satisfaction brought him back


Top 
 Profile  
Reply with quote  
 Post Posted: March 15th, 2017, 9:05 pm 
 

Joined: November 30th, 2013, 7:40 pm
Posts: 599
Location: Merville, British Columbia Canada
This is what it looks like


Attachments:
Image2.png [402.42 KiB]
Not downloaded yet
Image1.png [96.75 KiB]
Not downloaded yet

_________________
Curiosity killed the cat, satisfaction brought him back
Top 
 Profile  
Reply with quote  
 Post Posted: March 16th, 2017, 1:07 am 
Site Admin
User avatar

Joined: December 31st, 2011, 4:53 pm
Posts: 3467
Location: Japan
This is why I don't generally attempt to debug people's problems without the full code first :lol:

_________________
Chili


Top 
 Profile  
Reply with quote  
 Post Posted: March 16th, 2017, 1:35 am 
 

Joined: November 30th, 2013, 7:40 pm
Posts: 599
Location: Merville, British Columbia Canada
chili wrote:
This is why I don't generally attempt to debug people's problems without the full code first :lol:

fair enough

_________________
Curiosity killed the cat, satisfaction brought him back


Top 
 Profile  
Reply with quote  
 Post Posted: March 16th, 2017, 1:45 am 
 

Joined: November 30th, 2013, 7:40 pm
Posts: 599
Location: Merville, British Columbia Canada
I published to here
https://github.com/MrGodin67/3d-Test
some files in here are irrelevant.. i'll clean it up later

_________________
Curiosity killed the cat, satisfaction brought him back


Top 
 Profile  
Reply with quote  
 Post Posted: March 16th, 2017, 2:19 am 
 

Joined: November 30th, 2013, 7:40 pm
Posts: 599
Location: Merville, British Columbia Canada
I'll just say , this code is a freaking mess atm, in the middle of porting a new game and refactoring

_________________
Curiosity killed the cat, satisfaction brought him back


Top 
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 8 posts ] 

Board index » Everything


 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for: