-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGrid.cpp
77 lines (71 loc) · 1.35 KB
/
Grid.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "Grid.h"
Grid::Grid()
{
m_nWidth=16;
m_nLength=16;
m_nColor[0]=0;
m_nColor[1]=0;
m_nColor[2]=0;
m_nCenter[0]=0;
m_nCenter[1]=0;
}
Grid::Grid(int nLength, int nWidth)
{
m_nLength=nLength;
m_nWidth=nWidth;
m_nColor[0]=0;
m_nColor[1]=0;
m_nColor[2]=0;
m_nCenter[0]=0;
m_nCenter[1]=0;
}
void Grid::setColor(float nRed, float nGreen, float nBlue)
{
m_nColor[0]=nRed;
m_nColor[1]=nGreen;
m_nColor[2]=nBlue;
}
void Grid::setSize(int nLength, int nWidth)
{
m_nLength=nLength;
m_nWidth=nWidth;
}
void Grid::setCenter(float nX, float nY)
{
m_nCenter[0]=nX;
m_nCenter[1]=nY;
}
void Grid::draw()
{
float nU = (float)m_nWidth/2.0f;
float nV = (float)m_nLength/2.0f;
glLineWidth(2.0);
glVertexAttrib3f(2,0.0,0.0,0.0);
glVertexAttrib3f(3,0.0,0.0,0.0);
glVertexAttrib3f(4,0.0,0.0,0.0);
//glVertexAttrib3f(5,m_nColor[0],m_nColor[1],m_nColor[2]);
glColor3f(1.0,1.0,1.0);
for (int x=0;x<=m_nWidth;x++)
{
float a = m_nCenter[0]-nU+(float)x;
for (float i=-nV; i<nV-0.1; i+=0.1f)
{
glBegin(GL_LINES);
glVertex3f(a,0,m_nCenter[1]+i);
glVertex3f(a,0,m_nCenter[1]+i+0.1);
glEnd();
}
}
for (int y=0;y<=m_nLength;y++)
{
for (float i=-nU; i<nU-0.1; i+=0.1f)
{
float b = m_nCenter[1]-nV+(float)y;
glBegin(GL_LINES);
glVertex3f(m_nCenter[0]+i,0,b);
glVertex3f(m_nCenter[0]+i+0.1,0,b);
glEnd();
}
}
glLineWidth(1.0);
}