I am trying to pick object using ray collision and bullet physics
I am initializing my projection and view matrix only once, here is the code
projectionMatrix = glm::perspective(90.0f, 4.0f / 3.0f, 0.1f, 100.0f); float horizontalAngle = 3.14f; float verticalAngle =0.0f;/// problems here glm::vec3 direction( cos(verticalAngle) * sin(horizontalAngle), sin(verticalAngle), cos(verticalAngle) * cos(horizontalAngle) ); glm::vec3 position = glm::vec3( 0.0, 10.0, 32.0 ); glm::vec3 right = glm::vec3( sin(horizontalAngle - 3.14f/2.0 ), 0, cos(horizontalAngle - 3.14f/2.0 ) ); // Up vector glm::vec3 up = glm::cross( right, direction ); viewMatrix = glm::lookAt( position, // Camera is here position+direction, // and looks here : at the same position, plus "direction" up // Head is up (set to 0,-1,0 to look upside-down) );
See below screenshot with actual object in the world
when I click on red area - it does not pick up object, but when i am click on green one - it does.
SMALL DETAIL: I've used this tutorial http://www.opengl-tutorial.org/miscellaneous/clicking-on-objects/picking-with-a-physics-library. While I've applying constant change to view and projection matrix throug my mouse move and keys - detection work perfect, but once I've stooping doing it - it does not work.
Can someone help me out what I am doing wrong ?