jPCT-AE - a 3d engine for Android > Support

Need to drag an 3D object based on touch

(1/2) > >>

subhalakshmi27:
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]

EgonOlsen:
If you move your objects in a fixed plane in world space (for example z=10 or something), you can use reproject2D3D for this. Have a look at this thread: http://www.jpct.net/forum2/index.php/topic,2413.0.html. It's for desktop jPCT, but the actual solution is based on the same idea.

subhalakshmi27:
Hi Egon,

Thanks a lot. I am able to move the objects.  :D

Regards,
Subha

gourabf9systems:
Hi ,

Can some one post a good working example of moving android object for android. I try two attached code in this topic. But none of them give accurate result. So please provide me a good example.

gourabf9systems:
Please post working example......

Navigation

[0] Message Index

[#] Next page

Go to full version