vertex.c++
3.31 KB
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
#include "vertex.h"
const vertex& vertex::operator=(const vertex& v) {
if(this==&v)
return *this;
original=v.original;
transformed=v.transformed;
trans_stage=v.trans_stage;
return *this;
}
vertex operator*(const double& a, const vertex& v) {
return v * a;
}
vertex vertex::operator*(const double& a) const {
vertex v=*this;
v.original=v.original*a;
v.transformed=v.transformed*a;
return v;
}
double vertex::operator% (const vertex& v) const {
return transformed%v.transformed;
}
vertex vertex::operator| (const vertex& v) const {
vertex w=*this;
w.original=w.original|v.original;
w.transformed=w.transformed|v.transformed;
return w;
}
vertex vertex::operator+ (const vertex& v) const {
vertex w=*this;
w.original=w.original+v.original;
w.transformed=w.transformed+v.transformed;
return w;
}
vertex vertex::operator- (const vertex& v) const {
vertex w=*this;
w.original=w.original-v.original;
w.transformed=w.transformed-v.transformed;
return w;
}
vertex vertex::norm(void) const {
vertex w;
w.original=original*(1/original.v_betr());
w.transformed=transformed*(1/transformed.v_betr());
return w;
}
double vertex::betr(void) const {
return transformed.v_betr();
}
void vertex::reset(void) {
if(trans_stage!=0) {
trans_stage=0;
transformed=original;
}
}
void vertex::transform(const Mmn<double>& t_mat, int p) {
if(trans_stage < p) {
transformed=t_mat % transformed;
trans_stage=p;
}
}
void vertex::project_2d(double lcx, double sw, double sh,
double ph_ar, double sy, int p) {
if(trans_stage < p) {
transformed[X]=transformed[X]/transformed[Z] *
(lcx * sw) + 0.5*sw;
transformed[Y]=-transformed[Y]/transformed[Z] *
(lcx * ph_ar * sh) + 0.5*sy*sh;
transformed[Z]=1/transformed[Z]; // 1/Z ist linear im projezierten
// Polygon kann ich also über die
// Polygonkanten interpolieren
// brauche ich fuer z-Buffer,
// Texturemapping und evtl. noch mehr.
trans_stage=p;
}
}
inline double vertex::unproject_X(double tx, double tz,
double lcx, double sw) {
return (tx - 0.5*sw) / (lcx * sw) / tz;
}
inline double vertex::unproject_Y(double ty, double tz,
double lcx, double sh,
double ph_ar, double sy) {
return (ty - 0.5*sy*sh) / (lcx * ph_ar * sh) / tz;
}
inline double vertex::unproject_Z(double tz) {
return 1/tz;
}
inline double vertex::unproject_U(double tu, double tz,
double lcx, double sw) {
return (tu - 0.5*sw) / (lcx * sw) / tz;
}
inline double vertex::unproject_V(double tv, double tz,
double lcx, double sh,
double ph_ar, double sy) {
return (tv - 0.5*sy*sh) / (lcx * ph_ar * sh) / tz;
}
void vertex_list::reset(void) {
for(unsigned i=0; i<count; i++)
content[i].reset();
if(variable) {
delete [] variable;
variable=NULL;
var_count=0;
}
}