-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cone.h
executable file
·115 lines (91 loc) · 2.84 KB
/
Cone.h
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
#ifndef CONE_H
#define CONE_H
#include "Utility.h"
#include "Geometry.h"
#include "Shape.h"
class Cone : public Shape {
public:
Cone() {};
~Cone() {};
void draw() {
};
void drawNormal() {
};
double Intersect(Point eyePointP, Vector rayV, Matrix transformMatrix) {
return 0;
};
Vector findIsectNormal(Point eyePoint, Vector ray, double dist) {
Vector v;
return v;
};
protected:
PVList getPoints(int segX, int segY) {
if ( int(pvs.size()) != segX * (segY + 1) + 1){
// free memory
pvs.clear();
PVList().swap(pvs);
double r = DEFAULT_LENGTH;
double angle_x = 2 * PI / segX;
PVList line;
for (int i=0; i<segY+1; i++){
Point p(
r * (i/ float(segY)),
DEFAULT_LENGTH - (i/float(segY)),
0
);
Vector v(1.0,.5f,0.0);
v.normalize();
PV pv = {p, v};
line.push_back(pv);
}
// rotate the line around y
for (int i=0; i<segX; i++){
Matrix mtx = rotY_mat(i*angle_x);
PVList sideLine = rotatePVs(mtx, line);
pvs.insert(pvs.end(), sideLine.begin(), sideLine.end());
}
PV bottom = {Point(0,-DEFAULT_LENGTH,0), Vector(0, -1, 0)};
pvs.push_back(bottom);
}
return pvs;
};
Surface getSurface(int segX, int segY) {
if ( int(surface.size()) != segX * ((segY-1)*2 + 2) ){
surface.clear();
Surface().swap(surface);
for (int i=0; i<segX; i++){
for (int j=0; j<segY+1; j++){
int ri = (i+1)%segX; // right line index
if (j==0){ // tip
surface.push_back(toTriangle(
toIndex(i, j, segY + 1),
toIndex(i, j + 1, segY + 1),
toIndex(ri, j + 1, segY + 1)
));
}
else if (j == segY){ //bottom
surface.push_back(toTriangle(
toIndex(i, j, segY + 1),
toIndex(ri, j, segY + 1),
int( pvs.size()-1 )
));
}
else {
surface.push_back(toTriangle(
toIndex(i, j, segY + 1),
toIndex(i, j + 1, segY + 1),
toIndex(ri, j + 1, segY + 1)
));
surface.push_back(toTriangle(
toIndex(i, j, segY + 1),
toIndex(ri, j + 1, segY + 1),
toIndex(ri, j, segY + 1)
));
}
}
}
}
return surface;
}
};
#endif