Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have a walking stick:

enter image description here

Some information:

  • The handle is fixed, it cannot move
  • The bottom part can move

Using the mouse click position and mouse movement, how can I rotate this stick with OpenGL?

share|improve this question
    
I removed irrelevant text from your question, but it remains vague. To improve it: 1) Add an image of your stick being rendered, 2) add more useful "information": is the stick being held by a character, do you want a physics simulation, or just run the stick through an animation loop, 3) try to explain more carefully what mouse clicks and moves should do to the stick (preferably with a drawing), and 4) explain what you tried to fix this problem. –  Eric Nov 16 '12 at 9:38
    
@Eric thanks for –  gveaf Nov 16 '12 at 9:50
    
Try to make question titles as generic as possible. It helps for people searching in the future. I doubt "walking stick" is common enough to be searched for. –  Byte56 Nov 17 '12 at 3:32

2 Answers 2

Generally, to rotate an object you'll want to use a rotation matrix. However, this will rotate your object around its origin - you want to rotate it around the handle.

So, if the handle isn't at the origin, you will want to apply a transformation matrix that moves the stick so that the handle is at the origin, then apply your rotation around the handle, and then possibly apply another transformation to position the stick in the world again.

Now, how you want to rotate your stick is entirely up to you, you could just map x/y movement to the theta/phi angles of a spherical coordinate system.

share|improve this answer
    
(T) * (R) * (T^(-1)) –  Gustavo Maciel Nov 16 '12 at 16:07
    
I suppose so :) –  melak47 Nov 16 '12 at 16:58

glPushMatrix();

glTranslatef(250,250,0.0); // 3. Translate to the object's position.

glRotatef(angle,0.0,0.0,1.0); // 2. Rotate the object.

glTranslatef(-250,-250,0.0); // 1. Translate to the origin.

// Draw the object

glPopMatrix();

share|improve this answer
    
You should really explain why this code works and the general idea behind how it's working. –  Byte56 May 6 at 22:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.