D3D9创建一个圆圈

时间:2013-05-26 09:45:27

标签: c++ geometry directx-9 vertex-array drawing2d

我之前发布了一个不同的问题,使用D3DPT_TRIANGLEFAN给了我一个错误,但我尝试以不同的方式重新编码我的圈子。唯一的问题是它没有画到屏幕上......我已经尝试过调试但是一切似乎都很完美,这很奇怪。 这是我的整个“圆圈”课程(这是Pong游戏中较大程序的一部分)

    class Circle: public physicsObject
{
public:
    Circle(float x, float y, float r, D3DCOLOR col){
        xVel=3;
        yVel=3;
        xLB=0.0;
        xRB=800;
        yUB=600;
        yLB=0;
        this->r=r;
        this->x=x;
        this->y=y;
        for(float i = 0.0f; i<360.0f; i += 1.0f)
        {
            float angle = i;
            points[(int)i].x = x + (sinD(angle) * r);
            points[(int)i].y = y + (cosD(angle) * r);
            points[(int)i].z = 0;
            points[(int)i].Color = col;
        }
    }
    void update()
    {
        for(int i = 0; i < paddles.size(); ++i)
        {
            if(paddles[i]->left)
            {
                if(x - r + xVel < paddles[i]->x + 20 && y+yVel > paddles[i]->y && y+yVel< paddles[i]->y+80){
                    xVel *= -1;
                }
            }else{
                if(x + r + xVel > paddles[i]->x && y+yVel > paddles[i]->y && y+yVel< paddles[i]->y+80){
                    xVel *= -1;
                }
            }
        }
        if(x+r+10+xVel>xRB || x-r+xVel < xLB)
        {
            //MessageBox(0,"AWW SHEEIT","I LOSED",MB_OK);
            //ExitProcess(0);
        }   
        if(y+r+30+yVel > yUB || y-r+yVel < yLB)
            yVel*=-1;
        translate(xVel,yVel);
    }
    void translate(float x, float y)
    {
        if(GetAsyncKeyState(VK_SPACE))
        {
            gamestart = true;
        }
        if(gamestart){
            this->x+=x;
            this->y+=y;
            for(int i = 0; i < 360; ++i)
            {
                points[i].x+=x;
                points[i].y+=y;
            }
        }
    }
    void render()
    {
        update();
        d3ddev->SetTexture(0,0);
        d3ddev->SetFVF((D3DFVF_XYZRHW | D3DFVF_DIFFUSE)); 
        d3ddev->SetRenderState( D3DRS_LIGHTING, FALSE);
        d3ddev->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW);
        d3ddev->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
        d3ddev->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
        d3ddev->SetRenderState( D3DRS_ZENABLE, D3DZB_FALSE );
        d3ddev->SetRenderState( D3DRS_FOGENABLE, false);
        d3ddev->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 360, &points, sizeof(360));
    }
    Vertex points [360];
private:
    float r;
};

提前感谢您的帮助!

0 个答案:

没有答案