-
Notifications
You must be signed in to change notification settings - Fork 9
/
old_tries
174 lines (154 loc) · 4.8 KB
/
old_tries
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
void draw_and_share_tex(Sint16 const &x1_l,Sint16 const &z1_l,Sint16 const &u1_l,Sint16 const &v1_l,Sint16 const &x1_r,Sint16 const &z1_r,Sint16 const &u1_r,Sint16 const &v1_r,Sint16 const &y1,Sint16 const &x2_l,Sint16 const &z2_l,Sint16 const &u2_l,Sint16 const &v2_l,Sint16 const &x2_r,Sint16 const &z2_r,Sint16 const &u2_r,Sint16 const &v2_r,Sint16 const &y2,Uint16 const &color)
{
int ny = y1+y2>>1;
Sint16 nx_l = x1_l+x2_l>>1;
Sint16 nx_r = x1_r+x2_r>>1;
Sint16 nz_l = z1_l+z2_l>>1;
Sint16 nz_r = z1_r+z2_r>>1;
Sint16 nu_l = u1_l+u2_l>>1;
Sint16 nu_r = u1_r+u2_r>>1;
Sint16 nv_l = v1_l+v2_l>>1;
Sint16 nv_r = v1_r+v2_r>>1;
draw_pixel_tex_ztest_zset(nx_l,ny,nz_l,nu_l,nv_l,color);
draw_pixel_tex_ztest_zset(nx_r,ny,nz_r,nu_r,nv_r,color);
draw_and_share_X_tex(nx_l,nz_l,nu_l,nv_l,nx_r,nz_r,nu_r,nv_r,ny,color);
if (y1 != ny)
{
draw_and_share_tex(x1_l,z1_l,u1_l,v1_l,x1_r,z1_r,u1_r,v1_r,y1,nx_l,nz_l,nu_l,nv_l,nx_r,nz_r,nu_r,nv_r,ny,color);
if (ny+1 != y2)
draw_and_share_tex(nx_l,nz_l,nu_l,nv_l,nx_r,nz_r,nu_r,nv_r,ny,x2_l,z2_l,u2_l,v2_l,x2_r,z2_r,u2_r,v2_r,y2,color);
}
}
void draw_and_share_X_tex(Sint16 const &x1,Sint16 const &z1,Sint16 const &u1,Sint16 const &v1,Sint16 const &x2,Sint16 const &z2,Sint16 const &u2,Sint16 const &v2,Sint16 const &y,Uint16 const &color)
{
Sint16 nx = x1+x2>>1;
Sint16 nz = z1+z2>>1;
Sint16 nu = u1+u2>>1;
Sint16 nv = v1+v2>>1;
draw_pixel_tex_ztest_zset(nx,y,nz,nu,nv,color);
if (x1 != nx)
{
draw_and_share_X_tex(x1,z1,u1,v1,nx,nz,nu,nv,y,color);
if (nx+1 != x2)
draw_and_share_X_tex(nx,nz,nu,nv,x2,z2,u2,v2,y,color);
}
}
/*int div = y2-y1;
if (div!=0)
{
if (div<0)
div = -div;
int mul = y3-y1;
if (mul < 0)
mul = -mul;
Sint16 x4 = x1+(x2-x1)*mul/div;
Sint16 z4 = z1+(z2-z1)*mul/div;
Sint16 u4 = u1+(u2-u1)*mul/div;
Sint16 v4 = v1+(v2-v1)*mul/div;
draw_pixel_tex_ztest_zset(x1,y1,z1,u1,v1,color);
draw_pixel_tex_ztest_zset(x2,y2,z2,u2,v2,color);
draw_pixel_tex_ztest_zset(x3,y3,z3,u3,v3,color);
draw_pixel_tex_ztest_zset(x4,y3,z4,u4,v4,color);
if (x3<x4)
draw_and_share_X_tex(x3,z3,u3,v3,x4,z4,u4,v4,y3,color);
else
draw_and_share_X_tex(x4,z4,u4,v4,x3,z3,u3,v3,y3,color);
if (x4 < x3)
{
draw_and_share_tex(x1,z1,u1,v1,x1,z1,u1,v1,y1,x4,z4,u4,v4,x3,z3,u3,v3,y3,color);
draw_and_share_tex(x4,z4,u4,v4,x3,z3,u3,v3,y3,x2,z2,u2,v2,x2,z2,u2,v2,y2,color);
}
else
{
draw_and_share_tex(x1,z1,u1,v1,x1,z1,u1,v1,y1,x3,z3,u3,v3,x4,z4,u4,v4,y3,color);
draw_and_share_tex(x3,z3,u3,v3,x4,z4,u4,v4,y3,x2,z2,u2,v2,x2,z2,u2,v2,y2,color);
}
}*/
void draw_and_share_X(Sint16 x1,Sint16 z1,Sint16 x2,Sint16 z2,Sint16 y,Uint16 color)
{
if (x1 == x2)
return;
Sint16 nx = x1+x2>>1;
if (nx == x1)
return;
if (nx == x2)
return;
Sint16 nz = z1+z2>>1;
if (nx>=0 && y>=0 && nx<spTargetX && y<spTargetY && (!spZTest || (nz<0 && nz > spZBuffer[nx+y*spTargetX])))
{
spTargetPixel[nx+y*spTargetX] = color;
if (spZSet)
spZBuffer[nx+y*spTargetX] = nz;
}
draw_and_share_X(x1,z1,nx,nz,y,color);
draw_and_share_X(nx,nz,x2,z2,y,color);
}
void draw_and_share(Sint16 x1_l,Sint16 z1_l,Sint16 x1_r,Sint16 z1_r,Sint16 y1,Sint16 x2_l,Sint16 z2_l,Sint16 x2_r,Sint16 z2_r,Sint16 y2,Uint16 color)
{
if (y1 == y2)
return;
int ny = y1+y2>>1;
if (ny == y1)
return;
if (ny == y2)
return;
Sint16 nx_l = x1_l+x2_l>>1;
Sint16 nx_r = x1_r+x2_r>>1;
Sint16 nz_l = z1_l+z2_l>>1;
Sint16 nz_r = z1_r+z2_r>>1;
if (nx_l < nx_r)
draw_and_share_X(nx_l-1,nz_l,nx_r+1,nz_r,ny,color);
else
draw_and_share_X(nx_r-1,nz_r,nx_l+1,nz_l,ny,color);
draw_and_share(x1_l,z1_l,x1_r,z1_r,y1,nx_l,nz_l,nx_r,nz_r,ny,color);
draw_and_share(nx_l,nz_l,nx_r,nz_r,ny,x2_l,z2_l,x2_r,z2_r,y2,color);
}
PREFIX void spTriangle(Sint16 x1, Sint16 y1, Sint16 z1, Sint16 x2, Sint16 y2, Sint16 z2, Sint16 x3, Sint16 y3, Sint16 z3, Uint16 color)
{
if (y1 > y2)
{
Sint16 temp = y1;
y1 = y2;
y2 = temp;
temp = x1;
x1 = x2;
x2 = temp;
}
if (y1 > y3)
{
Sint16 temp = y1;
y1 = y3;
y3 = temp;
temp = x1;
x1 = x3;
x3 = temp;
}
if (y2 < y3)
{
Sint16 temp = y2;
y2 = y3;
y3 = temp;
temp = x2;
x2 = x3;
x3 = temp;
}
SDL_LockSurface(spTarget);
int div = y2-y1;
if (div!=0)
{
if (div<0)
div = -div;
int mul = y3-y1;
if (mul < 0)
mul = -mul;
Sint16 x4 = x1+(x2-x1)*mul/div;
Sint16 z4 = z1+(z2-z1)*mul/div;
if (x3 < x4)
draw_and_share_X(x3-1,z3,x4+1,z4,y3,color);
else
draw_and_share_X(x4-1,z4,x3+1,z3,y3,color);
draw_and_share(x1,z1,x1,z1,y1,x4,z4,x3,z3,y3,color);
draw_and_share(x4,z4,x3,z3,y3,x2,z2,x2,z2,y2,color);
}
SDL_UnlockSurface(spTarget);
}