⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 our_draw32.c

📁 这是一个简单的3d动画mmi,这是模拟器上的
💻 C
📖 第 1 页 / 共 4 页
字号:
                                                } // end if
                                                
                                            } break;
                                            
                                        case CLIP_CODE_NW: 
                                            {
                                                // north hline intersection
                                                yc2 = min_clip_y;
                                                xc2 = x2 + 0.5+(min_clip_y-y2)*(x1-x2)/(y1-y2);
                                                
                                                // test if intersection is valid, of so then done, else compute next
                                                if (xc2 < min_clip_x || xc2 > max_clip_x)
                                                {
                                                    xc2 = min_clip_x;
                                                    yc2 = y2 + 0.5+(min_clip_x-x2)*(y1-y2)/(x1-x2);	
                                                } // end if
                                                
                                            } break;
                                            
                                        case CLIP_CODE_SW:
                                            {
                                                // south hline intersection
                                                yc2 = max_clip_y;
                                                xc2 = x2 + 0.5+(max_clip_y-y2)*(x1-x2)/(y1-y2);	
                                                
                                                // test if intersection is valid, of so then done, else compute next
                                                if (xc2 < min_clip_x || xc2 > max_clip_x)
                                                {
                                                    xc2 = min_clip_x;
                                                    yc2 = y2 + 0.5+(min_clip_x-x2)*(y1-y2)/(x1-x2);	
                                                } // end if
                                                
                                            } break;
                                            
                                        default:break;
                                            
                                        } // end switch
                                        
                                        // do bounds check
                                        if ((xc1 < min_clip_x) || (xc1 > max_clip_x) ||
                                            (yc1 < min_clip_y) || (yc1 > max_clip_y) ||
                                            (xc2 < min_clip_x) || (xc2 > max_clip_x) ||
                                            (yc2 < min_clip_y) || (yc2 > max_clip_y) )
                                        {
                                            return(0);
                                        } // end if
                                        
                                        // store vars back
                                        *x11 = xc1;
                                        *y11 = yc1;
                                        *x21 = xc2;
                                        *y21 = yc2;
                                        
                                        return(1);
                                        
} // end Clip_Line
//=================================================================================
int OUR_Draw_Clip_Line32(int x0,int y0, int x1, int y1, int color, 
                         UCHAR *dest_buffer, int lpitch)
{
    // this function draws a clipped line
    
    int cxs, cys,
        cxe, cye;
    
    // clip and draw each line
    cxs = x0;
    cys = y0;
    cxe = x1;
    cye = y1;
    
    // clip the line
    if (OUR_Clip_Line(&cxs,&cys,&cxe,&cye))
        OUR_Draw_Line32(cxs, cys, cxe,cye,color,dest_buffer,lpitch);
    
    // return success
    return(1);
    
} // end Draw_Clip_Line32

//--------------------------------------------------------------------

void OUR_Draw_Wire32( OUR_3D_OBJ_PTR	obj,UCHAR *video_buffer, int lpitch)
{
    UINT i1,i2,i3;
    UINT poly;
    UINT num;
    UINT poly_change;
    FIX_POINT3D_PTR     point_work=obj->pPoints_work;
    OUR_3D_TRAG_PTR      triangle_work=obj->pTriangle;
    num=obj->pTriangle_num_changed;
    for (poly=0; poly <num; poly++)
    {
        //if(OUR_D_FrameTH==obj->pTriangle_changed[poly])
        {
            poly_change=obj->pTriangle_changed[poly];
            i1=triangle_work[poly_change].p1;
            i2=triangle_work[poly_change].p2;
            i3=triangle_work[poly_change].p3;
            OUR_Draw_Clip_Line32(point_work[i1].MM.x, 
                point_work[i1].MM.y,
                point_work[i2].MM.x, 
                point_work[i2].MM.y,
                // triangle_work[poly_change].CC_work.clor,
                obj->clor_work[poly_change],
                video_buffer, lpitch);
            OUR_Draw_Clip_Line32(	point_work[i3].MM.x, 
                point_work[i3].MM.y,
                point_work[i2].MM.x, 
                point_work[i2].MM.y,
                // triangle_work[poly_change].CC_work.clor,
                obj->clor_work[poly_change],
                video_buffer, lpitch);
            OUR_Draw_Clip_Line32(	point_work[i1].MM.x, 
                point_work[i1].MM.y,
                point_work[i3].MM.x, 
                point_work[i3].MM.y,
                // triangle_work[poly_change].CC_work.clor,
                obj->clor_work[poly_change],
                video_buffer, lpitch);
            OUR_D_triangle_drawed_num++;
            
        }
    }
} // end Draw_RENDERLIST4DV1_Wire

//===========================================================
//--------------------------------------------------------------------------
#define DRAW_T_SHIFT 20
void OUR_Draw_Triangle_2D32(	int x1,int y1,
                            int x2,int y2,
                            int x3,int y3,
                            CLR color,
                            UCHAR *dest_buffer, int mempitch)
{
    int xs,xe,ks,ke,xinc;
    int yinc;
    CLR *dest;
    //make sure y1<y2<y3
    if(y1>y2)
    {
        OUR_SWAP(y1,y2,xs);
        OUR_SWAP(x1,x2,xs);
    }
    if(y1>y3)
    {
        OUR_SWAP(y1,y3,xs);
        OUR_SWAP(x1,x3,xs);
    }
    if(y2>y3)
    {
        OUR_SWAP(y2,y3,xs);
        OUR_SWAP(x2,x3,xs);
    }					//18t
    
    //mempitch>>=2;//(sizeof(dest)/2);
    dest = (CLR*)dest_buffer +y1*mempitch;		//point to the line of y1
    if(y1<y2 )//the top part
    {		
        ks=((x1-x2)<<DRAW_T_SHIFT)/(y1-y2);		//slope 1 --> 2
        ke=((x1-x3)<<DRAW_T_SHIFT)/(y1-y3);		//slope 1 --> 3
        if(ks>ke)						//start slope must be smaller than the end one
        {
            OUR_SWAP(ks,ke,xs);
        }		
        xs=x1<<DRAW_T_SHIFT;
        xe=xs;
        for(yinc=y1;yinc<y2;yinc++)		//scan lines
        {			
            //y1=xe>>8;
            for(xinc=xs>>DRAW_T_SHIFT;xinc<=(xe>>DRAW_T_SHIFT);xinc++) 		//scan point 
            {
                dest[xinc] =color;		//display
            }
            dest+=mempitch;			//point to next line
            xs+=ks;					//next line xs
            xe+=ke;					//next line xe
        }		
        if(y2<y3)//the butt part
        {	
            x1=((x2-x3)<<DRAW_T_SHIFT)/(y2-y3);
            if(x1>ke)
            {
                ks=x1;
            }
            else
            {
                ke=x1;
            }
            for(;yinc<=y3;yinc++)
            {			
                //y1=xe>>8;
                for(xinc=xs>>DRAW_T_SHIFT;xinc<=(xe>>DRAW_T_SHIFT);xinc++)
                {
                    dest[xinc] =color;
                }
                dest+=mempitch;
                xs+=ks;
                xe+=ke;
            }		
            
        }
        return;
    }
    else
    {		
        if(y2<y3)//the butt part
        {	
            ks=((x2-x3)<<DRAW_T_SHIFT)/(y1-y3);
            ke=((x1-x3)<<DRAW_T_SHIFT)/(y1-y3);
            if(ks<ke)
            {
                OUR_SWAP(ks,ke,xs);
            }	
            if(x1<x2)
            {
                xs=x1<<DRAW_T_SHIFT;
                xe=(x2<<DRAW_T_SHIFT);//+(xei>>1);
            }
            else 
            {
                xs=x2<<DRAW_T_SHIFT;
                xe=(x1<<DRAW_T_SHIFT);//+(xei>>1);
                
            }
            for(yinc=y1;yinc<y3;yinc++)
            {			
                //y1=xe>>8;
                for(xinc=xs>>DRAW_T_SHIFT;xinc<=(xe>>DRAW_T_SHIFT);xinc++)
                {
                    dest[xinc] =color;
                }
                dest+=mempitch;
                xs+=ks;
                xe+=ke;
            }		
        }
        return;
    }
    
}

//--------------------------------------------------------------------------
//------------------------------------				
#define FILL_POINT	{				\
    dest[xinc] =color;	\
    xinc++;			\
}
//----------------------------------------------------------------------------

#define DRAW_P_SHFT_X 18
#define SHIFR_L 18
#define SHIFT 30
//------------------------------------------------------
#define FILE_GOURAUD32	{\
    dest[xinc++] =((k_r_inc>>(SHIFR_L-16))&OUR_RGB_MASK0800)+\
    ((k_g_inc>>(SHIFR_L-8))&OUR_RGB_MASK0080)+((k_b_inc>>SHIFR_L)&OUR_RGB_MASK0008);\
    \
    k_r_inc+=kre;\
    k_g_inc+=kge;\
    k_b_inc+=kbe;\
}
//------------------------------------------------------


void OUR_Draw_Gouraud_2D32(	int x1,int y1,
                           int x2,int y2,
                           int x3,int y3,
                           CLR color1,
                           CLR color2,
                           CLR color3,
                           UCHAR *dest_buffer, int mempitch)
{
    int xs,xe,ks,ke,xinc;
    int yinc;
    CLR rs,re,gs,ge,bs,be;
    int krs,kre,kgs,kge,kbs,kbe;
    int  k_r_inc;
    int  k_g_inc;
    int  k_b_inc;
    CLR *dest;
    /*
    x1=200;
    y1=0;
    x2=1;
    y2=200;
    x3=350;
    y3=350;
    
      
        color1 = 0x000000;
        color2 = 0xff0000;
        color3 = 0x000000;
    */
    //make sure y1<y2<y3
    if(y1>y2)
    {
        OUR_SWAP(y1,y2,xs);
        OUR_SWAP(x1,x2,xs);
        OUR_SWAP(color1,color2,rs);
    }
    if(y1>y3)
    {
        OUR_SWAP(y1,y3,xs);
        OUR_SWAP(x1,x3,xs);
        OUR_SWAP(color1,color3,rs);
    }
    if(y2>y3)
    {
        OUR_SWAP(y2,y3,xs);
        OUR_SWAP(x2,x3,xs);
        OUR_SWAP(color2,color3,rs);
    }								//18t
    
    //mempitch>>=2;					//(sizeof(dest)/2);
    dest = (CLR*)dest_buffer +y1*mempitch;		//point to the line of y1
#if 1
    if(y1<y2 )						//the top part
    {
        xs=(1<<(DRAW_P_SHFT_X))/(y1-y2);
        xe=(1<<(DRAW_P_SHFT_X))/(y1-y3);	
        ks=((x1-x2))*xs;				//slope 1 --> 2
        ke=((x1-x3))*xe;				//slope 1 --> 3
        xs>>=(DRAW_P_SHFT_X-SHIFR_L);
        xe>>=(DRAW_P_SHFT_X-SHIFR_L);
        if(ks>ke)						//start slope must be smaller than the end one
        {
            kre=(((color1&OUR_RGB_MASK0800)-(color2&OUR_RGB_MASK0800))>>16)*xs;
            krs=(((color1&OUR_RGB_MASK0800)-(color3&OUR_RGB_MASK0800))>>16)*xe;
            
            kge=(((color1&OUR_RGB_MASK0080)-(color2&OUR_RGB_MASK0080))>>8)*xs;
            kgs=(((color1&OUR_RGB_MASK0080)-(color3&OUR_RGB_MASK0080))>>8)*xe;
            
            kbe=(((color1&OUR_RGB_MASK0008)-(color2&OUR_RGB_MASK0008)))*xs;
            kbs=(((color1&OUR_RGB_MASK0008)-(color3&OUR_RGB_MASK0008)))*xe;
            OUR_SWAP(ks,ke,xs);
        }	
        else if(ks<ke)	
        {
            krs=(((color1&OUR_RGB_MASK0800)-(color2&OUR_RGB_MASK0800))>>16)*xs;
            kre=(((color1&OUR_RGB_MASK0800)-(color3&OUR_RGB_MASK0800))>>16)*xe;
            
            kgs=(((color1&OUR_RGB_MASK0080)-(color2&OUR_RGB_MASK0080))>>8)*xs;
            kge=(((color1&OUR_RGB_MASK0080)-(color3&OUR_RGB_MASK0080))>>8)*xe;
            
            kbs=(((color1&OUR_RGB_MASK0008)-(color2&OUR_RGB_MASK0008)))*xs;
            kbe=(((color1&OUR_RGB_MASK0008)-(color3&OUR_RGB_MASK0008)))*xe;
        }
        else
        {
            return;
        }
#define GND_KKKK 0
        if((ke-ks)<(2<<DRAW_P_SHFT_X))//
        {      
            xs=((1<<(SHIFT-4)))/((ke-ks));
            kre=(((kre-krs)>>5)*xs)>>(SHIFT-SHIFR_L-5-4);		
            kge=(((kge-kgs)>>5)*xs)>>(SHIFT-SHIFR_L-5-4);		

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -