The Partridge Family were neither partridges nor a family. Discuss.
-
MrGodin
- Posts: 721
- Joined: November 30th, 2013, 7:40 pm
- Location: Merville, British Columbia Canada
Post
by MrGodin » March 15th, 2017, 2:52 pm
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: Select all
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
-
albinopapa
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Post
by albinopapa » March 15th, 2017, 6:09 pm
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
-
MrGodin
- Posts: 721
- Joined: November 30th, 2013, 7:40 pm
- Location: Merville, British Columbia Canada
Post
by MrGodin » March 15th, 2017, 8:59 pm
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
-
MrGodin
- Posts: 721
- Joined: November 30th, 2013, 7:40 pm
- Location: Merville, British Columbia Canada
Post
by MrGodin » March 15th, 2017, 9:05 pm
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
-
chili
- Site Admin
- Posts: 3948
- Joined: December 31st, 2011, 4:53 pm
- Location: Japan
-
Contact:
Post
by chili » March 16th, 2017, 1:07 am
This is why I don't generally attempt to debug people's problems without the full code first
Chili
-
MrGodin
- Posts: 721
- Joined: November 30th, 2013, 7:40 pm
- Location: Merville, British Columbia Canada
Post
by MrGodin » March 16th, 2017, 1:35 am
chili wrote:This is why I don't generally attempt to debug people's problems without the full code first
fair enough
Curiosity killed the cat, satisfaction brought him back
-
MrGodin
- Posts: 721
- Joined: November 30th, 2013, 7:40 pm
- Location: Merville, British Columbia Canada
Post
by MrGodin » March 16th, 2017, 1:45 am
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
-
MrGodin
- Posts: 721
- Joined: November 30th, 2013, 7:40 pm
- Location: Merville, British Columbia Canada
Post
by MrGodin » March 16th, 2017, 2:19 am
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