MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / ClipEdge

Function ClipEdge

renderer/HardwareClipper.cpp:179–254  ·  view source on GitHub ↗

clips an edge against one plane.

Source from the content-addressed store, hash-verified

177
178// clips an edge against one plane.
179g3Point *ClipEdge(int plane_flag, g3Point *on_pnt, g3Point *off_pnt) {
180 float a, b, k;
181 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_FAR) {
187 return ClipFarEdge(on_pnt, off_pnt);
188 }
189
190 if ((plane_flag & CC_OFF_CUSTOM) && Clip_custom) {
191 return ClipCustomEdge(on_pnt, off_pnt);
192 }
193
194 if (plane_flag & (CC_OFF_RIGHT | CC_OFF_LEFT)) {
195 a = on_pnt->p3_x;
196 b = off_pnt->p3_x;
197 } else {
198 a = on_pnt->p3_y;
199 b = off_pnt->p3_y;
200 }
201
202 if (plane_flag & (CC_OFF_LEFT | CC_OFF_BOT)) {
203 a = -a;
204 b = -b;
205 }
206
207 k = (a - on_pnt->p3_z) / ((a - on_pnt->p3_z) - b + off_pnt->p3_z); //(xs-zs) / (xs-zs-xe+ze)
208
209 tmp = GetTempPoint();
210
211 tmp->p3_x = on_pnt->p3_x + ((off_pnt->p3_x - on_pnt->p3_x) * k);
212 tmp->p3_y = on_pnt->p3_y + ((off_pnt->p3_y - on_pnt->p3_y) * k);
213
214 if (plane_flag & (CC_OFF_TOP | CC_OFF_BOT)) {
215 tmp->p3_z = tmp->p3_y;
216 } else {
217 tmp->p3_z = tmp->p3_x;
218 }
219
220 if (plane_flag & (CC_OFF_LEFT | CC_OFF_BOT)) {
221 tmp->p3_z = -tmp->p3_z;
222 }
223
224 if (on_pnt->p3_flags & PF_UV) {
225 tmp->p3_u = on_pnt->p3_u + ((off_pnt->p3_u - on_pnt->p3_u) * k);
226 tmp->p3_v = on_pnt->p3_v + ((off_pnt->p3_v - on_pnt->p3_v) * k);
227
228 tmp->p3_flags |= PF_UV;
229 }
230
231 if (on_pnt->p3_flags & PF_UV2) {
232 tmp->p3_u2 = on_pnt->p3_u2 + ((off_pnt->p3_u2 - on_pnt->p3_u2) * k);
233 tmp->p3_v2 = on_pnt->p3_v2 + ((off_pnt->p3_v2 - on_pnt->p3_v2) * k);
234
235 tmp->p3_flags |= PF_UV2;
236 }

Callers 2

ClipLineFunction · 0.70
ClipPlaneFunction · 0.70

Calls 4

ClipFarEdgeFunction · 0.85
ClipCustomEdgeFunction · 0.85
GetTempPointFunction · 0.85
g3_CodePointFunction · 0.85

Tested by

no test coverage detected