pioneerspacesim / pioneer

A game of lonely space adventure
https://pioneerspacesim.net
1.64k stars 380 forks source link

[Suggestion] Apoapsis and Periapsis #1648

Closed Lillz closed 10 years ago

Lillz commented 12 years ago

I think it would be very useful for the game to have a small map somewhere where you could see what your orbit looks like around a planet. It would give your apoapsis height and your periapsis height. It would be very useful when trying to land as well.

Brianetta commented 12 years ago

I wrote this as a Lua script (it's in #1633). It doesn't tell you anything about your current orbit (there's nowhere near enough information exposed to Lua to do that at the moment) but it does give you some ideal speeds for the current altitude. Google+

It works well. This video shows you how this information can be used for a perfect entry, descent and landing.

There's no visualistion, and as I said no analysis of your actual current orbit. I'm not sure how we'd go about that at all - one of the C++ devs might have a better idea of what's possible.

Lillz commented 12 years ago

I understand. If you ever do figure something out, for a general idea of a cool idea to visualize it, you should check out Kerbal Space Program. The map on that game is incredible, but I'm sure it doesn't use lua

Brianetta commented 12 years ago

I'm sure somebody clever will find a way, eventually.

I've only seen Kerbal Space Program on Youtube, it being a Windowsy commercial demo game and me not feeling attracted to that sort of idea. I'd be very surprised if it used Lua at all.

fluffyfreak commented 12 years ago

@Brianetta if it can be run in WINE then I recommend giving at least the demo a go, despite the cutesy appearance it's also got a solid and fun physics side to it and as @Lillz says there's some really good visualisations for things like orbits.

irigi commented 12 years ago

It's not that hard for me to calculate the trajectory parameters (apoapsis, periapsis, eccentricity, x,y,z positions of apoapsis, periapsis, foci, major and minor semiaxes, etc.), but I can do almost nothing with graphics. If someone is willing to draw the trajectory, I can help to fill in the technical stuff. (Just tell me what trajectory parameters you find useful.)

skapusniak commented 12 years ago

Had a quick poke around in the code, and there is the promising looking PutOrbit method in SystemView (which you get to using F6 on the Map screen):

void SystemView::PutOrbit(SystemBody *b, vector3d offset)
{
    vector3f vts[100];
    Color green(0.f, 1.f, 0.f, 1.f);
    for (int i = 0; i < int(COUNTOF(vts)); ++i) {
        const double t = double(i) / double(COUNTOF(vts));
        vector3d pos = b->orbit.EvenSpacedPosAtTime(t);
        vts[i] = vector3f(offset + pos * double(m_zoom));
    }
    m_renderer->DrawLines(COUNTOF(vts), vts, green, LINE_LOOP);
}

Takes a SystemBody, which I'm not sure whether your ship is.or not (guessing no?), but it's just getting an Orbit structure from that which is defined as:

struct Orbit {
    Orbit(): orbitalPhaseAtStart(0.0) {};
    vector3d OrbitalPosAtTime(double t) const;
    // 0.0 <= t <= 1.0. Not for finding orbital pos
    vector3d EvenSpacedPosAtTime(double t) const;
    /* duplicated from SystemBody... should remove probably */
    double eccentricity;
    double semiMajorAxis;
    double orbitalPhaseAtStart; // 0 to 2 pi radians
    /* dup " " --------------------------------------- */
    double period; // seconds
    matrix4x4d rotMatrix;
};
skapusniak commented 12 years ago

Of course that's a full orbit ellipse (assumes stable), not a trajectory as such.

Lillz commented 12 years ago

KSP is available on mac already. Now I don't really understand the code above me, but it looks promising.

Ae-2222 commented 12 years ago

a small map somewhere where you could see what your orbit looks like around a planet

It's something I've thought about a bit before.. Along the lines of:

An intuitive way is probably needed to:

  1. allow players unfamiliar with orbital mechanics (pretty much everyone) to see and understand orbits and their elliptical nature (as well as other trajectories)
  2. set precise orbits with awareness of tactics (staying out of range of certain planetary installations/orbiting stations/drone nets, staying under cover of closely orbiting asteroids, low-on-fuel manoeuvres etc.)
  3. see the results of maintaining the current trajectory indefinitely (i.e. unpowered)
  4. allow modders to visualise orbits when setting up systems without knowledge of orbital mechanics. And allow lua output like in #1565.
  5. allow modders to visualise orbits of ships/cargo etc. when writing missions.
  6. possibly define orbital parameters using more intuitive terms (center to periapsis vector-avoids longitude of ascending node, mean anomaly - easily understood as a phase, ellipse aspect ratio - instead of eccentricity, period etc.)

My current state of thought is to have a general widget that allows an ellipse to be created and resized/rotated or just display an orbit non-interactively.

This needs things like (full-ish use, we likely won't need all of the features for quite a while):

And other stuff I can't recall off the top of my head:).

As for a 2d map showing the path of the orbit over a surface: I plan to look into some form of cylindrical projection for a variety of uses. A 2d map can be looked at after the map is developed. It's possible to either use this map to texture a 3d globe or use a mini-geosphere with patch restrictions (after multiple camera support is added) .


If a graphics person wants to work further on something a bit like this: A minimum widget (non-interactive) might need

SystemView::PutOrbit

This is a pretty good starting point:).

Takes a SystemBody, which I'm not sure whether your ship is.or not (guessing no?)

A SystemBody is a sysgen output representing something like a planet, starport/station. That struct and its member functions are also used by the physics for orbit rails. The ship is a dynamic body and doesn't use orbit rails.

A function that derives orbital parameters as well as the nature of the trajectory given position and velocity relative to a planet is useful.

The Orbit struct could be extended to provide position/velocity given orbital parameters, convert between more intuitive parameters, and any other related functions.

irigi commented 12 years ago

@skapusniak Offtopic question: How do you do these nice code-blocks with syntax highlighting? Thanks!

Brianetta commented 12 years ago

You click the link above and right, and scroll down to the "Code" section. I've copied the link here:

Comments are parsed with GitHub Flavored Markdown

irigi commented 12 years ago

Great, thanks!

skapusniak commented 12 years ago

@irigi Take a look at the syntax highlighting section on the Github Flavoured Markdown page. To do it inline like this just put the backticks around what you what syntax highlighted within the line.

Brianetta commented 12 years ago

I figured out how to mark down an example!

```lua
 print('Hello') -- Comment
```
 print('Hello') -- Comment
```c++
 printf("Hello"); // Comment
```
 printf("Hello"); // Comment
impaktor commented 10 years ago

Everything the original poster requested is now in the game, with 3133 merged. Beyond that I suggest dev forum for layout, mockups and feature speculation.