Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Touch & Drag problem #62

Open
NtcWai opened this issue Jun 10, 2015 · 1 comment
Open

Touch & Drag problem #62

NtcWai opened this issue Jun 10, 2015 · 1 comment

Comments

@NtcWai
Copy link

NtcWai commented Jun 10, 2015

I coded follow the class TouchAndDragFragment:

public void moveSelectedObject(float x, float y) {
            if (mSelectedObject == null)
                return;

            //
            // -- unproject the screen coordinate (2D) to the camera's near plane
            //

            GLU.gluUnProject(x, getViewportHeight() - y, 0, mViewMatrix.getDoubleValues(), 0,
                mProjectionMatrix.getDoubleValues(), 0, mViewport, 0, mNearPos4, 0);

            //
            // -- unproject the screen coordinate (2D) to the camera's far plane
            //

            GLU.gluUnProject(x, getViewportHeight() - y, 1.f, mViewMatrix.getDoubleValues(), 0,
                    mProjectionMatrix.getDoubleValues(), 0, mViewport, 0, mFarPos4, 0);

            //
            // -- transform 4D coordinates (x, y, z, w) to 3D (x, y, z) by dividing
            // each coordinate (x, y, z) by w.
            //

            mNearPos.setAll(mNearPos4[0] / mNearPos4[3], mNearPos4[1]
                    / mNearPos4[3], mNearPos4[2] / mNearPos4[3]);
            mFarPos.setAll(mFarPos4[0] / mFarPos4[3],
                    mFarPos4[1] / mFarPos4[3], mFarPos4[2] / mFarPos4[3]);

            //
            // -- now get the coordinates for the selected object
            //

            double factor = (Math.abs(mSelectedObject.getZ()) + mNearPos.z)
                    / (getCurrentCamera().getFarPlane() - getCurrentCamera()
                            .getNearPlane());

            mNewObjPos.setAll(mFarPos);
            mNewObjPos.subtract(mNearPos);
            mNewObjPos.multiply(factor);
            mNewObjPos.add(mNearPos);

            mSelectedObject.setX(mNewObjPos.x);
            mSelectedObject.setY(mNewObjPos.y);
        }

and got an error like this.
I want to pick and drag object smoothly, but it immediately jumps to the touched position.
1
How to correct it ?
Thank for any help!

@Angie-Ie
Copy link

Angie-Ie commented Nov 4, 2016

Hi @cuagia ,
I got same problem too, did you solve the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants