2013年9月22日星期日(准备工作:分离ddraw的math和interface)

在之前,要进行下封装。

好吧,先加个类,ddraw_math类吧。顺便把ddraw引擎中的几个矩阵弄到ddraw_math类中来,让接口和数学相分离开。

 

头文件有这些

 

#pragma once

 

 

// a 2D vertex

typedef struct VERTEX2DI_TYP

        {

        int x,y; // the vertex

        } VERTEX2DI, *VERTEX2DI_PTR;

typedef struct VERTEX2DF_TYP

        {

        float x,y; // the vertex

        } VERTEX2DF, *VERTEX2DF_PTR;

 

// a 2D polygon

typedef struct POLYGON2D_TYP

        {

        int state;        // state of polygon

        int num_verts;    // number of vertices

        int x0,y0;        // position of center of polygon 

        int xv,yv;        // initial velocity

        DWORD color;      // could be index or PALETTENTRY

        VERTEX2DF *vlist; // pointer to vertex list

 

        } POLYGON2D, *POLYGON2D_PTR;

 

typedef struct MATRIX1X2_TYP

{

     union

     {

         float M[2];

         struct

         {

              float M00,  M01;

         };

     };

 

}MATRIX1X2, * MATRIX1X2_PTR;

 

typedef struct MATRIX1X3_TYP

{

     union

     {

         float M[3];

         struct

         {

              float M00,  M01, M02;

         };

     };

 

}MATRIX1X3, * MATRIX1X3_PTR;

 

typedef struct MATRIX3X2_TYP

{

     union

     {

         float M[3][2];

         struct

         {

              float M00, M01;

              float M10, M11;

              float M20, M21;

 

         };

 

     };

 

}MATRIX3X2, * MATRIX3X2_PTR;

 

 

typedef struct MATRIX3X3_TYP

{

     union

     {

         float M[3][3];

         struct

         {

              float M00, M01, M02;

              float M10, M11, M12;

              float M20, M21, M22;

 

         };

 

     };

 

}MATRIX3X3, * MATRIX3X3_PTR;

 

class ddraw_math

{

public:

     ddraw_math(void);

     ~ddraw_math(void);

 

private:

    

     float                            cos_look[360];

     float                            sin_look[360];

    

public:

 

     void                        Build_Sin_Cos_Tables( void );

     int                              Clip_Line( int & x1, int & y1, int &x2, int & y2 );

 

    

 

     void                        Draw_Bottom_Tri( int x1, int y1, int x2, int y2, int x3, int y3, int color, UCHAR * dest_buffer, int mempitch );

     void                        Draw_Bottom_TriFP( int x1, int y1, int x2, int y2, int x3, int y3, int color, UCHAR * dest_buffer, int mempitch );       

     void                        Draw_Bottom_Tri16( int x1, int y1, int x2, int y2, int x3, int y3, int color, UCHAR * _dest_buffer, int mempitch );

     int                              Draw_Clip_Line( int x0, int y0, int x1, int y1, int color, UCHAR * dest_buffer, int lpitch );

     int                              Draw_Clip_Line16( int x0, int y0, int x1, int y1, int color, UCHAR * dest_buffer, int lpitch );

 

     int                              Draw_Line( int x0, int y0, int x1, int y1, int color, UCHAR * vb_start, int lpitch );

     int                              Draw_Line16( int x0, int y0, int x1, int y1, int color, UCHAR * vb_start, int lpitch );

 

     int                              Draw_Polygon2D( POLYGON2D_PTR poly, UCHAR * vbuffer, int lpitch );

     int                              Draw_Polygon2D16( POLYGON2D_PTR poly, UCHAR * vbuffer, int lpitch );

 

    

     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);

 

     void                        Draw_Top_Tri( int x1, int y1, int x2, int y2, int x3, int y3, int color, UCHAR * dest_buffer, int mempitch );

     void                        Draw_Top_TriFP( int x1, int y1, int x2, int y2, int x3, int y3, int color, UCHAR * dest_buffer, int mempitch );

     void                        Draw_Top_Tri16( int x1, int y1, int x2, int y2, int x3, int y3, int color, UCHAR * _dest_buffer, int mempitch );

     void                        Draw_Triangle_2D( int x1, int y1, int x2, int y2, int x3, int y3, int color, UCHAR * dest_buffer, int mempitch );

     void                        Draw_TriangleFP_2D( int x1, int y1, int x2, int y2, int x3, int y3, int color, UCHAR * dest_buffer, int mempitch );

     void                        Draw_Triangle_2D16( int x1, int y1, int x2, int y2, int x3, int y3, int color, UCHAR * dest_buffer, int mempitch );

 

     int                              Mat_Init_3X2( MATRIX3X2_PTR ma, float m00, float m01, float m10, float m11, float m20, float m21 );

 

     int                              Mat_Mul1X2_3X2( MATRIX1X2_PTR ma, MATRIX3X2_PTR mb, MATRIX1X2_PTR mprod );

     int                              Mat_Mul1X3_3X3( MATRIX1X2_PTR ma, MATRIX3X2_PTR mb, MATRIX1X2_PTR mprod );

     int                              Mat_Mul3X3( MATRIX1X2_PTR ma, MATRIX3X2_PTR mb, MATRIX1X2_PTR mprod );

     void                        Mem_Set_WORD( void * dest, USHORT data, int count );

 

     int                              Rotate_Polygon2D(POLYGON2D_PTR poly, int theta);

     int                              Rotate_Polygon2D_Mat(POLYGON2D_PTR poly, int theta);

 

     int                              Scale_Polygon2D(POLYGON2D_PTR poly, float sx, float sy);

     int                              Scale_Polygon2D_Mat(POLYGON2D_PTR poly, float sx, float sy);

 

     int                              Translate_Polygon2D( POLYGON2D_PTR poly, int dx, int dy );

     int                              Translate_Polygon2D_Mat( POLYGON2D_PTR poly, int dx, int dy );

 

 

};

当然,现在其实也能提取出矩阵来,不过,不过目前还没有必要,所以先放在这里,然后移植成员函数,

 

由于还有些数据类型没定义,所以

#include common.h

再次编译,发现那些m_min_clip_x等,没有定义,原因是和显示部分的裁剪区发生了耦合,那只能再加上个函数,

 

void ddraw_math::setClipRect( RECT rect )

{

     m_min_clip_x                = rect.left;

     m_max_clip_x                = rect.right;

     m_min_clip_y                = rect.bottom;

     m_max_clip_y                = rect.right;

}

 

然后在DDRAW初始化时,传递过去即可,

可以再次验证下。是OK的。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值