亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? demo8_4.cpp

?? 一本外國人寫的關于3D游戲編程的書的源碼
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
// DEMO8_4.CPP 8-bit polygon rotation demo

// INCLUDES ///////////////////////////////////////////////

#define WIN32_LEAN_AND_MEAN  // just say no to MFC

#define INITGUID


#include <windows.h>   // include important windows stuff
#include <windowsx.h> 
#include <mmsystem.h>
#include <iostream.h> // include important C/C++ stuff
#include <conio.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h> 
#include <math.h>
#include <io.h>
#include <fcntl.h>

#include <ddraw.h> // include directdraw

// DEFINES ////////////////////////////////////////////////

// defines for windows 
#define WINDOW_CLASS_NAME "WINCLASS1"

// default screen size
#define SCREEN_WIDTH    640  // size of screen
#define SCREEN_HEIGHT   480
#define SCREEN_BPP      8    // bits per pixel

#define BITMAP_ID            0x4D42 // universal id for a bitmap
#define MAX_COLORS_PALETTE   256

#define NUM_ASTEROIDS        64


const double PI = 3.1415926535;

// TYPES //////////////////////////////////////////////////////

// basic unsigned types
typedef unsigned short USHORT;
typedef unsigned short WORD;
typedef unsigned char  UCHAR;
typedef unsigned char  BYTE;

// a 2D vertex
typedef struct VERTEX2DI_TYP
        {
        int x,y; // the vertex
        } VERTEX2DI, *VERTEX2DI_PTR;

// a 2D vertex
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;


// PROTOTYPES  //////////////////////////////////////////////

int DDraw_Fill_Surface(LPDIRECTDRAWSURFACE7 lpdds,int color);

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

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

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

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

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

int Rotate_Polygon2D(POLYGON2D_PTR poly, int theta);

// MACROS /////////////////////////////////////////////////

// tests if a key is up or down
#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEYUP(vk_code)   ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)

// initializes a direct draw struct
#define DDRAW_INIT_STRUCT(ddstruct) { memset(&ddstruct,0,sizeof(ddstruct)); ddstruct.dwSize=sizeof(ddstruct); }

// some math macros
#define DEG_TO_RAD(ang) ((ang)*PI/180)
#define RAD_TO_DEG(rads) ((rads)*180/PI)

// GLOBALS ////////////////////////////////////////////////

HWND      main_window_handle = NULL; // globally track main window
int       window_closed      = 0;    // tracks if window is closed
HINSTANCE hinstance_app      = NULL; // globally track hinstance

// directdraw stuff
LPDIRECTDRAW7         lpdd         = NULL;   // dd object
LPDIRECTDRAWSURFACE7  lpddsprimary = NULL;   // dd primary surface
LPDIRECTDRAWSURFACE7  lpddsback    = NULL;   // dd back surface
LPDIRECTDRAWPALETTE   lpddpal      = NULL;   // a pointer to the created dd palette
LPDIRECTDRAWCLIPPER   lpddclipper  = NULL;   // dd clipper
PALETTEENTRY          palette[256];          // color palette
PALETTEENTRY          save_palette[256];     // used to save palettes
DDSURFACEDESC2        ddsd;                  // a direct draw surface description struct
DDBLTFX               ddbltfx;               // used to fill
DDSCAPS2              ddscaps;               // a direct draw surface capabilities struct
HRESULT               ddrval;                // result back from dd calls
DWORD                 start_clock_count = 0; // used for timing


// global clipping region

int min_clip_x = 0,      // clipping rectangle 
    max_clip_x = SCREEN_WIDTH - 1,
    min_clip_y = 0,
    max_clip_y = SCREEN_HEIGHT - 1;

char buffer[80];                             // general printing buffer

// storage for our lookup tables
float cos_look[360];
float sin_look[360];

POLYGON2D asteroids[NUM_ASTEROIDS]; // the asteroids

// FUNCTIONS ////////////////////////////////////////////////

int Draw_Polygon2D(POLYGON2D_PTR poly, UCHAR *vbuffer, int lpitch)
{
// this function draws a POLYGON2D based on 

// test if the polygon is visible
if (poly->state)
   {
   // loop thru and draw a line from vertices 1 to n
   for (int index=0; index < poly->num_verts-1; index++)
        {
        // draw line from ith to ith+1 vertex
        Draw_Clip_Line(poly->vlist[index].x+poly->x0, 
                       poly->vlist[index].y+poly->y0,
                       poly->vlist[index+1].x+poly->x0, 
                       poly->vlist[index+1].y+poly->y0,
                       poly->color,
                       vbuffer, lpitch);

        } // end for

       // now close up polygon
       // draw line from last vertex to 0th
       Draw_Clip_Line(poly->vlist[0].x+poly->x0, 
                      poly->vlist[0].y+poly->y0,
                      poly->vlist[index].x+poly->x0, 
                      poly->vlist[index].y+poly->y0,
                      poly->color,
                      vbuffer, lpitch);

   // return success
   return(1);
   } // end if
else 
   return(0);

} // end Draw_Polygon2D

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

int Translate_Polygon2D(POLYGON2D_PTR poly, int dx, int dy)
{
// this function translates the center of a polygon

// test for valid pointer
if (!poly)
   return(0);

// translate
poly->x0+=dx;
poly->y0+=dy;

// return success
return(1);

} // end Translate_Polygon2D

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

int Rotate_Polygon2D(POLYGON2D_PTR poly, int theta)
{
// this function rotates the local coordinates of the polygon

// test for valid pointer
if (!poly)
   return(0);

// loop and rotate each point, very crude, no lookup!!!
for (int curr_vert = 0; curr_vert < poly->num_verts; curr_vert++)
    {

    // perform rotation
    float xr = (float)poly->vlist[curr_vert].x*cos_look[theta] - 
                    (float)poly->vlist[curr_vert].y*sin_look[theta];

    float yr = (float)poly->vlist[curr_vert].x*sin_look[theta] + 
                    (float)poly->vlist[curr_vert].y*cos_look[theta];

    // store result back
    poly->vlist[curr_vert].x = xr;
    poly->vlist[curr_vert].y = yr;

    } // end for curr_vert

// return success
return(1);

} // end Rotate_Polygon2D

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

inline int Draw_Pixel(int x, int y,int color,
               UCHAR *video_buffer, int lpitch)
{
// this function plots a single pixel at x,y with color

video_buffer[x + y*lpitch] = color;

// return success
return(1);

} // end Draw_Pixel

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

int DDraw_Fill_Surface(LPDIRECTDRAWSURFACE7 lpdds,int color)
{
DDBLTFX ddbltfx; // this contains the DDBLTFX structure

// clear out the structure and set the size field 
DDRAW_INIT_STRUCT(ddbltfx);

// set the dwfillcolor field to the desired color
ddbltfx.dwFillColor = color; 

// ready to blt to surface
lpdds->Blt(NULL,       // ptr to dest rectangle
           NULL,       // ptr to source surface, NA            
           NULL,       // ptr to source rectangle, NA
           DDBLT_COLORFILL | DDBLT_WAIT,   // fill and wait                   
           &ddbltfx);  // ptr to DDBLTFX structure

// return success
return(1);
} // end DDraw_Fill_Surface

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

int Draw_Clip_Line(int x0,int y0, int x1, int y1,UCHAR color, 
                    UCHAR *dest_buffer, int lpitch)
{
// this helper 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 (Clip_Line(cxs,cys,cxe,cye))
	Draw_Line(cxs, cys, cxe,cye,color,dest_buffer,lpitch);

// return success
return(1);

} // end Draw_Clip_Line

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

int Clip_Line(int &x1,int &y1,int &x2, int &y2)
{
// 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 xc1=x1, 
    yc1=y1, 
	xc2=x2, 
	yc2=y2;

int p1_code=0, 
    p2_code=0;

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

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91精品国产综合久久蜜臀| 亚洲成人激情社区| 水野朝阳av一区二区三区| 国产一区二区影院| 在线日韩av片| 久久综合网色—综合色88| 性感美女极品91精品| 99久久久国产精品免费蜜臀| 欧美一区二区三区免费观看视频 | 91蜜桃婷婷狠狠久久综合9色| 欧美一区二区不卡视频| 亚洲精品视频在线| 国产精品一卡二| 欧美大片一区二区| 午夜精品久久久久影视| 一本到一区二区三区| 亚洲人成网站色在线观看| 国产盗摄精品一区二区三区在线 | 国产主播一区二区| 91精品欧美福利在线观看| 一区二区三国产精华液| 国产成人av一区二区| 久久久久久久综合| 毛片av中文字幕一区二区| 欧美精品久久天天躁| 亚洲a一区二区| 欧美色图免费看| 一区二区三区成人| 91国偷自产一区二区开放时间 | 久久精品日韩一区二区三区| 麻豆精品在线播放| 精品国产91洋老外米糕| 久久精品国产一区二区| 精品99一区二区| 国模无码大尺度一区二区三区| www久久精品| 成人性视频网站| 国产精品美女视频| 色狠狠色噜噜噜综合网| 亚洲综合图片区| 欧美精品aⅴ在线视频| 蜜臀久久99精品久久久久宅男| 国产精品亚洲第一区在线暖暖韩国 | 亚洲手机成人高清视频| 色香蕉久久蜜桃| 亚洲国产成人tv| 日韩一区二区电影在线| 国产电影一区在线| 亚洲色图清纯唯美| 欧美色窝79yyyycom| 成人永久aaa| 中文字幕一区二区三区在线观看| 91婷婷韩国欧美一区二区| 亚洲欧美日韩一区| 制服视频三区第一页精品| 麻豆精品视频在线观看视频| 国产丝袜美腿一区二区三区| 国产福利一区在线观看| 亚洲人成在线播放网站岛国| 欧美精品色综合| 国产精品亚洲成人| 一区二区国产盗摄色噜噜| 欧美日韩精品欧美日韩精品| 久久激情五月婷婷| 国产精品电影一区二区三区| 欧美久久久一区| 风流少妇一区二区| 日韩在线一二三区| 国产精品视频免费看| 欧美视频完全免费看| 狠狠色狠狠色综合| 亚洲美女一区二区三区| 日韩欧美一级二级| 91蜜桃婷婷狠狠久久综合9色| 日韩精品一二三区| 中文字幕的久久| 69堂国产成人免费视频| av综合在线播放| 蜜臀av一区二区| 亚洲伦理在线精品| 久久精品日韩一区二区三区| 欧美日韩大陆一区二区| 大桥未久av一区二区三区中文| 午夜精品视频一区| 亚洲女与黑人做爰| 久久婷婷一区二区三区| 欧美日本国产视频| 91在线国内视频| 国内不卡的二区三区中文字幕| 亚洲成人1区2区| 亚洲人成在线播放网站岛国| 久久先锋资源网| 日韩精品一区二区在线观看| 欧美亚洲国产一卡| 北岛玲一区二区三区四区| 国产乱对白刺激视频不卡| 日本视频一区二区| 亚洲成人激情自拍| 亚洲国产精品久久不卡毛片| 亚洲欧美另类小说视频| 亚洲三级小视频| 国产精品网站在线播放| 国产日韩欧美精品在线| 精品欧美久久久| 日韩欧美黄色影院| 精品久久国产字幕高潮| 欧美videos大乳护士334| 51精品久久久久久久蜜臀| 欧美人xxxx| 欧美挠脚心视频网站| 欧美女孩性生活视频| 欧美日产国产精品| 欧美一区二区三区男人的天堂| 国产午夜一区二区三区| 精品日韩欧美一区二区| 精品国精品国产| 久久麻豆一区二区| 国产欧美日产一区| 国产精品网友自拍| 综合久久综合久久| 亚洲男人的天堂在线aⅴ视频| 日韩美女视频一区| 一区二区三区免费网站| 亚洲国产视频直播| 日本亚洲视频在线| 加勒比av一区二区| 波多野结衣一区二区三区| 91免费看`日韩一区二区| 欧美日韩中文一区| 日韩欧美中文一区| 国产亚洲一区二区三区在线观看| 久久午夜色播影院免费高清| 国产精品色哟哟| 亚洲免费在线视频| 日韩精品电影在线| 国产一区999| 色婷婷亚洲婷婷| 欧美一级久久久久久久大片| 精品国产乱码久久久久久夜甘婷婷| 国产亚洲综合在线| 亚洲一区av在线| 韩国一区二区三区| 91麻豆精品一区二区三区| 欧美精品第1页| 国产精品麻豆视频| 亚洲成人av一区二区三区| 国产精品中文字幕日韩精品| 91亚洲国产成人精品一区二区三| 在线亚洲人成电影网站色www| 日韩一区二区三区免费观看| 中文字幕欧美区| 日韩成人精品视频| 成人久久18免费网站麻豆| 91麻豆精品国产91久久久久| 欧美国产1区2区| 日韩精品一卡二卡三卡四卡无卡| 国产精品综合一区二区三区| 精品视频在线免费| 中文字幕乱码久久午夜不卡| 日韩电影在线一区二区| 99精品欧美一区| 精品国产不卡一区二区三区| 亚洲夂夂婷婷色拍ww47| 国产精品亚洲午夜一区二区三区| 欧美三级电影在线看| 国产精品久线观看视频| 琪琪一区二区三区| 欧美在线免费视屏| 国产精品久久二区二区| 紧缚捆绑精品一区二区| 欧美日韩精品一区视频| 久久国产精品72免费观看| 精品视频一区二区不卡| 中文字幕日韩精品一区| 国产一二精品视频| 欧美一区二区性放荡片| 一区二区三区中文在线观看| 国产电影一区在线| 久久尤物电影视频在线观看| 蜜臀久久99精品久久久久宅男| 欧美性受xxxx黑人xyx| 成人免费小视频| yourporn久久国产精品| 久久嫩草精品久久久精品| 日韩av中文在线观看| 欧美性videosxxxxx| 亚洲人成网站影音先锋播放| 成人免费av网站| 中文字幕第一区| 成人动漫一区二区| 日本一区二区免费在线观看视频 | 久久精品一区二区| 韩日av一区二区| 久久尤物电影视频在线观看| 麻豆91在线观看| 日韩欧美在线1卡| 精品亚洲成a人| 久久这里都是精品| 国产成人综合在线播放| 国产日本欧洲亚洲|