dat-ng / ar-location-based-android

This AR app generally show where things are in the real-world by indicating where the app thinks they are over the camera view when the user holds the phone up and moves it about.
MIT License
206 stars 85 forks source link

Landscape orientation not working #12

Open ahmedalaa92 opened 6 years ago

ahmedalaa92 commented 6 years ago

i am using your code sample and your work is great but i have an issue i need the orientation to be landscape the points is not being drawn correctly and they are not correctly moving over the camera view appreciate your help

dat-ng commented 6 years ago

Did you modify width and height in camera view?

2017-10-25 16:05 GMT+07:00 ahmedalaa92 notifications@github.com:

i am using your code sample and your work is great but i have an issue i need the orientation to be landscape the points is not being drawn correctly and they are not correctly moving over the camera view appreciate your help

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/dat-ng/ar-location-based-android/issues/12, or mute the thread https://github.com/notifications/unsubscribe-auth/ABOmjC40d1TnXbnGUuSjvrSwx54CJ-zQks5svvn1gaJpZM4QFqok .

anuloo commented 6 years ago

where exactly need to change if i may ask kindly? I am new to this and its no much comment. Could you give a small example how to change it to landscape?

After changing the camera size by swapping the target height to the width.

still not scroll horizontally

int targetHeight = width;

ShantiRanjanDas commented 6 years ago

did you find the solution, I am also having the same problem ? @dat-ng please fix it. Or tell me where to change.

mulukalaabhisek commented 6 years ago

@dat-ng can you please tell us? @ShantiRanjanDas did you figure it out?

anelfdz commented 6 years ago

Has someone found a solution?

mulukalaabhisek commented 6 years ago

@anelfdz @ShantiRanjanDas @dat-ng @ahmedalaa92 found any solution?

tacoman667 commented 6 years ago

@dat-ng

Sorry to bother you, but I am having this issue where the landscape mode actually draws correctly, but when I move, the object reacts as if it was still in portrait mode. It is as if I need to rotate the rotational matrix or something but I am way out of my depth here.

Modifying the camera parameters hasn't produced any favorable results. I tried to add rotation to the camera parameters as well so that maybe it will recalculate projection matrix properly, but that failed me.

Do you have any insight into how to fix this? Thanks a ton!

tacoman667 commented 6 years ago

Ok. So I got much closer now using the code below. When in landscape mode, the objects are not moving as fast as one would expect during rotation. I am thinking the math might need adjusting somewhere in AROverlayView#onDraw. Can anyone take a look and let me know?

`int worldAxisForDeviceAxisX = SensorManager.AXIS_X; int worldAxisForDeviceAxisY = SensorManager.AXIS_Z;

        // Remap the axes as if the device screen was the instrument panel,
        // and adjust the rotation matrix for the device orientation.
        int rotation = this.getWindowManager().getDefaultDisplay().getRotation();
        switch (rotation) {
            case Surface.ROTATION_90:
                worldAxisForDeviceAxisX = SensorManager.AXIS_Y;
                worldAxisForDeviceAxisY = SensorManager.AXIS_MINUS_X;
                break;
            case Surface.ROTATION_180:
                worldAxisForDeviceAxisX = SensorManager.AXIS_MINUS_X;
                worldAxisForDeviceAxisY = SensorManager.AXIS_MINUS_Y;
                break;
            case Surface.ROTATION_270:
                worldAxisForDeviceAxisX = SensorManager.AXIS_MINUS_Y;
                worldAxisForDeviceAxisY = SensorManager.AXIS_X;
                break;
        }

        float[] adjustedRotationMatrixFromVector = new float[16];
        SensorManager.remapCoordinateSystem(rotationMatrixFromVector, worldAxisForDeviceAxisX, worldAxisForDeviceAxisY, adjustedRotationMatrixFromVector);

        // hack..  portrait mode is working so use original calculations. only if rotated will we calculate adjusted
        if (rotation == Surface.ROTATION_0) Matrix.multiplyMM(rotatedProjectionMatrix, 0, projectionMatrix, 0, rotationMatrixFromVector, 0);
        else Matrix.multiplyMM(rotatedProjectionMatrix, 0, projectionMatrix, 0, adjustedRotationMatrixFromVector, 0);`
ShantiRanjanDas commented 6 years ago

I have solved it by exchanging the values in onDraw of ArOverlayView

if ((rotation == Surface.ROTATION_0) || (rotation == Surface.ROTATION_180)) {
                        x = (0.5f + cameraCoordinateVector[0] / cameraCoordinateVector[3]) * canvas.getWidth();
                        y = (0.5f - cameraCoordinateVector[1] / cameraCoordinateVector[3]) * canvas.getHeight();

                    } else {
                        x = (0.5f + cameraCoordinateVector[1] / cameraCoordinateVector[3]) * canvas.getWidth();
                        y = (0.5f - cameraCoordinateVector[0] / cameraCoordinateVector[3]) * canvas.getHeight();

                    }
tacoman667 commented 6 years ago

@ShantiRanjanDas I am trying out your code, and it seems that left/right panning indeed works as expected. But up/down movement is reversed.