source: golgotha/src/i4/poly/poly.hh @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 14 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 2.0 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#ifndef I4_POLY_HH
10#define I4_POLY_HH
11
12
13#include "error/error.hh"
14#include "math/point.hh"
15
16struct i4_vertex_class
17{
18  w32 outcode;
19  i4_3d_point_class v;                         // unprojected x,y,z
20  i4_float s, t;                               // texture coordinates 0..1
21  i4_float px, py;                             // projected x,y
22  i4_float w;                                  // 1/v.z
23  i4_float r,g,b;                              // lighting intensity 0..1
24  i4_float a;                                  // alpha 0..1
25
26  // w is 1/z, cx and cy are center of window
27  void project(i4_float w, i4_float center_x, i4_float center_y)
28  {
29    px=v.x*w + center_x;
30    py=v.y*w + center_y;
31  }
32};
33
34
35class i4_polygon_class
36{
37public:
38  enum { V_BUF_SIZE=8 };
39
40  int t_verts;                                   // number of poly vertices
41  i4_vertex_class vert[V_BUF_SIZE];              // vertex buffer
42
43  i4_polygon_class() { t_verts=0; }
44
45  i4_vertex_class *add_vert(i4_3d_point_class v,
46                            i4_float s, i4_float t,
47                            i4_float r, i4_float g, i4_float b)
48  {
49    I4_ASSERT(t_verts<V_BUF_SIZE, "vert buffer full");
50
51    vert[t_verts].v=v;
52    vert[t_verts].s=s;
53    vert[t_verts].t=t;
54    vert[t_verts].r=r;
55    vert[t_verts].g=g;
56    vert[t_verts].b=b;
57    t_verts++;
58    return vert+t_verts-1;
59  }
60 
61  i4_vertex_class *add_vert(i4_vertex_class *src_vert)
62  {
63    I4_ASSERT(t_verts<V_BUF_SIZE, "vert buffer full");
64
65    vert[t_verts] = *src_vert;
66    t_verts++;
67    return vert+t_verts-1;   
68  }
69};
70
71
72#endif
Note: See TracBrowser for help on using the repository browser.