2013年9月16日星期一(DEMO8_8,多边形)

来源:互联网 发布:淘宝网名怎么改 编辑:程序博客网 时间:2024/06/07 03:50

此例子很简单,就是把四边形分为两个三角形绘制即可。

 

inline void Draw_QuadFP_2D(int x0,int y0,

                    int x1,int y1,

                    int x2,int y2,

                    int x3, int y3,

                    int color,

                    UCHAR *dest_buffer, int mempitch)

{

// this function draws a 2D quadrilateral

 

// simply call the triangle function 2x, let it do all the work

Draw_TriangleFP_2D(x0,y0,x1,y1,x3,y3,color,dest_buffer,mempitch);

Draw_TriangleFP_2D(x1,y1,x2,y2,x3,y3,color,dest_buffer,mempitch);

 

} // end Draw_QuadFP_2D

 

在Game_Main()中,

int x0     = rand()%SCREEN_WIDTH;

int y0     = rand()%SCREEN_HEIGHT;

int width  = rand()%SCREEN_WIDTH;

int height = rand()%SCREEN_HEIGHT;

 

// draw the triangle

Draw_QuadFP_2D(x0,y0,

               x0+width,y0,

               x0+width, y0+height,

               x0, y0+height,

               rand()%256,(UCHAR *)ddsd.lpSurface, ddsd.lPitch);

 

Ok,下一步进行封装,这个也简单,

 

成员函数

 

void DDRAW_Interface::Draw_QuadFP_2D( int x0,int y0,

                                                                                            int x1,int y1,

                                                                                            int x2,int y2,

                                                                                            int x3, int y3,

                                                                                            int color,

                                                                                             UCHAR *dest_buffer,int mempitch)

{

         // this function draws a 2D quadrilateral

 

         // simply call the triangle function 2x, let it do all the work

         Draw_TriangleFP_2D(x0,y0,x1,y1,x3,y3,color,dest_buffer,mempitch);

         Draw_TriangleFP_2D(x1,y1,x2,y2,x3,y3,color,dest_buffer,mempitch);

 

} // end Draw_Q

 

在game_main()中,

 

         int x0     = rand()%SCREEN_WIDTH;

         int y0     = rand()%SCREEN_HEIGHT;

         int width  = rand()%SCREEN_WIDTH;

         int height = rand()%SCREEN_HEIGHT;

 

         // draw the triangle

         ddraw->Draw_QuadFP_2D(x0,y0,

                   x0+width,y0,

                   x0+width, y0+height,

                   x0, y0+height,

         rand()%256, ddraw->getbackbuffer(), ddraw->getbacklpitch() );

 

OK

 

原创粉丝点击