home *** CD-ROM | disk | FTP | other *** search
/ Dream 55 / Amiga_Dream_55.iso / RISCOS / MAGAZINE / NEWS / 3DENGI.ZIP / 3DEngine / !PlotLib / src / h / PlotLib next >
Text File  |  1998-08-11  |  4KB  |  133 lines

  1. /*
  2.  *  Plotlib.h: Main plotting classes
  3.  */
  4.  
  5. #ifndef PLOTLIB_H
  6. #define PLOTLIB_H
  7.  
  8. #define MAX_VERTICES_ON_FACE    (4)
  9.  
  10. /* Some defines */
  11.  
  12. typedef int SCALAR;
  13.  
  14. typedef SCALAR t_vec;
  15. typedef t_vec t_vec2[2];
  16. typedef t_vec t_vec3[3];
  17.  
  18. typedef struct s_Texture
  19. {
  20.     char *identifier;
  21.     int width;
  22.     int height;
  23.     int basecol;
  24.     t_vec2 map;
  25.     void *data;
  26. } t_Texture;
  27.  
  28. typedef struct s_Vertex
  29. {
  30.     t_vec3 position;    /* 3D position */
  31.     t_vec2 scr_position;    /* 2D position */
  32.     t_vec3 normal;        /* Vertex normal */
  33. } t_Vertex;
  34.  
  35. typedef struct s_Face
  36. {
  37.     t_Vertex *p_verts[MAX_VERTICES_ON_FACE];    /* Optimised pointers used by renderers */
  38.     t_vec2 map[MAX_VERTICES_ON_FACE];        /* Texture coordinates */
  39.     SCALAR intensity[MAX_VERTICES_ON_FACE];        /* RGB intensity for each vertex */
  40.     t_vec3 normal;                    /* Face normal */
  41.     int verts[MAX_VERTICES_ON_FACE];        /* Index into vertex table */
  42.     t_Texture *texture;                /* Texture pointer */
  43. } t_Face;
  44.  
  45. typedef struct s_Model
  46. {
  47.     int nvertices;        /* Number of vertices */
  48.     int nfaces;        /* Number of faces */
  49.     t_Vertex *vertices;    /* Array of vertices */
  50.     t_Face *faces;        /* Array of faces */
  51.     SCALAR alpha;        /* Models alpha blend value */
  52.     char light;        /* Lighting calculated for this model flag */
  53. } t_Model;
  54.  
  55. typedef struct s_Matrix
  56. {
  57.     t_vec3 v[4];
  58. } t_Matrix;
  59.  
  60.  
  61. /* Some vector maths operations */
  62. #define Vector_Sub(dest,src1,src2)    ( (dest)[0] = (src1)[0] - (src2)[0]);\
  63.                     ( (dest)[1] = (src1)[1] - (src2)[1]);\
  64.                     ( (dest)[2] = (src1)[2] - (src2)[2]);
  65.  
  66. #define Vector_Add(dest,src1,src2)    ( (dest)[0] = (src1)[0] + (src2)[0]);\
  67.                     ( (dest)[1] = (src1)[1] + (src2)[1]);\
  68.                     ( (dest)[2] = (src1)[2] + (src2)[2]);
  69.  
  70. #define Vector_Copy(dest,src)    (dest)[0] = (src)[0];\
  71.                 (dest)[1] = (src)[1];\
  72.                 (dest)[2] = (src)[2];
  73.  
  74. /* Conversion from int&float to scalar and back again */
  75. #define ScalarToInt(x)  (int) ((x)>>16)
  76. #define IntToScalar(x)  (SCALAR) ((x)<<16)
  77.  
  78. #define ScalarToFloat(x)  (float) ((double)(x)/(double)(1<<16))
  79. #define FloatToScalar(x)  (SCALAR) ((float)(x)*(double)(1<<16))
  80.  
  81. /* Scalar adding, multiply and divide */
  82.  
  83. #define ScalarAdd(x,y) (SCALAR) ((x)+(y))
  84. #define Scalar3Add(x,y,z) (SCALAR) ((x)+(y)+(z))
  85. #define ScalarSub(x,y) (SCALAR) ((x)-(y))
  86. #define Scalar3Sub(x,y,z) (SCALAR) ((x)-(y)-(z))
  87. #define ScalarMul(x,y) (SCALAR) (((x)>>8)*((y)>>8))
  88. #define Scalar3Mul(x,y,z) (SCALAR) (((x)>>8)*((y)>>8)*((z)>>8))
  89. #define ScalarDiv(x,y) (SCALAR) (((x)<<8)/((y)>>8))
  90. #define ScalarDiv2(x,y) (SCALAR) (((x)<<8)/(y))
  91. #define ScalarSqrt(x) (MP_SCALAR) ( FloatToScalar(sqrt(ScalarToFloat(x))) )
  92. #define ScalarMulAcc(x,y) (SCALAR) ( FloatToScalar(ScalarToFloat(x) * ScalarToFloat(y)) )
  93.  
  94. typedef void (*t_Plotter)(t_Face *);
  95. typedef void (*t_PlotterAlpha)(t_Face *,int);
  96.  
  97. typedef struct {
  98.   t_Plotter      Draw;
  99.   t_Plotter      DrawTextured;
  100.   t_Plotter      DrawTexturedTrans;
  101.   t_Plotter      DrawGouraud;
  102.   t_Plotter      DrawTexturedGouraud;
  103.   t_Plotter      DrawTexturedGouraudTrans;
  104.   t_PlotterAlpha DrawAlpha;
  105.   t_PlotterAlpha DrawTexturedAlpha;
  106.   t_PlotterAlpha DrawTexturedAlphaTrans;
  107.   t_PlotterAlpha DrawAlphaGouraud;
  108.   t_PlotterAlpha DrawTexturedAlphaGouraud;
  109.   t_PlotterAlpha DrawTexturedAlphaGouraudTrans;
  110.   t_Plotter      DrawUC;
  111.   t_Plotter      DrawTexturedUC;
  112.   t_Plotter      DrawTexturedTransUC;
  113.   t_Plotter      DrawGouraudUC;
  114.   t_Plotter      DrawTexturedGouraudUC;
  115.   t_Plotter      DrawTexturedGouraudTransUC;
  116.   t_PlotterAlpha DrawAlphaUC;
  117.   t_PlotterAlpha DrawTexturedAlphaUC;
  118.   t_PlotterAlpha DrawTexturedAlphaTransUC;
  119.   t_PlotterAlpha DrawAlphaGouraudUC;
  120.   t_PlotterAlpha DrawTexturedAlphaGouraudUC;
  121.   t_PlotterAlpha DrawTexturedAlphaGouraudTransUC;
  122. } PlotClass;
  123.  
  124. extern PlotClass Plotters_8bit;
  125. extern PlotClass Plotters_16bit;
  126. extern PlotClass Plotters_24bit;
  127.  
  128. void PlotLib_SetFrameBufferSize(int width, int height);
  129.  
  130. void PlotLib_SetFrameBufferStart(char *memory);
  131.  
  132. #endif
  133.