N
N
Nikita Savinykh2017-12-21 20:49:21
C++ / C#
Nikita Savinykh, 2017-12-21 20:49:21

How to interact with models in openGL?

Good day to all.
I want to clarify such a small point - I have 17 models in the openGL scene, I use the glfw and glew libraries.
I can’t understand in any way - here we have a mouse cursor that we hide:

glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);

However, this does not change the fact that we can also calculate the coordinates, and it is the deviation of the coordinates that is used to turn the camera, with the subsequent return of the cursor to the center.
I started working with openGL relatively recently, so this code can be more adapted from tutorials, but not the author's work, at least for the most part.
The question itself - since we have the coordinates of the cursor, we have a unit vector (there is, am I not mistaken? Also an important point) of the camera direction (we must have a matrix of orthogonal camera vectors - position and rotation), then we can calculate , which object you are looking at, and, accordingly, we can somehow set a certain logical flag, which is checked in the left-click handler using standard glfw tools, and, for example, change the texture of an object (I now just have it set to LMB event without hover check, so there is no problem with this)
Below is the code both in C ++ and vertex and fragment shaders (uploaded on ideone - everything does not fit here):
C ++ - https://ideone.com/ZOplfT
Vertex shader - https://ideone.com/41DOoY
Fragment shader - https://ideone.com/QV6cVh
Many thanks to all who responded and plus to the universal karma! with:

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question