Hey.
I 'm trying to translate a model on a spherical surface (a planet), I need it to move around the sphere up/down and right/left (I don't need to freely set the orientation, only four directions)
(Y is up, X is right)
I 'm trying doing it in Spherical coordinates and then converting to Cartesian, but it doesn't work:
my theta angle is originally 0 degrees, phi is 90.
radius is the distance from the planet origin to the model.
double thetaSin = Math.sin(Math.toRadians(theta));
double thetaCos = Math.cos(Math.toRadians(theta));
double phiSin = Math.sin(Math.toRadians(phi));
double phiCos = Math.cos(Math.toRadians(phi));
//Translating based on the current direction (variable dir)
//Up:
theta += turnspeed;
if (theta >= 360) {
theta = 0;
}
//Right:
theta += turnspeed;
if (theta >= 360) {
theta = 0;
}
phi -= turnspeed;
if (phi < -180) {
phi = 180;
}
...................... left and down directions.
x = radius * (float) thetaSin*(float)phiCos;
y = radius * (float) thetaSin * (float)phiSin;
z = radius * (float) thetaCos;
model.setTranslation(x, y, z);
I mostly have trouble correctly changing theta/phi while moving right/left, but I'm generally not sure if I'm doing this right.
Can you guys help me?