Quantcast
Channel: Question and Answer » libgdx
Viewing all articles
Browse latest Browse all 434

Object orbiting a 3d sphere

$
0
0

I’m developing in libgdx java/android but not using any high-level environment like Unity.

I have a sphere at [0,0,0], with a PerspectiveCamera looking at it. Through the main game loop I have managed to have the camera orbiting the sphere in different directions. However, what I want to do is have a stationary camera and have 3 objects orbiting the sphere on their own accord, and their own orbital plane. Have been looking all day and struggled to get this working.

Eventually, I want to link the camera to always be above one of the orbitting objects, but that’s at a later stage.

I also want to be able to have these objects orbitting on their own “forwards” direction, but able to change their direction over time. Say, from their top-down view, they each have a heading 0-359 degrees.

Anyone lend a hand with this? I’ve tried using 2D X/Y maps transposing onto mercator projections and then converted to spherical coordinates; I’ve tried Vector3 and setFromSpherical(); I’ve tried looking at Quaternions, and just got lost.

It’s a relatively simple thing I’m trying to do, multiple orbiting objects around a sphere (radius 3, origin [0,0,0]), but just getting my initial approach wrong.

EDIT:

After talking the situation through, I have two options: I either keep track of the orbiting objects with theta/phi as to their position around the sphere, or just calculate the amount by which to rotate based on the object’s direction (0-359). On further talks with DMGregory, the latter option would introduce orbital instability/divergence with roudning errors so I have decided to change my requirement to the following:

  • Keep track of the object’s position based on 2×360 degree values for azimuth and polar, called theta and phi. The two coordinates are used to locate the object at any point in orbit around the sphere, but I need to be able to still “move” the orbital object “forwards” and thus change theta/phi accordingly, allowing the direction to still be changed.

Many thanks,


Viewing all articles
Browse latest Browse all 434

Trending Articles