Hi,
I have a requirement where I have to drag the object based on user touch movement (basically touch & drag). Based on the topic Picking, I am able to identify if an object is touched.
My understanding to achieve drag is the object must be translated based on touch coordinates.
I understood how to get 3D to 2D coordinates and viceversa. I am unable to understand,
i) how to co relate this to translation?
ii) How the screen width and height is translated to translate factors,
when I tried
object.translate(-100,100,0); the object was not seen. I tried by trial and error and found translate x should be in range of -30 to +30 and y in range of -45 to +45.
I did the following Math calculation on Touch listener
if (me.getAction() == MotionEvent.ACTION_MOVE) {
xpos = me.getX();
ypos = me.getY();
if(sphereclicked) // if the object is clicked
{
SimpleVector touchvector =
Interact2D.reproject2D3DWS(world.getCamera(), fb, (int)xpos, (int)ypos).normalize();
sphere_vector = Interact2D.projectCenter3D2D(fb,sphere); // sphere is the 3D object
if(diff == null)
{
diff = new SimpleVector();
}
diff.x = ((sphere_vector.x) - xpos)/-10.5f; // this is also trial and error , I didnt understand the Math behind it
diff.y = ((sphere_vector.x) - ypos)/-10.5f;
diff.z = 0;
Log.i("HelloWorldJPCT", "diff : %d %d %d" + diff.x+ " "+
diff.y+" "+ diff.z);
}
And on Draw Frame,
if(sphereclicked == true)
{
if(diff!=null)
{
sphere.clearTranslation();
sphere.translate(diff);
}
}
But after this code, object moves in y-axis and x-axis. But in negative y-axis, the object doesn't move till the end of the screen. The same with x-axis, it never moves till the end of X-Axis.
I am attaching my code for your reference. Please help me to understand the concept behind this. How to relate the touch cordinates to translate for an object.
Thanks in Advance,
[attachment deleted by admin]