[ad_1]
Heyho 🙂
I’m attempting to transform world coordinates to display coordinates. I’ve out there: fov, display width, display top, digicam place, digicam angle and clearly the place of the article in world house.
This is what I attempted:
glm::vec3 world_to_screen(glm::vec3 pos,
glm::vec3 cam_angle,
glm::vec3 cam_pos) {
glm::mat4 projection = glm::perspective(
glm::radians(FOV), (float)SCREEN_W / (float)SCREEN_H, NEAR, FAR);
glm::mat4 mannequin(1.0);
mannequin = glm::translate(mannequin, cam_pos);
mannequin = glm::rotate(mannequin, cam_angle.x, glm::vec3(1.0f, 0.0f, 0.0f));
mannequin = glm::rotate(mannequin, cam_angle.y, glm::vec3(0.0f, 1.0f, 0.0f));
mannequin = glm::rotate(mannequin, cam_angle.z, glm::vec3(0.0f, 0.0f, 1.0f));
glm::mat4 view = glm::inverse(mannequin);
glm::mat4 modelview = view * mannequin;
return glm::undertaking(pos, modelview, projection,
glm::vec4(0, 0, SCREEN_W, SCREEN_H));
}
However it isn’t working, the output display coords are over 30000 (I haven’t got a 30k monitor…) and I’m undecided what I did improper.
There is a correlation although, generally the display coords occur to be in my display (I draw an indicator on the place to see if I did it proper) and if the article strikes the indicator additionally strikes with (kinda) the identical pace and so forth.
Help could be very a lot appreciated 🙂 Thanks rather a lot upfront!
[ad_2]