Author Topic: Different camera rotation than device rotation  (Read 1279 times)

Offline billda

  • byte
  • *
  • Posts: 12
    • View Profile
Different camera rotation than device rotation
« on: September 09, 2014, 01:32:06 pm »
Hi, Ok i have another silly question. I am implementing some kind of augmented reality application. I am displaying camera preview and overlaying it with 3D object. I am getting data from gyroscope and rotating camera of jpct so object is rotated corresponding with device rotation. My problem is that model is moving quicker than "real world" at camera preview. I thought that it has something to do with FOV so i took that "FOV" code from vuforia sample, but it didnt solve that problem, model was streched and problem with rotation was not solved.

Is there any way how I can "normalize" this movements?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12011
    • View Profile
    • http://www.jpct.net
Re: Different camera rotation than device rotation
« Reply #1 on: September 10, 2014, 08:16:43 am »
I'm not sure. If you are doing the transformation between the different coordinate systems properly, i would expect the rotations to be in sync. But then again, i've never used this stuff, so i've no real idea what kind of matrix the gyroscope API returns.

Offline billda

  • byte
  • *
  • Posts: 12
    • View Profile
Re: Different camera rotation than device rotation
« Reply #2 on: September 15, 2014, 04:27:46 pm »
Here is code for my transformation:
Code: [Select]
            cam = world.getCamera();
            Matrix r = getRotationMatrix(rotationMatrix);
            r.transformToGL();
            cam.setBack(r);

where rotationMatrix is matrix from gyroscope. Method getRotationMatrix is just converting between different data types for matrices. Do you think that I should do some extra transformation? I thought that its not necessary when all three rotations are in the right direction.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12011
    • View Profile
    • http://www.jpct.net
Re: Different camera rotation than device rotation
« Reply #3 on: September 16, 2014, 02:55:29 pm »
Looks fine at first glance. it would be nice to see getRotationMatrix() anyway...

Offline billda

  • byte
  • *
  • Posts: 12
    • View Profile
Re: Different camera rotation than device rotation
« Reply #4 on: September 16, 2014, 03:51:37 pm »
Okey, its only converting from 3x3 array to 4x4 matrix:

Code: [Select]
private Matrix getRotationMatrix(float[] data) {
            Matrix ret = new Matrix();

            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {
                    ret.set(i, j, data[i * 3 + j]);
                }
            }
            ret.setRow(3, 0, 0, 0, 1);
            ret.setColumn(3, 0, 0, 0, 1);
            return ret;
       }

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12011
    • View Profile
    • http://www.jpct.net
Re: Different camera rotation than device rotation
« Reply #5 on: September 18, 2014, 08:14:00 pm »
Looks ok...have you tried to leave out the r.transformToGL(); call just to make sure that the matrix isn't in the correct format already?