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

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

?? demo8_6.cpp

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

// 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

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;


// matrices
typedef struct MATRIX1X2_TYP
        {
        float M[2]; // data storage
        } MATRIX1X2, *MATRIX1X2_PTR;
// note that 1x2 has the same memory layout as a VERTEX2DF, hence we
// can use the matrix function written for a MATRIX1X2 to multiply a 
// VERTEX2DF by casting

typedef struct MATRIX3X2_TYP
        {
        float M[3][2]; // data storage
        } MATRIX3X2, *MATRIX3X2_PTR;


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

int Draw_Text_GDI(char *text, int x,int y,int color, LPDIRECTDRAWSURFACE7 lpdds);

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

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

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

int Rotate_Polygon2D_Mat(POLYGON2D_PTR poly, int theta);

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

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

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


// 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;   // dd4 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 ship; // the ship

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


inline int Mat_Init_3X2(MATRIX3X2_PTR ma, 
                        float m00, float m01,
                        float m10, float m11,
                        float m20, float m21)
{
// this function fills a 3x2 matrix with the sent data in row major form
ma->M[0][0] = m00; ma->M[0][1] = m01; 
ma->M[1][0] = m10; ma->M[1][1] = m11; 
ma->M[2][0] = m20; ma->M[2][1] = m21; 

// return success
return(1);

} // end Mat_Init_3X2

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

int Mat_Mul1X2_3X2(MATRIX1X2_PTR ma, 
                   MATRIX3X2_PTR mb,
                   MATRIX1X2_PTR mprod)
{
// this function multiplies a 1x2 matrix against a 
// 3x2 matrix - ma*mb and stores the result
// using a dummy element for the 3rd element of the 1x2 
// to make the matrix multiply valid i.e. 1x3 X 3x2

    for (int col=0; col<2; col++)
        {
        // compute dot product from row of ma 
        // and column of mb

        float sum = 0; // used to hold result

        for (int index=0; index<2; index++)
             {
             // add in next product pair
             sum+=(ma->M[index]*mb->M[index][col]);
             } // end for index

        // add in last element * 1 
        sum+= mb->M[index][col];

        // insert resulting col element
        mprod->M[col] = sum;

        } // end for col

return(1);

} // end Mat_Mul_1X2_3X2

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

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

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

// the following 3 functions are the standard transforms (no matrices)

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

// test for negative rotation angle
if (theta < 0)
   theta+=360;

// 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

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

int Scale_Polygon2D(POLYGON2D_PTR poly, float sx, float sy)
{
// this function scalesthe local coordinates of the polygon

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

// loop and scale each point
for (int curr_vert = 0; curr_vert < poly->num_verts; curr_vert++)
    {
    // scale and store result back
    poly->vlist[curr_vert].x *= sx;
    poly->vlist[curr_vert].y *= sy;

    } // end for curr_vert

// return success
return(1);

} // end Scale_Polygon2D

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

// these are the matrix versions, note they are more inefficient for
// single transforms, but their power comes into play when you concatenate
// multiple transformations, not to mention that all transforms are accomplished
// with the same code, just the matrix differs

int Translate_Polygon2D_Mat(POLYGON2D_PTR poly, int dx, int dy)
{
// this function translates the center of a polygon by using a matrix multiply
// on the the center point, this is incredibly inefficient, but for educational purposes
// if we had an object that wasn't in local coordinates then it would make more sense to
// use a matrix, but since the origin of the object is at x0,y0 then 2 lines of code can
// translate, but lets do it the hard way just to see :)

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

MATRIX3X2 mt; // used to hold translation transform matrix

// initialize the matrix with translation values dx dy
Mat_Init_3X2(&mt,1,0, 0,1, dx, dy); 

// create a 1x2 matrix to do the transform
MATRIX1X2 p0 = {poly->x0, poly->y0};
MATRIX1X2 p1 = {0,0}; // this will hold result

// now translate via a matrix multiply
Mat_Mul1X2_3X2(&p0, &mt, &p1);

// now copy the result back into polygon
poly->x0 = p1.M[0];
poly->y0 = p1.M[1];

// return success
return(1);

} // end Translate_Polygon2D_Mat

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

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

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

// test for negative rotation angle
if (theta < 0)
   theta+=360;

MATRIX3X2 mr; // used to hold rotation transform matrix

// initialize the matrix with translation values dx dy
Mat_Init_3X2(&mr,cos_look[theta],sin_look[theta], 
                 -sin_look[theta],cos_look[theta], 
                  0, 0); 

// loop and rotate each point, very crude, no lookup!!!
for (int curr_vert = 0; curr_vert < poly->num_verts; curr_vert++)
    {
    // create a 1x2 matrix to do the transform
    MATRIX1X2 p0 = {poly->vlist[curr_vert].x, poly->vlist[curr_vert].y};
    MATRIX1X2 p1 = {0,0}; // this will hold result

    // now rotate via a matrix multiply
    Mat_Mul1X2_3X2(&p0, &mr, &p1);

    // now copy the result back into vertex
    poly->vlist[curr_vert].x = p1.M[0];
    poly->vlist[curr_vert].y = p1.M[1];

    } // end for curr_vert

// return success
return(1);

} // end Rotate_Polygon2D_Mat

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

int Scale_Polygon2D_Mat(POLYGON2D_PTR poly, float sx, float sy)
{
// this function scalesthe local coordinates of the polygon

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


MATRIX3X2 ms; // used to hold scaling transform matrix

// initialize the matrix with translation values dx dy
Mat_Init_3X2(&ms,sx,0, 
                 0,sy, 
                 0, 0); 


// loop and scale each point
for (int curr_vert = 0; curr_vert < poly->num_verts; curr_vert++)
    {
    // scale and store result back
    
    // create a 1x2 matrix to do the transform
    MATRIX1X2 p0 = {poly->vlist[curr_vert].x, poly->vlist[curr_vert].y};
    MATRIX1X2 p1 = {0,0}; // this will hold result

    // now scale via a matrix multiply
    Mat_Mul1X2_3X2(&p0, &ms, &p1);

    // now copy the result back into vertex
    poly->vlist[curr_vert].x = p1.M[0];

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产亚洲人成网站| 欧美色综合网站| 国产女人18毛片水真多成人如厕| 国产在线不卡一区| 久久久精品免费免费| 99热精品一区二区| 亚洲在线视频免费观看| 中文幕一区二区三区久久蜜桃| 国内外成人在线| 国产精品国产三级国产普通话三级 | 亚洲免费在线视频一区 二区| 色悠悠久久综合| 日韩国产在线观看一区| 精品国产凹凸成av人网站| 国产suv精品一区二区三区 | 一区二区三区中文字幕精品精品| 91年精品国产| 日本中文字幕不卡| 亚洲国产岛国毛片在线| 在线日韩av片| 久久精品噜噜噜成人88aⅴ| 欧美国产一区二区在线观看 | 欧美色倩网站大全免费| 日韩一区精品视频| 国产欧美日韩卡一| 精品视频在线免费观看| 国产一区二区在线看| 亚洲精品久久久久久国产精华液| 欧美一级艳片视频免费观看| 国产成人综合自拍| 亚洲成a天堂v人片| 亚洲国产精品激情在线观看| 欧美亚洲尤物久久| 国产乱人伦偷精品视频免下载 | 高清在线观看日韩| 亚洲成人动漫一区| 中文字幕不卡在线| 日韩免费性生活视频播放| 99久久久精品| 精品无人码麻豆乱码1区2区 | 欧美在线一二三四区| 国产一区二区三区久久久| 亚洲一区二区在线视频| 久久一二三国产| 欧美精品黑人性xxxx| 北条麻妃一区二区三区| 久久成人久久鬼色| 亚洲成人激情综合网| 亚洲手机成人高清视频| 国产三级精品三级在线专区| 欧美一三区三区四区免费在线看| 91网址在线看| 成人免费毛片高清视频| 久久99精品久久久久久国产越南| 亚洲国产综合视频在线观看| 中文成人综合网| 久久综合色综合88| 欧美一区二区三区在线| 欧美色图免费看| 色综合久久99| 91一区二区三区在线观看| 国产精品一区二区久久不卡| 日韩精品电影一区亚洲| 亚洲自拍偷拍欧美| 亚洲精品高清在线| 亚洲人妖av一区二区| 欧美韩日一区二区三区| 国产亚洲人成网站| 久久九九国产精品| 久久网这里都是精品| 日韩欧美色电影| 日韩精品一区二区三区蜜臀| 91精品国产综合久久小美女| 欧美日韩国产综合一区二区| 91啪亚洲精品| 色94色欧美sute亚洲线路一ni| 9色porny自拍视频一区二区| 波多野结衣在线一区| 国产91精品一区二区麻豆亚洲| 国产精品一区二区三区网站| 国产高清久久久| 成人一级视频在线观看| 成人精品一区二区三区四区| 波多野结衣亚洲| 色综合久久久久久久久久久| 色综合激情五月| 欧美午夜电影网| 欧美日本国产视频| 日韩欧美在线一区二区三区| 日韩精品一区二区三区视频| 久久综合九色综合欧美就去吻| 久久久久国色av免费看影院| 久久精品免费在线观看| 国产视频一区二区在线观看| 欧美国产成人精品| 亚洲欧美区自拍先锋| 午夜视频在线观看一区二区 | 国产成人亚洲综合a∨婷婷| 国产 欧美在线| 色综合久久综合| 欧美一区二区三区人| 久久婷婷国产综合国色天香| 亚洲欧美自拍偷拍色图| 午夜影院久久久| 美腿丝袜亚洲综合| 国产福利不卡视频| 色哟哟国产精品| 日韩亚洲欧美中文三级| 国产亚洲精品aa午夜观看| 尤物视频一区二区| 久久精品国产99| av不卡免费电影| 欧美一级精品大片| 日韩电影在线观看电影| 激情小说欧美图片| 色综合中文综合网| 91精品办公室少妇高潮对白| 欧美一区二区精品在线| 国产精品乱人伦中文| 亚洲综合久久久久| 国产乱人伦精品一区二区在线观看| 91麻豆swag| 日韩精品一区二区三区四区| 亚洲人成影院在线观看| 狂野欧美性猛交blacked| 91麻豆精东视频| 精品国产区一区| 亚洲一区视频在线观看视频| 国产成人亚洲综合色影视| 欧美电影在线免费观看| 中文字幕高清一区| 久久电影网电视剧免费观看| 色哦色哦哦色天天综合| 久久一区二区视频| 日本欧洲一区二区| 在线日韩国产精品| 中文字幕亚洲一区二区va在线| 免费欧美日韩国产三级电影| 在线观看www91| 中文字幕第一区二区| 韩国视频一区二区| 91精品国产高清一区二区三区 | 中文字幕在线视频一区| 老司机免费视频一区二区三区| 一本一本大道香蕉久在线精品| 久久久国产一区二区三区四区小说 | 7777精品伊人久久久大香线蕉的 | 久久精品国产亚洲高清剧情介绍| 欧美在线一二三四区| 最新日韩av在线| 国产成人三级在线观看| 欧美精品一区二区三区蜜桃视频| 午夜欧美视频在线观看| 91视频www| 中文字幕一区不卡| 99九九99九九九视频精品| 久久久99精品久久| 国产精品一区二区在线观看不卡| 日韩欧美一区二区三区在线| 青青草原综合久久大伊人精品优势 | 日韩和的一区二区| 91麻豆精品国产自产在线观看一区 | 亚洲欧洲日韩女同| 成人免费视频app| 国产精品久久久久aaaa| 99综合电影在线视频| 国产精品天美传媒| 成人av在线资源| 国产精品久久国产精麻豆99网站| caoporn国产精品| 中文字幕一区二区三区乱码在线| 成人免费视频免费观看| 中文av一区二区| 日韩欧美一级片| 日韩 欧美一区二区三区| 欧美一级在线免费| 精久久久久久久久久久| 国产日韩欧美高清| 成人h版在线观看| 亚洲乱码国产乱码精品精98午夜| 日本韩国欧美在线| 亚洲mv在线观看| 欧美一区二区黄| 国产乱码精品一区二区三| 国产精品久久久久久久久久免费看 | 成人亚洲一区二区一| 国产精品对白交换视频| 日本韩国一区二区三区| 日本欧美在线看| 国产欧美综合色| 色又黄又爽网站www久久| 水野朝阳av一区二区三区| 精品成人一区二区三区| 丰满亚洲少妇av| 亚洲线精品一区二区三区| 欧美一区二区三区在线观看| 国产91清纯白嫩初高中在线观看| 亚洲美女视频在线观看| 欧美一级二级三级蜜桃| 丰满白嫩尤物一区二区|