-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrid.c
68 lines (61 loc) · 1.27 KB
/
grid.c
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
#include "grid.h"
#include <math.h>
#include <GL/glut.h>
#include <GL/glu.h>
#include <GL/gl.h>
int grid_representation[10][10];
/* Representation of grid */
void init_grid(void){
for(int i = 0; i < 10; i++){
for(int j = 0; j < 10; j++){
grid_representation[i][j] = 0;
}
}
}
/* Grid function */
void draw_grid(void){
glEnable(GL_COLOR_MATERIAL);
glNormal3f(1, 1, 0);
glColor3f(1, 1, 1);
for(int i = -5; i <= 5; i++){
glBegin(GL_LINES);
glVertex3f(i, 0, 5);
glVertex3f(i, 0, -5);
glEnd();
}
for(int i = -5; i <= 5; i++){
glBegin(GL_LINES);
glVertex3f(-5, 0, i);
glVertex3f(5, 0, i);
glEnd();
}
glDisable(GL_COLOR_MATERIAL);
}
/* Coord helper */
void draw_cords(){
glEnable(GL_COLOR_MATERIAL);
glColor3f(1,0,0);
glBegin(GL_LINE_STRIP);
glVertex3f(0,0,0);
glVertex3f(10,0,0);
glEnd();
glColor3f(0,1,0);
glBegin(GL_LINE_STRIP);
glVertex3f(0,0,0);
glVertex3f(0,10,0);
glEnd();
glColor3f(0,0,1);
glBegin(GL_LINE_STRIP);
glVertex3f(0,0,0);
glVertex3f(0,0,10);
glEnd();
glDisable(GL_COLOR_MATERIAL);
}
/* Function that updates matrix of the grid */
void add_to_matrix(float x, float y){
int indx = x;
int indy = fabs(y);
if(grid_representation[indy][indx] != 1){
grid_representation[indy][indx] = 1;
}
}