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

📄 t3dlib6.h

📁 3D游戏编程大师技巧第九章的源代码
💻 H
📖 第 1 页 / 共 2 页
字号:
// T3DLIB6.H - header file for T3DLIB6.H

// watch for multiple inclusions
#ifndef T3DLIB6
#define T3DLIB6

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

#define VERTEX_FLAGS_INVERT_X               0x0001   // inverts the Z-coordinates
#define VERTEX_FLAGS_INVERT_Y               0x0002   // inverts the Z-coordinates
#define VERTEX_FLAGS_INVERT_Z               0x0004   // inverts the Z-coordinates
#define VERTEX_FLAGS_SWAP_YZ                0x0008   // transforms a RHS model to a LHS model
#define VERTEX_FLAGS_SWAP_XZ                0x0010   
#define VERTEX_FLAGS_SWAP_XY                0x0020
#define VERTEX_FLAGS_INVERT_WINDING_ORDER   0x0040   // invert winding order from cw to ccw or ccw to cc


#define VERTEX_FLAGS_TRANSFORM_LOCAL        0x0200   // if file format has local transform then do it!
#define VERTEX_FLAGS_TRANSFORM_LOCAL_WORLD  0x0400  // if file format has local to world then do it!


// defines for materials, follow our polygon attributes as much as possible
#define MATV1_ATTR_2SIDED                 0x0001
#define MATV1_ATTR_TRANSPARENT            0x0002
#define MATV1_ATTR_8BITCOLOR              0x0004
#define MATV1_ATTR_RGB16                  0x0008
#define MATV1_ATTR_RGB24                  0x0010

#define MATV1_ATTR_SHADE_MODE_CONSTANT    0x0020
#define MATV1_ATTR_SHADE_MODE_EMMISIVE    0x0020 // alias
#define MATV1_ATTR_SHADE_MODE_FLAT        0x0040
#define MATV1_ATTR_SHADE_MODE_GOURAUD     0x0080
#define MATV1_ATTR_SHADE_MODE_FASTPHONG   0x0100
#define MATV1_ATTR_SHADE_MODE_TEXTURE     0x0200

// defines for material system
#define MAX_MATERIALS                     256

// states of materials
#define MATV1_STATE_ACTIVE                0x0001
#define MATV1_STATE_INACTIVE              0x0001

// defines for light types
#define LIGHTV1_ATTR_AMBIENT      0x0001    // basic ambient light
#define LIGHTV1_ATTR_INFINITE     0x0002    // infinite light source
#define LIGHTV1_ATTR_DIRECTIONAL  0x0002    // infinite light source (alias)
#define LIGHTV1_ATTR_POINT        0x0004    // point light source
#define LIGHTV1_ATTR_SPOTLIGHT1   0x0008    // spotlight type 1 (simple)
#define LIGHTV1_ATTR_SPOTLIGHT2   0x0010    // spotlight type 2 (complex)

#define LIGHTV1_STATE_ON          1         // light on
#define LIGHTV1_STATE_OFF         0         // light off

#define MAX_LIGHTS                8         // good luck with 1!

// polygon sorting, and painters algorithm defines

// flags for sorting algorithm
#define SORT_POLYLIST_AVGZ  0  // sorts on average of all vertices
#define SORT_POLYLIST_NEARZ 1  // sorts on closest z vertex of each poly
#define SORT_POLYLIST_FARZ  2  // sorts on farthest z vertex of each poly


#define PARSER_DEBUG_OFF // enables/disables conditional compilation 

#define PARSER_STRIP_EMPTY_LINES        1   // strips all blank lines
#define PARSER_LEAVE_EMPTY_LINES        2   // leaves empty lines
#define PARSER_STRIP_WS_ENDS            4   // strips ws space at ends of line
#define PARSER_LEAVE_WS_ENDS            8   // leaves it
#define PARSER_STRIP_COMMENTS           16  // strips comments out
#define PARSER_LEAVE_COMMENTS           32  // leaves comments in

#define PARSER_BUFFER_SIZE              256 // size of parser line buffer
#define PARSER_MAX_COMMENT              16  // maximum size of comment delimeter string

#define PARSER_DEFAULT_COMMENT          "#"  // default comment string for parser

// pattern language
#define PATTERN_TOKEN_FLOAT   'f'
#define PATTERN_TOKEN_INT     'i'
#define PATTERN_TOKEN_STRING  's'
#define PATTERN_TOKEN_LITERAL '\''

// state machine defines for pattern matching
#define PATTERN_STATE_INIT       0

#define PATTERN_STATE_RESTART    1
#define PATTERN_STATE_FLOAT      2
#define PATTERN_STATE_INT        3 
#define PATTERN_STATE_LITERAL    4
#define PATTERN_STATE_STRING     5
#define PATTERN_STATE_NEXT       6

#define PATTERN_STATE_MATCH      7
#define PATTERN_STATE_END        8

#define PATTERN_MAX_ARGS         16
#define PATTERN_BUFFER_SIZE      80

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

// RGB+alpha color
typedef struct RGBAV1_TYP
{
union 
    {
    int rgba;                    // compressed format
    UCHAR rgba_M[4];             // array format
    struct {  UCHAR a,b,g,r;  }; // explict name format
    }; // end union
    
} RGBAV1, *RGBAV1_PTR;


// a first version of a "material"
typedef struct MATV1_TYP
{
int state;           // state of material
int id;              // id of this material, index into material array
char name[64];       // name of material
int  attr;           // attributes, the modes for shading, constant, flat, 
                     // gouraud, fast phong, environment, textured etc.
                     // and other special flags...

RGBAV1 color;            // color of material
float ka, kd, ks, power; // ambient, diffuse, specular, 
                         // coefficients, note they are 
                         // separate and scalars since many 
                         // modelers use this format
                         // along with specular power

RGBAV1 ra, rd, rs;       // the reflectivities/colors pre-
                         // multiplied, to more match our 
                         // definitions, each is basically
                         // computed by multiplying the 
                         // color by the k's, eg:
                         // rd = color*kd etc.

char texture_file[80];   // file location of texture
BITMAP_IMAGE texture;    // actual texture map (if any)

int   iaux1, iaux2;      // auxiliary vars for future expansion
float faux1, faux2;
void *ptr;

} MATV1, *MATV1_PTR;


// first light structure
typedef struct LIGHTV1_TYP
{
int state; // state of light
int id;    // id of light
int attr;  // type of light, and extra qualifiers

RGBAV1 c_ambient;   // ambient light intensity
RGBAV1 c_diffuse;   // diffuse light intensity
RGBAV1 c_specular;  // specular light intensity

POINT4D  pos;       // position of light
VECTOR4D dir;       // direction of light
float kc, kl, kq;   // attenuation factors
float spot_inner;   // inner angle for spot light
float spot_outer;   // outer angle for spot light
float pf;           // power factor/falloff for spot lights

int   iaux1, iaux2; // auxiliary vars for future expansion
float faux1, faux2;
void *ptr;

} LIGHTV1, *LIGHTV1_PTR;


// pcx file header
typedef struct PCX_HEADER_TYP 
{
UCHAR  manufacturer;    // always 0x0A
UCHAR  version;         // version 0x05 for version 3.0 and later
UCHAR  encoding;        // always 1
UCHAR  bits_per_pixel;  // bits per pixel 1,2,4,8
USHORT xmin, ymin;      // coordinates of upper left corner
USHORT xmax, ymax;      // coordinates of lower right corner
USHORT hres;            // horizontal resolution of image in dpi 75/100 typ
USHORT yres;            // vertical resolution of image in dpi 75/100
UCHAR  EGAcolors[48];   // ega palette, not used for 256 color images
UCHAR  reserved;        // reserved for future use, video mode?
UCHAR  color_planes;    // number of color planes 3 for 24-bit imagery
USHORT bytes_per_line;  // bytes per line, always even!
USHORT palette_type;    // 1 for gray scale, 2 for color palette
USHORT scrnw;           // width of screen image taken from
USHORT scrnh;           // height of screen image taken from     
UCHAR  filler[54];      // filler bytes
} PCX_HEADER, *PCX_HEADER_PTR;


// CLASSES /////////////////////////////////////////////////////////////////

// parser class ///////////////////////////////////////////////
class CPARSERV1
{
public:

    // constructor /////////////////////////////////////////////////
    CPARSERV1();

⌨️ 快捷键说明

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