Moving an object along with mousepointer

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.

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)

Thanks for the reply.But how can i move the object along with mousepointer.Is there any function ?