-
Notifications
You must be signed in to change notification settings - Fork 0
/
Obsolete.txt
129 lines (109 loc) · 4.29 KB
/
Obsolete.txt
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
// ---------------------------------------------------------------------------display_pixel
// raw_color is the pixel color computed by the ray tracer
// its RGB floating point components can be arbitrarily large
// mapped_color has all components in the range [0, 1], but still floating point
// display color has integer components for computer display
// the Mac's components are in the range [0, 65535]
// a PC's components will probably be in the range [0, 255]
// the system-dependent code is in the function convert_to_display_color
// the function SetCPixel is a Mac OS function
//
//void
//World::display_pixel(const int row, const int column, const RGBAPixel& raw_color) const {
// RGBAPixel mapped_color;
//
// if (vp.show_out_of_gamut)
// mapped_color = clamp_to_color(raw_color);
// else
// mapped_color = max_to_one(raw_color);
//
// if (vp.gamma != 1.0)
// mapped_color = mapped_color.powc(vp.inv_gamma);
//
// //have to start from max y coordinate to convert to screen coordinates
// int x = column;
// int y = vp.vres - row - 1;
//
// paintArea->setPixel(x, y, (int)(mapped_color.r * 255),
// (int)(mapped_color.g * 255),
// (int)(mapped_color.b * 255));
//}
//
//------------------------------------------------------------------ clamp
//This function is not needed, in RGBAPixel, the rgb values are bounded by u8int;
//RGBAPixel
//World::max_to_one(const RGBAPixel& c) const {
// float max_value = max(c.red, max(c.green, c.blue));
//
// if (max_value > 255)
// return (c / max_value);
// else
// return (c);
//}
//
// ------------------------------------------------------------------ clamp_to_color
// Set color to red if any component is greater than one
//
//RGBAPixel
//World::clamp_to_color(const RGBAPixel& raw_color) const {
// RGBAPixel c(raw_color);
//
// if (raw_color.red > 1.0 || raw_color.green > 1.0 || raw_color.blue > 1.0) {
// c.red = 1.0; c.green = 0.0; c.blue = 0.0;
// }
//
// return (c);
//}
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
src = http://www.scratchapixel.com/code.php?id=9&origin=/lessons/3d-basic-rendering/ray-tracing-rendering-a-triangle
// bool rayTriangleIntersect(
// const Vec3f &orig, const Vec3f &dir,
// const Vec3f &v0, const Vec3f &v1, const Vec3f &v2,
// float &t, float &u, float &v)
// {
// #ifdef MOLLER_TRUMBORE
// Vec3f v0v1 = v1 - v0;
// Vec3f v0v2 = v2 - v0;
// Vec3f pvec = dir.crossProduct(v0v2);
// float det = v0v1.dotProduct(pvec);
// #ifdef CULLING
// // if the determinant is negative the triangle is backfacing
// // if the determinant is close to 0, the ray misses the triangle
// if (det < kEpsilon) return false;
// #else
// // ray and triangle are parallel if det is close to 0
// if (fabs(det) < kEpsilon) return false;
// #endif
// float invDet = 1 / det;
// Vec3f tvec = orig - v0;
// u = tvec.dotProduct(pvec) * invDet;
// if (u < 0 || u > 1) return false;
// Vec3f qvec = tvec.crossProduct(v0v1);
// v = dir.dotProduct(qvec) * invDet;
// if (v < 0 || u + v > 1) return false;
// t = v0v2.dotProduct(qvec) * invDet;
// return true;
// #else
// // compute plane's normal
// Vec3f v0v1 = v1 - v0;
// Vec3f v0v2 = v2 - v0;
// // no need to normalize
// Vec3f N = v0v1.crossProduct(v0v2); // N
// float denom = N.dotProduct(N);
// // Step 1: finding P
// // check if ray and plane are parallel ?
// float NdotRayDirection = N.dotProduct(dir);
// if (fabs(NdotRayDirection) < kEpsilon) // almost 0
// return false; // they are parallel so they don't intersect !
// // compute d parameter using equation 2
// float d = N.dotProduct(v0);
// // compute t (equation 3)
// t = (N.dotProduct(orig) + d) / NdotRayDirection;
// // check if the triangle is in behind the ray
// if (t < 0) return false; // the triangle is behind
// // compute the intersection point using equation 1
// Vec3f P = orig + t * dir;
// // Step 2: inside-outside test
//
// #endif
// }