so i have been trying to perfect spherical orbiting, what i have is a sphere located at (0, 0, 0), and a camera that rotates around it in a...spherical way. i can make rotations in the x-z plane (around) just fine but when it comes to rotating in the y-z plane (rotating towards the top or bottom of something, not around) it bugs out and won't rotate properly. I am trying to achieve the same effect as peasycam minus the enertia and fancy stuff. here is my code:
- import processing.opengl.*;
- PVector cam;
- float camRadius, camTheta, camPhi;
- private final static float compensation = 0.05f;
- void setup() {
- size(500, 500, OPENGL);
- hint(ENABLE_OPENGL_4X_SMOOTH);
- hint(DISABLE_DEPTH_TEST);
- cam = new PVector();
- camRadius = 250.0f;
- camTheta = 70.0f;
- camPhi = -25.0f;
- updateCamera();
- }
- void draw() {
- background(255);
- lights();
- if (mousePressed) {
- camTheta += (mouseX-pmouseX)*compensation;
- camPhi += (mouseY-pmouseY)*compensation;
- println(camPhi);
- }
- updateCamera();
- camera(cam.x, cam.y, cam.z, 0, 0, 0, 0, 1, 0);
- sphereDetail(15);
- fill(255);
- stroke(255);
- sphere(25);
- }
- public void updateCamera() {
- cam.x = camRadius * sin(camTheta)*sin(camPhi);
- cam.y = camRadius * -cos(camPhi);
- cam.z = camRadius * -cos(camTheta)*sin(camPhi);
- redraw();
- }
1