Rotate mit CDC



  • Schien ja extrem wichtig gewesen zu sein.



  • Jo, wirklich ein Riesenproblemm 😃



  • Hmm, nein nix mit sinus und so weiter!

    Könnt ihr mir ein Bsp. Code geben oder so?



  • Guck dir vorher einmal die Winkelfunktionen an: http://www.mathe-online.at/mathint/wfun/i.html#sincosRechtwDr

    Dann gehst du wie folgt vor:

    Du hast: Den Rotationswinkel und den Radius (In diesem Fall die Hypotenuse)...
    Du brauchst: Ankathete und Gegenkathete
    Es gilt: sin = G/H und cos = A/H und tan = G/A

    Hilft dir dieser Denkansatz weiter?



  • Btw: Bei solchen Sachen ist eine Skizze am "Papiercomputer" immer eine gute Hilfe... 🕶



  • Bohhhhhh, versteh mich nicht falsch ich bin Hauptschüler!!

    Kann mit dem nichts anfangen



  • Hier mein Bisheriger Code!

    #include <math.h>

    void CBalkenCtrl::DrawRotatFx(CDC* pDC)
    {
    //nPosition ist die Gesamtgrösse das Bass
    CRect rect;
    GetClientRect(rect);
    CPen pen(PS_SOLID, 1, RGB(255,180,0));
    pDC->SelectObject(pen);
    pDC->MoveTo(10, rect.Height() / 2);
    pDC->LineTo(rect.Width() - 10, rect.Height() / 2);
    pDC->MoveTo(rect.Width() / 2, 10);
    pDC->LineTo(rect.Width() / 2, rect.Height() - 10);
    }



  • So habe gerade was hingekriegt ist aber nich das was ich will!

    Hier der ganze code!

    // BalkenCtrl.cpp: Implementierungsdatei
    //

    #include "stdafx.h"
    #include "BalkenCtrl.h"

    #ifdef DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE
    _;
    #endif

    double m_Winkel;
    const double pi = 3.14159265359;
    /////////////////////////////////////////////////////////////////////////////
    // CBalkenCtrl

    CBalkenCtrl::CBalkenCtrl()
    {
    CurrentBalken = 0;
    for(int i=0;i<9;i++)
    {
    BalkenPos[i] = 0;
    }
    Visual = 1;
    OldPoint.x = 0;
    OldPoint.y = 0;
    NewPoint.x = 0;
    NewPoint.y = 0;
    m_Winkel = pi / 4;
    }

    CBalkenCtrl::~CBalkenCtrl()
    {
    }

    BEGIN_MESSAGE_MAP(CBalkenCtrl, CStatic)
    //{{AFX_MSG_MAP(CBalkenCtrl)
    ON_WM_PAINT()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()

    /////////////////////////////////////////////////////////////////////////////
    // Behandlungsroutinen für Nachrichten CBalkenCtrl

    void CBalkenCtrl::SetRange(float nMax)
    {
    CRect rect;
    GetClientRect(rect);
    nRange = rect.Height() / nMax;
    MaxRange = nMax;
    }

    void CBalkenCtrl::SetPos(float nPos)
    {
    CRect rect;
    GetClientRect(rect);
    nPosition = nPos * nRange;
    if(CurrentBalken == 😎
    {
    CurrentBalken = 0;
    }
    else
    {
    BalkenPos[CurrentBalken] = rect.Height() - nPosition;
    BalkenTopPos[CurrentBalken] = (rect.Height() - nPosition) - 3;
    CurrentBalken += 1;
    }
    RedrawWindow();

    }

    void CBalkenCtrl::SetNextVisual()
    {
    if(Visual == 4)
    {
    Visual = 0;
    }
    else
    {
    Visual += 1;
    }
    }

    void CBalkenCtrl::OnPaint()
    {
    CPaintDC dc(this); // device context for painting
    CRect rect;
    GetClientRect(rect);
    CBrush m_brush;
    m_brush.CreateSolidBrush(RGB(0,0,0));
    dc.FillRect(&rect, &m_brush);
    if(Visual == 1)
    {
    DrawBalken(&dc);
    }
    else if(Visual == 2)
    {
    DrawText(&dc);
    }
    else if(Visual == 3)
    {
    DrawLineFx(&dc);
    }
    else if(Visual == 4)
    {
    DrawRotatFx(&dc);
    }
    else
    {
    dc.SetTextColor(RGB(255,0,0));
    dc.SetBkMode(TRANSPARENT);
    dc.DrawText("XMMS BETA", -1, rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
    }
    ReleaseDC(&dc);
    }

    void CBalkenCtrl::DrawBalken(CDC* pDC)
    {
    CRect rect;
    GetClientRect(rect);

    CBrush m_brush;
    m_brush.CreateSolidBrush(RGB(0,128,192));
    //
    int BalkenLenght = rect.Width() / 8;
    srand((unsigned)time(NULL));
    rect.right = 0;
    for(int i=0;i<8;i++)
    {
    rect.left = rect.right + 4;
    rect.right += BalkenLenght;
    rect.top = BalkenPos[i];
    pDC->FillRect(&rect, &m_brush);
    CPen pen(PS_SOLID, 1, RGB(0,180,0));
    pDC->SelectObject(pen);
    pDC->MoveTo(rect.left, BalkenTopPos[i]);
    pDC->LineTo(rect.right, BalkenTopPos[i]);
    }
    }

    void CBalkenCtrl::DrawText(CDC* pDC)
    {
    CRect rect;
    GetClientRect(rect);
    CFont font;
    srand((unsigned)time(NULL));
    font.CreateFont((nPosition / MaxRange) * 2, (nPosition / MaxRange),0,0,true,false,false,false,0,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,PROOF_QUALITY,DEFAULT_PITCH|FF_DONTCARE,"Arial");
    pDC->SelectObject(&font);
    pDC->SetTextColor(RGB(rand() % 255,rand() % 255,rand() % 255));
    pDC->SetBkMode(TRANSPARENT);
    pDC->DrawText("Boom", rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
    }

    void CBalkenCtrl::DrawLineFx(CDC* pDC)
    {
    CRect rect;
    GetClientRect(rect);
    CPen pen(PS_SOLID, 1, RGB(255,180,0));
    pDC->SelectObject(pen);
    pDC->MoveTo(rect.Width() / 2, 0);
    pDC->LineTo(rect.Width() / 2 - nPosition / 2, rect.Height() / 2);
    pDC->LineTo(rect.Width() / 2, rect.Height());
    pDC->LineTo(rect.Width() / 2 + nPosition / 2, rect.Height() / 2);
    pDC->LineTo(rect.Width() / 2, 0);
    }

    #include <math.h>

    void CBalkenCtrl::DrawRotatFx(CDC* pDC)
    {
    //nPosition ist die Gesamtgrösse das Bass
    CRect rect;
    GetClientRect(rect);
    const double l = rect.Width() - 10;
    const int h = rect.Height() / 2;
    m_Winkel += pi / 180;
    //----------------------
    CPen pen(PS_SOLID, 1, RGB(255,180,0));
    pDC->SelectObject(pen);

    //------------
    pDC->MoveTo(rect.Width() / 2, rect.Height() / 2);
    pDC->LineTo(l * cos(m_Winkel), h-l * sin(m_Winkel));
    }

    void CBalkenCtrl::OnTimer(UINT nIDEvent)
    {
    CDC* pDC = GetDC();
    CRect rect;
    GetClientRect(rect);
    CPen pen(PS_SOLID, 1, RGB(0,180,0));
    pDC->SelectObject(pen);
    NewPoint = OldPoint;
    pDC->MoveTo(OldPoint);
    if(NewPoint.x == rect.Width())
    {
    NewPoint.x = 0;
    OldPoint.x = 0;
    RedrawWindow();
    }
    else
    {
    NewPoint.x += 3;
    NewPoint.y = rect.Height() - nPosition;
    OldPoint = NewPoint;
    pDC->LineTo(NewPoint);
    }
    CStatic::OnTimer(nIDEvent);
    }



  • hi,

    ich weiß ja jetzt nicht was du genau rotieren willst... aber eine kreisfunktion sollte eigentlich so realisierbar sein !!!

    // PSEUDO-CODE
    int x,y; // x,y koordinaten welche die kreisbahn beschreibt
    
    for ( double i = 0; i < 2*PI; i + 0.1f ) 
    {
        x = 80 * sin ( i ) + 320;
        y = 80 * cos ( i ) + 200;
    
        SetzePixel ( x,y );
    }
    

    sollte einen kreis zeichnen !!! mittelpunkt 320/200 und der durchmesser ist 80 pixel !!!

    wenn du das jetzt mit 4 punkten machst und die punkte dann untereinander verbindest... sollte sich ein rechteck einmal um die achse drehen !!!

    hoffe sehr das ich keinen stuß gepostet habe... aber seit 1995 kann man schon mal etwas vergessen 😉

    MfG veganza

    [ Dieser Beitrag wurde am 28.06.2003 um 16:30 Uhr von veganza editiert. ]



  • Wieso wird der Strich kleiner und macht keine ganze Elipes?

    Der Hauptteil ist in DrawRotatFx(CDC* pDC)!!


Anmelden zum Antworten