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

📄 pvision.h

📁 一个高性能的3D游戏引擎源代码
💻 H
📖 第 1 页 / 共 2 页
字号:
// Panard-Vision
// 3D real time engine
// (C) 1997, Olivier Brunet
// Email: bruneto@efrei.fr
//
//
// Before using this library consult the LICENSE file


#ifndef _PVISION_H_
#define _PVISION_H_

#define __PV_VERSION__ 95         // Under 100 means, huuuu beta ? :)

//#include <unistd.h>             // NULL, SEEK_SET ... on SunOS
#include "config.h"


// Assembly code & HLine routines calling convention is __cdecl
#ifdef  __GNUC__
#define __cdecl     // GCC doesn't know about __cdecl modifier
#endif

#ifndef inline
#define inline
#endif

#ifndef PI
#define PI 3.141592654
#endif

#ifndef max
#define max(a,b) (a>b?a:b)
#endif

#ifndef min
#define min(a,b) (a<b?a:b)
#endif

// Float MiniMax
#ifndef MAXFLOAT
#include <float.h>
#define MINFLOAT -FLT_MAX
#define MAXFLOAT FLT_MAX
#endif

// (not) Useful macros
#define ISFLAGSET(f,ftt) (f&ftt)
#define ADDFLAG(f,ftt) (f|=ftt)
#define REMOVEFLAG(f,ftt) (f&=~ftt)

// Nothing interesting here
extern char *PVISION_DATE;
extern char *PVISION_TIME;
extern char *PVISION_VERSION;

//------------------------------------------ Panard Vision working modes
// PV_Mode, PV_SetMode()

#define PVM_PALETIZED8      1
#define PVM_RGB16           2
#define PVM_RGB             4
#define PVM_SBUFFER         8
#define PVM_MIPMAPPING      16

/***************************************************************************
********************************* STRUCTS & FLAGS **************************
****************************************************************************/
//------------------------------------------ Basics

typedef struct _Quat
{
    float w,x,y,z;
} Quat;

typedef int PVFLAGS;                      // 32 bits

typedef char PVD8;
typedef unsigned char UPVD8;

typedef short PVD16;
typedef unsigned short UPVD16;

typedef int PVD32;
typedef unsigned int UPVD32;

// Matrices
typedef float Mat3x3[3][3];
typedef float Mat4x3[4][3];             // La 4eme ligne est le produit des 2 colonnes
                                        // Pour faire les rotations en 6 muls
typedef struct _Point
{
    float xf,yf,zf,bf;
} Point;

typedef struct _RGB
{
   UPVD8 r,g,b;
} RGB;

typedef struct _RGBF
{
   float r,g,b;
} RGBF;

//------------------------------------------ Camera

typedef struct _Camera
{
    char *Name;
    float fieldofview;
    unsigned Height,Width;
    float roll,pitch,yaw;
    float xscreenscale,yscreenscale,fscale;
    Point pos;
    Point target;
    Mat3x3 Matrix;                // [0][x]=vright [1][x]=vup [2][x]=vpn
} PVCam;

//------------------------------------------ Light

typedef enum _PVLightType {PVL_DIRECTIONAL,PVL_PARALLEL,PVL_INFINITEPOINT,PVL_POINT,PVL_SPOT,PVL_USER_LIGHT} PVLightType;

#define LIGHT_NORMAL 0
#define LIGHT_FORGET 1                  // Switch off the light

typedef struct _TLight
{
    char *Name;
    PVLightType Type;
    PVFLAGS Flags;
    RGBF Color;
    float Intensity;
    float Range;
    float Attenuation0,Attenuation1,Attenuation2;
    float FallOff,Theta,Phi;
    float cosTh,cosPh;
    Point Position;
    Point Direction;
    Point Target;
    struct _TLight *Next;
    void *UserData;
} PVLight;

//--------------------------------------------- Material
// Material Flags
// Shading
#define NOTHING         0
#define FLAT            1
#define GOURAUD         2
#define PHONG           4
#define BUMP            8
#define U_PHONG         128
#define U_BUMP          256
#define SHADE_MASK      (1+2+4+8+128+256)

// rendering
#define MAPPING                     16
#define PERSPECTIVE_MAPPING         32
#define AMBIANT_MAPPING             64
#define RENDER_MASK              (16+32+64)

#define AUTOMATIC                   512           // Used with PERSPECTIVE_MAPPING
#define USER_FX                     1024          // Used to create special effects handled by user routines

// Texture Flags
#define TEXTURE_NONE            0
#define TEXTURE_PALETIZED8      1
#define TEXTURE_RGB             2
#define TEXTURE_MIPMAP          4

// added after materials compilation
#define TEXTURE_RGBDIRECT       8
#define TEXTUREQUANTIZED        64
#define TEXTURE_PROCESSED       256

typedef struct _Texture
{
    unsigned Width,Height;
    unsigned ShiftHeight,ShiftWidth;
    UPVD8 *Texture;
} PVTexture;

typedef struct _BumpInfo
{
    PVD8 nx,ny;
}PVBumpInfo;

typedef struct _BumpMap
{
    unsigned Width,Height;
    PVBumpInfo *Map;
} PVBumpMap;

typedef struct _Mat
{
    char *Name;
    PVFLAGS Type;

    unsigned char NbrMipMaps;
    PVFLAGS TextureFlags;
    RGB *Pal;
    PVTexture *Tex;

    PVTexture AuxiliaryTexture;

    PVBumpMap BumpMap;

    UPVD8  StartingColorIndex,EndingColorIndex;           // for pure colors

    RGBF Diffuse,Specular,Emissive;
    unsigned SpecularPower;

    UPVD8 *PaletteTranscodeTable;
    UPVD16 *RGB16TranscodeTable;

    RGBF Color;

    PVD32 UserData;                                       // Used to handle special FX by users routines

    struct _Mat *Next;
} PVMaterial;

//------------------------------------------ Mesh

#define MESH_FORGET          1          // Hide mesh

// Flags used to indicate wrapped mapping on faces
#define U_WRAP          (1<<30)
#define V_WRAP          (1<<31)

typedef struct _PVVertex3D
{
    float xf,yf,zf,bf;
    Point Normal;
    int Flags;
} PVVertex;

typedef struct _PVMapInfo
{
    float u,v;
    float AmbiantU,AmbiantV;
    float InvertZ;
} PVMapInfo;

typedef struct _PVScreenPoint
{
    float xf,yf;
} PVScreenPoint;

typedef struct _ShadingInfo
{
    unsigned Shade;
    RGBF Color;
} PVShadeInfo;

typedef struct _Box
{
    unsigned int NbrFaces;
    Point p0,t0;
    unsigned *FaceIndex;
    struct _Box *Next;
} PVBox;

typedef struct _PVFace
{
    char *Material;
    PVMaterial *MaterialInfo;
    void (PVAPI * Filler)(struct _PVFace *f);
    PVFLAGS Flags;
    unsigned int V[3];
    int ZAvg;
    float DistanceToCam;
    struct _PVMesh *Father;
    Point Normal;
} PVFace;

typedef struct _PVClippedFace
{
    unsigned int a,b;                      // Contient les points originaux
} PVClippedFace;

typedef struct _PVMesh
{
        char *Name;
        PVFLAGS Flags;
        unsigned int NbrFaces,NbrVertexes,NbrVisibles,NbrBoxes;
        Point Pivot;

        char *VertexVisible;
        unsigned nbrclipf,nbrclipv;          // Nombre de faces clipp俿
        PVClippedFace *ClippedOrg;           // pt originaux

        Point OldPos,OldPosv,Pos;
        Mat3x3 OldMatrix,OldMatrixv,Matrix;
        float ScaleX,ScaleY,ScaleZ;

        PVVertex *Vertex;
        PVFace *Face;

        PVMapInfo *Mapping;

⌨️ 快捷键说明

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