Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Hoop.cpp
Go to the documentation of this file.
1 /* Project Starshatter 4.5
2  Destroyer Studios LLC
3  Copyright © 1997-2005. All Rights Reserved.
4 
5  SUBSYSTEM: Stars.exe
6  FILE: Hoop.cpp
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  ILS Hoop (HUD display) class
13 */
14 
15 #include "MemDebug.h"
16 #include "Hoop.h"
17 
18 #include "Game.h"
19 #include "Bitmap.h"
20 #include "DataLoader.h"
21 #include "Window.h"
22 
23 static Color ils_color;
24 
25 // +--------------------------------------------------------------------+
26 
28 : width(360), height(180), mtl(0)
29 {
30  foreground = 1;
31  radius = (float) width;
32 
34 
35  loader->SetDataPath("HUD/");
37  loader->SetDataPath(0);
38 
39  CreatePolys();
40 }
41 
43 { }
44 
45 // +--------------------------------------------------------------------+
46 
48 {
49  ils_color = c;
50 }
51 
52 // +--------------------------------------------------------------------+
53 
54 void
56 {
57  Material* mtl = new(__FILE__,__LINE__) Material;
58 
61 
62  int w = width /2;
63  int h = height/2;
64 
65  model = new(__FILE__,__LINE__) Model;
66  own_model = 1;
67 
68  Surface* surface = new(__FILE__,__LINE__) Surface;
69 
70  surface->SetName("hoop");
71  surface->CreateVerts(4);
72  surface->CreatePolys(2);
73 
74  VertexSet* vset = surface->GetVertexSet();
75  Poly* polys = surface->GetPolys();
76 
77  ZeroMemory(polys, sizeof(Poly) * 2);
78 
79  for (int i = 0; i < 4; i++) {
80  int x = w;
81  int y = h;
82  float u = 0;
83  float v = 0;
84 
85  if (i == 0 || i == 3)
86  x = -x;
87  else
88  u = 1;
89 
90  if (i < 2)
91  y = -y;
92  else
93  v = 1;
94 
95  vset->loc[i] = Vec3(x, y, 0);
96  vset->nrm[i] = Vec3(0, 0, 0);
97 
98  vset->tu[i] = u;
99  vset->tv[i] = v;
100  }
101 
102  for (int i = 0; i < 2; i++) {
103  Poly& poly = polys[i];
104 
105  poly.nverts = 4;
106  poly.vertex_set = vset;
107  poly.material = mtl;
108 
109  poly.verts[0] = i ? 3 : 0;
110  poly.verts[1] = i ? 2 : 1;
111  poly.verts[2] = i ? 1 : 2;
112  poly.verts[3] = i ? 0 : 3;
113 
114  poly.plane = Plane(vset->loc[poly.verts[0]],
115  vset->loc[poly.verts[2]],
116  vset->loc[poly.verts[1]]);
117 
118  surface->AddIndices(6);
119  }
120 
121  // then assign them to cohesive segments:
122  Segment* segment = new(__FILE__,__LINE__) Segment;
123  segment->npolys = 2;
124  segment->polys = &polys[0];
125  segment->material = segment->polys->material;
126 
127  surface->GetSegments().append(segment);
128 
129  model->AddSurface(surface);
130 
131 
132  SetLuminous(true);
133 }
134 
135 // +--------------------------------------------------------------------+
136 
137 void
139 {
140  if (mtl)
141  mtl->Ke = ils_color;
142 
143  if (model && luminous) {
144  ListIter<Surface> s_iter = model->GetSurfaces();
145  while (++s_iter) {
146  Surface* surface = s_iter.value();
147  VertexSet* vset = surface->GetVertexSet();
148 
149  for (int i = 0; i < vset->nverts; i++) {
150  vset->diffuse[i] = ils_color.Value();
151  }
152  }
153 
155  }
156 }