Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualbelfegor

Posted 26 April 2013 - 06:00 AM

Why not with triangle fan?

 

 

D3DXVECTOR2* D3DXVec2Rotate(D3DXVECTOR2* vOut, D3DXVECTOR2* vIn, float rad, const D3DXVECTOR2* vCenter)
{
    float cr = std::cos(rad);
    float sr = std::sin(rad);

    float X = vIn->x;
    float Y = vIn->y;

    X -= vCenter->x;
    Y -= vCenter->y;

    vOut->x = X * cr - Y * sr;
    vOut->y = X * sr + Y * cr;

    vOut->x += vCenter->x;
    vOut->y += vCenter->y;

    return vOut;
}
 
...
struct VERTEX
    {
        D3DXVECTOR4 p;
    };

    static const std::size_t numPts = 20; // points cnt on circle
    std::vector<VERTEX> vVertices;
    d3d9device->SetFVF(D3DFVF_XYZRHW); // pre-tranformed vertex
    VERTEX center; // vertex in center of circle
    center.p = D3DXVECTOR4(500.0f, 400.0f, 0.0f, 1.0f); // set circle center on screen center (1000x800) / 2
    D3DXVECTOR2 ct(center.p.x, center.p.y);
    vVertices.push_back(center); // add center first beause of triangle fan "rule"
    static const float rad = 200.0f; // circle radius
    for(std::size_t i = 0; i < numPts; ++i)
    {
        float ang = (D3DX_PI * 2.0f) * ((float)i / (float)numPts);
        D3DXVECTOR2 pt(center.p.x + rad, center.p.y + rad);
        D3DXVec2Rotate(&pt, &pt, ang, &ct);
        VERTEX vert;
        vert.p = D3DXVECTOR4(pt.x, pt.y, 0.0f, 1.0f);
        vVertices.push_back(vert);
    }
    vVertices.push_back(vVertices[1]); // add first point (on circle) to close
    d3d9device->DrawPrimitiveUP( D3DPT_TRIANGLEFAN, numPts, &vVertices[0], sizeof(VERTEX) );

#3belfegor

Posted 26 April 2013 - 05:58 AM

Why not with triangle fan?

 

 

D3DXVECTOR2* D3DXVec2Rotate(D3DXVECTOR2* vOut, D3DXVECTOR2* vIn, float rad, const D3DXVECTOR2* vCenter)
{
    float cr = std::cos(rad);
    float sr = std::sin(rad);

    float X = vIn->x;
    float Y = vIn->y;

    X -= vCenter->x;
    Y -= vCenter->y;

    vOut->x = X * cr - Y * sr;
    vOut->y = X * sr + Y * cr;

    vOut->x += vCenter->x;
    vOut->y += vCenter->y;

    return vOut;
}
 
...
struct VERTEX
    {
        D3DXVECTOR4 p;
    };

    static const std::size_t numPts = 20; // points cnt on circle
    std::vector<VERTEX> vVertices;
    d3d9device->SetFVF(D3DFVF_XYZRHW); // pre-tranformed vertex
    VERTEX center; // vertex in center of circle
    center.p = D3DXVECTOR4(500.0f, 400.0f, 0.0f, 1.0f); // set circle center on screen center (1000x800) / 2
    D3DXVECTOR2 ct(center.p.x, center.p.y);
    vVertices.push_back(center); // add center first beause of triangle fan "rule"
    static const float rad = 200.0f; // circle radius
    for(std::size_t i = 0; i < numPts; ++i)
    {
        float ang = (D3DX_PI * 2.0f) * ((float)i / (float)numPts);
        D3DXVECTOR2 pt(center.p.x + rad, center.p.y + rad);
        D3DXVec2Rotate(&pt, &pt, ang, &ct);
        VERTEX vert;
        vert.p = D3DXVECTOR4(pt.x, pt.y, 1.0f, 1.0f);
        vVertices.push_back(vert);
    }
    vVertices.push_back(vVertices[1]); // add first point (on circle) to close
    d3d9device->DrawPrimitiveUP( D3DPT_TRIANGLEFAN, numPts, &vVertices[0], sizeof(VERTEX) );

#2belfegor

Posted 26 April 2013 - 05:57 AM

Why not with triangle fan?

 

 

D3DXVECTOR2* D3DXVec2Rotate(D3DXVECTOR2* vOut, D3DXVECTOR2* vIn, float rad, const D3DXVECTOR2* vCenter)
{
    float cr = std::cos(rad);
    float sr = std::sin(rad);

    float X = vIn->x;
    float Y = vIn->y;

    X -= vCenter->x;
    Y -= vCenter->y;

    vOut->x = X * cr - Y * sr;
    vOut->y = X * sr + Y * cr;

    vOut->x += vCenter->x;
    vOut->y += vCenter->y;

    return vOut;
}
 
...
struct VERTEX
    {
        D3DXVECTOR4 p;
    };

    static const std::size_t numPts = 20; // points cnt around circle
    std::vector<VERTEX> vVertices;
    d3d9device->SetFVF(D3DFVF_XYZRHW); // pre-tranformed vertex
    VERTEX center; // vertex in center of circle
    center.p = D3DXVECTOR4(500.0f, 400.0f, 0.0f, 1.0f); // set circle center on screen center (1000x800) / 2
    D3DXVECTOR2 ct(center.p.x, center.p.y);
    vVertices.push_back(center); // add center first beause of triangle fan "rule"
    static const float rad = 200.0f; // circle radius
    for(std::size_t i = 0; i < numPts; ++i)
    {
        float ang = (D3DX_PI * 2.0f) * ((float)i / (float)numPts);
        D3DXVECTOR2 pt(center.p.x + rad, center.p.y + rad);
        D3DXVec2Rotate(&pt, &pt, ang, &ct);
        VERTEX vert;
        vert.p = D3DXVECTOR4(pt.x, pt.y, 1.0f, 1.0f);
        vVertices.push_back(vert);
    }
    vVertices.push_back(vVertices[1]); // add first point (on circle) to close
    d3d9device->DrawPrimitiveUP( D3DPT_TRIANGLEFAN, numPts, &vVertices[0], sizeof(VERTEX) );

#1belfegor

Posted 26 April 2013 - 05:57 AM

Why not with triangle fan?

 

D3DXVECTOR2* D3DXVec2Rotate(D3DXVECTOR2* vOut, D3DXVECTOR2* vIn, float rad, const D3DXVECTOR2* vCenter)
{
    float cr = std::cos(rad);
    float sr = std::sin(rad);

    float X = vIn->x;
    float Y = vIn->y;

    X -= vCenter->x;
    Y -= vCenter->y;

    vOut->x = X * cr - Y * sr;
    vOut->y = X * sr + Y * cr;

    vOut->x += vCenter->x;
    vOut->y += vCenter->y;

    return vOut;
}
 
struct VERTEX
    {
        D3DXVECTOR4 p;
    };

    static const std::size_t numPts = 20; // points cnt around circle
    std::vector<VERTEX> vVertices;
    d3d9device->SetFVF(D3DFVF_XYZRHW); // pre-tranformed vertex
    VERTEX center; // vertex in center of circle
    center.p = D3DXVECTOR4(500.0f, 400.0f, 0.0f, 1.0f); // set circle center on screen center (1000x800) / 2
    D3DXVECTOR2 ct(center.p.x, center.p.y);
    vVertices.push_back(center); // add center first beause of triangle fan "rule"
    static const float rad = 200.0f; // circle radius
    for(std::size_t i = 0; i < numPts; ++i)
    {
        float ang = (D3DX_PI * 2.0f) * ((float)i / (float)numPts);
        D3DXVECTOR2 pt(center.p.x + rad, center.p.y + rad);
        D3DXVec2Rotate(&pt, &pt, ang, &ct);
        VERTEX vert;
        vert.p = D3DXVECTOR4(pt.x, pt.y, 1.0f, 1.0f);
        vVertices.push_back(vert);
    }
    vVertices.push_back(vVertices[1]); // add first point (on circle) to close
    d3d9device->DrawPrimitiveUP( D3DPT_TRIANGLEFAN, numPts, &vVertices[0], sizeof(VERTEX) );

PARTNERS