I want to make a game where I fire a bullet to where my mouse cursor is or where it lands on in 3d space. So what I could use for the movement is a unit vector. I think I can figure out what is hit and I can show code for it.
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];
};
void RayTrace::trace()
{
for (int i = 0; i < relinfo.size(); i++) {
float lowx = 2;
float lowy = 2;
float higx = -2;
float higy = -2;
glm::vec4 location;
for (int j = 0; j < 6; j++) {
location = projection * view * glm::vec4(relinfo.at(i).verts[i].position, 1.0f);
if (location.x < lowx) lowx = location.x;
if (location.y < lowy) lowy = location.y;
if (location.x > higx) higx = location.x;
if (location.y > higy) higy = location.y;
}
if (cursx > lowx && cursx < higx && cursy > lowy && cursy < higy) {
if (location.z < depth) {
depth = location.z;
//What do I put here
}
}
}
}