1 #include "screengrid.h"
3 ScreenGrid::ScreenGrid()
11 ScreenGrid::~ScreenGrid()
18 \fn ScreenGrid::Init()
20 void ScreenGrid::Init()
22 extern Options options
;
23 grid_step
= options
.getFloatValue( Options::GRID_STEP
);
27 grid_size
= GlScreenSize
.val
.x
/ 2 + 2 * (grid_step
* bold_step
);
31 void ScreenGrid::RegenerateGrid()
36 grid_list
= glGenLists(1);
37 glNewList(grid_list
,GL_COMPILE
);
39 GLint bold_step_counter
= 0;
41 for ( GLfloat x
= - grid_size
; x
<= grid_size
; x
+= grid_step
) {
43 if(bold_step_counter
) {
45 glColor3f(0.0f
, 0.10f
, 0.0f
);
48 glVertex2f( x
, - grid_size
);
49 glVertex2f( x
, grid_size
);
53 glVertex2f( - grid_size
, x
);
54 glVertex2f( grid_size
, x
);
60 if (bold_step_counter
>= bold_step
) bold_step_counter
= 0;
64 for ( GLfloat x
= - grid_size
; x
<= grid_size
; x
+= grid_step
* bold_step
) {
66 glColor3f(0.0,0.3,0.0);
69 glVertex2f( x
, - grid_size
);
70 glVertex2f( x
, grid_size
);
74 glVertex2f( - grid_size
, x
);
75 glVertex2f( grid_size
, x
);
87 \fn ScreenGrid::display_labels()
89 void ScreenGrid::display_labels()
92 GLfloat gl_width
= GlScreenSize
.val
.x
/ 2;
93 GLfloat gl_height
= - GlScreenSize
.val
.y
/ 2;
97 // Show labels - horisontal
98 glColor3f(1.0,0.6,0.0);
103 glTranslatef(grid_center_x
, -gl_height
* otstup
, -gl_depth
);
105 for ( GLfloat x
= - grid_size
; x
<= grid_size
; x
+= grid_step
* bold_step
) {
107 glBegin( GL_TRIANGLES
);
108 glVertex2f( x
, 0.0f
);
109 glVertex2f( x
+ labels_size
, labels_size
);
110 glVertex2f( x
- labels_size
, labels_size
);
117 // Show labels - vertical
121 glTranslatef( - gl_width
* otstup
, grid_center_y
, -gl_depth
);
123 for ( GLfloat y
= - grid_size
; y
<= grid_size
; y
+= grid_step
* bold_step
) {
125 glBegin( GL_TRIANGLES
);
126 glVertex2f( 0.0f
, 0.0f
+ y
);
127 glVertex2f( -labels_size
, labels_size
+ y
);
128 glVertex2f( -labels_size
, -labels_size
+y
);
138 void ScreenGrid::display( Vector2D view_coord
)
141 if ( regenerate
) { regenerate
= false; RegenerateGrid(); }
143 grid_center_x
= - fmodf ( (float)view_coord
.val
.x
, fabs(grid_step
* bold_step
) );
144 grid_center_y
= - fmodf ( (float)view_coord
.val
.y
, fabs(grid_step
* bold_step
) );
148 glTranslatef(grid_center_x
, grid_center_y
, 0.0f
);
150 // Отключим на время рисования сетки тест глубины и задних плоскостей
151 glDisable(GL_DEPTH_TEST
);
152 glDisable(GL_CULL_FACE
);
154 glCallList(grid_list
); // сетка
155 display_labels(); // сверху рисуем метки
157 // Вернём тест глубины и задних плоскостей
158 glEnable(GL_DEPTH_TEST
);
159 glEnable(GL_CULL_FACE
);