I
I
IliaNeverov2021-01-23 12:20:46
OpenGL
IliaNeverov, 2021-01-23 12:20:46

Why does the scale of a shape change when rotated?

Hello! Why do I have to change the transformation matrix (for rotation) at some values, the scale of the object changes?
c++

glm::mat4 ModelMatrix(1.0f);
  ModelMatrix = glm::translate(ModelMatrix, glm::vec3(0.0f,0.0f,0.0f));
  ModelMatrix = glm::rotate(ModelMatrix,  2.0f ,  glm::vec3( 1.0f, 0.0f, 0.0f));
  ModelMatrix = glm::rotate(ModelMatrix, 0.0f, glm::vec3(0.0f, 0.0f, 1.0f));
  ModelMatrix = glm::rotate(ModelMatrix, 0.0f, glm::vec3(0.0f, 1.0f, 0.0f));

  while (!glfwWindowShouldClose(mWindow))
  {
    //first.setMatrix("ModelMatrix", ModelMatrix);
    glClearColor(0, 0, 0, 1);
    glClear(GL_COLOR_BUFFER_BIT);
      glUniformMatrix4fv(glGetUniformLocation(first.mProgram, "ModelMatrix"), 1 , GL_FALSE, glm::value_ptr(ModelMatrix));
    vao.draw(GL_TRIANGLES);
    glfwSwapBuffers(mWindow);
    glfwPollEvents();
  }

vertex shader
#version 330
// версия

// нулевой атрибут. Название атрибута должно совпадать с вызовом функции bindAttribute
layout (location = 0) in vec3 position;
in vec2 uv;

uniform mat4 ModelMatrix;
// выход на вход в фрагментный шейдер
// Приписка 'pass_' для моего удобства
out vec2 pass_uv;

// здесь не int!
void main() {
    
  // стандартная, типа глобальная переменная. В неё нужно записывать координату вершины
  gl_Position =  ModelMatrix * vec4(position, 1);

  pass_uv = uv;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Armenian Radio, 2021-01-23
@gbg

The same transformation matrix should not be rotated and rotated between frames all the time - this accumulates an error (the matrix ceases to be orthogonal), which looks like a change in scale.
Compose a new transformation matrix on each frame.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question