# Need Help with Math on rotating a texture needle for a Speedometer

This topic is 3633 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am unsure what is wrong, but can tell you what is happening. I rotate my needle say 45degrees and then its not in the middle of the texture anymore. So I am thinking I need to rotate the needle then transform it back some amount so the needle is back on center? This is what I have so far
Matrix4x4 orientate;
orientate.Rotate(45.0f, false, false, true);
glMatrixMode(GL_TEXTURE);
glMultMatrixf(orientate.matrix);
glMatrixMode(GL_MODELVIEW);


or do I need to think of this in X,Y axes...

##### Share on other sites
I thing you'll need to set the origin of the rotation to the center of the texture:

1. Translate to the center (0.5|0.5)
2. Rotate
3. Translate back to 0|0

(function names are only placeholders)
glMatrixMode(GL_TEXTURE);glMultMatrixf(getTranslationMatrix(0.5,0.5));glMultMatrixf(getRotationMatrix(45));glMultMatrixf(getTranslationMatrix(-0.5,-0.5));

Hope I understood your problem correctly.

Alexander

##### Share on other sites
Usually what you want to do is take the quad and transform it into texture space. From there you get the texture coordinates of the vertices. What this means is that the visual effect you wish to achieve is the opposite of the transform you perform on the texture coordinates. For instance, rotating the texture coordinates counter-clockwise would rotate the texture image itself clockwise, and likewise for all the other transformations. Essentially, you're dealing with inverse transformation.

The easiest way to build the proper transform would probably be to build the texture-to-world matrix (i.e. the transform that places the needle in the world, or on the screen, or into whatever space you're interested in), and then invert it. You'll also need to apply the proper scaling, but that depends on how you've built your needle texture.

##### Share on other sites
Thanks to both of you for the help. I went with Porthos idea and seems to work.

Now how are most people transforming the MPH into radians or degrees to match the speedometers reading...

##### Share on other sites
Now I hit a different problem, I decided to add a gas gauge, the problem is this isn't in the center its the lower left corner and rotate to the right. Any ideas? Thanks again.

Can I just flip the xy

glMatrixMode(GL_TEXTURE);

glMultMatrixf(getTranslationMatrix(-0.5,-0.5));

glMultMatrixf(getRotationMatrix(45));

glMultMatrixf(getTranslationMatrix(0.5,0.5));

##### Share on other sites
Bah guess not. Sigh back to the drawing board!

• 48
• 12
• 10
• 10
• 9
• ### Forum Statistics

• Total Topics
631374
• Total Posts
2999654
×