I am creating a pool game written in C++ using plain OpenGL (no external tools), but I can use GLUT. I have drawn a pool cue which I want to follow the mouse cursor but I am not sure how to do this.
I know how to use keyboard input to move things e.g camera position or draw an object but I m not sure how to move an object using mouse input.
This is the cue i am trying to move via mouse input:
void cue () {
glBegin;
glTranslatef(-10,5,0);
glRotatef(90,0,1,0);
glutSolidCone(0.25, 15, 20, 20);
glEnd();
}
Glut has a few mouse callback function
Mouse callback
Motion callback
You could use the callback to figure out the movement of the mouse, the rest is pure math.
NeHe has a tutorial that covers the basics of rotation in OpenGL: http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=04
If you want to rotate around another point see How to change the Center-of-Rotation in OpenGL . It basically comes down to this:
Translate it so that the point you want to rotate around is at the origin, then rotate, then translate it to the location you want it at.
Also use glPushMatrix/glPopMatrix or glLoadIdentity to isolate transformations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With