Jump to content
  • Advertisement
Sign in to follow this  
CProgrammer

model viewer

This topic is 3767 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
Advertisement
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;

glPushMatrix();
glTranslatef(...);
glRotatef(rotateX, 1, 0, 0);
glRotatef(rotateY, 0, 1, 0);

drawObject();

glPopMatrix();




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:

ModelViewer.zip

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 GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!