What am I doing wrong when trying to calculate a ray from the camera?
glm::vec4 mouseClip = {ev.cursor.x * 2 / 640.f - 1, 1 - ev.cursor.y * 2 / 480.f, 0, 1};
glm::mat4 inv = glm::inverse(game::camera->projection * game::camera->transform);
glm::vec4 p = inv * mouseClip;
p.x /= p.w;
p.y /= p.w;
p.z /= p.w;
glm::vec3 direction = glm::normalize(glm::vec3{p});
I can guarantee that mouseClip's x and y is correct (from [-1, -1] to [1, 1]).
glm::vec3 intPos, intNor;
if(glm::intersectRaySphere(glm::vec3{game::camera->transform[3]}, direction, glm::vec3{0, 0, 0}, 1, intPos, intNor)) {
printf("intersect\n");
}
intersectRaySphere does as it says, here is it's documentation.
Problem is that.. well.. basically everything is off. There is nothing I can accurately describe, it seems as if the camera's transformation is always exaggerated. I know this is all very vague, please ask questions if you have any.