How to correctly calculate the 3d coordinates of the object's vertices so that it is constantly in one position relative to the camera (in front of it) during any movements and turns of the camera and always faces the camera on one side?

Obviously, we are talking about the matrix of the model, which must be built according to the coordinates of the "Look-To" point and the direction of the vector ("Look-To" - "Look-From"). I assume that you can use a view matrix for this. How to build such a matrix model?

  • Thanks, I understand. I know this way. But I was fascinated by the task itself - mathematically: in theory, everything is beautiful, but in practice it does not work at all. And I would also like to practically assess whether there will be a gain in the speed of a single pass render from the method described by you. - bigov
  • @Kromster where is the GUI? - ampawd
  • @ampawd look at the text of the question before the edit, there is mentioned HUD - Kromster
  • Yes, I first compared the figure in front of the camera with the HUD, so that the essence of the question was more understandable. But then he corrected - as they say, "The right question is half the answer." I apologize to Kromster. - bigov

1 answer 1

First I want to say about the matrix. Completely confused the head with these transformations. So, the matrices are needed for the shader engine when calculating the scene. If we calculate the coordinates of a single figure in a fixed environment, the use of matrices will not bring an acceleration of the calculation and understanding of the code.

I knowingly wrote in the comments about the "correctly asked question." Indeed, it was the thoughtful and corrected wording of the question that helped find the correct answer (C ++):

// исходноС Π½Π°ΠΏΡ€Π°Π²Π»Π΅Π½ΠΈΠ΅ ΠΊΠ°ΠΌΠ΅Ρ€Ρ‹: вдоль оси Π₯ Π² сторону + // ΠŸΠΎΡΡ‚Ρ€ΠΎΠΈΠΌ ΠΏΠ΅Ρ€Π΅Π΄ ΠΊΠ°ΠΌΠ΅Ρ€ΠΎΠΉ плоский ΠΏΡ€ΡΠΌΠΎΡƒΠ³ΠΎΠ»ΡŒΠ½ΠΈΠΊ, Π½Π΅ΠΌΠ½ΠΎΠ³ΠΎ // смСстив Π΅Π³ΠΎ (x = t) навстрСчу ΠΊΠ°ΠΌΠ΅Ρ€Π΅. ПослС "сдвига" ΠΊΠΎΠΎΡ€Π΄ΠΈΠ½Π°Ρ‚ // ΠΏΡ€ΠΈ ΠΏΠΎΠΌΠΎΡ‰ΠΈ слоТСния с Π²Π΅ΠΊΡ‚ΠΎΡ€ΠΎΠΌ ViewTo это смСщСниС // компСнсируСтся. double s = 0.01, t = -0.9; std::vector<glm::vec3> p { glm::vec3(t,-s,-s), glm::vec3(t,-s, s), glm::vec3(t, s, s), glm::vec3(t, s,-s) }; // ΠΊΠ°ΠΆΠ΄ΡƒΡŽ Π²Π΅Ρ€ΡˆΠΈΠ½Ρƒ ΠΏΠΎΠ²ΠΎΡ€Π°Ρ‡ΠΈΠ²Π°Π΅ΠΌ Π½Π° ΡƒΠ³Π»Ρ‹ полоТСния ΠΊΠ°ΠΌΠ΅Ρ€Ρ‹ ΠΈ смСщаСм // Π½Π° Π²Π΅ΠΊΡ‚ΠΎΡ€ ViewTo (ΠΊ Ρ‚ΠΎΡ‡ΠΊΠ΅, Π½Π° ΠΊΠΎΡ‚ΠΎΡ€ΡƒΡŽ Π½Π°ΠΏΡ€Π°Π²Π»Π΅Π½Π° ΠΊΠ°ΠΌΠ΅Ρ€Π°). for (size_t i = 0; i < 4; i++) { p[i] = glm::rotateZ(p[i], look_zenith); // Π°Π·ΠΈΠΌΡƒΡ‚ ΠΎΡ‚Ρ€ΠΈΡ†Π°Ρ‚Π΅Π»ΡŒΠ½Ρ‹ΠΉ ΠΈΠ·-Π·Π° Ρ€Π΅Π°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ ΠΏΠΎΠ²ΠΎΡ€ΠΎΡ‚Π° Π² // Π² Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΠ΅ GLM, Π½Π΅ совпавшСй с ΠΌΠΎΠ΅ΠΉ модСлью вращСния. p[i] = glm::rotateY(p[i], 0 - look_azimuth); p[i] += ViewTo; } 

demo scene

In the image, the white rectangle is the plane in front of the camera, which is always stationary relative to the camera.