146 if (!_list.empty()) {
147 _created_data =
nullptr;
158 LineList::const_iterator ll;
159 SegmentList::const_iterator sl;
161 for (ll = _list.begin(); ll != _list.end(); ll++) {
164 if (segs.size() < 2) {
166 for (sl = segs.begin(); sl != segs.end(); sl++) {
167 points->add_vertex(v);
169 color.add_data4((*sl)._color);
172 points->close_primitive();
176 for (sl = segs.begin(); sl != segs.end(); sl++) {
177 lines->add_vertex(v);
179 color.add_data4((*sl)._color);
182 lines->close_primitive();
186 if (lines->get_num_vertices() != 0) {
188 geom->add_primitive(lines);
189 _previous->add_geom(geom);
191 if (points->get_num_vertices() != 0) {
193 geom->add_primitive(points);
194 _previous->add_geom(geom);
207 _portal_node =
nullptr;
208 if (node->
is_of_type(PortalNode::get_class_type())) {
213 portal_cat.spam() << *_portal_node << endl;
219 LMatrix4 cmat = ctransform->
get_mat();
220 portal_cat.spam() << cmat << endl;
228 portal_cat.spam() <<
"before transformation to camera space" << endl;
229 portal_cat.spam() << temp[0] << endl;
230 portal_cat.spam() << temp[1] << endl;
231 portal_cat.spam() << temp[2] << endl;
232 portal_cat.spam() << temp[3] << endl;
234 temp[0] = temp[0]*cmat;
235 temp[1] = temp[1]*cmat;
236 temp[2] = temp[2]*cmat;
237 temp[3] = temp[3]*cmat;
239 LPlane portal_plane(temp[0], temp[1], temp[2]);
241 portal_cat.debug() <<
"portal failed 1st level test (isn't facing the camera)\n";
245 portal_cat.spam() <<
"after transformation to camera space" << endl;
246 portal_cat.spam() << temp[0] << endl;
247 portal_cat.spam() << temp[1] << endl;
248 portal_cat.spam() << temp[2] << endl;
249 portal_cat.spam() << temp[3] << endl;
263 else if (forward[2]) {
269 if ((temp[0][forward_axis] * forward[forward_axis] <= 0) ||
270 (temp[1][forward_axis] * forward[forward_axis] <= 0) ||
271 (temp[2][forward_axis] * forward[forward_axis] <= 0) ||
272 (temp[3][forward_axis] * forward[forward_axis] <= 0)) {
273 portal_cat.debug() <<
"portal intersects with center of projection.." << endl;
278 LPoint3 projected_coords[4];
279 lens->
project(temp[0], projected_coords[0]);
280 lens->
project(temp[1], projected_coords[1]);
281 lens->
project(temp[2], projected_coords[2]);
282 lens->
project(temp[3], projected_coords[3]);
284 portal_cat.spam() <<
"after projection to 2d" << endl;
285 portal_cat.spam() << projected_coords[0] << endl;
286 portal_cat.spam() << projected_coords[1] << endl;
287 portal_cat.spam() << projected_coords[2] << endl;
288 portal_cat.spam() << projected_coords[3] << endl;
291 PN_stdfloat min_x, max_x, min_y, max_y;
292 min_x = min(min(min(projected_coords[0][0], projected_coords[1][0]), projected_coords[2][0]), projected_coords[3][0]);
293 max_x = max(max(max(projected_coords[0][0], projected_coords[1][0]), projected_coords[2][0]), projected_coords[3][0]);
294 min_y = min(min(min(projected_coords[0][1], projected_coords[1][1]), projected_coords[2][1]), projected_coords[3][1]);
295 max_y = max(max(max(projected_coords[0][1], projected_coords[1][1]), projected_coords[2][1]), projected_coords[3][1]);
297 portal_cat.spam() <<
"min_x " << min_x <<
";max_x " << max_x <<
";min_y " << min_y <<
";max_y " << max_y << endl;
300 min_x = max(min_x, _reduced_viewport_min[0]);
301 min_y = max(min_y, _reduced_viewport_min[1]);
302 max_x = min(max_x, _reduced_viewport_max[0]);
303 max_y = min(max_y, _reduced_viewport_max[1]);
305 portal_cat.spam() <<
"after clipping: min_x " << min_x <<
";max_x " << max_x <<
";min_y " << min_y <<
";max_y " << max_y << endl;
307 if ((min_x >= max_x) || (min_y >= max_y)) {
308 portal_cat.debug() <<
"portal got clipped away \n";
313 _reduced_viewport_min.set(min_x, min_y);
314 _reduced_viewport_max.set(max_x, max_y);
317 LPoint3 near_point[4];
318 LPoint3 far_point[4];
319 lens->
extrude(LPoint2(min_x, min_y), near_point[0], far_point[0]);
320 lens->
extrude(LPoint2(max_x, min_y), near_point[1], far_point[1]);
321 lens->
extrude(LPoint2(max_x, max_y), near_point[2], far_point[2]);
322 lens->
extrude(LPoint2(min_x, max_y), near_point[3], far_point[3]);
325 _reduced_frustum =
new BoundingHexahedron(far_point[0], far_point[1], far_point[2], far_point[3],
326 near_point[0], near_point[1], near_point[2], near_point[3]);
328 portal_cat.debug() << *_reduced_frustum << endl;
331 if (debug_portal_cull) {
333 _color = LColor(0,0,1,1);
337 _color = LColor(1,1,0,1);
338 move_to((near_point[0]*0.99+far_point[0]*0.01));
339 draw_to((near_point[1]*0.99+far_point[1]*0.01));
340 draw_to((near_point[2]*0.99+far_point[2]*0.01));
341 draw_to((near_point[3]*0.99+far_point[3]*0.01));
342 draw_to((near_point[0]*0.99+far_point[0]*0.01));
345 _color = LColor(0,1,1,1);