Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6894255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:45:35+00:00 2026-05-27T06:45:35+00:00

NOTE: this is in the Processing IDE I am trying to get spherical orbiting

  • 0

NOTE: this is in the Processing IDE

I am trying to get spherical orbiting down and i’ve almost got it. this is what i have so far:

float cameraTheta, cameraPhi, cameraRadius; //camera position in spherical coordinates
float camx, camy, camz;

void setup() {
  size(500, 500, P3D);
  background(255);
  cameraRadius = 200.0f;
  cameraTheta = 2.80;
  cameraPhi = 2.0;
  recomputeOrientation();
}


void draw() {
  background(255);
  lights();
  mouseMotion();
  camera(camx, camy, camz, 0, 0, 0, 0, -1, 0);
  sphereDetail(10);
  sphere(25);
}

void mouseMotion()
{
  if (mousePressed) {
    cameraTheta += (mouseX - pmouseX)*0.05;
    cameraPhi   += (mouseY - pmouseY)*0.05;
  }
  recomputeOrientation();     //update camera (x,y,z) based on (radius,theta,phi)
}

void recomputeOrientation()
{
  camx = cameraRadius * sin(cameraTheta)*sin(cameraPhi);
  camz = cameraRadius * -cos(cameraTheta)*sin(cameraPhi);
  camy = cameraRadius * -cos(cameraPhi);
  redraw();
}

the x rotation works great however the y rotation sort of tumbles from the top to the bottom and then back up again over and over as the mouseY changes, what i need is for it to continue to tumble in one direction as long as the mouse moves up and back the other direction as the mouse moves down. can anyone help me figure this out?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:45:36+00:00Added an answer on May 27, 2026 at 6:45 am

    The problem has to do with the up vector for the camera. If you imagine holding the camera and bringing it closer and closer to the pole of the sphere, how do you hold the camera when you go past the pole? Processing knows what to do because of the upY argument of the camera function.

    In your current code, the upY is always -1, which means when the camera orients itself, it will always use the vector <0, -1, 0> as its reference for up. You need to change this so that when it gets to the pole of the sphere, it flips upside down.

    boolean flip = false;
    ...
    void draw() {
        ...
        camera(camx, camy, camz, 0, 0, 0, 0, flip ? 1.0 : -1.0, 0);
        ...
    }
    
    void mouseMotion()
    {
        if (mousePressed) {
            cameraTheta += (mouseX - pmouseX) * 0.05;
    
            if (cameraTheta < 0) cameraTheta += 2 * PI;
            else if (cameraTheta >= 2 * PI) cameraTheta -= 2 * PI;
    
            if (flip)
                cameraPhi += (mouseY - pmouseY) * 0.05;
            else
                cameraPhi -= (mouseY - pmouseY) * 0.05;
    
            if (cameraPhi >= PI) {
                cameraPhi = PI - 0.01;
                cameraTheta += PI;
                flip = !flip;
            }
            else if (cameraPhi <= 0) {
                cameraPhi = 0.01;
                cameraTheta -= PI;
                flip = !flip;
            }
        }
    
        recomputeOrientation();
    }
    

    Notable things:

    1. I added code to keep cameraTheta in the range [0, 2 * PI) and cameraPhi in the range [0.01, PI – 0.01). Mathematically, cameraPhi should be in the range [0, PI), but this causes a flicker at the poles. For the math behind this, check here.
    2. cameraPhi is incremented inversely when flip is true.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(Note: This is for MySQL's SQL, not SQL Server.) I have a database column
Note: This is the opposite direction to most similar questions! I have an iPhone
Note: This question has broadened in scope from previous revisions. I have tried to
I have the following: C:\temp\dowork.exe < input.txt processing....... complete C:\ I try this: processArguments
Okay I've been trying to figure this out for a while now. I have
NOTE: this question is almost a dupe of: stop Ms Excel auto-formatting numeric strings
So we have this Image processing course at the university and we'll be using
I have (Test-A) fully annotated testng test in one project. Note: this test runs
Note: This was posted when I was starting out C#. With 2014 knowledge, I
Note This is not a REBOL-specific question. You can answer it in any language.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.