diff --git a/panda/src/pgraph/cullTraverser.cxx b/panda/src/pgraph/cullTraverser.cxx index 21a3152600..0f43d09c1c 100644 --- a/panda/src/pgraph/cullTraverser.cxx +++ b/panda/src/pgraph/cullTraverser.cxx @@ -96,11 +96,11 @@ traverse(const NodePath &root, bool python_cull_control) { portal_viewer.draw_camera_frustum(); // for each portal draw its frustum - for (int portal_idx=1; portal_idx<2; ++portal_idx) { + for (int portal_idx=2; portal_idx<3; ++portal_idx) { PT(BoundingVolume) reduced_frustum; portal_viewer.prepare_portal(portal_idx); - portal_viewer.clip_portal(portal_idx); + //portal_viewer.clip_portal(portal_idx); if ((reduced_frustum = portal_viewer.get_reduced_frustum(portal_idx))) { // This reduced frustum is in camera space pgraph_cat.debug() << "got reduced frustum " << reduced_frustum << endl; diff --git a/panda/src/pgraph/portalClipper.cxx b/panda/src/pgraph/portalClipper.cxx index 96b73d1587..16298301f8 100755 --- a/panda/src/pgraph/portalClipper.cxx +++ b/panda/src/pgraph/portalClipper.cxx @@ -363,46 +363,62 @@ get_reduced_frustum(int idx) // than bounding planes (which I might have to implement soon) if (!_num_vert) - return false; + return NULL; float t; + bool visible = true; // find intersection of 7->0 with far LPoint3f from_origin = _hex_frustum->get_point(7); LVector3f from_direction = _coords[0] - from_origin; bool is_intersect = _hex_frustum->get_plane(0).intersects_line(t, from_origin, from_direction); - if (is_intersect) { + if (is_intersect && t >= 0.0) { // has to be positive, else camera is not looking at the portal pgraph_cat.debug() << "far plane intersected 7->0 at t=" << t << endl; intersect_points[0] = from_origin + t*from_direction; pgraph_cat.debug() << intersect_points[0] << endl; } - + else + visible = false; + // find intersection of 4->1 with far from_origin = _hex_frustum->get_point(4); from_direction = _coords[1] - from_origin; is_intersect = _hex_frustum->get_plane(0).intersects_line(t, from_origin, from_direction); - if (is_intersect) { + if (is_intersect && t >= 0.0) { // has to be positive, else camera is not looking at the portal pgraph_cat.debug() << "far plane intersected 4->1 at t=" << t << endl; intersect_points[1] = from_origin + t*from_direction; pgraph_cat.debug() << intersect_points[1] << endl; } + else + visible = false; + // find intersection of 5->2 with far from_origin = _hex_frustum->get_point(5); from_direction = _coords[2] - from_origin; is_intersect = _hex_frustum->get_plane(0).intersects_line(t, from_origin, from_direction); - if (is_intersect) { + if (is_intersect && t >= 0.0) { // has to be positive, else camera is not looking at the portal pgraph_cat.debug() << "far plane intersected 5->2 at t=" << t << endl; intersect_points[2] = from_origin + t*from_direction; pgraph_cat.debug() << intersect_points[2] << endl; } + else + visible = false; + // find intersection of 6->3 with far from_origin = _hex_frustum->get_point(6); from_direction = _coords[3] - from_origin; is_intersect = _hex_frustum->get_plane(0).intersects_line(t, from_origin, from_direction); - if (is_intersect) { + if (is_intersect && t >= 0.0) { // has to be positive, else camera is not looking at the portal pgraph_cat.debug() << "far plane intersected 6->3 at t=" << t << endl; intersect_points[3] = from_origin + t*from_direction; pgraph_cat.debug() << intersect_points[3] << endl; } + else + visible = false; + + if (!visible) { + pgraph_cat.debug() << "portal" << idx << " is not visible from current camera look at" << endl; + return NULL; + } // With these intersect_points, construct the new reduced frustum PT(BoundingVolume) reduced_frustum = new diff --git a/panda/src/pgraph/portalNode.cxx b/panda/src/pgraph/portalNode.cxx index 699d3c5d5a..f3942752fb 100755 --- a/panda/src/pgraph/portalNode.cxx +++ b/panda/src/pgraph/portalNode.cxx @@ -229,7 +229,17 @@ recompute_internal_bound() { BoundingVolume *bound = PandaNode::recompute_internal_bound(); nassertr(bound != (BoundingVolume *)NULL, bound); + GeometricBoundingVolume *gbv = DCAST(GeometricBoundingVolume, bound); + // Now actually compute the bounding volume by putting it around all + // of our vertices. + + const LPoint3f *vertices_begin = &_vertices[0]; + const LPoint3f *vertices_end = vertices_begin + _vertices.size(); + + // Now actually compute the bounding volume by putting it around all + gbv->around(vertices_begin, vertices_end); + return bound; }