PDA

View Full Version : Moving an object along with mousepointer



saiabhishek
02-24-2012, 03:44 AM
Hi,

i have drawn an square,now i want to move it along the plane following the mouse pointer.I am using open GL es 1.0.I tried to get difference in motion position with the below code.

-----------------------------------------

public boolean onTouchEvent(MotionEvent e) {
float x = e.getX();
float y = e.getY();
switch (e.getAction()) {
case MotionEvent.ACTION_MOVE:
mRenderer.dx = x - mPreviousX;
mRenderer.dy = y - mPreviousY;
requestRender();
}
mPreviousX = x;
mPreviousY = y;
return true;
}
----------------------------------------------------

and then i am translating the object by using gtranslatef function with dx and dy values.

gl.glTranslatef(dx, dy,0);

but for a little movement in mouse pointer.there is large displacement in object position.

How can i move object along with mouse.Please help me to get out of this.

BionicBytes
02-24-2012, 07:08 AM
but for a little movement in mouse pointer.there is large displacement in object position.

That's because the coordinate systems are different. Window coordinates are not the same as the coordinates you plot with in OpenGL. These GL coordinates are transformed by the various matricies along the way (obj --> world --> eye --> clip --> NDC --> screen)

saiabhishek
02-27-2012, 04:05 AM
Thanks for the reply.But how can i move the object along with mousepointer.Is there any function ?