Debian Codegraph @

renderer/HardwareClipper.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "pserror.h"cxx . . $ `<file>/misc/pserror.h`/
20 #include "3d.h"cxx . . $ `<file>/lib/3d.h`/
21 #include "HardwareInternal.h"cxx . . $ `<file>/renderer/HardwareInternal.h`/
22
23 static int free_point_numcxx . . $ free_point_num. = -1;
24 static g3Pointcxx . . $ g3Point# temp_pointscxx . . $ temp_points.[MAX_POINTS_IN_POLYcxx . . $ `renderer/HardwareInternal.h:24:9`!];
25 static g3Pointcxx . . $ g3Point# *free_pointscxx . . $ free_points.[MAX_POINTS_IN_POLYcxx . . $ `renderer/HardwareInternal.h:24:9`!];
26 vectorcxx . . $ vector# Clip_plane_pointcxx . . $ Clip_plane_point.;
27
28 void InitFreePointscxx . . $ InitFreePoints(49f6e7a06ebc5aa8).(void) {
29 int i;
30
31 for (i = 0; i < MAX_POINTS_IN_POLYcxx . . $ `renderer/HardwareInternal.h:24:9`!; i++) {
32 free_pointscxx . . $ free_points.[i] = &temp_pointscxx . . $ temp_points.[i];
33 }
34 free_point_numcxx . . $ free_point_num. = 0;
35 }
36
37 g3Pointcxx . . $ g3Point# *GetTempPointcxx . . $ GetTempPoint(16f6bc482de7b758).(void) {
38 ASSERTcxx . . $ `misc/pserror.h:246:9`!(free_point_num < MAX_POINTS_IN_POLYcxx . . $ `renderer/HardwareInternal.h:24:9`!);
39
40 g3Pointcxx . . $ g3Point# *p = free_pointscxx . . $ free_points.[free_point_numcxx . . $ free_point_num.++];
41 p->p3_flagscxx . . $ g3Point#p3_flags. = PF_TEMP_POINTcxx . . $ `lib/3d.h:216:9`!;
42 return p;
43 }
44
45 void FreeTempPointcxx . . $ FreeTempPoint(4c7ad40c64d4fb9c).(g3Pointcxx . . $ g3Point# *p) {
46 if (free_point_numcxx . . $ free_point_num. < 1) {
47 mprintfcxx . . $ `ddebug/mono.h:82:9`!(1, "clipper: no temp points to free\n");
48 free_point_numcxx . . $ free_point_num. = 1;
49 Int3cxx . . $ `misc/pserror.h:247:9`!();
50 }
51 ASSERTcxx . . $ `misc/pserror.h:246:9`!(p->p3_flags & PF_TEMP_POINTcxx . . $ `lib/3d.h:216:9`!);
52
53 free_pointscxx . . $ free_points.[--free_point_numcxx . . $ free_point_num.] = p;
54
55 p->p3_flagscxx . . $ g3Point#p3_flags. &= ~PF_TEMP_POINTcxx . . $ `lib/3d.h:216:9`!;
56 }
57
58 // Verify that all the temp points are free, and free them it they are not.
59 #ifdef _DEBUGcxx . . $ `<built-in>:480:9`!
60 void CheckTempPointscxx . . $ CheckTempPoints(49f6e7a06ebc5aa8).(void) {
61 if (free_point_numcxx . . $ free_point_num.) {
62 Int3cxx . . $ `misc/pserror.h:247:9`!();
63 InitFreePointscxx . . $ InitFreePoints(49f6e7a06ebc5aa8).();
64 }
65 }
66 #endif
67
68 // Free up any temp points (created by the clipper) in the given pointlist
69 // Parameters: pointlist - pointer to list of pointers to points, returned by g3_ClipPolygon()
70 // nv - the number of points in pointlist
71 void g3_FreeTempPointscxx . . $ g3_FreeTempPoints(3ae387dc3696f211).(g3Pointcxx . . $ g3Point# **pointlist, int nv) {
72 // Go through list
73 int i;
74 for (i = 0; i < nv; i++) {
75 if (pointlist[i]->p3_flagscxx . . $ g3Point#p3_flags. & PF_TEMP_POINTcxx . . $ `lib/3d.h:216:9`!) {
76 FreeTempPointcxx . . $ FreeTempPoint(4c7ad40c64d4fb9c).(pointlist[i]);
77 }
78 }
79
80 // Make sure all temp points are freed
81 CheckTempPointscxx . . $ CheckTempPoints(49f6e7a06ebc5aa8).();
82 }
83
84 // Clips an edge against the far plane
85 g3Pointcxx . . $ g3Point# *ClipFarEdgecxx . . $ ClipFarEdge(b63d0e562e5b43ea).(g3Pointcxx . . $ g3Point# *on_pnt, g3Pointcxx . . $ g3Point# *off_pnt) {
86 float z_on = on_pnt->p3_zcxx . . $ `lib/3d.h:247:9`!;
87 float z_off = off_pnt->p3_zcxx . . $ `lib/3d.h:247:9`!;
88
89 float k = 1.0f - ((z_off - Far_clip_zcxx . . $ Far_clip_z.) / (z_off - z_on));
90
91 g3Pointcxx . . $ g3Point# *tmp = GetTempPointcxx . . $ GetTempPoint(16f6bc482de7b758).();
92 tmp->p3_zcxx . . $ `lib/3d.h:247:9`! = on_pnt->p3_zcxx . . $ `lib/3d.h:247:9`! + ((off_pnt->p3_zcxx . . $ `lib/3d.h:247:9`! - on_pnt->p3_zcxx . . $ `lib/3d.h:247:9`!) * k);
93 tmp->p3_xcxx . . $ `lib/3d.h:245:9`! = on_pnt->p3_xcxx . . $ `lib/3d.h:245:9`! + ((off_pnt->p3_xcxx . . $ `lib/3d.h:245:9`! - on_pnt->p3_xcxx . . $ `lib/3d.h:245:9`!) * k);
94 tmp->p3_ycxx . . $ `lib/3d.h:246:9`! = on_pnt->p3_ycxx . . $ `lib/3d.h:246:9`! + ((off_pnt->p3_ycxx . . $ `lib/3d.h:246:9`! - on_pnt->p3_ycxx . . $ `lib/3d.h:246:9`!) * k);
95
96 if (on_pnt->p3_flagscxx . . $ g3Point#p3_flags. & PF_UVcxx . . $ `lib/3d.h:217:9`!) {
97 tmp->p3_ucxx . . $ `lib/3d.h:250:9`! = on_pnt->p3_ucxx . . $ `lib/3d.h:250:9`! + ((off_pnt->p3_ucxx . . $ `lib/3d.h:250:9`! - on_pnt->p3_ucxx . . $ `lib/3d.h:250:9`!) * k);
98 tmp->p3_vcxx . . $ `lib/3d.h:251:9`! = on_pnt->p3_vcxx . . $ `lib/3d.h:251:9`! + ((off_pnt->p3_vcxx . . $ `lib/3d.h:251:9`! - on_pnt->p3_vcxx . . $ `lib/3d.h:251:9`!) * k);
99 tmp->p3_flagscxx . . $ g3Point#p3_flags. |= PF_UVcxx . . $ `lib/3d.h:217:9`!;
100 }
101
102 if (on_pnt->p3_flagscxx . . $ g3Point#p3_flags. & PF_UV2cxx . . $ `lib/3d.h:220:9`!) {
103 tmp->p3_u2cxx . . $ `lib/3d.h:257:9`! = on_pnt->p3_u2cxx . . $ `lib/3d.h:257:9`! + ((off_pnt->p3_u2cxx . . $ `lib/3d.h:257:9`! - on_pnt->p3_u2cxx . . $ `lib/3d.h:257:9`!) * k);
104 tmp->p3_v2cxx . . $ `lib/3d.h:258:9`! = on_pnt->p3_v2cxx . . $ `lib/3d.h:258:9`! + ((off_pnt->p3_v2cxx . . $ `lib/3d.h:258:9`! - on_pnt->p3_v2cxx . . $ `lib/3d.h:258:9`!) * k);
105 tmp->p3_flagscxx . . $ g3Point#p3_flags. |= PF_UV2cxx . . $ `lib/3d.h:220:9`!;
106 }
107
108 if (on_pnt->p3_flagscxx . . $ g3Point#p3_flags. & PF_Lcxx . . $ `lib/3d.h:218:9`!) {
109 tmp->p3_lcxx . . $ `lib/3d.h:252:9`! = on_pnt->p3_lcxx . . $ `lib/3d.h:252:9`! + ((off_pnt->p3_lcxx . . $ `lib/3d.h:252:9`! - on_pnt->p3_lcxx . . $ `lib/3d.h:252:9`!) * k);
110 tmp->p3_flagscxx . . $ g3Point#p3_flags. |= PF_Lcxx . . $ `lib/3d.h:218:9`!;
111 }
112
113 if (on_pnt->p3_flagscxx . . $ g3Point#p3_flags. & PF_RGBAcxx . . $ `lib/3d.h:219:9`!) {
114 tmp->p3_rcxx . . $ `lib/3d.h:253:9`! = on_pnt->p3_rcxx . . $ `lib/3d.h:253:9`! + ((off_pnt->p3_rcxx . . $ `lib/3d.h:253:9`! - on_pnt->p3_rcxx . . $ `lib/3d.h:253:9`!) * k);
115 tmp->p3_gcxx . . $ `lib/3d.h:254:9`! = on_pnt->p3_gcxx . . $ `lib/3d.h:254:9`! + ((off_pnt->p3_gcxx . . $ `lib/3d.h:254:9`! - on_pnt->p3_gcxx . . $ `lib/3d.h:254:9`!) * k);
116 tmp->p3_bcxx . . $ `lib/3d.h:255:9`! = on_pnt->p3_bcxx . . $ `lib/3d.h:255:9`! + ((off_pnt->p3_bcxx . . $ `lib/3d.h:255:9`! - on_pnt->p3_bcxx . . $ `lib/3d.h:255:9`!) * k);
117 tmp->p3_acxx . . $ `lib/3d.h:256:9`! = on_pnt->p3_acxx . . $ `lib/3d.h:256:9`! + ((off_pnt->p3_acxx . . $ `lib/3d.h:256:9`! - on_pnt->p3_acxx . . $ `lib/3d.h:256:9`!) * k);
118 tmp->p3_flagscxx . . $ g3Point#p3_flags. |= PF_RGBAcxx . . $ `lib/3d.h:219:9`!;
119 }
120
121 g3_CodePointcxx . . $ g3_CodePoint(1c2cda054d3314c5).(tmp);
122 return tmp;
123 }
124
125 // Clips an edge against the far plane
126 g3Pointcxx . . $ g3Point# *ClipCustomEdgecxx . . $ ClipCustomEdge(b63d0e562e5b43ea).(g3Pointcxx . . $ g3Point# *on_pnt, g3Pointcxx . . $ g3Point# *off_pnt) {
127 g3Pointcxx . . $ g3Point# *tmp = GetTempPointcxx . . $ GetTempPoint(16f6bc482de7b758).();
128
129 vectorcxx . . $ vector# ray_direction = off_pnt->p3_veccxx . . $ g3Point#p3_vec. -cxx . . $ operator-(b77b703cd1e43e33). on_pnt->p3_veccxx . . $ g3Point#p3_vec.;
130 ray_direction.xcxx . . $ vector#x. /= Matrix_scalecxx . . $ Matrix_scale..xcxx . . $ vector#x.;
131 ray_direction.ycxx . . $ vector#y. /= Matrix_scalecxx . . $ Matrix_scale..ycxx . . $ vector#y.;
132 ray_direction.zcxx . . $ vector#z. /= Matrix_scalecxx . . $ Matrix_scale..zcxx . . $ vector#z.;
133
134 vectorcxx . . $ vector# w = on_pnt->p3_veccxx . . $ g3Point#p3_vec. -cxx . . $ operator-(b77b703cd1e43e33). Clip_plane_pointcxx . . $ Clip_plane_point.;
135 w.xcxx . . $ vector#x. /= Matrix_scalecxx . . $ Matrix_scale..xcxx . . $ vector#x.;
136 w.ycxx . . $ vector#y. /= Matrix_scalecxx . . $ Matrix_scale..ycxx . . $ vector#y.;
137 w.zcxx . . $ vector#z. /= Matrix_scalecxx . . $ Matrix_scale..zcxx . . $ vector#z.;
138
139 float k, den = -(Clip_planecxx . . $ Clip_plane. *cxx . . $ `operator*`(4a721543d64e126a). ray_direction);
140 if (den == 0.0f) {
141 k = 1.0f;
142 } else {
143 float num = Clip_planecxx . . $ Clip_plane. *cxx . . $ `operator*`(4a721543d64e126a). w;
144 k = num / den;
145 }
146
147 tmp->p3_veccxx . . $ g3Point#p3_vec. =cxx . . $ vector#`operator=`(c0842353a20857d). on_pnt->p3_veccxx . . $ g3Point#p3_vec. +cxx . . $ operator+(b77b703cd1e43e33). ((off_pnt->p3_veccxx . . $ g3Point#p3_vec. -cxx . . $ operator-(b77b703cd1e43e33). on_pnt->p3_veccxx . . $ g3Point#p3_vec.) *cxx . . $ `operator*`(252247219a31502c). k);
148
149 if (on_pnt->p3_flagscxx . . $ g3Point#p3_flags. & PF_UVcxx . . $ `lib/3d.h:217:9`!) {
150 tmp->p3_ucxx . . $ `lib/3d.h:250:9`! = on_pnt->p3_ucxx . . $ `lib/3d.h:250:9`! + ((off_pnt->p3_ucxx . . $ `lib/3d.h:250:9`! - on_pnt->p3_ucxx . . $ `lib/3d.h:250:9`!) * k);
151 tmp->p3_vcxx . . $ `lib/3d.h:251:9`! = on_pnt->p3_vcxx . . $ `lib/3d.h:251:9`! + ((off_pnt->p3_vcxx . . $ `lib/3d.h:251:9`! - on_pnt->p3_vcxx . . $ `lib/3d.h:251:9`!) * k);
152 tmp->p3_flagscxx . . $ g3Point#p3_flags. |= PF_UVcxx . . $ `lib/3d.h:217:9`!;
153 }
154
155 if (on_pnt->p3_flagscxx . . $ g3Point#p3_flags. & PF_UV2cxx . . $ `lib/3d.h:220:9`!) {
156 tmp->p3_u2cxx . . $ `lib/3d.h:257:9`! = on_pnt->p3_u2cxx . . $ `lib/3d.h:257:9`! + ((off_pnt->p3_u2cxx . . $ `lib/3d.h:257:9`! - on_pnt->p3_u2cxx . . $ `lib/3d.h:257:9`!) * k);
157 tmp->p3_v2cxx . . $ `lib/3d.h:258:9`! = on_pnt->p3_v2cxx . . $ `lib/3d.h:258:9`! + ((off_pnt->p3_v2cxx . . $ `lib/3d.h:258:9`! - on_pnt->p3_v2cxx . . $ `lib/3d.h:258:9`!) * k);
158 tmp->p3_flagscxx . . $ g3Point#p3_flags. |= PF_UV2cxx . . $ `lib/3d.h:220:9`!;
159 }
160
161 if (on_pnt->p3_flagscxx . . $ g3Point#p3_flags. & PF_Lcxx . . $ `lib/3d.h:218:9`!) {
162 tmp->p3_lcxx . . $ `lib/3d.h:252:9`! = on_pnt->p3_lcxx . . $ `lib/3d.h:252:9`! + ((off_pnt->p3_lcxx . . $ `lib/3d.h:252:9`! - on_pnt->p3_lcxx . . $ `lib/3d.h:252:9`!) * k);
163 tmp->p3_flagscxx . . $ g3Point#p3_flags. |= PF_Lcxx . . $ `lib/3d.h:218:9`!;
164 }
165
166 if (on_pnt->p3_flagscxx . . $ g3Point#p3_flags. & PF_RGBAcxx . . $ `lib/3d.h:219:9`!) {
167 tmp->p3_rcxx . . $ `lib/3d.h:253:9`! = on_pnt->p3_rcxx . . $ `lib/3d.h:253:9`! + ((off_pnt->p3_rcxx . . $ `lib/3d.h:253:9`! - on_pnt->p3_rcxx . . $ `lib/3d.h:253:9`!) * k);
168 tmp->p3_gcxx . . $ `lib/3d.h:254:9`! = on_pnt->p3_gcxx . . $ `lib/3d.h:254:9`! + ((off_pnt->p3_gcxx . . $ `lib/3d.h:254:9`! - on_pnt->p3_gcxx . . $ `lib/3d.h:254:9`!) * k);
169 tmp->p3_bcxx . . $ `lib/3d.h:255:9`! = on_pnt->p3_bcxx . . $ `lib/3d.h:255:9`! + ((off_pnt->p3_bcxx . . $ `lib/3d.h:255:9`! - on_pnt->p3_bcxx . . $ `lib/3d.h:255:9`!) * k);
170 tmp->p3_acxx . . $ `lib/3d.h:256:9`! = on_pnt->p3_acxx . . $ `lib/3d.h:256:9`! + ((off_pnt->p3_acxx . . $ `lib/3d.h:256:9`! - on_pnt->p3_acxx . . $ `lib/3d.h:256:9`!) * k);
171 tmp->p3_flagscxx . . $ g3Point#p3_flags. |= PF_RGBAcxx . . $ `lib/3d.h:219:9`!;
172 }
173
174 g3_CodePointcxx . . $ g3_CodePoint(1c2cda054d3314c5).(tmp);
175 return tmp;
176 }
177
178 // clips an edge against one plane.
179 g3Pointcxx . . $ g3Point# *ClipEdgecxx . . $ ClipEdge(bea1a68e9edcc75d).(int plane_flag, g3Pointcxx . . $ g3Point# *on_pnt, g3Pointcxx . . $ g3Point# *off_pnt) {
180 float a, b, k;
181 g3Pointcxx . . $ g3Point# *tmp;
182
183 // compute clipping value k = (xs-zs) / (xs-xe-zs+ze)
184 // use x or y as appropriate, and negate x/y value as appropriate
185
186 if (plane_flag & CC_OFF_FARcxx . . $ `lib/3d.h:228:9`!) {
187 return ClipFarEdgecxx . . $ ClipFarEdge(b63d0e562e5b43ea).(on_pnt, off_pnt);
188 }
189
190 if ((plane_flag & CC_OFF_CUSTOMcxx . . $ `lib/3d.h:229:9`!) && Clip_customcxx . . $ Clip_custom.) {
191 return ClipCustomEdgecxx . . $ ClipCustomEdge(b63d0e562e5b43ea).(on_pnt, off_pnt);
192 }
193
194 if (plane_flag & (CC_OFF_RIGHTcxx . . $ `lib/3d.h:225:9`! | CC_OFF_LEFTcxx . . $ `lib/3d.h:224:9`!)) {
195 a = on_pnt->p3_xcxx . . $ `lib/3d.h:245:9`!;
196 b = off_pnt->p3_xcxx . . $ `lib/3d.h:245:9`!;
197 } else {
198 a = on_pnt->p3_ycxx . . $ `lib/3d.h:246:9`!;
199 b = off_pnt->p3_ycxx . . $ `lib/3d.h:246:9`!;
200 }
201
202 if (plane_flag & (CC_OFF_LEFTcxx . . $ `lib/3d.h:224:9`! | CC_OFF_BOTcxx . . $ `lib/3d.h:226:9`!)) {
203 a = -a;
204 b = -b;
205 }
206
207 k = (a - on_pnt->p3_zcxx . . $ `lib/3d.h:247:9`!) / ((a - on_pnt->p3_zcxx . . $ `lib/3d.h:247:9`!) - b + off_pnt->p3_zcxx . . $ `lib/3d.h:247:9`!); //(xs-zs) / (xs-zs-xe+ze)
208
209 tmp = GetTempPointcxx . . $ GetTempPoint(16f6bc482de7b758).();
210
211 tmp->p3_xcxx . . $ `lib/3d.h:245:9`! = on_pnt->p3_xcxx . . $ `lib/3d.h:245:9`! + ((off_pnt->p3_xcxx . . $ `lib/3d.h:245:9`! - on_pnt->p3_xcxx . . $ `lib/3d.h:245:9`!) * k);
212 tmp->p3_ycxx . . $ `lib/3d.h:246:9`! = on_pnt->p3_ycxx . . $ `lib/3d.h:246:9`! + ((off_pnt->p3_ycxx . . $ `lib/3d.h:246:9`! - on_pnt->p3_ycxx . . $ `lib/3d.h:246:9`!) * k);
213
214 if (plane_flag & (CC_OFF_TOPcxx . . $ `lib/3d.h:227:9`! | CC_OFF_BOTcxx . . $ `lib/3d.h:226:9`!)) {
215 tmp->p3_zcxx . . $ `lib/3d.h:247:9`! = tmp->p3_ycxx . . $ `lib/3d.h:246:9`!;
216 } else {
217 tmp->p3_zcxx . . $ `lib/3d.h:247:9`! = tmp->p3_xcxx . . $ `lib/3d.h:245:9`!;
218 }
219
220 if (plane_flag & (CC_OFF_LEFTcxx . . $ `lib/3d.h:224:9`! | CC_OFF_BOTcxx . . $ `lib/3d.h:226:9`!)) {
221 tmp->p3_zcxx . . $ `lib/3d.h:247:9`! = -tmp->p3_zcxx . . $ `lib/3d.h:247:9`!;
222 }
223
224 if (on_pnt->p3_flagscxx . . $ g3Point#p3_flags. & PF_UVcxx . . $ `lib/3d.h:217:9`!) {
225 tmp->p3_ucxx . . $ `lib/3d.h:250:9`! = on_pnt->p3_ucxx . . $ `lib/3d.h:250:9`! + ((off_pnt->p3_ucxx . . $ `lib/3d.h:250:9`! - on_pnt->p3_ucxx . . $ `lib/3d.h:250:9`!) * k);
226 tmp->p3_vcxx . . $ `lib/3d.h:251:9`! = on_pnt->p3_vcxx . . $ `lib/3d.h:251:9`! + ((off_pnt->p3_vcxx . . $ `lib/3d.h:251:9`! - on_pnt->p3_vcxx . . $ `lib/3d.h:251:9`!) * k);
227
228 tmp->p3_flagscxx . . $ g3Point#p3_flags. |= PF_UVcxx . . $ `lib/3d.h:217:9`!;
229 }
230
231 if (on_pnt->p3_flagscxx . . $ g3Point#p3_flags. & PF_UV2cxx . . $ `lib/3d.h:220:9`!) {
232 tmp->p3_u2cxx . . $ `lib/3d.h:257:9`! = on_pnt->p3_u2cxx . . $ `lib/3d.h:257:9`! + ((off_pnt->p3_u2cxx . . $ `lib/3d.h:257:9`! - on_pnt->p3_u2cxx . . $ `lib/3d.h:257:9`!) * k);
233 tmp->p3_v2cxx . . $ `lib/3d.h:258:9`! = on_pnt->p3_v2cxx . . $ `lib/3d.h:258:9`! + ((off_pnt->p3_v2cxx . . $ `lib/3d.h:258:9`! - on_pnt->p3_v2cxx . . $ `lib/3d.h:258:9`!) * k);
234
235 tmp->p3_flagscxx . . $ g3Point#p3_flags. |= PF_UV2cxx . . $ `lib/3d.h:220:9`!;
236 }
237
238 if (on_pnt->p3_flagscxx . . $ g3Point#p3_flags. & PF_Lcxx . . $ `lib/3d.h:218:9`!) {
239 tmp->p3_lcxx . . $ `lib/3d.h:252:9`! = on_pnt->p3_lcxx . . $ `lib/3d.h:252:9`! + ((off_pnt->p3_lcxx . . $ `lib/3d.h:252:9`! - on_pnt->p3_lcxx . . $ `lib/3d.h:252:9`!) * k);
240 tmp->p3_flagscxx . . $ g3Point#p3_flags. |= PF_Lcxx . . $ `lib/3d.h:218:9`!;
241 }
242
243 if (on_pnt->p3_flagscxx . . $ g3Point#p3_flags. & PF_RGBAcxx . . $ `lib/3d.h:219:9`!) {
244 tmp->p3_rcxx . . $ `lib/3d.h:253:9`! = on_pnt->p3_rcxx . . $ `lib/3d.h:253:9`! + ((off_pnt->p3_rcxx . . $ `lib/3d.h:253:9`! - on_pnt->p3_rcxx . . $ `lib/3d.h:253:9`!) * k);
245 tmp->p3_gcxx . . $ `lib/3d.h:254:9`! = on_pnt->p3_gcxx . . $ `lib/3d.h:254:9`! + ((off_pnt->p3_gcxx . . $ `lib/3d.h:254:9`! - on_pnt->p3_gcxx . . $ `lib/3d.h:254:9`!) * k);
246 tmp->p3_bcxx . . $ `lib/3d.h:255:9`! = on_pnt->p3_bcxx . . $ `lib/3d.h:255:9`! + ((off_pnt->p3_bcxx . . $ `lib/3d.h:255:9`! - on_pnt->p3_bcxx . . $ `lib/3d.h:255:9`!) * k);
247 tmp->p3_acxx . . $ `lib/3d.h:256:9`! = on_pnt->p3_acxx . . $ `lib/3d.h:256:9`! + ((off_pnt->p3_acxx . . $ `lib/3d.h:256:9`! - on_pnt->p3_acxx . . $ `lib/3d.h:256:9`!) * k);
248 tmp->p3_flagscxx . . $ g3Point#p3_flags. |= PF_RGBAcxx . . $ `lib/3d.h:219:9`!;
249 }
250
251 g3_CodePointcxx . . $ g3_CodePoint(1c2cda054d3314c5).(tmp);
252
253 return tmp;
254 }
255
256 // clips a line to the viewing pyramid.
257 void ClipLinecxx . . $ ClipLine(c1cfda758dd1a0e3).(g3Pointcxx . . $ g3Point# **p0, g3Pointcxx . . $ g3Point# **p1, uint8_tcxx . . $ uint8_t# codes_or) {
258 int plane_flag;
259 g3Pointcxx . . $ g3Point# *old_p1;
260
261 // might have these left over
262 //(*p0)->p3_flags &= ~(PF_UV|PF_L|PF_RGBA|PF_UV2);
263 //(*p1)->p3_flags &= ~(PF_UV|PF_L|PF_RGBA|PF_UV2);
264
265 for (plane_flag = 1; plane_flag <= 32; plane_flag <<= 1) {
266 if (codes_or & plane_flag) {
267 if ((*p0)->p3_codescxx . . $ g3Point#p3_codes. & plane_flag) {
268 // swap!
269 g3Pointcxx . . $ g3Point# *t = *p0;
270 *p0 = *p1;
271 *p1 = t;
272 }
273
274 old_p1 = *p1;
275
276 *p1 = ClipEdgecxx . . $ ClipEdge(bea1a68e9edcc75d).(plane_flag, *p0, *p1);
277
278 codes_or = (*p0)->p3_codescxx . . $ g3Point#p3_codes. | (*p1)->p3_codescxx . . $ g3Point#p3_codes.; // get new codes
279
280 if (old_p1->p3_flagscxx . . $ g3Point#p3_flags. & PF_TEMP_POINTcxx . . $ `lib/3d.h:216:9`!) {
281 FreeTempPointcxx . . $ FreeTempPoint(4c7ad40c64d4fb9c).(old_p1);
282 }
283 }
284 }
285 }
286
287 int ClipPlanecxx . . $ ClipPlane(6199f2612c2a578f).(int plane_flag, g3Pointcxx . . $ g3Point# **src, g3Pointcxx . . $ g3Point# **dest, int *nv, g3Codescxx . . $ g3Codes# *cc) {
288 int i, prev, next;
289 g3Pointcxx . . $ g3Point# **save_dest = dest;
290
291 // Init codes
292 cc->cc_andcxx . . $ g3Codes#cc_and. = 0xff;
293 cc->cc_orcxx . . $ g3Codes#cc_or. = 0;
294
295 for (i = 0, prev = *nv - 1, next = 1; i < *nv; i++) {
296 if (src[i]->p3_codescxx . . $ g3Point#p3_codes. & plane_flag) {
297 // cur point off?
298 if (!(src[prev]->p3_codescxx . . $ g3Point#p3_codes. & plane_flag)) {
299 // prev not off?
300 *dest = ClipEdgecxx . . $ ClipEdge(bea1a68e9edcc75d).(plane_flag, src[prev], src[i]);
301 cc->cc_orcxx . . $ g3Codes#cc_or. |= (*dest)->p3_codescxx . . $ g3Point#p3_codes.;
302 cc->cc_andcxx . . $ g3Codes#cc_and. &= (*dest)->p3_codescxx . . $ g3Point#p3_codes.;
303 dest++;
304 }
305
306 if (!(src[next]->p3_codescxx . . $ g3Point#p3_codes. & plane_flag)) {
307 *dest = ClipEdgecxx . . $ ClipEdge(bea1a68e9edcc75d).(plane_flag, src[next], src[i]);
308 cc->cc_orcxx . . $ g3Codes#cc_or. |= (*dest)->p3_codescxx . . $ g3Point#p3_codes.;
309 cc->cc_andcxx . . $ g3Codes#cc_and. &= (*dest)->p3_codescxx . . $ g3Point#p3_codes.;
310 dest++;
311 }
312
313 // see if must free discarded point
314 if (src[i]->p3_flagscxx . . $ g3Point#p3_flags. & PF_TEMP_POINTcxx . . $ `lib/3d.h:216:9`!) {
315 FreeTempPointcxx . . $ FreeTempPoint(4c7ad40c64d4fb9c).(src[i]);
316 }
317 } else {
318 // cur not off, copy to dest buffer
319 *dest++ = src[i];
320
321 cc->cc_orcxx . . $ g3Codes#cc_or. |= src[i]->p3_codescxx . . $ g3Point#p3_codes.;
322 cc->cc_andcxx . . $ g3Codes#cc_and. &= src[i]->p3_codescxx . . $ g3Point#p3_codes.;
323 }
324
325 prev = i;
326 if (++next == *nv) {
327 next = 0;
328 }
329 }
330
331 return (dest - save_dest);
332 }
333
334 // temp buffers for clipping
335 static g3Pointcxx . . $ g3Point# *Vbuf0cxx . . $ Vbuf0.[MAX_POINTS_IN_POLYcxx . . $ `renderer/HardwareInternal.h:24:9`!];
336 static g3Pointcxx . . $ g3Point# *Vbuf1cxx . . $ Vbuf1.[MAX_POINTS_IN_POLYcxx . . $ `renderer/HardwareInternal.h:24:9`!];
337
338 // Clips a polygon
339 // Parameters: pointlist - pointer to a list of pointers to points
340 // nv - the number of points in the polygon
341 // cc - the clip codes for this polygon
342 // Returns: a pointer to a list of pointer of points in the clipped polygon
343 // NOTE: You MUST call g3_FreeTempPoints() when you're done with the clipped polygon
344 g3Pointcxx . . $ g3Point# **g3_ClipPolygoncxx . . $ g3_ClipPolygon(729f60102f660017).(g3Pointcxx . . $ g3Point# **pointlist, int *nv, g3Codescxx . . $ g3Codes# *cc) {
345 int plane_flag;
346 g3Pointcxx . . $ g3Point# **dest;
347
348 dest = Vbuf0cxx . . $ Vbuf0.;
349
350 //& ASSERT(free_point_num == 0); //DAJ UTB CMO
351 if (free_point_numcxx . . $ free_point_num. != 0) {
352 mprintfcxx . . $ `ddebug/mono.h:82:9`!(1, "clipper: leftover temp point\n");
353 free_point_numcxx . . $ free_point_num. = 0;
354 Int3cxx . . $ `misc/pserror.h:247:9`!();
355 }
356
357 for (plane_flag = 1; plane_flag <= 32; plane_flag <<= 1) {
358 if (cc->cc_orcxx . . $ g3Codes#cc_or. & plane_flag) {
359
360 *nv = ClipPlanecxx . . $ ClipPlane(6199f2612c2a578f).(plane_flag, pointlist, dest, nv, cc);
361
362 if (cc->cc_andcxx . . $ g3Codes#cc_and.) // clipped away
363 return dest;
364
365 pointlist = dest;
366 dest = (pointlist == Vbuf0cxx . . $ Vbuf0.) ? Vbuf1cxx . . $ Vbuf1. : Vbuf0cxx . . $ Vbuf0.;
367 }
368 }
369 return pointlist; // we swapped after we copied
370 }
371
372 // sets the z distance of the far clipping plane
373 void g3_SetFarClipZcxx . . $ g3_SetFarClipZ(9364e6e7bff7660).(float z) { Far_clip_zcxx . . $ Far_clip_z. = z; }
374
375 // Sets up a custom clipping plane - g3_StartFrame must be called before this is called
376 void g3_SetCustomClipPlanecxx . . $ g3_SetCustomClipPlane(212e55486d77b625).(uint8_tcxx . . $ uint8_t# state, vectorcxx . . $ vector# *pnt, vectorcxx . . $ vector# *normal) {
377 Clip_customcxx . . $ Clip_custom. = state;
378 if (state) {
379 vectorcxx . . $ vector# tempv;
380 vectorcxx . . $ vector# norm = *normal;
381
382 tempv =cxx . . $ vector#`operator=`(c0842353a20857d). *pnt -cxx . . $ operator-(b77b703cd1e43e33). View_positioncxx . . $ View_position.;
383 Clip_plane_pointcxx . . $ Clip_plane_point. =cxx . . $ vector#`operator=`(c0842353a20857d). tempv *cxx . . $ `operator*`(14b8f9ac5c1e7b85). View_matrixcxx . . $ View_matrix.;
384
385 Clip_planecxx . . $ Clip_plane. =cxx . . $ vector#`operator=`(c0842353a20857d). norm *cxx . . $ `operator*`(14b8f9ac5c1e7b85). Unscaled_matrixcxx . . $ Unscaled_matrix.; // View_matrix;
386 vm_NormalizeVectorcxx . . $ vm_NormalizeVector(4939a7e530383cd4).(&Clip_planecxx . . $ Clip_plane.);
387 }
388 }