Example #1
0
void SegmentGL::CalculateSegmentContour(QVector<GLfloat> *positions, float lat_first, float lon_first, float lat_last, float lon_last)
{
    QVector3D pos;

    double sinlatdiff = sin((lat_first-lat_last)/2);
    double sinlondiff = sin((lon_first-lon_last)/2);

    double sinpsi = sqrt(sinlatdiff * sinlatdiff + cos(lat_first)*cos(lat_last)*sinlondiff * sinlondiff);
    double delta = 2*asin(sinpsi);

    int nDelta = 10;
    double deltax = delta / (nDelta - 1);
    double lonpos, latpos, dlon, tc;

    tc = fmod(atan2(sin(lon_first-lon_last)*cos(lat_last), cos(lat_first)*sin(lat_last)-sin(lat_first)*cos(lat_last)*cos(lon_first-lon_last)) , 2 * PI);
    for (int pix = 0 ; pix < nDelta; pix++)
    {
        latpos = asin(sin(lat_first)*cos(deltax * pix)+cos(lat_first)*sin(deltax * pix)*cos(tc));
        dlon=atan2(sin(tc)*sin(deltax * pix)*cos(lat_first),cos(deltax * pix)-sin(lat_first)*sin(latpos));
        lonpos=fmod( lon_first-dlon + PI,2*PI )-PI;

        LonLat2PointRad(latpos, lonpos, &pos, 1.001f);

        positions->append(pos.x());
        positions->append(pos.y());
        positions->append(pos.z());
    }
}
Example #2
0
void SatGL::RenderTrail(Satellite *sat, QMatrix4x4 projection, float distance, QQuaternion quat, bool trackon) // QMatrix4x4 modelview, bool trackon)
{
    QVector<GLfloat> postrail;

    double
            tsince,            // Time since epoch (in minutes)
            jul_epoch,         // Julian date of epoch
            jul_utc;           // Julian UTC date


    QSgp4Date nowutc = QSgp4Date::NowUTC();
    jul_utc = nowutc.Julian();
    jul_epoch = Julian_Date_of_Epoch(sat->GetEpoch());

    QMatrix4x4 model;
    model.translate(0.0, 0.0, distance);
    model.rotate(quat);

    QMatrix4x4 modelview;
    modelview = model;
    QMatrix4x4 modelocta;
    QColor col(0,255,255);

    QEci qeci;
    QVector3D pos;
    double id;
    int nbrVertices = 0;

    tsince = (jul_utc - jul_epoch) * MIN_PER_DAY; // in minutes

    for( id = tsince - 5; id < tsince; id++ )
    {
        (*sat).qsgp4->getPosition(id, qeci);
        QGeodetic qgeo = qeci.ToGeo();
        LonLat2PointRad(qgeo.latitude, qgeo.longitude, &pos, 1.001f);
        if(id < tsince && id >= tsince - 5 )
        {
            modelocta = model;
            modelocta.translate(pos.x(), pos.y(), pos.z());
            modelocta.scale(0.004f);
            octa->render(projection, modelocta, col);
        }
    }


    if(trackon)
    {
        for( id = tsince - opts.realminutesshown + 1; id <= tsince + opts.realminutesshown; id++ )  // nbr of id's = 2 * opts.realminutesshown
        {
            (*sat).qsgp4->getPosition(id, qeci);
            QGeodetic qgeo = qeci.ToGeo();
            LonLat2PointRad(qgeo.latitude, qgeo.longitude, &pos, 1.001f);
            postrail.append(pos.x());
            postrail.append(pos.y());
            postrail.append(pos.z());
        }

        positionsTrail.bind();

        if(tdiff != opts.realminutesshown)
        {
            tdiff = opts.realminutesshown;
            positionsTrail.allocate(postrail.data(), postrail.size() * sizeof(GLfloat));

        }
        else
        {
            positionsTrail.write(0, postrail.data(), postrail.size() * sizeof(GLfloat));
        }

        nbrVertices = positionsTrail.size() / (3 * sizeof(GLfloat));

        positionsTrail.release();

        QOpenGLVertexArrayObject::Binder vaoBinder(&vaotrail);

        program->bind();

        program->setUniformValue("MVP", projection * modelview);
        QMatrix3x3 norm = modelview.normalMatrix();
        program->setUniformValue("NormalMatrix", norm);

        QColor rendercolor(opts.sattrackcolor);
        program->setUniformValue("outcolor", QVector4D(rendercolor.redF(), rendercolor.greenF(), rendercolor.blueF(), 1.0f));

        glDrawArrays(GL_LINE_STRIP, 0, nbrVertices);

    }
}
Example #3
0
void SegmentGL::RenderContour(Segment *seg, QMatrix4x4 projection, QMatrix4x4 modelview, int width, int height)
{

    QVector3D vec;
    QVector3D pos;
    QVector<GLfloat> positions;
    QEci qeci;


    CalculateSegmentContour(&positions, seg->cornerpointfirst1.latitude, seg->cornerpointfirst1.longitude, seg->cornerpointlast1.latitude, seg->cornerpointlast1.longitude);
    CalculateSegmentContour(&positions,seg->cornerpointlast1.latitude, seg->cornerpointlast1.longitude, seg->cornerpointlast2.latitude, seg->cornerpointlast2.longitude);
    CalculateSegmentContour(&positions, seg->cornerpointlast2.latitude, seg->cornerpointlast2.longitude, seg->cornerpointfirst2.latitude, seg->cornerpointfirst2.longitude);
    CalculateSegmentContour(&positions,seg->cornerpointfirst2.latitude, seg->cornerpointfirst2.longitude, seg->cornerpointfirst1.latitude, seg->cornerpointfirst1.longitude);

    seg->qsgp4->getPosition(seg->minutes_since_state_vector, qeci);
    QGeodetic qgeo = qeci.ToGeo();
    double lat1 = qgeo.latitude;
    double lon1 = qgeo.longitude;

    seg->qsgp4->getPosition(seg->minutes_since_state_vector + seg->minutes_sensing, qeci);
    qgeo = qeci.ToGeo();
    double lat2 = qgeo.latitude;
    double lon2 = qgeo.longitude;

    CalculateSegmentContour(&positions, lat1, lon1, lat2, lon2);

    positionsBuf.bind();
    positionsBuf.write(0, positions.data(), positions.size() * sizeof(GLfloat));
    positionsBuf.release();

    QOpenGLVertexArrayObject::Binder vaoBinder(&vao);

    program->bind();
    program->setUniformValue("MVP", projection * modelview);
    QColor rendercolor(opts.satsegmentcolor);
    QColor rendercolorsel(opts.satsegmentcolorsel);

    if((*seg).segmentselected)
        program->setUniformValue("outcolor", QVector4D(rendercolorsel.redF(), rendercolorsel.greenF(), rendercolorsel.blueF(), 1.0f));
    else
        program->setUniformValue("outcolor", QVector4D(rendercolor.redF(), rendercolor.greenF(), rendercolor.blueF(), 1.0f));

    QMatrix3x3 norm = modelview.normalMatrix();
    program->setUniformValue("NormalMatrix", norm);

    glDrawArrays(GL_LINE_LOOP, 0, nbrOfVertices - 10);
    glDrawArrays(GL_LINE_STRIP, nbrOfVertices - 10, 10);


    float mvmatrix[16], projmatrix[16];
    QMatrix4x4 MVP;
    MVP = projection * modelview;

    float *ptr = modelview.data();
    for(int i = 0; i < 16; i++)
        mvmatrix[i] = *(ptr + i);

    ptr = projection.data();
    for(int i = 0; i < 16; i++)
        projmatrix[i] = *(ptr + i);

    QVector2D win;

    LonLat2PointRad((float)seg->cornerpointfirst1.latitude, (float)seg->cornerpointfirst1.longitude, &vec, 1.0);
    win = glhProjectf (vec, mvmatrix, projmatrix, width, height);
    seg->winvecend1 = win;

    LonLat2PointRad((float)seg->cornerpointfirst2.latitude, (float)seg->cornerpointfirst2.longitude, &vec, 1.0);
    win = glhProjectf (vec, mvmatrix, projmatrix, width, height);
    seg->winvecend2 = win;

    LonLat2PointRad((float)seg->cornerpointlast1.latitude, (float)seg->cornerpointlast1.longitude, &vec, 1.0);
    win = glhProjectf (vec, mvmatrix, projmatrix, width, height);
    seg->winvecend3 = win;

    LonLat2PointRad((float)seg->cornerpointlast2.latitude, (float)seg->cornerpointlast2.longitude, &vec, 1.0);
    win = glhProjectf (vec, mvmatrix, projmatrix, width, height);
    seg->winvecend4 = win;

    win = glhProjectf (seg->vec1, mvmatrix, projmatrix, width, height);
    seg->winvec1 = win;

    win = glhProjectf (seg->vec2, mvmatrix, projmatrix, width, height);
    seg->winvec2 = win;

}