Skip to main content
gamedev.net
🔒 Locked

mouse motion

Started by 51mpls 2 replies 450+ views
Original Post
51mpls
51mpls
I am creating a 3D space game using glutMouseFunc(), and glutMotionFunc(). On left mouse drag I modify the thrust in the XY plane. On shift left mouse drag I modify the thrust in the XZ plane. However I cannot get the shift left mouse to work correctly. Heres my code: int stateK=0; glutMouseFunc(mouse); glutMotionFunc(mouseDrag); void mouse(int button, int state, int x, int y) { stateK = glutGetModifiers(); if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) { tX = x; tZ = y; } else { tX = x; tY = y; tZ = 0; } } void mouseDrag(int x, int y) { if(stateK != GLUT_ACTIVE_SHIFT) { mX += (x - tX); tX = x; mY += (tY - y); tY = y; } else { mX += (x - tX); tX = x; mZ += (tZ - y); tZ = y; stateK=0; } glutPostRedisplay(); }
benjamin bunny
benjamin bunny
Quote:
However I cannot get the shift left mouse to work correctly.

In what way does it not work correctly? Presumably you tried to debug it before posting?

BTW, you can make properly formatted source code blocks with [ source ] tags.
51mpls
51mpls
Sorry about the format. What I want to accomplish is when the shift key is pressed with a left mouse drag I want my object to translate in the x, z direction. But when I run the code it continues to translate in x, y direction. Not going in the else statement of the mousedrag function when the shift key is pressed.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.