void SkServer::setExtFrame(const QString &data) { QStringList args = data.split(","); if (args.count() != 5) { sendData(SKS_INVALID); return; } double w; double h; double ra, dec; double angle; auto getVal = [this](const QString &str) -> double { QString tmp = str; if (str.endsWith("'")) { tmp.chop(1); return tmp.toDouble() * 60.0; } else if (str.endsWith("\"")) { tmp.chop(1); return tmp.toDouble(); } else { sendData(SKS_INVALID); return -1; } }; w = getVal(args[0]); if (w <= 0) return; h = getVal(args[1]); if (h <= 0) return; angle = args[2].toDouble(); ra = D2R(args[3].toDouble()); dec = D2R(args[4].toDouble()); radec_t rd; rangeDbl(&ra, R360); dec = CLAMP(dec, -R90, R90); CMapView *view = m_mainWin->getView(); if (!view->m_mapView.epochJ2000 && view->m_mapView.coordType == SMCT_RA_DEC) { precess(&ra, &dec, view->m_mapView.jd, JD2000); } rd.Ra = ra; rd.Dec = dec; w /= 3600.0; h /= 3600.0; w = D2R(w); h = D2R(h); g_cDrawing.insertExtFrame(&rd, w, h, angle, tr("External frame field")); sendData(SKS_OK); }
/** Private helper function to calculate the time when the sun will rise * or set on the given day. * @param event Sunrise or sunset * @param day_of_year The day of the year we want the sunrise/set time for * @param latitude The latitude in degrees * @param longitude The longitude in degrees * @param utc_offset The UTC offset in hours * * Note: calculations derived from SunTime class found on CodeProject * Note: these angles would be better to be kept as radians all the time * but that's gonna be tricky, so I'll do it later. */ int _getSunTime(DayTimeEvent event, int day_of_year, double latitude, double longitude, double utc_offset) { // number of hours away from GMT double long_offset = 24 * longitude / 360; // sorry, don't know what this one represents ("appr. time") double t; switch(event) { case DAY_TIME_SUNRISE: t = day_of_year + (6 - long_offset) / 24; break; case DAY_TIME_SUNSET: t = day_of_year + (18 - long_offset) / 24; break; default: dp(0, "bad event type %d\n", event); return INT_MIN; } // mean anomaly double mean = (T_COEFF1 * t) - MEAN_OFFSET; // true longitude double true_long = bound(mean + SIN_MEAN_COEFF * sin(D2R(mean)) + SIN_2MEAN_COEFF * sin(D2R(2 * mean)) + TRUE_LONG_OFFSET, 0, 360); // right ascension double right_asc = bound(R2D(atan(TRUE_LONG_COEFF * tan(D2R(true_long)))), 0, 360); // adjust quadrant of right ascension double base = floor(true_long / 90) * 90; right_asc = base + fmod(right_asc, 90.0); // convert right ascension to an hour offset double right_asc_offset = 24 * right_asc / 360; // more unknown temporaries double sinDec = SIN_TRUE_LONG_COEFF * sin(D2R(true_long)); double cosDec = cos(asin(sinDec)); // local hour angle double cos_hour = (cos(D2R(ZENITH)) - sinDec * sin(D2R(latitude))) / (cosDec * cos(D2R(latitude))); double hour; switch(event) { case DAY_TIME_SUNRISE: hour = 24 * (1 - R2D(acos(cos_hour)) / 360); break; case DAY_TIME_SUNSET: hour = 24 * R2D(acos(cos_hour)) / 360; break; default: dp(0, "bad event type %d\n", event); return INT_MIN; } // local time double local_hour = hour + right_asc_offset - T_COEFF2 * t - LOCAL_OFFSET; // universal time double universal = bound(local_hour - long_offset + utc_offset, 0, 24); int seconds = (int)(universal * 3600); /* printf("N%d, lH%f, t%f, M%f, L%f, RA%f, cH%f, H%f, T%f, UT%f, s%d\n", day_of_year, long_offset, t, mean, true_long, right_asc, cos_hour, hour, local_hour, universal, seconds); */ // time in seconds return seconds; }
static STATUS_T CmdHandLaidTurnout( wAction_t action, coOrd pos ) { ANGLE_T angle, angle2, angle3, reverseR, pointA, reverseA1, angle0; EPINX_T ep, ep1, ep2, ep2a=-1, ep2b=-1, pointEp0, pointEp1; DIST_T dist, reverseD, pointD; coOrd off, intersectP; coOrd pointP, pointC, pointP1, reverseC, point0; track_p trk, trk1, trk2, trk2a=NULL, trk2b=NULL, pointT; trkSeg_p segP; BOOL_T right; track_p trks[4], *trkpp; switch (action) { case C_START: InfoMessage( _("Place frog and drag angle") ); DYNARR_SET( trkSeg_t, tempSegs_da, 1 ); Dhlt.state = 0; Dhlt.normalT = NULL; tempSegs_da.cnt = 0; DYNARR_SET( trkSeg_t, tempSegs_da, 2 ); tempSegs(0).color = drawColorBlack; tempSegs(0).width = 0; tempSegs(1).color = drawColorBlack; tempSegs(1).width = 0; return C_CONTINUE; case C_DOWN: if (Dhlt.state == 0) { if ((Dhlt.normalT = OnTrack( &pos, TRUE, TRUE )) == NULL) break; if ( QueryTrack( Dhlt.normalT, Q_NOT_PLACE_FROGPOINTS ) ) { ErrorMessage( MSG_CANT_PLACE_FROGPOINTS, _("frog") ); Dhlt.normalT = NULL; break; } Dhlt.normalP = Dhlt.reverseP = Dhlt.reverseP1 = pos; Dhlt.normalA = GetAngleAtPoint( Dhlt.normalT, Dhlt.normalP, NULL, NULL ); InfoMessage( _("Drag to set angle") ); DrawLine( &tempD, Dhlt.reverseP, Dhlt.reverseP1, 0, wDrawColorBlack ); Dhlt.state = 1; pointC = pointP = pointP1 = reverseC = zero; return C_CONTINUE; } case C_MOVE: case C_UP: if (Dhlt.normalT == NULL) break; if (Dhlt.state == 1) { DrawLine( &tempD, Dhlt.reverseP, Dhlt.reverseP1, 0, wDrawColorBlack ); Dhlt.reverseP1 = pos; Dhlt.reverseA = FindAngle( Dhlt.reverseP, Dhlt.reverseP1 ); Dhlt.frogA = NormalizeAngle( Dhlt.reverseA - Dhlt.normalA ); /*printf( "RA=%0.3f FA=%0.3f ", Dhlt.reverseA, Dhlt.frogA );*/ if (Dhlt.frogA > 270.0) { Dhlt.frogA = 360.0-Dhlt.frogA; right = FALSE; } else if (Dhlt.frogA > 180) { Dhlt.frogA = Dhlt.frogA - 180.0; Dhlt.normalA = NormalizeAngle( Dhlt.normalA + 180.0 ); /*ep = Dhlt.normalEp0; Dhlt.normalEp0 = Dhlt.normalEp1; Dhlt.normalEp1 = ep;*/ right = TRUE; } else if (Dhlt.frogA > 90.0) { Dhlt.frogA = 180.0 - Dhlt.frogA; Dhlt.normalA = NormalizeAngle( Dhlt.normalA + 180.0 ); /*ep = Dhlt.normalEp0; Dhlt.normalEp0 = Dhlt.normalEp1; Dhlt.normalEp1 = ep;*/ right = FALSE; } else { right = TRUE; } /*printf( "NA=%0.3f FA=%0.3f R=%d\n", Dhlt.normalA, Dhlt.frogA, right );*/ Dhlt.frogNo = tan(D2R(Dhlt.frogA)); if (Dhlt.frogNo > 0.01) Dhlt.frogNo = 1.0/Dhlt.frogNo; else Dhlt.frogNo = 0.0; if (action == C_MOVE) { if (Dhlt.frogNo != 0) { InfoMessage( _("Angle = %0.2f Frog# = %0.2f"), Dhlt.frogA, Dhlt.frogNo ); } else { InfoMessage( _("Frog angle is too close to 0") ); } } else { InfoMessage( _("Select point position") ); Dhlt.state = 2; Translate( &Dhlt.reverseP, Dhlt.reverseP, Dhlt.normalA+(right?+90:-90), trackGauge ); Translate( &Dhlt.reverseP1, Dhlt.reverseP1, Dhlt.normalA+(right?+90:-90), trackGauge ); } DrawLine( &tempD, Dhlt.reverseP, Dhlt.reverseP1, 0, wDrawColorBlack ); return C_CONTINUE; } else if ( Dhlt.state == 2 ) { DrawSegs( &tempD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack ); tempSegs_da.cnt = 0; pointP = pos; if ((pointT = OnTrack( &pointP, TRUE, TRUE )) == NULL) break; if ( QueryTrack( pointT, Q_NOT_PLACE_FROGPOINTS ) ) { ErrorMessage( MSG_CANT_PLACE_FROGPOINTS, _("points") ); break; } dist = FindDistance( Dhlt.normalP, pointP ); pointA = GetAngleAtPoint( pointT, pointP, &pointEp0, &pointEp1 ); angle = NormalizeAngle( pointA + 180.0 - Dhlt.reverseA ); PTRACE(( "rA=%0.1f pA=%0.1f a=%0.1f ", Dhlt.reverseA, pointA, angle )) if ( angle > 90.0 && angle < 270.0 ) { pointA = NormalizeAngle( pointA + 180.0 ); angle = NormalizeAngle( angle + 180.0 ); PTRACE(( " {pA=%0.1f a=%0.1f} ", pointA, angle )) } else {
void translate( coOrd *res, coOrd orig, double a, double d ) { res->x = orig.x + d * sin( D2R(a) ); res->y = orig.y + d * cos( D2R(a) ); }
void XGraphicsOpenGL::DrawPie( float x, float y, float radius, float angStart, float angEnd, XCOLOR color, int maxSlice ) { if( angStart == angEnd ) return; GLfloat r, g, b, a; r = XCOLOR_RGB_R(color) / 255.0f; g = XCOLOR_RGB_G(color) / 255.0f; b = XCOLOR_RGB_B(color) / 255.0f; a = XCOLOR_RGB_A(color) / 255.0f; GLfloat pos[MAX_VERTEX * 2]; GLfloat col[MAX_VERTEX * 4]; float angSlice = 360.0f / (float)maxSlice; // float ang = 0; int i = 0; POSX(i) = x; POSY(i) = y; COLOR(i, r, g, b, a); i++; POSX(i) = x + (sinf(D2R(angStart)) * radius); // 시작각도 버텍스 하나 만들어줌 POSY(i) = y + (-cosf(D2R(angStart)) * radius); COLOR(i, r, g, b, a); i++; ang += angSlice; int num = 0; while( ang < angEnd ) { if( ang >= angStart ) // 각도범위에 포함되면 버텍스를 추가 { float rAng = D2R(ang); // 디그리 각도를 라디안각도로 변환 POSX(i) = x + (sinf(rAng) * radius); POSY(i) = y + (-cosf(rAng) * radius); COLOR(i, r, g, b, a) i++; num++; // 삼각형 개수 if( XBREAK(i >= MAX_VERTEX) ) // 버퍼 오버플로우 되지 않도록 break; } ang += angSlice; } // 마지막각도에 버텍스 하나 더 추가 POSX(i) = x + (sinf(D2R(angEnd)) * radius); POSY(i) = y + (-cosf(D2R(angEnd)) * radius); COLOR(i,r,g,b,a); i++; num++; // gl draw glPushMatrix(); glLoadIdentity(); glDisable( GL_TEXTURE_2D ); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); // 이건 안해줘도 되네. glVertexPointer(2, GL_FLOAT, 0, pos); glEnableClientState(GL_VERTEX_ARRAY); glColorPointer(4, GL_FLOAT, 0, col); glEnableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDrawArrays(GL_TRIANGLE_FAN, 0, i); // i==버텍스개수 glDisableClientState(GL_COLOR_ARRAY); glEnable( GL_TEXTURE_2D ); glPopMatrix(); /* FVF_2DVERTEX *aVertex = m_aVertex; aVertex[0].vPos.x = x; aVertex[0].vPos.y = y; // 파이의 중심점 aVertex[0].dwColor = color; aVertex[1].vPos.x = x + (sinf(D2R(angStart)) * radius); // 시작각도 버텍스 하나 만들어줌 aVertex[1].vPos.y = y + (-cosf(D2R(angStart)) * radius); aVertex[1].dwColor = color; ang += angSlice; aVertex = &m_aVertex[2]; const FVF_2DVERTEX *pEnd = &m_aVertex[ MAX_2DVERTEX ]; int num = 0; while( ang < angEnd ) { if( ang >= angStart ) // 각도범위에 포함되면 버텍스를 추가 { float rAng = D2R(ang); // 디그리 각도를 라디안각도로 변환 aVertex->vPos.x = x + (sinf(rAng) * radius); aVertex->vPos.y = y + (-cosf(rAng) * radius); aVertex->dwColor = color; aVertex++; num++; // 삼각형 개수 if( aVertex > pEnd ) // 버퍼 오버플로우 되지 않도록 break; } ang += angSlice; } // 마지막각도에 버텍스 하나 더 추가 aVertex->vPos.x = x + (sinf(D2R(angEnd)) * radius); aVertex->vPos.y = y + (-cosf(D2R(angEnd)) * radius); aVertex->dwColor = color; num++; D3DXMATRIX m; D3DXMatrixIdentity( &m ); m_pd3dDevice->SetTexture( 0, NULL ); m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE ); m_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA ); m_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA ); m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE ); m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE ); m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); m_pd3dDevice->SetTransform( D3DTS_WORLD, &m ); m_pd3dDevice->SetFVF( D3DFVF_2DVERTEX ); m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLEFAN, num, m_aVertex, sizeof(FVF_2DVERTEX) ); */ }
void XGraphicsOpenGL::DrawPieClip( const XE::VEC2 *pvLines, int numLine, float x, float y, float radius, float angStart, float angEnd, XCOLOR color, int maxSlice ) { if( angStart == angEnd ) return; XE::VEC2 *pvList = _vLists; float angSlice = 360.0f / (float)maxSlice; // float ang = 0; pvList->x = x; pvList->y = y; // 파이의 중심점 pvList++; XE::VEC2 vOut; XE::VEC2 vo; vo.x = x + (sinf(D2R(angStart)) * radius); // 시작각도 버텍스 하나 만들어줌 vo.y = y + (-cosf(D2R(angStart)) * radius); if( ClippingLine( &vOut, pvLines, numLine, x, y, vo.x, vo.y ) ) *pvList = vOut; else *pvList = vo; pvList++; ang += angSlice; const XE::VEC2 *pEnd = &_vLists[ MAX_VERTEX ]; int num = 0; while( ang < angEnd ) { if( ang >= angStart ) // 각도범위에 포함되면 버텍스를 추가 { float rAng = D2R(ang); // 디그리 각도를 라디안각도로 변환 vo.x = x + (sinf(rAng) * radius); vo.y = y + (-cosf(rAng) * radius); if( ClippingLine( &vOut, pvLines, numLine, x, y, vo.x, vo.y ) ) *pvList = vOut; else *pvList = vo; pvList++; num++; // 삼각형 개수 if( XBREAK(pvList > pEnd) ) // 버퍼 오버플로우 되지 않도록 break; } ang += angSlice; } // 마지막각도에 버텍스 하나 더 추가 vo.x = x + (sinf(D2R(angEnd)) * radius); vo.y = y + (-cosf(D2R(angEnd)) * radius); if( ClippingLine( &vOut, pvLines, numLine, x, y, vo.x, vo.y ) ) *pvList = vOut; else *pvList = vo; num++; // gl버텍스버퍼에 옮김 { GLfloat r, g, b, a; r = XCOLOR_RGB_R(color) / 255.0f; g = XCOLOR_RGB_G(color) / 255.0f; b = XCOLOR_RGB_B(color) / 255.0f; a = XCOLOR_RGB_A(color) / 255.0f; GLfloat pos[MAX_VERTEX * 2]={0,}; GLfloat col[MAX_VERTEX * 4]={0,}; // float ratioX = ((float)GetPhyScreenWidth() / GetScreenWidth()) ; // float ratioY = ((float)GetPhyScreenHeight() / GetScreenHeight()); for( int i = 0; i < num+2; i ++ ) // num은 삼각형개수고 +2를 해야 버텍스 개수다 { POS(i, _vLists[i].x, _vLists[i].y); COLOR(i,r,g,b,a); // m_aVertex[i].vPos.x = _vLists[i].x * ratioX; // m_aVertex[i].vPos.y = _vLists[i].y * ratioY; // m_aVertex[i].dwColor = color; } // gl draw glPushMatrix(); glLoadIdentity(); glDisable( GL_TEXTURE_2D ); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); // 이건 안해줘도 되네. glVertexPointer(2, GL_FLOAT, 0, pos); glEnableClientState(GL_VERTEX_ARRAY); glColorPointer(4, GL_FLOAT, 0, col); glEnableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDrawArrays(GL_TRIANGLE_FAN, 0, num+2); // num+2: 버텍스개수 glDisableClientState(GL_COLOR_ARRAY); glEnable( GL_TEXTURE_2D ); glPopMatrix(); } }
void XViewSpline::FrameMove() { // 관절을 클릭한상태로 움직인다. if( m_idxSelected >= 0 ) { if( m_bIK ) { // 목표지점이 주어지면 각각의 IK알고리즘에 따라 관절들을 회전시킨다. if( m_typeIK == IK_DOT ) { for( int i = m_idxSelected; i >= 0; --i ) { JOINT *j = &m_listJoint[ i ]; D3DXVECTOR2 v0( LEN_JOINT, 0 ), v0T; D3DXVec2TransformCoord( &v0T, &v0, &j->m_mWorld ); D3DXVECTOR2 vF = D3DXVECTOR2( m_vTarget.x, m_vTarget.y ) - v0T; // 관절끝좌표에서 현재 마우스 위치로의 벡터 D3DXVec2Normalize( &j->m_vForce, &vF ); // 노말라이즈 float dot = D3DXVec2Dot( &j->m_vNormal, &j->m_vForce ); j->dot = dot; float torque = dot * 0.02f; j->m_rAngle -= torque; } } else if( m_typeIK == IK_CCD ) { // 관절의 끝에서 부터 시작 // 관절의 시작점에서 관절의 최하위관절의 끝지점을 연결하는 벡터A를 구함 // 관절의 시작점에서 목표지점까지를 연결하는 벡터B를 구함 // 벡터B - 벡터A만큼의 각도를 현재관절에 회전시킴 // 윗단계 관절로 이동 후 반복 for( int i = m_idxSelected; i >= 0; --i ) { JOINT *j = &m_listJoint[ i ]; D3DXVECTOR2 vA = m_listJoint[ m_idxSelected ].m_vEnd - j->m_vStart; // 관절의 시작점에서 관절의 최하위관절의 끝지점을 연결하는 벡터A를 구함 D3DXVECTOR2 vB = m_vTarget - j->m_vStart; // 관절의 시작점에서 목표지점까지를 연결하는 벡터B를 구함 float rA = GetAngle( vA ); // 벡터의 각도 구함 float rB = GetAngle( vB ); float rDist = rB - rA; // 두 벡터간의 각도차 if( rDist > D2R(180.f) ) rDist -= D2R(360.f); else if( rDist < D2R(-180.f) ) rDist += D2R(360.f); if( D2R(0.01f) > fabs( rDist ) ) { if( rDist > 0 ) rDist = D2R(0.01f); else if( rDist < 0 ) rDist = D2R(-0.01f); } float rOld = j->m_rAngle; j->m_rAngle += rDist; // 현재 관절에 각도차를 더함 // 각도제한 if( j->m_rAngle > D2R(45.f) ) j->m_rAngle = D2R(45.f); else if( j->m_rAngle < D2R(-45.f) ) j->m_rAngle = D2R(-45.f); UpdateMatrix( i ); } } }/* else { D3DXVECTOR2 vDist = m_vMouse - s_vPrev; // 마우스가 움직인 거리 JOINT *j = &m_listJoint[ m_idxSelected ]; if( vDist.x > 0 ) j->m_rAngle += D2R(1.f); else j->m_rAngle -= D2R(1.f); } */ // 행렬, 노말 갱신 UpdateMatrix(); } }
void XViewSpline::Draw() { // TODO: 여기에 특수화된 코드를 추가 및/또는 기본 클래스를 호출합니다. if( GetChain() ) { LPDIRECT3DSURFACE9 pBackBuffer = nullptr; GetChain()->GetBackBuffer( 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer ); if( pBackBuffer ) { D3DDEVICE->SetRenderTarget( 0, pBackBuffer ); D3DDEVICE->Clear( 0, nullptr, D3DCLEAR_TARGET, XCOLOR_GRAY, 1.0f, 0 ); RECT rect; GetClientRect( &rect ); XE::SetProjection( rect.right-rect.left, rect.bottom-rect.top ); if(SUCCEEDED(D3DDEVICE->BeginScene())) { // FrameMove FrameMove(); // D3DXVECTOR2 v( 0, 0 ); // D3DXMATRIX mWorld, mRot, mTrans, mLocal; D3DXMatrixIdentity( &mWorld ); D3DXMatrixTranslation( &mWorld, vCenter.x, vCenter.y, 0 ); for( int i = 0; i < MAX_JOINT; ++i ) { JOINT *j = &m_listJoint[i]; // 관절부위에 원을 그림 D3DCOLOR col = XCOLOR_WHITE; if( m_idxSelected == i ) col = XCOLOR_RED; GRAPHICS->DrawCircle( j->m_vEnd.x, j->m_vEnd.y, 5.f, col ); // 관절끝 부위에 원을 그림 GRAPHICS->DrawLine( j->m_vStart.x, j->m_vStart.y, j->m_vEnd.x, j->m_vEnd.y, col ); // 관절 그림 // test { D3DXVECTOR2 vA; vA = D3DXVECTOR2( m_vMouse.x, m_vMouse.y ) - s_vC; float rDist = GetAngle( s_vB ) - GetAngle( vA ); if( rDist > D2R(180.f) ) rDist -= D2R(360.f); else if( rDist < D2R(-180.f) ) rDist += D2R(360.f); // draw GRAPHICS->DrawLine( s_vC.x - 100.f, s_vC.y, s_vC.x + 100.f, s_vC.y, XCOLOR_BLUE ); GRAPHICS->DrawLine( s_vC.x, s_vC.y - 100.f, s_vC.x, s_vC.y + 100.f, XCOLOR_BLUE ); // 십자선 GRAPHICS->DrawLine( s_vC.x, s_vC.y, s_vC.x + s_vB.x, s_vC.y + s_vB.y, XCOLOR_RED ); // 목표벡터 GRAPHICS->DrawLine( s_vC.x, s_vC.y, s_vC.x + vA.x, s_vC.y + vA.y, XCOLOR_WHITE ); // 시작 벡터 SE::g_pFDBasic->DrawString( s_vC.x + 5.f, s_vC.y + 5.f, XCOLOR_WHITE, _T("%f(%f)"), R2D(rDist), rDist ); } // info SE::g_pFDBasic->DrawString( 5.f, 5.f, XCOLOR_WHITE, _T("%d-%d"), (int)m_vMouse.x, (int)m_vMouse.y ); /* D3DXMatrixRotationZ( &mRot, j->m_rAngle ); D3DXMatrixTranslation( &mTrans, j->m_vLocal.x, j->m_vLocal.y, 0 ); mLocal = mRot * mTrans; mWorld = mLocal * mWorld; j->m_mWorld = mWorld; D3DXVECTOR2 v0 = D3DXVECTOR2( 0, 0 ); // 관절원점 D3DXVECTOR2 v1 = D3DXVECTOR2( LEN_JOINT, 0 ); // 관절끝위치 D3DXVECTOR2 v0T, v1T; D3DXVec2TransformCoord( &v0T, &v0, &mWorld ); D3DXVec2TransformCoord( &v1T, &v1, &mWorld ); // 관절부위에 원을 그림 D3DCOLOR col = XCOLOR_WHITE; if( m_idxSelected == i ) col = XCOLOR_RED; GRAPHICS->DrawCircle( v1T.x, v1T.y, 5.f, col ); // 관절부위에 원을 그림 GRAPHICS->DrawLine( v0T.x, v0T.y, v1T.x, v1T.y, col ); // 관절 그림 if( m_bDrawDebug ) { // SE::g_pFDBasic->DrawString( v1T.x + 20.f, v1T.y - 20.f, XCOLOR_WHITE, _T("%f"), j->dot ); // normal D3DXVECTOR2 v2T; v1 = j->m_vNormal * 50.f + v0T; // D3DXVec2TransformCoord( &v2T, &v1, &mWorld ); GRAPHICS->DrawLine( v0T.x, v0T.y, v1.x, v1.y, XCOLOR_BLUE ); // 노말벡터 // 힘벡터 v1 = j->m_vForce * 300.f; v2T = v1T + v1; GRAPHICS->DrawLine( v1T.x, v1T.y, v2T.x, v2T.y, XCOLOR_GREEN ); // 노말벡터 } */ } // D3DDEVICE->EndScene(); } GetChain()->Present( nullptr, nullptr, GetSafeHwnd(), nullptr, 0 ); pBackBuffer->Release(); } } }
CRestoreTM::CRestoreTM(QWidget *parent) : QDialog(parent), ui(new Ui::CRestoreTM) { ui->setupUi(this); QStandardItemModel *m = new QStandardItemModel(0, 4); m->setHeaderData(0, Qt::Horizontal, QObject::tr("Date/Time")); m->setHeaderData(1, Qt::Horizontal, QObject::tr("Desc.")); m->setHeaderData(2, Qt::Horizontal, QObject::tr("R.A.")); m->setHeaderData(3, Qt::Horizontal, QObject::tr("Dec.")); ui->treeView->sortByColumn(0); ui->treeView->setSortingEnabled(true); SkFile f(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/data/timemarks/timemarks.dat"); QTextStream s(&f); int row = 0; if (f.open(SkFile::ReadOnly | SkFile::Text)) { QStringList list; while (!s.atEnd()) { QString line = s.readLine(); list = line.split(';'); if (list.count() == 2 || list.count() == 4) { item_t *i = new item_t; i->desc = list.at(0); i->jd = list.at(1).toDouble(); CTimeMarkItem *i0 = new CTimeMarkItem; QStandardItem *i1 = new QStandardItem; CTimeMarkItemRD *i2 = new CTimeMarkItemRD; CTimeMarkItemRD *i3 = new CTimeMarkItemRD; i0->setText(getStrDate(i->jd, 0) + " " + getStrTime(i->jd, 0)); i0->setData((qint64)i); i1->setText(i->desc); if (list.count() == 4) { i->ra = D2R(list.at(2).toDouble()); i->dec = D2R(list.at(3).toDouble()); i2->setText(getStrRA(i->ra)); i2->setData(i->ra); i3->setText(getStrDeg(i->dec)); i3->setData(i->dec); } else { i->ra = CM_UNDEF; i->dec = CM_UNDEF; i2->setText(tr("N/A")); i2->setData(CM_UNDEF); i3->setText(tr("N/A")); i3->setData(CM_UNDEF); } m->setItem(row, 0, i0); m->setItem(row, 1, i1); m->setItem(row, 2, i2); m->setItem(row, 3, i3); row++; } } } ui->treeView->setModel(m); ui->treeView->header()->resizeSection(0, 140); QShortcut *sh1 = new QShortcut(QKeySequence(Qt::Key_Delete), ui->treeView, 0, 0, Qt::WidgetShortcut); connect(sh1, SIGNAL(activated()), this, SLOT(slotDelete())); }
inline void Player::draw(Coordinate unused) { glColor3f(1,1,1); string s; s.assign("Score: "); s.append(int2String(score)); renderString(412, 354, s); int currentFps = Fps::getFps(); if (currentFps < 1) { currentFps = 1; } if (l) { if (dTheta <= 1.1) { dTheta += 0.02; } } else if (r) { if (dTheta >= -1.1) { dTheta -= 0.02; } } else { dTheta /= 1.1; if (dTheta < 0.3 && dTheta > -0.3) { dTheta = 0; } } direction += dTheta; if (direction >= 360) { direction -= 360; } if (direction < 0) { direction += 360; } if (f) { dX = acceleration*cos(D2R(direction)); dY = acceleration*sin(D2R(direction)); velocity.vx += dX; velocity.vy += dY; } else if (b) { dX = -(acceleration*cos(D2R(direction))); dY = -(acceleration*sin(D2R(direction))); velocity.vx += dX; velocity.vy += dY; } else { velocity.vx *= ((1-deceleration)); velocity.vy *= ((1-deceleration)); } velocity.magnitude = sqrt(velocity.vx*velocity.vx + velocity.vy*velocity.vy); if(velocity.magnitude > 2) { float tempDecel = (2/velocity.magnitude); velocity.vx *= tempDecel; velocity.vy *= tempDecel; } if(this->cell != -1) { Collision collision = detectCollisions(); if(collision.happened) { velocity.vx = collision.vx; velocity.vy = collision.vy; } } if(sucked) { Coordinate dw; dw.x = wpLoc.x - location.x; dw.y = wpLoc.y - location.y; if(abs(dw.x) < 10 && abs(dw.y) < 10) { velocity.vx = 0; velocity.vy = 0; location.x = wpLoc.x; location.y = wpLoc.y; finishLevel(); } else { velocity.vx = dw.x * 0.2; velocity.vy = dw.y * 0.2; } } location.x += velocity.vx; location.y += velocity.vy; if(attacking) { int atkspeed = 6; atkspin += atkspeed; if(atkspeed < 0) { attacking = false; } if (atkspin >= 180) { atkspeed -= 0.0001; } if (atkspin > 360) { atkspin -= 360; atkspeed -= 0.0001; } bbox.hheight = 42; } else { bbox.hheight = 25; } if(hit) { if(glutGet(GLUT_ELAPSED_TIME) - safetimer > 3000) { hit = false; safe = false; } if(!flash) { flash = true; } else { drawPlayer(); flash = false; } } else { drawPlayer(); } };
void XGraphicsOpenGL::DrawPieClip( const XE::VEC2 *pvLines, int numLine, float x, float y, float radius, float angStart, float angEnd, XCOLOR color, int maxSlice ) { CHECK_GL_ERROR(); if( angStart == angEnd ) return; XE::VEC2 *pvList = _vLists; float angSlice = 360.0f / (float)maxSlice; // float ang = 0; pvList->x = x; pvList->y = y; // 파이의 중심점 pvList++; XE::VEC2 vOut; XE::VEC2 vo; vo.x = x + (sinf(D2R(angStart)) * radius); // 시작각도 버텍스 하나 만들어줌 vo.y = y + (-cosf(D2R(angStart)) * radius); if( ClippingLine( &vOut, pvLines, numLine, x, y, vo.x, vo.y ) ) *pvList = vOut; else *pvList = vo; pvList++; ang += angSlice; const XE::VEC2 *pEnd = &_vLists[ MAX_VERTEX ]; int num = 0; while( ang < angEnd ) { if( ang >= angStart ) // 각도범위에 포함되면 버텍스를 추가 { float rAng = D2R(ang); // 디그리 각도를 라디안각도로 변환 vo.x = x + (sinf(rAng) * radius); vo.y = y + (-cosf(rAng) * radius); if( ClippingLine( &vOut, pvLines, numLine, x, y, vo.x, vo.y ) ) *pvList = vOut; else *pvList = vo; pvList++; num++; // 삼각형 개수 if( XBREAK(pvList > pEnd) ) // 버퍼 오버플로우 되지 않도록 break; } ang += angSlice; } // 마지막각도에 버텍스 하나 더 추가 vo.x = x + (sinf(D2R(angEnd)) * radius); vo.y = y + (-cosf(D2R(angEnd)) * radius); if( ClippingLine( &vOut, pvLines, numLine, x, y, vo.x, vo.y ) ) *pvList = vOut; else *pvList = vo; num++; // gl버텍스버퍼에 옮김 { GLfloat r, g, b, a; r = XCOLOR_RGB_R(color) / 255.0f; g = XCOLOR_RGB_G(color) / 255.0f; b = XCOLOR_RGB_B(color) / 255.0f; a = XCOLOR_RGB_A(color) / 255.0f; GLfloat pos[MAX_VERTEX * 2]={0,}; GLfloat col[MAX_VERTEX * 4]={0,}; // float ratioX = (GetRatioWidth()) ; // float ratioY = (GetRatioHeight()); for( int i = 0; i < num+2; i ++ ) // num은 삼각형개수고 +2를 해야 버텍스 개수다 { POS(i, _vLists[i].x, _vLists[i].y); COLOR(i,r,g,b,a); // m_aVertex[i].vPos.x = _vLists[i].x * ratioX; // m_aVertex[i].vPos.y = _vLists[i].y * ratioY; // m_aVertex[i].dwColor = color; } GetpColorShader()->SetShader( XE::x_mViewProjection, 1.0f, 1.0f, 1.0f, 1.0f ); // MATRIX mModel; // MatrixIdentity( mModel ); // GetpColorShader()->SetMatrixModel( mModel ); // glDisable( GL_TEXTURE_2D ); glBindBuffer(GL_ARRAY_BUFFER, 0); glEnableVertexAttribArray( XE::ATTRIB_POS ); glVertexAttribPointer( XE::ATTRIB_POS, 2, GL_FLOAT, GL_FALSE, 0, pos); glEnableVertexAttribArray( XE::ATTRIB_COLOR ); glVertexAttribPointer( XE::ATTRIB_COLOR, 4, GL_FLOAT, GL_FALSE, 0, col); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); #ifdef _XVAO glBindVertexArrayOES( 0 ); #endif glDrawArrays(GL_TRIANGLE_FAN, 0, num+2); // glEnable( GL_TEXTURE_2D ); } CHECK_GL_ERROR(); }
static void sunpos(int inYY, int inMM, int inDD, double UTCOFFSET, int inHOUR, int inMIN, int inSEC, double eastlongitude, double latitude, double *L, double *DEC) { int Y; double ZJ, D, T, M, epsilon, lambda, alpha, HA, UTHM; ZJ = ZJtable[inMM]; if (inMM <= 2 && isleap(inYY)) ZJ -= 1.0; UTHM = inHOUR + inMIN / FMINSPERHOUR + inSEC / FSECSPERHOUR - UTCOFFSET; Y = inYY - 1900; /* 1 */ D = floor(365.25 * Y) + ZJ + inDD + UTHM / FHOURSPERDAY; /* 3 */ T = D / 36525.0; /* 4 */ *L = 279.697 + 36000.769 * T; /* 5 */ fixup(L); M = 358.476 + 35999.050 * T; /* 6 */ fixup(&M); epsilon = 23.452 - 0.013 * T; /* 7 */ fixup(&epsilon); lambda = *L + (1.919 - 0.005 * T) * SIN(M) + 0.020 * SIN(2 * M);/* 8 */ fixup(&lambda); alpha = ATAN(TAN(lambda) * COS(epsilon)); /* 9 */ /* Alpha should be in the same quadrant as lamba */ { int lssign = sin(D2R(lambda)) < 0 ? -1 : 1; int lcsign = cos(D2R(lambda)) < 0 ? -1 : 1; while (((sin(D2R(alpha)) < 0) ? -1 : 1) != lssign || ((cos(D2R(alpha)) < 0) ? -1 : 1) != lcsign) alpha += 90.0; } fixup(&alpha); *DEC = ASIN(SIN(lambda) * SIN(epsilon)); /* 10 */ fixup(DEC); fixup(&eastlongitude); HA = *L - alpha + 180 + 15 * UTHM + eastlongitude; /* 12 */ fixup(&HA); fixup(&latitude); #ifdef NOTDEF printf("%02d/%02d %02d:%02d:%02d l:%g d:%g h:%g\n", inMM, inDD, inHOUR, inMIN, inSEC, latitude, *DEC, HA); #endif return; /* * The following calculations are not used, so to save time * they are not calculated. */ #ifdef NOTDEF *ALT = ASIN(SIN(latitude) * SIN(*DEC) + COS(latitude) * COS(*DEC) * COS(HA)); /* 13 */ fixup(ALT); *AZ = ATAN(SIN(HA) / (COS(HA) * SIN(latitude) - TAN(*DEC) * COS(latitude))); /* 14 */ if (*ALT > 180) *ALT -= 360; if (*ALT < -180) *ALT += 360; printf("a:%g a:%g\n", *ALT, *AZ); #endif #ifdef NOTDEF printf("Y:\t\t\t %d\t\t %d\t\t %d\n", Y, expY, Y - expY); comp("ZJ", ZJ, expZJ); comp("UTHM", UTHM, expUTHM); comp("D", D, expD); comp("T", T, expT); comp("L", L, fixup(&expL)); comp("M", M, fixup(&expM)); comp("epsilon", epsilon, fixup(&expepsilon)); comp("lambda", lambda, fixup(&explambda)); comp("alpha", alpha, fixup(&expalpha)); comp("DEC", DEC, fixup(&expDEC)); comp("eastlongitude", eastlongitude, fixup(&expeastlongitude)); comp("latitude", latitude, fixup(&explatitude)); comp("HA", HA, fixup(&expHA)); comp("ALT", ALT, fixup(&expALT)); comp("AZ", AZ, fixup(&expAZ)); #endif }
bool LoadRTLights( void ) { FILE * fp; int8_t Filename[ 256 ]; char * NewExt = ".RTL"; u_int32_t MagicNumber; u_int32_t VersionNumber; int j; RT_LIGHT * light; u_int16_t type; XLIGHT * xlight; RT_FIXED_LIGHT *fixed; RT_PULSING_LIGHT *pulse; RT_FLICKERING_LIGHT *flicker; RT_SPOT_LIGHT *spot; Change_Ext( &LevelNames[ LevelNum ][ 0 ], &Filename[ 0 ], NewExt ); fp = file_open( &Filename[ 0 ], "rb" ); if( fp ) { fread_var( fp, MagicNumber ); fread_var( fp, VersionNumber ); if( ( MagicNumber != MAGIC_NUMBER ) || ( VersionNumber != RTL_VERSION_NUMBER ) ) { fclose( fp ); Msg( "LoadRTLights() Incompatible Real-Time Lights (.RTL) file %s", &Filename[ 0 ] ); return( false ); } fread_var( fp, rt_lights ); if ( rt_lights ) { rt_light = (RT_LIGHT *) calloc( rt_lights, sizeof( RT_LIGHT ) ); if ( !rt_light ) { fclose( fp ); Msg( "LoadRTLights() malloc failed for %d Real-Time Lights ", rt_lights ); rt_lights = 0; return false ; } for ( j = 0; j < rt_lights; j++ ) { rt_light[ j ].xlight = (u_int16_t) -1; rt_light[ j ].enabled = false; } for ( j = 0; j < rt_lights; j++ ) { light = &rt_light[ j ]; fread_var( fp, type ); light->type = (LIGHTTYPE) type; fread_var( fp, light->group ); fread_var( fp, light->pos.x ); fread_var( fp, light->pos.y ); fread_var( fp, light->pos.z ); fread_var( fp, light->range ); fread_var( fp, light->r ); fread_var( fp, light->g ); fread_var( fp, light->b ); light->r *= 255.0F; light->g *= 255.0F; light->b *= 255.0F; fread_var( fp, type ); light->generation_type = (GENTYPE) type; fread_var( fp, light->generation_delay ); switch ( light->type ) { case LIGHT_FIXED: fixed = &light->fixed; fread_var( fp, type ); fixed->on_type = (PULSETYPE) type; fread_var( fp, type ); fixed->off_type = (PULSETYPE) type; fread_var( fp, fixed->on_time ); fread_var( fp, fixed->off_time ); fixed->on_time *= ANIM_SECOND; fixed->off_time *= ANIM_SECOND; break; case LIGHT_PULSING: pulse = &light->pulse; fread_var( fp, type ); pulse->type = (PULSETYPE) type; fread_var( fp, pulse->on_time ); fread_var( fp, pulse->stay_on_time ); fread_var( fp, pulse->off_time ); fread_var( fp, pulse->stay_off_time ); pulse->on_time *= ANIM_SECOND; pulse->stay_on_time *= ANIM_SECOND; pulse->off_time *= ANIM_SECOND; pulse->stay_off_time *= ANIM_SECOND; pulse->stay_on_point = pulse->on_time + pulse->stay_on_time; pulse->off_point = pulse->stay_on_point + pulse->off_time; pulse->total_time = pulse->off_point + pulse->stay_off_time; break; case LIGHT_FLICKERING: flicker = &light->flicker; fread_var( fp, flicker->stay_on_chance ); fread_var( fp, flicker->stay_off_chance ); fread_var( fp, flicker->stay_on_time ); fread_var( fp, flicker->stay_off_time ); flicker->stay_on_time *= ANIM_SECOND; flicker->stay_off_time *= ANIM_SECOND; break; case LIGHT_SPOT: spot = &light->spot; fread_var( fp, spot->dir.x ); fread_var( fp, spot->dir.y ); fread_var( fp, spot->dir.z ); fread_var( fp, spot->up.x ); fread_var( fp, spot->up.y ); fread_var( fp, spot->up.z ); fread_var( fp, spot->cone ); fread_var( fp, spot->rotation_period ); if ( spot->rotation_period ) spot->rotation_speed = 2 * PI / ( spot->rotation_period * ANIM_SECOND ); else spot->rotation_speed = 0.0F; spot->angle = 0.0F; break; } light->now_time = 0.0F; switch ( light->generation_type ) { case GENTYPE_Initialised: light->enabled = true; light->state = STATE_TURNING_ON; light->delay = 0.0F; break; case GENTYPE_Time: light->enabled = false; light->state = STATE_OFF; light->delay = light->generation_delay * ANIM_SECOND; break; case GENTYPE_Trigger: light->enabled = false; light->state = STATE_OFF; light->delay = 0.0F; break; } light->xlight = FindFreeXLight(); if ( light->xlight != (u_int16_t) -1 ) { xlight = &XLights[ light->xlight ]; xlight->Pos = light->pos; xlight->Size = light->range; xlight->SizeCount = 0.0F; xlight->r = light->r; xlight->g = light->g; xlight->b = light->b; xlight->Group = light->group; xlight->Visible = false; if ( light->type == LIGHT_SPOT ) { xlight->Type = SPOT_LIGHT; xlight->CosArc = (float) cos( D2R( light->spot.cone * 0.5F ) ); } } } } fclose( fp ); } return true; }
void comRender(CSkPainter *p, mapView_t *view, float maxMag) //////////////////////////////////////////////////////////// { if (tComets.count() == 0) return; int size = g_skSet.map.comet.radius; int lineSize = size * 4; int offsetX = lineSize * sin(D2R(22.5)); int offsetY = lineSize * cos(D2R(22.5)); int offset = lineSize; // TODO: dat asi cAstro do kazdeho vlakna #pragma omp parallel for shared(size, lineSize, offset, offsetX, offsetY) for (int i = 0; i < tComets.count(); i++) { int comaSize = 5; comet_t *a = &tComets[i]; if (!a->selected) continue; if (a->lastJD != view->jd || g_forcedRecalculate) { if (!comSolve(a, view->jd)) continue; // TODO: dat nejak najevo chybu vypoctu a->lastJD = view->jd; } if ((a->orbit.mag > maxMag + g_skSet.map.comet.plusMag) || (a->orbit.mag > g_skSet.map.comet.maxMag)) { continue; } SKPOINT pt; SKPOINT pt1; SKPOINT pt2; radec_t tail = {a->orbit.params[0], a->orbit.params[1]}; trfRaDecToPointCorrectFromTo(&a->orbit.lRD, &pt1, view->jd, JD2000); trfRaDecToPointCorrectFromTo(&tail, &pt2, view->jd, JD2000); if (trfProjectLine(&pt1, &pt2)) { float frac = a->orbit.mag / 10.; frac = 1 - CLAMP(frac, 0, 1); float opacity = LERP(frac, 0.25, 1); double cs = trfGetArcSecToPix(a->orbit.params[2]); if (!g_onPrinterBW) { QImage tailImage = QImage(":/res/comet_tail.png"); QImage comaImage = QImage(":/res/comet_coma.png"); trfRaDecToPointCorrectFromTo(&a->orbit.lRD, &pt1, view->jd, JD2000); trfRaDecToPointCorrectFromTo(&tail, &pt2, view->jd, JD2000); trfProjectLineNoCheck(&pt1, &pt2); double vx = pt1.sy - pt2.sy; double vy = -(pt1.sx - pt2.sx); double d = sqrt(POW2(vx) + POW2(vy)); double dx = pt1.sx - pt2.sx; double dy = pt1.sy - pt2.sy; double d1 = sqrt(POW2(dx) + POW2(dy)); vx /= d; vy /= d; dx /= d1; dy /= d1; double s = d * 0.5 * (tailImage.height() / (double)tailImage.width()); double s1 = d * 0.02; QPoint pts[4]; // tail pts[0] = QPoint((pt1.sx + (vx * s)) + (dx * s1), (pt1.sy + (vy * s)) + (dy * s1)); pts[1] = QPoint((pt1.sx - (vx * s)) + (dx * s1), (pt1.sy - (vy * s)) + (dy * s1)); pts[2] = QPoint(pt2.sx + vx * s, pt2.sy + vy * s); pts[3] = QPoint(pt2.sx - vx * s, pt2.sy - vy * s); #pragma omp critical { scanRender.resetScanPoly(p->image()->width(), p->image()->height()); scanRender.scanLine(pts[0].x(), pts[0].y(), pts[2].x(), pts[2].y(), 0, 0, 1, 0); scanRender.scanLine(pts[2].x(), pts[2].y(), pts[3].x(), pts[3].y(), 1, 0, 1, 1); scanRender.scanLine(pts[3].x(), pts[3].y(), pts[1].x(), pts[1].y(), 1, 1, 0, 1); scanRender.scanLine(pts[1].x(), pts[1].y(), pts[0].x(), pts[0].y(), 0, 1, 0, 0); scanRender.setOpacity(opacity); scanRender.renderPolygonAlpha(p->image(), &tailImage); p->save(); p->setOpacity(opacity); p->setRenderHint(QPainter::SmoothPixmapTransform, scanRender.isBillinearInt()); p->drawImage(QRect(pt1.sx - cs, pt1.sy - cs, cs * 2, cs * 2), comaImage); p->restore(); } } comaSize = qMax(cs, 1.0); } trfRaDecToPointCorrectFromTo(&a->orbit.lRD, &pt, view->jd, JD2000); if (trfProjectPoint(&pt)) { #pragma omp critical { double sunAng = -trfGetPosAngle(a->orbit.lRD.Ra, a->orbit.lRD.Dec, sunOrbit.lRD.Ra, sunOrbit.lRD.Dec); rangeDbl(&sunAng, R360); p->setBrush(QColor(g_skSet.map.comet.color)); p->setPen(g_skSet.map.comet.color); float ang = (float)trfGetAngleToNPole(a->orbit.lRD.Ra, a->orbit.lRD.Dec, view->jd); if (view->flipX + view->flipY == 1) { ang = R2D(R180 - sunAng + ang); } else { ang = R2D(R180 + sunAng + ang); } double sep = anSep(a->orbit.params[0], a->orbit.params[1], a->orbit.lRD.Ra, a->orbit.lRD.Dec); double r2 = trfGetArcSecToPix(R2D(sep) * 3600); if (r2 <= 20) { p->save(); p->translate(pt.sx, pt.sy); p->rotate(ang); p->drawEllipse(QPoint(0, 0), size, size); p->drawLine(0, 0, -offsetX, -offsetY); p->drawLine(0, 0, 0, -offset); p->drawLine(0, 0, offsetX, -offsetY); p->restore(); } else if (g_onPrinterBW) { p->save(); p->translate(pt.sx, pt.sy); p->rotate(ang); p->drawEllipse(QPoint(0, 0), size, size); double r1 = r2 * 0.1; double focus = sqrt(POW2(r2) - POW2(r1)); p->setBrush(Qt::NoBrush); p->drawEllipse(QPointF(0, -focus), r1, r2); p->drawLine(0, 0, -offsetX, -offsetY); p->drawLine(0, 0, 0, -offset); p->drawLine(0, 0, offsetX, -offsetY); p->restore(); } if (g_showLabels) { int align; if (sunAng >= 0 && sunAng < R90) { align = SL_AL_BOTTOM_LEFT; } else if (sunAng >= R90 && sunAng < R180) { align = SL_AL_TOP_LEFT; } else if (sunAng >= R180 && sunAng < R270) { align = SL_AL_TOP_RIGHT; } else { align = SL_AL_BOTTOM_RIGHT; } g_labeling.addLabel(QPoint(pt.sx, pt.sy), comaSize + 2, a->name, FONT_COMET, align, SL_AL_ALL); } addMapObj(pt.sx, pt.sy, MO_COMET, MO_CIRCLE, comaSize + 2, i, (qint64)a, a->orbit.mag); } } } }
bool CSearch::search(mapView_t *mapView, QString str, double &ra, double &dec, double &fov, mapObj_t &obj) { QString what = str.mid(0, 4); str = str.mid(4); QRegExp reg("\\b" + str + "\\b", Qt::CaseInsensitive); str = str.simplified(); cAstro.setParam(mapView); if (SS_CHECK_OR(SS_PLANET, what)) { if (!str.compare("es", Qt::CaseInsensitive)) { orbit_t o, m; cAstro.calcPlanet(PT_MOON, &m); cAstro.calcEarthShadow(&o, &m); ra = o.lRD.Ra; dec = o.lRD.Dec; fov = getOptObjFov(o.sx / 3600.0, o.sy / 3600.0); obj.type = MO_EARTH_SHD; return(true); } } if (SS_CHECK_OR(SS_STAR, what)) { if (str.startsWith("HD", Qt::CaseInsensitive)) { str = str.mid(2); int hd = str.toInt(); int reg, index; tychoStar_t *star; if (cTYC.findStar(NULL, TS_HD, 0, hd, 0, 0, 0, 0, 0, 0, reg, index)) { cTYC.getStar(&star, reg, index); ra = star->rd.Ra; dec = star->rd.Dec; precess(&ra, &dec, JD2000, mapView->jd); fov = DMS2RAD(10, 0, 0); obj.type = MO_TYCSTAR; obj.par1 = reg; obj.par2 = index; return true; } } if (str.startsWith("TYC", Qt::CaseInsensitive)) { str = str.mid(3); QStringList list = str.split("-"); if (list.count() == 3) { int t1 = list[0].toInt(); int t2 = list[1].toInt(); int t3 = list[2].toInt(); int reg, index; tychoStar_t *star; if (cTYC.findStar(NULL, TS_TYC, 0, 0, 0, 0, t1, t2, t3, 0, reg, index)) { cTYC.getStar(&star, reg, index); ra = star->rd.Ra; dec = star->rd.Dec; precess(&ra, &dec, JD2000, mapView->jd); fov = DMS2RAD(10, 0, 0); obj.type = MO_TYCSTAR; obj.par1 = reg; obj.par2 = index; return true; } } } if (str.startsWith("UCAC4", Qt::CaseInsensitive)) { str = str.mid(5); QStringList list = str.split("-"); if (list.count() == 2) { int zone = list[0].toInt(); int num = list[1].toInt(); ucac4Star_t star; if (cUcac4.searchStar(zone, num, &star)) { ra = star.rd.Ra; dec = star.rd.Dec; precess(&ra, &dec, JD2000, mapView->jd); fov = DMS2RAD(0, 30, 0); // FIX: region a poradi v GSC regionu /* obj.type = MO_UCAC4; obj.par1 = star.zone; obj.par2 = star.number; */ return true; } } return false; } if (str.startsWith("USNO2", Qt::CaseInsensitive)) { str = str.mid(5); QStringList list = str.split("-"); if (list.count() == 2) { int zone = list[0].toInt(); int num = list[1].toInt(); usnoStar_t star; if (usno.searchStar(zone, num, &star)) { ra = star.rd.Ra; dec = star.rd.Dec; precess(&ra, &dec, JD2000, mapView->jd); fov = DMS2RAD(0, 30, 0); // FIX: region a poradi v GSC regionu /* obj.type = MO_USNO2; obj.par1 = star.zone; obj.par2 = star.number; */ return true; } } return false; } if (str.startsWith("GSC", Qt::CaseInsensitive)) { str = str.mid(3); QStringList list = str.split("-"); if (list.count() == 2) { int reg = list[0].toInt(); int num = list[1].toInt(); int index; gsc_t *star; if (cGSC.searchStar(reg, num, &star, index)) { ra = star->Ra; dec = star->Dec; precess(&ra, &dec, JD2000, mapView->jd); fov = DMS2RAD(0, 30, 0); obj.type = MO_GSCSTAR; obj.par1 = reg - 1; obj.par2 = index; return true; } } return false; } } if (SS_CHECK_OR(SS_POS, what)) { // ra/dec { QStringList list = str.split(' '); if (list.count() == 6) { double rah, ram, ras; double decd, decm, decs; bool ok; for (int i = 0; i < 6; i++) { list.at(0).toDouble(&ok); if (!ok) { break; } } if (ok) { rah = list.at(0).toDouble(); ram = list.at(1).toDouble(); ras = list.at(2).toDouble(); decd = list.at(3).toDouble(); decm = list.at(4).toDouble(); decs = list.at(5).toDouble(); double mra = HMS2RAD(qAbs(rah), qAbs(ram), qAbs(ras)); double mdec = DMS2RAD(qAbs(decd), qAbs(decm), qAbs(decs)); if (decd < 0) { mdec = -mdec; } if (mra >= 0 && mra <= R360 && mdec >= -R90 && mdec <= R90) { ra = mra; dec = mdec; fov = CM_UNDEF; if (mapView->epochJ2000 && mapView->coordType == SMCT_RA_DEC) { precess(&ra, &dec, JD2000, mapView->jd); } return true; } } } } } QApplication::processEvents(); if (SS_CHECK_OR(SS_CONSTEL, what)) { // constellation if (constFind(str, ra, dec, fov, mapView->jd)) return(true); } QApplication::processEvents(); if (SS_CHECK_OR(SS_STAR_NAME, what)) { // star names for (int i = 0; i < cTYC.tNames.count(); i++) { int offs = cTYC.tNames[i]->supIndex; QString name = cTYC.getStarName(&cTYC.pSupplement[offs]); if (!str.compare(name, Qt::CaseInsensitive)) { ra = cTYC.tNames[i]->rd.Ra; dec = cTYC.tNames[i]->rd.Dec; precess(&ra, &dec, JD2000, mapView->jd); fov = D2R(30); int reg, index; if (cTYC.findStar(NULL, TS_TYC, 0, 0, 0, 0, cTYC.tNames[i]->tyc1, cTYC.tNames[i]->tyc2, cTYC.tNames[i]->tyc3, 0, reg, index)) { obj.type = MO_TYCSTAR; obj.par1 = reg; obj.par2 = index; } return(true); } } } QApplication::processEvents(); if (SS_CHECK_OR(SS_PLANET, what)) { // search planet/sun/moon for (int i = PT_SUN; i <= PT_MOON; i++) { orbit_t o; cAstro.setParam(mapView); cAstro.calcPlanet(i, &o); QString name = o.name; QString english = o.englishName; if (!str.compare(name, Qt::CaseInsensitive) || !str.compare(english, Qt::CaseInsensitive)) { ra = o.lRD.Ra; dec = o.lRD.Dec; fov = getOptObjFov(o.sx / 3600.0, o.sy / 3600.0); obj.type = MO_PLANET; obj.par1 = i; obj.par2 = 0; return(true); } } } QApplication::processEvents(); if (SS_CHECK_OR(SS_DSO, what)) { // dso dso_t *dso; int index; if (cDSO.findDSO((char *)qPrintable(str), &dso, index) != -1) { ra = dso->rd.Ra; dec = dso->rd.Dec; precess(&ra, &dec, JD2000, mapView->jd); fov = getOptObjFov(dso->sx / 3600., dso->sy / 3600.); obj.type = MO_DSO; obj.par1 = (qint64)dso; obj.par2 = 0; return(true); } } QApplication::processEvents(); if (SS_CHECK_OR(SS_ART_SAT, what)) { // satellites QString satName = str; sgp4.setObserver(mapView); for (int i = 0; i < sgp4.count(); i++) { satellite_t out; radec_t rd; if (sgp4.getName(i).compare(satName, Qt::CaseInsensitive) == 0) { if (sgp4.solve(i, mapView, &out)) { cAstro.convAA2RDRef(out.azimuth, out.elevation, &rd.Ra, &rd.Dec); ra = rd.Ra; dec = rd.Dec; fov = getOptObjFov(0, 0, D2R(2.5)); obj.type = MO_SATELLITE; obj.par1 = i; obj.par2 = 0; return true; } } } } QApplication::processEvents(); if (SS_CHECK_OR(SS_ASTER, what)) { // asteroids for (int i = 0; i < tAsteroids.count(); i++) { asteroid_t *a = &tAsteroids[i]; if (!a->selected) continue; if (QString(a->name).contains(reg) || a->name == str) { qDebug() << a->name << reg; astSolve(a, mapView->jd); ra = a->orbit.lRD.Ra; dec = a->orbit.lRD.Dec; fov = AST_ZOOM; obj.type = MO_ASTER; obj.par1 = i; obj.par2 = (qint64)a; return(true); } } } QApplication::processEvents(); if (SS_CHECK_OR(SS_COMET, what)) { // comets for (int i = 0; i < tComets.count(); i++) { comet_t *a = &tComets[i]; if (!a->selected) continue; if (QString(a->name).contains(reg) || a->name == str) { comSolve(a, mapView->jd); ra = a->orbit.lRD.Ra; dec = a->orbit.lRD.Dec; fov = qMin(COM_ZOOM, 8 * D2R(a->orbit.params[2] / 3600.)); obj.type = MO_COMET; obj.par1 = i; obj.par2 = (qint64)a; return(true); } } } QApplication::processEvents(); if (SS_CHECK_OR(SS_LUNAR_FEAT, what)) { if (cLunarFeatures.search(str, mapView, ra, dec, fov)) { return(true); } } return(false); }