实现double CIlluminationViewGouraud int Pt3 int Vertices43 double Normals43 int lightPos3 double Ip double Kd
{ // 计算视点到顶点的向量 double viewVector[3]; viewVector[0] = Pt[0] - lightPos[0]; viewVector[1] = Pt[1] - lightPos[1]; viewVector[2] = Pt[2] - lightPos[2];
// 计算每个顶点的光强度
double intensities[4];
for (int i = 0; i < 4; i++) {
// 计算光线和法向量的点积
double dotProduct = 0.0;
for (int j = 0; j < 3; j++) {
dotProduct += Normals[i][j] * viewVector[j];
}
// 根据光线和法向量的夹角计算光强度
if (dotProduct > 0) {
intensities[i] = Ip * Kd * dotProduct;
} else {
intensities[i] = 0.0;
}
}
// 计算每个像素的颜色
double colors[3];
for (int i = 0; i < 3; i++) {
colors[i] = 0.0;
for (int j = 0; j < 4; j++) {
colors[i] += intensities[j] * Vertices[j][i];
}
colors[i] = max(0.0, min(255.0, colors[i]));
}
// 返回像素的颜色
return (colors[0] << 16) | (colors[1] << 8) | colors[2];
}
原文地址: https://www.cveoy.top/t/topic/CJt 著作权归作者所有。请勿转载和采集!