Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

Rotation

Started by iluka Sep 18, 2005 at 2:30 PM 1 replies 600+ views
Original Post
iluka
iluka
Hi Im rotating a mesh around the y-axis. Works fine, but problem is its beeing rotated around its left side rather than its center. I guess its because its "base-vertice" or whatevert its called is that point. Im rotating it with this line: device.Transform.World = fontScalingMatrix * rotationMatrix* fontTranslationMatrix; and the rotationMatrix is calculated like this: rotationMatrix = Matrix.RotationY(totalTime); anyway, i was thinking the problem might be solved if i can somehow point to a vertice thats the middle of the mesh... Or should i translate it once before rotating? if you feel like it, feel free to post a codesample. - Kasper
dave
dave
Well you could translate it once before rotation. Or you could run through the vertices in the mesh manually altering the xyz so that it reflects the shift.

ace
sirob
sirob
Well, by default, anything transformed by a rotation matrix is rotated around the point (0.0f, 0.0f, 0.0f).

If you want to rotate a mesh, for example, around it's center, you need to know where that center is.

Once you know where the center is, you'll need to first translate the mesh so the the center you want is at (0.0f, 0.0f, 0.0f) -- this is simply translating by -x, -y, and -z. Then, you rotate around the correct center. Finally, to put things back to normal (you might not want to do this step - as it's standard for a mesh's center to be at (0.0f, 0.0f, 0.0f)) you'd translate it back into place, using x, y and z.

To find the Mesh's center, I'd recommend using it's axis aligned bounding-box. From there it's shouldn't be too difficult.

Hope this helps.
Sirob Yes.» - status: Work-O-Rama.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.