I am developing a space sandbox (3D). Now I am working on an asteroid belt around a planet. I have an Asteroid
class and an AsteroidBelt
class that has a collection of the Asteroid
instances. Each Asteroid
object is placed randomly during initialization.
Asteroid class:
Matrix4 transform;
double angle;
float x, y, z;
Vector3 initPosition;
public Asteroid(ModelObject object, Texture diffuseTex){
initPosition = new Vector3(
MathUtils.random(-Settings.RingsDepth, Settings.RingsDepth), //x
MathUtils.random(-.5f, .5f), //y
MathUtils.random(-Settings.RingsDepth, Settings.RingsDepth)); //z
}
public void update(Camera camera){
angle += Settings.RingsRotationalSpeed;
if(angle>360) angle=0;
if(angle<0) angle = 360;
double angleRad = angle * MathUtils.degreesToRadians;
x = (float) (Math.sin(angleRad) * Settings.RingsRadius + initPosition.x);
y = initPosition.y;
z = (float) (Math.cos(angleRad) * Settings.RingsRadius + initPosition.z);
transform.idt();
transform.translate(x, y, z);
}
The code above works correctly, but it doesn't allow to rotate the asteroid belt around a planet. How to modify x, y, and z to rotate the asteroid belt around a planet freely? I hope the illustration below will clarify my problem:
Now the asteroid belt looks like below: But I need to rotate it from -90 to 90 degrees by X and Y axis: Any help will be appreciated!