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

Function ClipCustomEdge

renderer/HardwareClipper.cpp:126–176  ·  view source on GitHub ↗

Clips an edge against the far plane

Source from the content-addressed store, hash-verified

124
125// Clips an edge against the far plane
126g3Point *ClipCustomEdge(g3Point *on_pnt, g3Point *off_pnt) {
127 g3Point *tmp = GetTempPoint();
128
129 vector ray_direction = off_pnt->p3_vec - on_pnt->p3_vec;
130 ray_direction.x /= Matrix_scale.x;
131 ray_direction.y /= Matrix_scale.y;
132 ray_direction.z /= Matrix_scale.z;
133
134 vector w = on_pnt->p3_vec - Clip_plane_point;
135 w.x /= Matrix_scale.x;
136 w.y /= Matrix_scale.y;
137 w.z /= Matrix_scale.z;
138
139 float k, den = -(Clip_plane * ray_direction);
140 if (den == 0.0f) {
141 k = 1.0f;
142 } else {
143 float num = Clip_plane * w;
144 k = num / den;
145 }
146
147 tmp->p3_vec = on_pnt->p3_vec + ((off_pnt->p3_vec - on_pnt->p3_vec) * k);
148
149 if (on_pnt->p3_flags & PF_UV) {
150 tmp->p3_u = on_pnt->p3_u + ((off_pnt->p3_u - on_pnt->p3_u) * k);
151 tmp->p3_v = on_pnt->p3_v + ((off_pnt->p3_v - on_pnt->p3_v) * k);
152 tmp->p3_flags |= PF_UV;
153 }
154
155 if (on_pnt->p3_flags & PF_UV2) {
156 tmp->p3_u2 = on_pnt->p3_u2 + ((off_pnt->p3_u2 - on_pnt->p3_u2) * k);
157 tmp->p3_v2 = on_pnt->p3_v2 + ((off_pnt->p3_v2 - on_pnt->p3_v2) * k);
158 tmp->p3_flags |= PF_UV2;
159 }
160
161 if (on_pnt->p3_flags & PF_L) {
162 tmp->p3_l = on_pnt->p3_l + ((off_pnt->p3_l - on_pnt->p3_l) * k);
163 tmp->p3_flags |= PF_L;
164 }
165
166 if (on_pnt->p3_flags & PF_RGBA) {
167 tmp->p3_r = on_pnt->p3_r + ((off_pnt->p3_r - on_pnt->p3_r) * k);
168 tmp->p3_g = on_pnt->p3_g + ((off_pnt->p3_g - on_pnt->p3_g) * k);
169 tmp->p3_b = on_pnt->p3_b + ((off_pnt->p3_b - on_pnt->p3_b) * k);
170 tmp->p3_a = on_pnt->p3_a + ((off_pnt->p3_a - on_pnt->p3_a) * k);
171 tmp->p3_flags |= PF_RGBA;
172 }
173
174 g3_CodePoint(tmp);
175 return tmp;
176}
177
178// clips an edge against one plane.
179g3Point *ClipEdge(int plane_flag, g3Point *on_pnt, g3Point *off_pnt) {

Callers 1

ClipEdgeFunction · 0.85

Calls 2

GetTempPointFunction · 0.85
g3_CodePointFunction · 0.85

Tested by

no test coverage detected