-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot.cpp
98 lines (78 loc) · 2.26 KB
/
plot.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <stdio.h>
#include <stdlib.h>
#include "GL/freeglut.h"
#include "GL/gl.h"
struct particles_struct
{
int N;
int *ID;
double *x;
double *y;
int *color;
double *extra;
} particles;
void read_in_positions()
{
FILE *inputfile;
int intholder;
float floatholder;
int i;
inputfile = fopen("results.mvi","rb");
//Number of partciles
fread(&intholder,sizeof(int),1,inputfile);
printf("N = %d\n",intholder);
particles.N = intholder;
particles.ID = (int *)malloc(particles.N*sizeof(int));
particles.x = (double *)malloc(particles.N*sizeof(double));
particles.y = (double *)malloc(particles.N*sizeof(double));
particles.color = (int *)malloc(particles.N*sizeof(int));
particles.extra = (double *)malloc(particles.N*sizeof(double));
//Frame number in file
fread(&intholder,sizeof(int),1,inputfile);
printf("frame = %d\n",intholder);
for(i=0;i<particles.N;i++)
{
fread(&intholder,sizeof(int),1,inputfile);
particles.color[i] = intholder;
fread(&intholder,sizeof(int),1,inputfile);
particles.ID[i] = intholder;
fread(&floatholder,sizeof(float),1,inputfile);
particles.x[i] = (double)floatholder;
fread(&floatholder,sizeof(float),1,inputfile);
particles.y[i] = (double)floatholder;
fread(&floatholder,sizeof(float),1,inputfile);
particles.extra[i] = (double)floatholder;
}
fclose(inputfile);
}
void draw()
{
int i;
double x0,y0,xf,yf;
glClearColor(1.0, 1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
for(i=0;i<particles.N;i++)
{
glPushMatrix();
glTranslatef(particles.x[i]/10.0-1.0,particles.y[i]/10.0-1.0,0);
if (particles.color[i]==2) glColor3f(1.0, 0.0, 0.0);
if (particles.color[i]==3) glColor3f(0.0, 0.0, 1.0);
glutSolidSphere(0.02,30,30);
glPopMatrix();
}
glutSwapBuffers();
}
int main(int argc, char **argv)
{
printf("Plotter program\n");
read_in_positions();
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(1200, 1200);
glutInitWindowPosition(100, 100);
glutCreateWindow("Plot for BD Simulations");
glutDisplayFunc(draw);
glutMainLoop();
return 0;
}