home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dream 55
/
Amiga_Dream_55.iso
/
RISCOS
/
MAGAZINE
/
NEWS
/
3DENGI.ZIP
/
3DEngine
/
!PlotLib
/
src
/
h
/
PlotLib
next >
Wrap
Text File
|
1998-08-11
|
4KB
|
133 lines
/*
* Plotlib.h: Main plotting classes
*/
#ifndef PLOTLIB_H
#define PLOTLIB_H
#define MAX_VERTICES_ON_FACE (4)
/* Some defines */
typedef int SCALAR;
typedef SCALAR t_vec;
typedef t_vec t_vec2[2];
typedef t_vec t_vec3[3];
typedef struct s_Texture
{
char *identifier;
int width;
int height;
int basecol;
t_vec2 map;
void *data;
} t_Texture;
typedef struct s_Vertex
{
t_vec3 position; /* 3D position */
t_vec2 scr_position; /* 2D position */
t_vec3 normal; /* Vertex normal */
} t_Vertex;
typedef struct s_Face
{
t_Vertex *p_verts[MAX_VERTICES_ON_FACE]; /* Optimised pointers used by renderers */
t_vec2 map[MAX_VERTICES_ON_FACE]; /* Texture coordinates */
SCALAR intensity[MAX_VERTICES_ON_FACE]; /* RGB intensity for each vertex */
t_vec3 normal; /* Face normal */
int verts[MAX_VERTICES_ON_FACE]; /* Index into vertex table */
t_Texture *texture; /* Texture pointer */
} t_Face;
typedef struct s_Model
{
int nvertices; /* Number of vertices */
int nfaces; /* Number of faces */
t_Vertex *vertices; /* Array of vertices */
t_Face *faces; /* Array of faces */
SCALAR alpha; /* Models alpha blend value */
char light; /* Lighting calculated for this model flag */
} t_Model;
typedef struct s_Matrix
{
t_vec3 v[4];
} t_Matrix;
/* Some vector maths operations */
#define Vector_Sub(dest,src1,src2) ( (dest)[0] = (src1)[0] - (src2)[0]);\
( (dest)[1] = (src1)[1] - (src2)[1]);\
( (dest)[2] = (src1)[2] - (src2)[2]);
#define Vector_Add(dest,src1,src2) ( (dest)[0] = (src1)[0] + (src2)[0]);\
( (dest)[1] = (src1)[1] + (src2)[1]);\
( (dest)[2] = (src1)[2] + (src2)[2]);
#define Vector_Copy(dest,src) (dest)[0] = (src)[0];\
(dest)[1] = (src)[1];\
(dest)[2] = (src)[2];
/* Conversion from int&float to scalar and back again */
#define ScalarToInt(x) (int) ((x)>>16)
#define IntToScalar(x) (SCALAR) ((x)<<16)
#define ScalarToFloat(x) (float) ((double)(x)/(double)(1<<16))
#define FloatToScalar(x) (SCALAR) ((float)(x)*(double)(1<<16))
/* Scalar adding, multiply and divide */
#define ScalarAdd(x,y) (SCALAR) ((x)+(y))
#define Scalar3Add(x,y,z) (SCALAR) ((x)+(y)+(z))
#define ScalarSub(x,y) (SCALAR) ((x)-(y))
#define Scalar3Sub(x,y,z) (SCALAR) ((x)-(y)-(z))
#define ScalarMul(x,y) (SCALAR) (((x)>>8)*((y)>>8))
#define Scalar3Mul(x,y,z) (SCALAR) (((x)>>8)*((y)>>8)*((z)>>8))
#define ScalarDiv(x,y) (SCALAR) (((x)<<8)/((y)>>8))
#define ScalarDiv2(x,y) (SCALAR) (((x)<<8)/(y))
#define ScalarSqrt(x) (MP_SCALAR) ( FloatToScalar(sqrt(ScalarToFloat(x))) )
#define ScalarMulAcc(x,y) (SCALAR) ( FloatToScalar(ScalarToFloat(x) * ScalarToFloat(y)) )
typedef void (*t_Plotter)(t_Face *);
typedef void (*t_PlotterAlpha)(t_Face *,int);
typedef struct {
t_Plotter Draw;
t_Plotter DrawTextured;
t_Plotter DrawTexturedTrans;
t_Plotter DrawGouraud;
t_Plotter DrawTexturedGouraud;
t_Plotter DrawTexturedGouraudTrans;
t_PlotterAlpha DrawAlpha;
t_PlotterAlpha DrawTexturedAlpha;
t_PlotterAlpha DrawTexturedAlphaTrans;
t_PlotterAlpha DrawAlphaGouraud;
t_PlotterAlpha DrawTexturedAlphaGouraud;
t_PlotterAlpha DrawTexturedAlphaGouraudTrans;
t_Plotter DrawUC;
t_Plotter DrawTexturedUC;
t_Plotter DrawTexturedTransUC;
t_Plotter DrawGouraudUC;
t_Plotter DrawTexturedGouraudUC;
t_Plotter DrawTexturedGouraudTransUC;
t_PlotterAlpha DrawAlphaUC;
t_PlotterAlpha DrawTexturedAlphaUC;
t_PlotterAlpha DrawTexturedAlphaTransUC;
t_PlotterAlpha DrawAlphaGouraudUC;
t_PlotterAlpha DrawTexturedAlphaGouraudUC;
t_PlotterAlpha DrawTexturedAlphaGouraudTransUC;
} PlotClass;
extern PlotClass Plotters_8bit;
extern PlotClass Plotters_16bit;
extern PlotClass Plotters_24bit;
void PlotLib_SetFrameBufferSize(int width, int height);
void PlotLib_SetFrameBufferStart(char *memory);
#endif