www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: 4ebureG on October 18, 2013, 07:05:43 pm

Title: Move object
Post by: 4ebureG on October 18, 2013, 07:05:43 pm
Hello all!
I am a novice in jpct! Can you help me?
I want my object to move but it looks horrible:

 @Override
   ......
       public boolean onTouchEvent(MotionEvent me) {
       if (me.getAction() == MotionEvent.ACTION_DOWN) {     
          return true;
      }
        if (me.getAction() == MotionEvent.ACTION_UP) {
              x=me.getX();
              y=me.getY();         
       return true;
       }
         if (me.getAction() == MotionEvent.ACTION_MOVE) {           
       return true;
   }
                          try {
               Thread.sleep(15);
           } catch (Exception e) {
           }
           return super.onTouchEvent(me);
       }
            ....
              public void onDrawFrame(GL10 gl) {
      cub = new SimpleVector(Interact2D.projectCenter3D2D(fb, cube));
      if ((x!=0) && (Math.abs(cub.x-x)>5) && (Math.abs(cub.y-y)>5))
      {
      trans = new SimpleVector(Interact2D.reproject2D3DWS(world.getCamera(), fb, (int)x,(int)y));
      trans.z= cube.getCenter().z;
      cub.translate(trans);
      }
              .....
      }
Modify message
Title: Re: Move object
Post by: EgonOlsen on October 18, 2013, 08:40:12 pm
So this is supposed to detect if the object is close to the touch position and if it isn't, it should move it there? If so, it think that it has two flaws:


Try something like

Code: [Select]
trans = new SimpleVector(Interact2D.reproject2D3DWS(world.getCamera(), fb, (int)x,(int)y, cube.getCenter().z));
cube.clearTranslation();
cube.translate(trans);
Title: Re: Move object
Post by: 4ebureG on October 21, 2013, 06:44:35 am
Thank you for answer!
If I do how you wrote above, my object is moving on a pixel because of cube.clearTranslation();
Now I do so:

            ..........
              if (me.getAction() == MotionEvent.ACTION_UP) {
              x=me.getX();
              y=me.getY();
          
              trans = new SimpleVector(Interact2D.reproject2D3DWS(world.getCamera(), fb, (int)x,(int) y));
               pos = world.getCamera().getPosition();
               float Z_PLANE=0;
            float a = (Z_PLANE - pos.z) / trans.z;
               float xn = pos.x + a * trans.x;
               float yn = pos.y + a * trans.y;
               moveVector = new SimpleVector(xn,yn,Z_PLANE);

               return true;

           }


                   ..........             
                   if (moveVector!=null){
              сube.translate(moveVector.normalize());
                }

But my object is moving properly. Help me please!
Title: Re: Move object
Post by: EgonOlsen on October 21, 2013, 08:31:48 pm
You code doesn't do what i suggested. You are still ignoring the depth in the back-projection and that won't work.