Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - sebasalazar

#1
Support / Android Move Object3D onTouch
November 04, 2016, 05:17:54 AM
Hi.

I'm new to Android programming and augmented reality, but I would like to move an object that appears with a marker. I have relied on a library that integrates ARToolkit and JPCT-AE ( https://github.com/plattysoft/ArToolKitJpctBaseLib ). I have read some forum threads, but without success.

In my mind it sounded pretty good to implement a onTouch from the Renderer, but it has not worked for me.

@Override
    public boolean onTouch(View view, MotionEvent event) {
        Log.d(TAG, "Tocando pantalla");


        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            xpos = event.getX();
            ypos = event.getY();
            Log.d(TAG, String.format("Action Down (%f,%f)", xpos, ypos));

            if (mBuffer != null) {
                SimpleVector pos = Interact2D.reproject2D3D(mCamera, mBuffer, (int) xpos, (int) ypos, 50f);
                pos.matMul(mCamera.getBack().invert3x3());
                this.mTrackableObjects.get(0).clearTranslation();
                this.mTrackableObjects.get(0).translate(pos);
            }
            return true;
        }

        if (event.getAction() == MotionEvent.ACTION_UP) {
            xpos = -1;
            ypos = -1;
            touchTurn = 0;
            touchTurnUp = 0;
            Log.d(TAG, "Action Up");
            return true;
        }

        if (event.getAction() == MotionEvent.ACTION_MOVE) {
            float xd = event.getX() - xpos;
            float yd = event.getY() - ypos;

            xpos = event.getX();
            ypos = event.getY();

            touchTurn = xd / -100f;
            touchTurnUp = yd / -100f;

            if (mBuffer != null) {
                SimpleVector pos = Interact2D.reproject2D3D(mCamera, mBuffer, (int) xpos, (int) ypos, 50f);
                pos.matMul(mCamera.getBack().invert3x3());
                this.mTrackableObjects.get(0).clearTranslation();
                this.mTrackableObjects.get(0).translate(pos);
            }

            Log.d(TAG, String.format("Action Move (%f,%f)", xpos, ypos));
            return true;
        }

        try {
            Thread.sleep(15);
        } catch (Exception e) {
            // No need for this...
        }
        return false;
}


If you need more context, I have the project https://github.com/sebasalazar/Haunter

I would ask any advice or suggestions, or any guide as it should do, because I'm very lost: S

PD: Sorry for my english.