# How do I get a vector from a point like my camera center to where the rendering geometry intersects my mouse coordinates

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
}
}
}
}
``````

Of course this is just some of the stuff.

Hit detection is normally performed in two stages. The broad-phase stage uses simplified bounding geometry such as spheres, cubes or convex polyhedra. Hits which intersect the bounding geometry progress to the narrow-phase stage which uses the actual rendered geometry. For complex models, there may be multiple broad-phase stages using a hierarchy of bounding volumes.

GLM offers a selection of useful functions for calculating ray intersections.

What about if I try to get the Z location from the normal?

Another thing is I have to make sure that what I am including is in front of the camera.