# I am having trouble with collision between a mesh and a plane

The planes that I am using are all quite straight (90 degrees) their normals are all of almost 1 in ether x, y or z. I can show the ingenious code that I wrote that doesn’t work, bummer!!!

struct BulletInfo {
glm::vec3 position;
glm::vec3 movement;
glm::vec2 angles;
float time;
};

struct NormalVertex {
glm::vec3 position;
glm::vec3 normal;
glm::vec2 texCoord;
float wallType;
glm::vec3 tangent;
glm::vec3 bitangent;
};

struct RenderInfo {
glm::vec3 loc;
NormalVertex verts[6];
};

//vector<RenderInfo> relinfo;

bool RayTrace::ishit(BulletInfo pos)
{
bool retv = false;
for (int i = 0; i < relinfo.size(); i++) {
float lowx = 20000000;
float higx = -20000000;
float lowy = 20000000;
float higy = -20000000;
float lowz = 20000000;
float higz = -20000000;
for (int j = 0; j < 6; j++) {
if (relinfo.at(i).verts[j].position.x < lowx) lowx = relinfo.at(i).verts[j].position.x;
if (relinfo.at(i).verts[j].position.x > higx) higx = relinfo.at(i).verts[j].position.x;
if (relinfo.at(i).verts[j].position.y < lowy) lowy = relinfo.at(i).verts[j].position.y;
if (relinfo.at(i).verts[j].position.y > higy) higy = relinfo.at(i).verts[j].position.y;
if (relinfo.at(i).verts[j].position.z < lowz) lowz = relinfo.at(i).verts[j].position.z;
if (relinfo.at(i).verts[j].position.z > higz) higz = relinfo.at(i).verts[j].position.z;
}
if (abs(relinfo.at(i).verts[0].normal.x) > .5) {
if (pos.position.y >= lowy && pos.position.y <= higy && pos.position.z >= lowz && pos.position.z <= higz) {
if (pos.movement.x >= 0) {
if (pos.position.x > relinfo.at(i).verts[0].position.x) retv = true;
}
else {
if (pos.position.x < relinfo.at(i).verts[0].position.x) retv = true;
}
}
}
else if (abs(relinfo.at(i).verts[0].normal.y) > .5) {
if (pos.position.x >= lowx && pos.position.x <= higx && pos.position.z >= lowz && pos.position.z <= higz) {
if (pos.movement.y >= 0) {
if (pos.position.y > relinfo.at(i).verts[0].position.y) retv = true;
}
else {
if (pos.position.y < relinfo.at(i).verts[0].position.y) retv = true;
}
}
}else {
if (pos.position.y >= lowy && pos.position.y <= higy && pos.position.x >= lowx && pos.position.x <= higx) {
if (pos.movement.z >= 0) {
if (pos.position.z > relinfo.at(i).verts[0].position.z) retv = true;
}
else {
if (pos.position.z < relinfo.at(i).verts[0].position.z) retv = true;
}
}
}
}
return retv;
}

What does this have to do with OpenGL?

You’re posting in an OpenGL forum.

This is what I have tried and it works.

bool RayTrace::ishit(BulletInfo pos, glm::vec3 prevpos)
{
bool retv = false;
for (int i = 0; i < relinfo.size(); i++) {
float lowx = 20000000;
float higx = -20000000;
float lowy = 20000000;
float higy = -20000000;
float lowz = 20000000;
float higz = -20000000;
for (int j = 0; j < 6; j++) {
if (relinfo.at(i).verts[j].position.x < lowx) lowx = relinfo.at(i).verts[j].position.x;
if (relinfo.at(i).verts[j].position.x > higx) higx = relinfo.at(i).verts[j].position.x;
if (relinfo.at(i).verts[j].position.y < lowy) lowy = relinfo.at(i).verts[j].position.y;
if (relinfo.at(i).verts[j].position.y > higy) higy = relinfo.at(i).verts[j].position.y;
if (relinfo.at(i).verts[j].position.z < lowz) lowz = relinfo.at(i).verts[j].position.z;
if (relinfo.at(i).verts[j].position.z > higz) higz = relinfo.at(i).verts[j].position.z;
}
if (abs(relinfo.at(i).verts[0].normal.x) > .5) {
if (pos.position.y >= lowy && pos.position.y <= higy && pos.position.z >= lowz && pos.position.z <= higz) {
if (pos.movement.x >= 0) {
if (pos.position.x > relinfo.at(i).verts[0].position.x && prevpos.x <= relinfo.at(i).verts[0].position.x) retv = true;
}
else {
if (pos.position.x < relinfo.at(i).verts[0].position.x && prevpos.x >= relinfo.at(i).verts[0].position.x) retv = true;
}
}
}
else if (abs(relinfo.at(i).verts[0].normal.y) > .5) {
if (pos.position.x >= lowx && pos.position.x <= higx && pos.position.z >= lowz && pos.position.z <= higz) {
if (pos.movement.y >= 0) {
if (pos.position.y > relinfo.at(i).verts[0].position.y && prevpos.y <= relinfo.at(i).verts[0].position.y) retv = true;
}
else {
if (pos.position.y < relinfo.at(i).verts[0].position.y && prevpos.y >= relinfo.at(i).verts[0].position.y) retv = true;
}
}
}else {
if (pos.position.y >= lowy && pos.position.y <= higy && pos.position.x >= lowx && pos.position.x <= higx) {
if (pos.movement.z >= 0) {
if (pos.position.z > relinfo.at(i).verts[0].position.z && prevpos.z <= relinfo.at(i).verts[0].position.z) retv = true;
}
else {
if (pos.position.z < relinfo.at(i).verts[0].position.z && prevpos.z >= relinfo.at(i).verts[0].position.z) retv = true;
}
}
}
}
return retv;
}