PDA

View Full Version : Having 2 objects being controlled and moved at the same time



zemprof
03-31-2013, 09:35 PM
I've created 2 spheres and I want to be able to control both of them separately with the keyboard at the same time. Right now I'm only able to control only one of them at a time. How can I go about doing this? What I'm doing is incrementing and decrementing the x and z coordinates through the keyboard.
e.g.
glPushMatrix();
glTranslatef(p1x, 0 , p1z);
drawSphere(1, 1, 1, 1);
glPopMatrix();

glPushMatrix();
glTranslatef(p2x, 0 , p2z);
drawSphere(1, 1, 1, 1);
glPopMatrix();

and then I have functions that update the p1x, p1z, p2x, p2z when the key is pressed

Anyone have an elegant solution for this?

tonyo_au
04-01-2013, 05:51 AM
Don't use keypress but directly check keyup and keydown events. When you detect a key down start moving corresponding item with a timer until you get a keyup event. But you are limited to 10 keys (because you only have 10 fingers:whistle:)