1

I've generated 3D overlay using jMonkey in my Android app. Everything works fine - my ninja model is walking in loop. Awsome !

Now I want to rotate camera according to direction of the phone. I thought compass is the best way BUT unfortunatly I have a lot of problems. So here I go

I've created method that is invoked in activity

public void rotate(float x, float y, float z) {
    Log.d(TAG, "simpleUpdate: Nowa rotacja: " + y);
    newX = x;
    newY = y;
    newZ = z;
    newPosition = true;
}

in 'simpleUpdate' method I've managed it this way

    if(newPosition && ninja != null) {
        Log.d(TAG, "simpleUpdate: rotacja: " + newY);
        ninja.rotate((float)Math.toRadians(newX), (float)Math.toRadians(newY), (float)Math.toRadians(newZ));
        newPosition = false;
    }

in my activity I'm checking if phone moved

            if(lastAzimuth != (int)azimuthInDegress) {
                lastAzimuth = (int)azimuthInDegress;

I cast to int so the distortion won't be so big problem

                if ((com.fixus.towerdefense.model.SuperimposeJME) app != null) {
                    ((com.fixus.towerdefense.model.SuperimposeJME) app).rotate(0f, azimuthInDegress, 0f);
                }

At the moment I want to rotate it only in Y axis

Now the main problem is that the rotations is more like jump that rotation. When I move my phone a bit and I have 6 degrees diffrence (i see this in my log) the model is rotated like for 90 degrees and he turns back. This has nothing to do with rotation or change taken from my compas.

Any ideas ?

UPDATE

I think I got it. Method rotate, rotates from current state with value I've set. So it looks more like old Y rotate + new value. So I'm setting the diffrence between current value and old value and it now look almoust fine. Is it the good way ?

Fixus
  • 4,631
  • 10
  • 38
  • 67
  • 1
    "Cast to int" is not a way to make distortion no big problem. What if your compass is returning 1.9, 1.95, 2.05, 2.01, 1.8, 2.2, etc? Then you're suddenly using the sequence 1, 1, 2, 2, 1, 2. That's not less distortion. – Tommy Mar 03 '15 at 20:14
  • @Tommy problem you've discribed maybe will occure in the later stage. At the moment my app works like I would receive sequence 1, 10, 90, 40 :) – Fixus Mar 03 '15 at 20:19

0 Answers0