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

📄 our_draw32.c

📁 这是一个简单的3d动画mmi,这是模拟器上的
💻 C
📖 第 1 页 / 共 4 页
字号:
/**************************************************************************
Copyright (C) jianbo miao Corporation.  All Rights Released.
this is a 3d engin named our_3d_engin.
our_3d_engin feature:
1:there is no float.
2:it do the 3d things all by softwear.
3:base on 1 and 2 , it can execution on arm which have no 3d hardwear accelerate.

  if you have any  suggestion or question,pls contact with me
  mail:miaojb@126.com
  msn:miaojianbo@hotmail.com
  qq:30209027
  
    2008/01/01
***************************************************************************/
#ifdef OUR_MAIN_C
#ifndef OUR_DRAW32_C
#define  OUR_DRAW32_C

#include "our_math.h"
#include "our_3d.h"
#include "our_draw32.h"
#include "our_draw16.h"
#include "our_bmp.h"


#if 0
//FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
//FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
//==================================================================================
int OUR_Draw_Line32(int x0, int y0, 	// starting position 
                    int x1, int y1, 	// ending position
                    int color,     	// color index
                    UCHAR *vb_start, int lpitch_2) // video buffer and memory pitch
{
    // this function draws a line from xo,yo to x1,y1 using differential error
    // terms (based on Bresenahams work)
    
    int dx,             // difference in x's
        dy,             // difference in y's
        dx2,            // dx,dy * 2
        dy2, 
        x_inc,          // amount in pixel space to move during drawing
        y_inc,          // amount in pixel space to move during drawing
        error,          // the discriminant i.e. error i.e. decision variable
        index;          // used for looping
    UINT *vb_start2;
    lpitch_2 = lpitch_2>>2 ; // USHORT strided lpitch
    
    // pre-compute first pixel address in video buffer based on 32bit data
    vb_start2 = (UINT*)vb_start + x0 + y0*lpitch_2;
    // pre-compute first pixel address in video buffer based on 32bit data
    //UINT*vb_start2 = (UINT*)vb_start + x0 + y0*lpitch_2;
    
    // compute horizontal and vertical deltas
    dx = x1-x0;
    dy = y1-y0;
    
    // test which direction the line is going in i.e. slope angle
    if (dx>=0)
    {
        x_inc = 1;
    } // end if line is moving right
    else
    {
        x_inc = -1;
        dx    = -dx;  // need absolute value
    } // end else moving left
    // test y component of slope
    if (dy>=0)
    {
        y_inc = lpitch_2;
    } // end if line is moving down
    else
    {
        y_inc = -lpitch_2;
        dy    = -dy;  // need absolute value
    } // end else moving up
    
    dx2 = dx << 1;// compute (dx,dy) * 2
    dy2 = dy << 1;
    
    if (dx > dy)// now based on which delta is greater we can draw the line
    {
        
        error = dy2 - dx; // initialize error term
        
        for (index=0; index <= dx; index++)// draw the line
        {
            
            *vb_start2 = (UINT)color;// set the pixel
            
            if (error >= 0) // test if error has overflowed
            {
                error-=dx2;
                
                vb_start2+=y_inc;// move to next line
            } // end if error overflowed
            
            error+=dy2;// adjust the error term
            
            vb_start2+=x_inc;// move to the next pixel
        } // end for
    } // end if |slope| <= 1
    else
    {
        // initialize error term
        error = dx2 - dy; 
        // draw the line
        for (index=0; index <= dy; index++)
        {
            // set the pixel
            *vb_start2 = (UINT)color;
            
            // test if error overflowed
            if (error >= 0)
            {
                error-=dy2;
                // move to next line
                vb_start2+=x_inc;
            } // end if error overflowed
            // adjust the error term
            error+=dx2;
            // move to the next pixel
            vb_start2+=y_inc;
        } // end for
    } // end else |slope| > 1
    // return success
    return(1);
} // end Draw_Line32

                    ///////////////////////////////////////////////////////////
                    
                    ///////////////////////////////////////////////////////////

                    int OUR_Clip_Line(int *x11,int *y11,int *x21, int *y21)
                    {
                        // this function clips the sent line using the globally defined clipping
                        // region
                        
                        // internal clipping codes
#define CLIP_CODE_C  0x0000
#define CLIP_CODE_N  0x0008
#define CLIP_CODE_S  0x0004
#define CLIP_CODE_E  0x0002
#define CLIP_CODE_W  0x0001
                        
#define CLIP_CODE_NE 0x000a
#define CLIP_CODE_SE 0x0006
#define CLIP_CODE_NW 0x0009 
#define CLIP_CODE_SW 0x0005
                        
                        int x1,x2,y1,y2;
                        
                        int xc1,xc2,yc1,yc2;
                        
                        
                        int p1_code=0, 
                            p2_code=0;
                        
                        int min_clip_y=0;
                        int min_clip_x=0;
                        int max_clip_y=OUR_D_screem_h;
                        int max_clip_x=OUR_D_screem_w;
                        xc1=x1; 
                        yc1=y1;
                        xc2=x2; 
                        yc2=y2;
                        x1=*x11; 
                        y1=*y11; 
                        x2=*x21; 
                        y2=*y21;
                        // determine codes for p1 and p2
                        if (y1 < min_clip_y)
                            p1_code|=CLIP_CODE_N;
                        else
                            if (y1 > max_clip_y)
                                p1_code|=CLIP_CODE_S;
                            
                            if (x1 < min_clip_x)
                                p1_code|=CLIP_CODE_W;
                            else
                                if (x1 > max_clip_x)
                                    p1_code|=CLIP_CODE_E;
                                
                                if (y2 < min_clip_y)
                                    p2_code|=CLIP_CODE_N;
                                else
                                    if (y2 > max_clip_y)
                                        p2_code|=CLIP_CODE_S;
                                    
                                    if (x2 < min_clip_x)
                                        p2_code|=CLIP_CODE_W;
                                    else
                                        if (x2 > max_clip_x)
                                            p2_code|=CLIP_CODE_E;
                                        
                                        // try and trivially reject
                                        if ((p1_code & p2_code)) 
                                            return(0);
                                        
                                        // test for totally visible, if so leave points untouched
                                        if (p1_code==0 && p2_code==0)
                                            return(1);
                                        
                                        // determine end clip point for p1
                                        switch(p1_code)
                                        {
                                        case CLIP_CODE_C: break;
                                            
                                        case CLIP_CODE_N:
                                            {
                                                yc1 = min_clip_y;
                                                xc1 = x1 + 0.5+(min_clip_y-y1)*(x2-x1)/(y2-y1);
                                            } break;
                                        case CLIP_CODE_S:
                                            {
                                                yc1 = max_clip_y;
                                                xc1 = x1 + 0.5+(max_clip_y-y1)*(x2-x1)/(y2-y1);
                                            } break;
                                            
                                        case CLIP_CODE_W:
                                            {
                                                xc1 = min_clip_x;
                                                yc1 = y1 + 0.5+(min_clip_x-x1)*(y2-y1)/(x2-x1);
                                            } break;
                                            
                                        case CLIP_CODE_E:
                                            {
                                                xc1 = max_clip_x;
                                                yc1 = y1 + 0.5+(max_clip_x-x1)*(y2-y1)/(x2-x1);
                                            } break;
                                            
                                            // these cases are more complex, must compute 2 intersections
                                        case CLIP_CODE_NE:
                                            {
                                                // north hline intersection
                                                yc1 = min_clip_y;
                                                xc1 = x1 + 0.5+(min_clip_y-y1)*(x2-x1)/(y2-y1);
                                                
                                                // test if intersection is valid, of so then done, else compute next
                                                if (xc1 < min_clip_x || xc1 > max_clip_x)
                                                {
                                                    // east vline intersection
                                                    xc1 = max_clip_x;
                                                    yc1 = y1 + 0.5+(max_clip_x-x1)*(y2-y1)/(x2-x1);
                                                } // end if
                                                
                                            } break;
                                            
                                        case CLIP_CODE_SE:
                                            {
                                                // south hline intersection
                                                yc1 = max_clip_y;
                                                xc1 = x1 + 0.5+(max_clip_y-y1)*(x2-x1)/(y2-y1);	
                                                
                                                // test if intersection is valid, of so then done, else compute next
                                                if (xc1 < min_clip_x || xc1 > max_clip_x)
                                                {
                                                    // east vline intersection
                                                    xc1 = max_clip_x;
                                                    yc1 = y1 + 0.5+(max_clip_x-x1)*(y2-y1)/(x2-x1);
                                                } // end if
                                                
                                            } break;
                                            
                                        case CLIP_CODE_NW: 
                                            {
                                                // north hline intersection
                                                yc1 = min_clip_y;
                                                xc1 = x1 + 0.5+(min_clip_y-y1)*(x2-x1)/(y2-y1);
                                                
                                                // test if intersection is valid, of so then done, else compute next
                                                if (xc1 < min_clip_x || xc1 > max_clip_x)
                                                {
                                                    xc1 = min_clip_x;
                                                    yc1 = y1 + 0.5+(min_clip_x-x1)*(y2-y1)/(x2-x1);	
                                                } // end if
                                                
                                            } break;
                                            
                                        case CLIP_CODE_SW:
                                            {
                                                // south hline intersection
                                                yc1 = max_clip_y;
                                                xc1 = x1 + 0.5+(max_clip_y-y1)*(x2-x1)/(y2-y1);	
                                                
                                                // test if intersection is valid, of so then done, else compute next
                                                if (xc1 < min_clip_x || xc1 > max_clip_x)
                                                {
                                                    xc1 = min_clip_x;
                                                    yc1 = y1 + 0.5+(min_clip_x-x1)*(y2-y1)/(x2-x1);	
                                                } // end if
                                                
                                            } break;
                                            
                                        default:break;
                                            
                                        } // end switch
                                        
                                        // determine clip point for p2
                                        switch(p2_code)
                                        {
                                        case CLIP_CODE_C: break;
                                            
                                        case CLIP_CODE_N:
                                            {
                                                yc2 = min_clip_y;
                                                xc2 = x2 + (min_clip_y-y2)*(x1-x2)/(y1-y2);
                                            } break;
                                            
                                        case CLIP_CODE_S:
                                            {
                                                yc2 = max_clip_y;
                                                xc2 = x2 + (max_clip_y-y2)*(x1-x2)/(y1-y2);
                                            } break;
                                            
                                        case CLIP_CODE_W:
                                            {
                                                xc2 = min_clip_x;
                                                yc2 = y2 + (min_clip_x-x2)*(y1-y2)/(x1-x2);
                                            } break;
                                            
                                        case CLIP_CODE_E:
                                            {
                                                xc2 = max_clip_x;
                                                yc2 = y2 + (max_clip_x-x2)*(y1-y2)/(x1-x2);
                                            } break;
                                            
                                            // these cases are more complex, must compute 2 intersections
                                        case CLIP_CODE_NE:
                                            {
                                                // 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)
                                                {
                                                    // east vline intersection
                                                    xc2 = max_clip_x;
                                                    yc2 = y2 + 0.5+(max_clip_x-x2)*(y1-y2)/(x1-x2);
                                                } // end if
                                                
                                            } break;
                                            
                                        case CLIP_CODE_SE:
                                            {
                                                // 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)
                                                {
                                                    // east vline intersection
                                                    xc2 = max_clip_x;
                                                    yc2 = y2 + 0.5+(max_clip_x-x2)*(y1-y2)/(x1-x2);

⌨️ 快捷键说明

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