Planet Chilihttp://forum.planetchili.net/ does this look right?http://forum.planetchili.net/viewtopic.php?f=3&t=3962 Page 1 of 1

 Author: MrGodin [ March 15th, 2017, 2:52 pm ] Post subject: does this look right? 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);         }                  }

 Author: albinopapa [ March 15th, 2017, 6:09 pm ] Post subject: Re: does this look right? 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.

 Author: MrGodin [ March 15th, 2017, 8:59 pm ] Post subject: Re: does this look right? 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

Author:  MrGodin [ March 15th, 2017, 9:05 pm ]
Post subject:  Re: does this look right?

This is what it looks like