-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphics.cpp
135 lines (111 loc) · 3.76 KB
/
graphics.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//
// graphics.cpp
// CG_Assignment
//
// Created by Shikhar on 26/11/16.
// Copyright © 2016 Shikhar . All rights reserved.
//
#include "graphics.h"
void func(double *a,double *b,int count){
FILE *fp = fopen("file.off","w");
double x[10000];
double y[10000];
double z[10000];
for(int i=0;i<count;i++){
x[i] = a[i];
y[i] = b[i];
z[i]= 0;
}
struct face f[1000];
struct edge e[1000];
double x1[count],y1[count],z1[count],x2[count],y2[count],z2[count];
int c_v = count;
int c_e = 0;
int c_f = 0;
for(int i=0;i<count;i++){
x1[i]=x[i];
y1[i]=y[i];
z1[i]=z[i];
}
for(int i=0;i<360;i+=10){
for(int j=0;j<count;j++){
x2[j] = x1[j]*cos(pi*10/180) + z1[j]*sin(pi*10/180);
y2[j] = y1[j];
z2[j] = -x1[j]*sin(pi*10/180) + z1[j]*cos(pi*10/180);
}
for(int j=0;j<count-1;j++){
//e[c_e].next=e[c_v+1];
//e[c_e].prev=e[c_v+3];
/*e[c_e].x1 = &x[c_v-count+j];
e[c_e].y1 = &y[c_v-count+j];
e[c_e].z1 = &z[c_v-count+j];
e[c_e].x2 = &x[c_v-count+j+1];
e[c_e].y2 = &y[c_v-count+j+1];
e[c_e].z2 = &z[c_v-count+j+1];
c_e+=1;
//e[c_e].next=e[c_v+1];
//e[c_e].prev=e[c_v-1];
e[c_e].x1 = &x[c_v-count+j+1];
e[c_e].y1 = &y[c_v-count+j+1];
e[c_e].z1 = &z[c_v-count+j+1];
e[c_e].x2 = &x[c_v-count+1];
e[c_e].y2 = &y[c_v-count+1];
e[c_e].z2 = &z[c_v-count+1];
c_e+=1;
//e[c_e].next=e[c_v+1];
//e[c_e].prev=e[c_v-1];
e[c_e].x1 = &x[c_v-count+1];
e[c_e].y1 = &y[c_v-count+1];
e[c_e].z1 = &z[c_v-count+1];
e[c_e].x2 = &x[c_v-count];
e[c_e].y2 = &y[c_v-count];
e[c_e].z2 = &z[c_v-count];
c_e+=1;
//e[c_e].next=e[c_v-3];
//e[c_e].prev=e[c_v-1];
e[c_e].x1 = &x[c_v-count];
e[c_e].y1 = &y[c_v-count];
e[c_e].z1 = &z[c_v-count];
e[c_e].x2 = &x[c_v-count+j];
e[c_e].y2 = &y[c_v-count+j];
e[c_e].z2 = &z[c_v-count+j];
c_e+=1;*/
f[c_f].points[0] = c_v-count+j;
f[c_f].x1 = &x[c_v-count+j];
f[c_f].y1 = &y[c_v-count+j];
f[c_f].z1 = &z[c_v-count+j];
f[c_f].points[1] = c_v-count+j+1;
f[c_f].x2 = &x[c_v-count+j+1];
f[c_f].y2 = &y[c_v-count+j+1];
f[c_f].z2 = &z[c_v-count+j+1];
f[c_f].points[2] = c_v+j+1;
f[c_f].x3 = &x[c_v+j+1];
f[c_f].y3 = &y[c_v+j+1];
f[c_f].z3 = &z[c_v+j+1];
f[c_f].points[3] = c_v+j;
f[c_f].x4 = &x[c_v+j];
f[c_f].y4 = &y[c_v+j];
f[c_f].z4 = &z[c_v+j];
c_f+=1;
}
for(int j=0;j<count;j++){
x[c_v]=x2[j];
y[c_v]=y2[j];
z[c_v]=z2[j];
x1[j]=x2[j];
y1[j]=y2[j];
z1[j]=z2[j];
c_v+=1;
}
}
fprintf(fp,"OFF\n");
fprintf(fp,"%d %d %d\n",c_v,c_f,c_e);
for(int i=0;i<c_v;i++){
fprintf(fp,"%lf %lf %lf\n",x[i],y[i],z[i]);
}
for(int i=0;i<c_f;i++){
fprintf(fp,"4 %d %d %d %d\n",f[i].points[3],f[i].points[2],f[i].points[1],f[i].points[0]);
}
printf("File Closed");
fclose(fp);
}