Camera last position

Hi!



For detecting if camera has moved or not, I use pretty simple technique:

  1. get camera position and store it in a variable (curPos).
  2. if (curPos != lastPos) then do things
  3. get camera position and store as (lastPos)



    and I use such code in simpleApplication's simpleUpdate overriden function:


        cameraCurrentPos = cam.getLocation();

        if ( (cameraCurrentPos.x!=cameraPrevPos.x) || (cameraCurrentPos.y!=cameraPrevPos.y) || (cameraCurrentPos.z!=cameraPrevPos.z) ) {
            System.out.println("camera moved");
        }

        cameraPrevPos = cam.getLocation();



Nothings works, and if I set breakpoint inside "IF", programm won't stop there.

First I tried to use something like:

if ( (cameraCurrentPos != cameraPrevPos)


but since they both just point to the memory location they will always be different, and that leads to the fact, that this "IF" will always "do things inside it".

What am I doing wrong?

Sorry, problem solved just by modifying the code a bit.


cameraCurrentPos = cam.getLocation();

        if ( (cameraCurrentPos.x!=cameraPrevPos.x) || (cameraCurrentPos.y!=cameraPrevPos.y) || (cameraCurrentPos.z!=cameraPrevPos.z) ) {
            System.out.println("camera moved");
        }

        cameraPrevPos = cameraCurrentPos.clone(); // here