10 this->zbuffer =
new int[this->width * this->height];
24 for (
int i = 0; i<this->width * this->height; i++) {
25 this->zbuffer[i] = -9999999;
29 for (
int brickIndex = 0; brickIndex < bricks->
objects.size(); brickIndex++)
32 COLORREF color = brick->
color;
34 #pragma omp parallel for schedule(dynamic, 1) 35 for (
int faceIndex = 0; faceIndex < brick->
facesCount(); faceIndex++)
53 this->fillFaces(A, B, C, nA, nB, nC, color, light, cam);
58 void Render::line(
int x0,
int y0,
int x1,
int y1)
61 if (abs(x0 - x1) < abs(y0 - y1)) {
74 int derror2 = abs(dy) * 2;
79 for (
int x = x0; x <= x1; x++) {
81 this->pixels[x*this->width + y] = 0x00ffffff;
84 this->pixels[y*this->width + x] = 0x00ffffff;
89 y += (y1 > y0 ? 1 : -1);
97 if (A.
Y == B.
Y && A.
Y == C.
Y)
return;
99 if (A.
Y > B.
Y) { std::swap(A, B); std::swap(normA, normB); }
100 if (A.
Y > C.
Y) { std::swap(A, C); std::swap(normA, normC); }
101 if (B.
Y > C.
Y) { std::swap(B, C); std::swap(normB, normC); }
103 if (
int(A.
Y + .5) ==
int(B.
Y + .5) && B.
X < A.
X) { std::swap(A, B); std::swap(normA, normB); }
105 int x1 = int(A.
X + .5);
106 int x2 = int(B.
X + .5);
107 int x3 = int(C.
X + .5);
108 int y1 = int(A.
Y + .5);
109 int y2 = int(B.
Y + .5);
110 int y3 = int(C.
Y + .5);
111 int z1 = int(A.
Z + .5);
112 int z2 = int(B.
Z + .5);
113 int z3 = int(C.
Z + .5);
115 if ((y1 == y2) && (x1 > x2)) { std::swap(A, B); std::swap(normA, normB); }
121 double dx13 = 0, dx12 = 0, dx23 = 0;
122 double dz13 = 0, dz12 = 0, dz23 = 0;
129 dz13 = (z3 - z1) / (
double)(y3 - y1);
130 dx13 = (x3 - x1) / (
double)(y3 - y1);
131 dn13 = (normC - normA) / (y3 - y1);
135 dz12 = (z2 - z1) / (
double)(y2 - y1);
136 dx12 = (x2 - x1) / (
double)(y2 - y1);
137 dn12 = (normB - normA) / (
double)(y2 - y1);
141 dz23 = (z3 - z2) / (
double)(y3 - y2);
142 dx23 = (x3 - x2) / (
double)(y3 - y2);
143 dn23 = (normC - normB) / (
double)(y3 - y2);
165 std::swap(dn13, dn12);
166 std::swap(dx13, dx12);
167 std::swap(dz13, dz12);
181 std::swap(_dn13, dn23);
182 std::swap(_dx13, dx23);
183 std::swap(_dz13, dz23);
186 for (
int yCoord = y1; yCoord < y3; yCoord++)
193 dz = (wz2 - wz1) / (
double)(wx2 - wx1);
194 dnorm = (wn2 - wn1) / (
double)(wx2 - wx1);
197 for (
int xCoord = wx1; xCoord < wx2; xCoord++)
199 int pix = yCoord * this->width + xCoord;
200 if (pix >= 0 && pix <= this->width * this->height)
202 if (this->zbuffer[pix] < z)
204 double I = this->intencity(xCoord, yCoord, z, normP, light, cam);
205 if (this->zbuffer[pix] < z)
207 this->zbuffer[pix] = z;
208 this->pixels[pix] = RGB(GetBValue(color) * I, GetGValue(color) * I, GetRValue(color) * I);
213 normP = normP + dnorm;
236 double Render::intencity(
double X,
double Y,
double Z,
GVector N,
Vertex light,
Camera cam)
238 GVector D(X - light.
X, Y - light.
Y, Z - light.
Z, 1);
242 double Iconst = 0.20;
252 I = Iconst + Idiff + Iblinn;
void run(Composite *bricks, Camera cam, Vertex light)
Define vertex consisting 3 double coordinates.
Define face consisting 3 links to vetices.
Define normal (object container for GVector)
vector< vector< Normal > > sVNormal
vector< Brick * > objects
static double scalar(GVector first, GVector second)
Render(unsigned long *pixels, int height, int width)