void DrawFig HDC hdc Vector vec POINT int red grn blu Vector intens_v

 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
void DrawFig(HDC hdc, Vector vec[])
{
POINT P[3];
int red,grn,blu;
Vector intens_v(int_x,int_y,int_z),max,mid,min,max1,min1,v1,v2,a,b,n,T;
double k=0.5,K=1,Int,d;
for (int i = 0; i < NS; i++)
{
if(!visible[i]) continue;
a=(v[side[i][0]-1]-v[side[i][1]-1]);
b=(v[side[i][2]-1]-v[side[i][1]-1]);
n=a^b;
n=Normalize(n);
T=((v[side[i][0]-1]+v[side[i][1]-1])/2+v[side[i][2]-1])/2;
T=T-intens_v;
d=pow(T.x*T.x+T.y*T.y+T.z*T.z,0.5);
Int=(n&Normalize(intens_v))*intens*k*1000/(d+K);
if(Int<2.0) Int=2.0;
red=R*Int/3; grn=G*Int/3; blu=B*Int/3;
if(red>255) red=255; if(grn>255) grn=255; if(blu>255) blu=255;
HPEN hPen=CreatePen(PS_SOLID,3, RGB(red,grn,blu));
SelectObject(hdc, hPen);
if(vec[side[i][0]-1].y>vec[side[i][1]-1].y&&vec[side[i][0]-1].y>vec[side[i][2]-1].y)
{
max=vec[side[i][0]-1];
if(vec[side[i][1]-1].y>vec[side[i][2]-1].y)
{
mid=vec[side[i][1]-1];
min=vec[side[i][2]-1];
}
else
{
mid=vec[side[i][2]-1];
min=vec[side[i][1]-1];
}
}
else
{
if(vec[side[i][1]-1].y>vec[side[i][2]-1].y)
{
max=vec[side[i][1]-1];
if(vec[side[i][0]-1].y>vec[side[i][2]-1].y)
{
mid=vec[side[i][0]-1];
min=vec[side[i][2]-1];
}
else
{
mid=vec[side[i][2]-1];
min=vec[side[i][0]-1];
}
}
else
{
max=vec[side[i][2]-1];
if(vec[side[i][0]-1].y>vec[side[i][1]-1].y)
{
mid=vec[side[i][0]-1];
min=vec[side[i][1]-1];
}
else
{
mid=vec[side[i][1]-1];
min=vec[side[i][0]-1];
}
}
}
max1=max; min1=mid;
for(double i=max.y;i>=min.y;i-=0.5)
{
if(i<=mid.y)
{
max1=mid; min1=min;
}
if(max1.y!=min1.y)
{
v1=(1-(max1.y-i)/(max1.y-min1.y))*max1+(max1.y-i)/(max1.y-min1.y)*min1;
v2=(1-(max.y-i)/(max.y-min.y))*max+(max.y-i)/(max.y-min.y)*min;
MoveToEx(hdc,v1.x,v1.y,NULL);
LineTo(hdc,v2.x,v2.y);
}
else
{
MoveToEx(hdc,max1.x,max1.y,NULL);
LineTo(hdc,min1.x,min1.y);
}
}
DeleteObject(hPen);
}
}