Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Grid.cpp
Go to the documentation of this file.
1 /* Project Starshatter 4.5
2  Destroyer Studios LLC
3  Copyright © 1997-2004. All Rights Reserved.
4 
5  SUBSYSTEM: Stars.exe
6  FILE: Grid.cpp
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  Tactical Grid class
13 */
14 
15 #include "MemDebug.h"
16 #include "Grid.h"
17 
18 #include "Game.h"
19 #include "Video.h"
20 #include "Window.h"
21 
22 static const Color DARK_LINE( 8, 8, 8);
23 static const Color LITE_LINE(16, 16, 16);
24 
25 // +--------------------------------------------------------------------+
26 
27 Grid::Grid(int asize, int astep)
28 : size(asize), step(astep), drawn(0)
29 {
30  radius = (float) (size * 1.414);
31 }
32 
34 { }
35 
36 // +--------------------------------------------------------------------+
37 
38 int Grid::CollidesWith(Graphic& o) { return 0; }
39 
40 // +--------------------------------------------------------------------+
41 
42 void Grid::Render(Video* video, DWORD flags)
43 {
44  if (!video || hidden) return;
45 
46  int c = 0;
47  Color line;
48 
49  for (int i = 0; i <= size; i += step) {
50  Point p1( i, 0, -size); p1 += Location();
51  Point p2( i, 0, size); p2 += Location();
52  Point p3(-i, 0, -size); p3 += Location();
53  Point p4(-i, 0, size); p4 += Location();
54 
55  if (c) line = DARK_LINE;
56  else line = LITE_LINE;
57 
58  DrawLine(video, p1,p2,line);
59  DrawLine(video, p3,p4,line);
60 
61  c++;
62  if (c > 3) c = 0;
63  }
64 
65  c = 0;
66 
67  for (int i = 0; i <= size; i += step) {
68  Point p1(-size, 0, i); p1 += Location();
69  Point p2( size, 0, i); p2 += Location();
70  Point p3(-size, 0, -i); p3 += Location();
71  Point p4( size, 0, -i); p4 += Location();
72 
73  if (c) line = DARK_LINE;
74  else line = LITE_LINE;
75 
76  DrawLine(video, p1,p2,line);
77  DrawLine(video, p3,p4,line);
78 
79  c++;
80  if (c > 3) c = 0;
81  }
82 }
83 
84 void Grid::DrawLine(Video* video, Point& p1, Point& p2, Color grid_color)
85 {
86  Vec3 v[2];
87 
88  v[0] = p1;
89  v[1] = p2;
90 
91  video->DrawLines(1, v, grid_color, Video::BLEND_ADDITIVE);
92 }