Pergunta

I use glfw and glm.

If I scroll up - I want to make object bigger, when I scroll down - I want to make object smaller.

How to do it? I use this function to handle mouse scrolling.

static void mousescroll(GLFWwindow* window, double xoffset, double yoffset)
{
   if (yoffset > 0) { 
       scaler += yoffset * 0.01; //make it bigger than current size
       world = glm::scale(world, glm::vec3(scaler, scaler, scaler));
   }
   else {
       scaler -= yoffset * 0.01; //make it smaller than current size
       world = glm::scale(world, glm::vec3(scaler, scaler, scaler));
   }
}

By default scaler is 1.0.

I can describe the problem like this.

There is an object. If I scroll up - the value of scaler will become 1.01. So the object will be bigger in 1.01 times. When I scroll up again - as far as I can understand in my case the size of object will be bigger in 1.02 than the previous size(which is bigger than the original in 1.01 times)! But I want its size to be bigger than the original in 1.02 times.

How to solve this problem?

Matrix world looks like this

glm::mat4 world = glm::mat4(
glm::vec4(1.0f, 0.0f, 0.0f, 0.0f),
glm::vec4(0.0f, 1.0f, 0.0f, 0.0f),
glm::vec4(0.0f, 0.0f, 1.0f, 0.0f),
glm::vec4(0.0f, 0.0f, 0.0f, 1.0f));

And I calculate the positions of vertex in the shader

gl_Position = world * vec4(Position, 1.0);

Foi útil?

Solução

But I want its size to be bigger than the original in 1.02 times.

Then reset the transform each time instead of accumulating the scales:

world = glm::scale( scaler, scaler, scaler );
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top