I never got it fully working with Peasycam. If my memory serves me well, the problem with PeasyCam is that it's designed as a camera rotated around a center. Like a camera moving on a sphere and always pointed to the center of the sphere. That might not be exactly it, but it was something like that. This is why cam.getLookAt() and cam.getPosition() do work, because for those there is no difference with Sunflow. However once you start rotating problems arise. Because the
cam.getRotations() of PeasyCam is really not the same as the camera rotations of Sunflow. And the difference is not a simple matter of a minus sign, but more fundamental I believe. I could be wrong though.
For full disclosure. Here is some of my flawed PeasyCam code from a year ago...
- cameraPosition = cam.getPosition();
- cameraLookAt = cam.getLookAt();
- cameraRotation = cam.getRotations();
- // note: all of this roll stuff isn't working, apparantly I though this could lead to a solution then ;-)
- roll = cameraRotation[2];
- if (abs(roll) <= HALF_PI) { rollX = roll/(HALF_PI); }
- else if (roll < -HALF_PI) { rollX = -2-roll/HALF_PI; }
- else { rollX = 2-roll/HALF_PI; }
- rollY = (HALF_PI-abs(roll))/HALF_PI;
- // all of this does not work
- sunflow.setCameraPosition(cameraPosition[0], -cameraPosition[1], cameraPosition[2]);
- sunflow.setCameraTarget(cameraLookAt[0], -cameraLookAt[1], cameraLookAt[2]);
- sunflow.setCameraUp(rollX,rollY,0); // doesn't work
Anyway, that's why for HemeshGui I moved to a custom movement system (translation, rotation, zoom) which I was able to sync with Sunflow. However I cheated, because the movement of the camera is limited. For example you can't fly through shapes.
Which is where the code example above comes in, my third attempt. Although very basic, it does allow to freely move all around and still be in sync. As mentioned above it still lacks the final formula, so initially needs some manual syncing. Perhaps it's a focal length vs field of view thing. Don't know. It's the closest I got so far.
I still hope to crack this nut one day, however I've been busy working on other things. I feel the last code is almost there but as with most attempts there always seems to be one last missing puzzle piece. One route that I haven't explored yet, but that may be a solution is the statement on the
Sunflow wiki that "cameras can also use matrix transforms in place of the eye, target, and up values". There might also be some other remaining possibilities. But right now I'm working on other things.