• Advertisement
Sign in to follow this  

3D Rotation?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

High gang, I'm pretty new to 3D programming and OpenGL. I can't for the life of me come up with a way to rotate a 3D model. I've tried glRotatef() but all that does is rotate the model around the point (0, 0, 0). I need to model to rotate in place, at it's own position. Is there a function for this already? Basically I need something that will loop through all of my vertices and rotate them around a center point so that the whole model will rotate in place to "look at" a vertex out in space. Sounds easy but I've been banging my head against the wall. Is this the kind of thing I have to write from scratch or is there an easier way of doing it? I'm writing a simple 3D game. Nothing fancy and I don't have much done yet. So far I can load up models created using MilkShape3D and move 'em around. However they all stare off in the same direction as I can't figure out how to rotate them. The point of all this is I'd like to create a 3rd person shooter like the old Duke Nukem/Tomb Raider games. How on Earth do I rotate? Any help would be much appreciated. Sorry if this makes no sense or if this is incredibly easy to do and I'm just dumb. -Art

Share this post


Link to post
Share on other sites
Advertisement
Place the model at 0,0,0 then rotate it, is should rotate as expected. If you want to place your model at a different location, rotate it first then use translation to move it at the desired point.

Share this post


Link to post
Share on other sites
Your post referes to a couple of different problems, so I'll just address the easiest. Presumably your model is constructed so that it's more or less centered at the origin (if it's not, it should be). To render the model, you want to rotate it to the desired orientation, and then translate to the desired position. The code might look something like this:
glTranslatef(modelX, modelY, modelZ);
glRotatef(modelAngle, 0.0f, 1.0f, 0.0f);
RenderModel();
Exactly how you use glRotatef() depends on what sort of rotation you want. For example, you might call it three times, once for each of three Euler angles (yaw, pitch and roll).

For some types of rotation you will have to do it on your own using your own code, but for simple rotations, glRotate*() should suffice.

Share this post


Link to post
Share on other sites
Thank you guys so much! I was completely doing the wrong thing. I was moving the model then rotating, then moving again and then rotating around the global origin.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement