Advertisement Jump to content
Sign in to follow this  

model viewer

This topic is 3862 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

Hey guys. I need to make something like a model viewer so I need some code to rotate the model usng the mouse. Now I've heard that quaternions would be my best bet here since I want a smooth intuitive rotation style. However Ive never worked with quaternions and I couldnt really find a good tutorial on rotating objets with the mouse so does anyone have any good resources. The simpler the better. Thanks in advance. -CProgrammer

Share this post

Link to post
Share on other sites
The 'mouse' is really just an x,y position. Depending on what mechanism you're using to detect mouse movement, it may provide both an absolute position, and a relative (the change in x,y) position. You use the change in the position to make changes to your scene. The mouse moved -5,0? Well 5 is 5/800 of my screen's width. I want to rotate my object by (5/800)*some_constant_factor.

some non-quaternion pseudo code:

const float screenWidth = 800;
const float screenHeight = 600;
const float factor = 10;
int changeInX = 0;
int changeInY = 0;

getMouseInput(&changeInX, &changeInY);

float rotateX = (changeInX/screenWidth) * factor;
float rotateY = (changeInY/ScreenHeight) * factor;

glRotatef(rotateX, 1, 0, 0);
glRotatef(rotateY, 0, 1, 0);



Share this post

Link to post
Share on other sites
Here is one I made that's exactly what you are describing. It is a single file of code so should be easy to read:

Here is a pic, click to enlarge:

Edit: oops you didn't specify language, this is C#/XNA. Also it doesn't use quaternions. It's very simple though. =)

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!