0

Intro I want to render celestial bodies based on their real-world positions in a geocentric system using OpenGL. I pull the daily updated real-world coordinates from NASA's Horizons system via a custom Python script and write them to a CSV file. Here is an example of the CSV file that I pass as input to my C++/OpenGL program: emphemerides.csv

The figure shows that the coordinates are outside the range [1, -1]. As a result, OpenGL will not render them. I hold this positional data in a float-vector, which I then pass to the vertex buffer object:

RenderingData convert(const EphemerisParsingResult &parsing_result) {
    const size_t num_positions = parsing_result.num_parsed_rows;
    const unsigned int vector_dimension = 3;
    std::vector<float> positions(num_positions * vector_dimension);
    for (int i = 0; i < parsing_result.num_parsed_rows; ++i) {
        positions[i + 0] = static_cast<float>(parsing_result.position_x_km[i]); // x coordinate of ephemeris i
        positions[i + 1] = static_cast<float>(parsing_result.position_y_km[i]); // y coordinate of ephemeris i
        positions[i + 2] = static_cast<float>(parsing_result.position_z_km[i]); // z coordinate of ephemeris i
    }
    RenderingData renderingPacket;
    renderingPacket.positions = positions;
    return renderingPacket;
}

// ...

VertexBufferObject::VertexBufferObject(const std::vector<float> &vertices, const GLenum usage)
        : AbstractOpenGlBufferObject(GL_ARRAY_BUFFER, vertices.size(), sizeof(float) * vertices.size()),
          vertices_(vertices), usage_(usage) {
}

void VertexBufferObject::setBufferData() {
    glBufferData(GL_ARRAY_BUFFER, getUsedMemorySize(), &vertices_[0], usage_);
}

Question

How to transform such real coordinates into normalized device coordinates? I would appreciate the exact transformation matrix.

Spektre
  • 45,598
  • 10
  • 100
  • 347
Dawid
  • 168
  • 8
  • 2
    Actually you are looking for a tutorial. Start here: [LearnOpenGL - Coordinate Systems](https://learnopengl.com/Getting-started/Coordinate-Systems). – Rabbid76 Apr 14 '22 at 17:57
  • there are quite a few chalenges ahead of your see [Is it possible to make realistic n-body solar system simulation in matter of size and mass?](https://stackoverflow.com/a/28020934/2521214) ... I am doing this by creating transform matrix representing Earth center of mass , then derive local observer matrix from it and use that to transform the global positions into local viewer one. As you have already geocentric locations you do not need Earths position in that first matrix just the rotations (dayly rotation, nutation, precession) ... – Spektre Apr 15 '22 at 09:14

0 Answers0