OceanJeff40

12-13-2016, 10:44 PM

Ok, I've got a question about the GLM::Rotate function. :biggrin-new:

When I apply this rotation around a static, center of the screen 2D object.....

Am I running into a combination of the GLM::Rotate function applying trig to the vertices, so the trigonometry is affecting the length of my object, or...

is it the aspect ratio of the screen that is changing the shape of my object as it rotates....or....

is it some combination of the two?

To tackle this problem, and make the 2D object (sprite) appear normal throughout the rotation, is it easier to just rotate the sprite images and load them in and work with them, or actually figure out the correct combination to undo the trig and aspect ratio combo that's morphing the sprite as it rotates?

The closest I've come so far.....is with the following code:

glm::mat4 transform;

transform = glm::rotate(transform, glm::radians(shipRotation), glm::vec3(0.0, 0.0, 1.0));

// width goes from 128 to 226 from angle 0 to 90. aspect ratio 1 / 1.778 = 0.5625

// figure out aspect ratio adjustment for rotation

shipScaleX = 1.0f +(0.778f * glm::abs(glm::sin(glm::radians(shipRotation))));

shipScaleY = 1.0f -(0.4375f * glm::abs(glm::sin(glm::radians(shipRotation))));

transform = glm::scale(transform, glm::vec3(shipScaleX, shipScaleY, 1.0));

This code makes the 2D sprite maintain as close to it's shape as possible as it rotates (5 degree increments), but it still wobbles noticeably in and out of shape as it rotates.

I am very good at math, once upon a time, being a calculus tutor in college, but it's been a while....

Alright, I'm still working on this tonight for at least another hour, then I'll start again tomorrow with another program, or any solutions that you guys could help me with.

Thanks in advance,

Jeff

:confused:

When I apply this rotation around a static, center of the screen 2D object.....

Am I running into a combination of the GLM::Rotate function applying trig to the vertices, so the trigonometry is affecting the length of my object, or...

is it the aspect ratio of the screen that is changing the shape of my object as it rotates....or....

is it some combination of the two?

To tackle this problem, and make the 2D object (sprite) appear normal throughout the rotation, is it easier to just rotate the sprite images and load them in and work with them, or actually figure out the correct combination to undo the trig and aspect ratio combo that's morphing the sprite as it rotates?

The closest I've come so far.....is with the following code:

glm::mat4 transform;

transform = glm::rotate(transform, glm::radians(shipRotation), glm::vec3(0.0, 0.0, 1.0));

// width goes from 128 to 226 from angle 0 to 90. aspect ratio 1 / 1.778 = 0.5625

// figure out aspect ratio adjustment for rotation

shipScaleX = 1.0f +(0.778f * glm::abs(glm::sin(glm::radians(shipRotation))));

shipScaleY = 1.0f -(0.4375f * glm::abs(glm::sin(glm::radians(shipRotation))));

transform = glm::scale(transform, glm::vec3(shipScaleX, shipScaleY, 1.0));

This code makes the 2D sprite maintain as close to it's shape as possible as it rotates (5 degree increments), but it still wobbles noticeably in and out of shape as it rotates.

I am very good at math, once upon a time, being a calculus tutor in college, but it's been a while....

Alright, I'm still working on this tonight for at least another hour, then I'll start again tomorrow with another program, or any solutions that you guys could help me with.

Thanks in advance,

Jeff

:confused: