Author Topic: Camera rotation issue  (Read 3246 times)

Offline AeroShark333

  • float
  • ****
  • Posts: 319
    • View Profile
Camera rotation issue
« on: July 14, 2018, 01:34:13 pm »
Hello,

I got a small issue with camera rotations.
My camera automatically rotates around a spherical object like this:
1. Set camera position to center of sphere.
2. Apply rotations
3. Camera.MOVE_OUT
This all works fine but after a long while (let's say 8+ hours) the rotation around the sphere don't seem spherical any more (or the rotation pivot center has some offset).
But the spherical object that the camera is facing isn't in the center any more but slightly offset. The longer you wait the worse this offset gets.
I suppose it'd have to do something with floating point precision but I'm not sure.
Any solutions?

Cheers

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Camera rotation issue
« Reply #1 on: July 16, 2018, 11:19:02 am »
Yes, shoulds like some accuracy issue, but some your description, it's hard to tell where it comes from!? What does step 2/apply rotations actually do?

Offline AeroShark333

  • float
  • ****
  • Posts: 319
    • View Profile
Re: Camera rotation issue
« Reply #2 on: July 17, 2018, 02:50:48 pm »
So I have a spherical object (which position changes every draw call).
For that, I need to move the camera along with the object which is step 1 (settings the camera's position to the center of the sphere)
But the user might have some touch interaction going on (which changes the camera rotation)
Also autorotation could be enabled (which also changes camera rotation)
I basically change the rotation of the camera while the camera is in the center of the spherical object.
And only after that I apply step 3 (Camera.MOVE_OUT), this makes sure that the camera faces the center of the spherical object.
But it's not like I'm using Camera.MOVE_OUT with diffferent radia, it's fixed.

EDIT: I just noticed that I swapped step 1 and step 2 in my code... but that still shouldn't matter I believe

Only when autorotation is enabled it will start to get messy after a while. (the spherical object is no longer perfectly in the center)
When you try to change the rotation with touch(or autorotation), it will look like the spherical object is also rotating around some (really small) pivot point (which isn't really there since it should just be the object's center)
But at launch (when autorotation hasn't been active for long) the rotation using touch (or autorotation) works fine and there's no weird offsets or extra 'pivot point'.

The spherical object does actually rotate around some pivot, but this position is reset every draw call (so I don't think it's related to this).
The camera's rotation is never reset so I think the issue might lie here... (long-term rotations causing accuracy issues)

_______________________
SIMPLIFIED CODE FOR DRAW CALLS:
_______________________
object.clearRotation();
object.clearTranslation();
object.translate(blahblah1);
object.rotate(blahblah2); // I personally don't think the issue is here since the rotations aren't accumulated but reset for every draw call

camera.rotateX(touchX+autorotationX);
camera.rotateX(touchY+autorotationY);
camera.rotateZ(dualTouchZ+autorotationZ);

camera.setPosition(object.getTransformedCenter());

camera.moveCamera(Camera.CAMERA_MOVEOUT, someRadius);

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Camera rotation issue
« Reply #3 on: July 17, 2018, 03:09:38 pm »
Quote
The camera's rotation is never reset so I think the issue might lie here...
Yes, most likely. You can try to apply http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Matrix.html#orthonormalize() from time to time to it and see if that helps.

Offline AeroShark333

  • float
  • ****
  • Posts: 319
    • View Profile
Re: Camera rotation issue
« Reply #4 on: July 23, 2018, 06:07:52 pm »
I think this would solve the problem, thanks! :)
I'll report back later if I can test it

Offline AeroShark333

  • float
  • ****
  • Posts: 319
    • View Profile
Re: Camera rotation issue
« Reply #5 on: July 30, 2018, 09:15:40 pm »
Doing the orthonormalization fixed the issue :)

Also I reported some SIGSEGV errors earlier at some point...
I thought that loading models/vertex data before texture data would fix the issue...
While it completely fixed the issue on the emulator (I was never able to reproduce it again), there are still SIGSEGV's happening according to the Play Store Console...
But I think the amount of reports did decrease

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Camera rotation issue
« Reply #6 on: July 31, 2018, 09:13:26 am »
There will always be SIGSEGVs...no driver is perfect and people are doing all kinds of strange things with their devices that are out of your control.