44 _reduced_viewport_min(-1,-1),
45 _reduced_viewport_max(1,1),
48 _previous =
new GeomNode(
"my_frustum");
53 _scene_setup = scene_setup;
72 segs.push_back(Point(v, _color));
75 _list.push_back(segs);
95 segs.push_back(Point(v, _color));
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);
172 points->close_primitive();
176 for (sl = segs.begin(); sl != segs.end(); sl++) {
177 lines->add_vertex(v);
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);
A basic node of the scene graph or data graph.
This object provides a high-level interface for quickly writing a sequence of numeric values from a v...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool prepare_portal(const NodePath &node_path)
Given the portal draw the frustum with line segs for now.
A base class for any number of different kinds of lenses, linear and otherwise.
Defines a series of disconnected points.
void move_to(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Moves the pen to the given point without drawing a line.
void draw_lines()
Draw all the lines in the buffer Cyan portal is the original geometry of the portal Yellow portal is ...
bool is_facing_view(const LPlane &portal_plane)
checks if the portal plane (in camera space) is facing the camera's near plane
const Lens * get_lens() const
Returns the particular Lens used for rendering.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void add_data4(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z, PN_stdfloat w)
Sets the write row to a particular 4-component value, and advances the write row.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void draw_current_portal()
_portal_node is the current portal, draw it.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is our own Panda specialization on the default STL vector.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void draw_hexahedron(BoundingHexahedron *frustum)
Given the BoundingHexahedron draw it using lines.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool project(const LPoint3 &point3d, LPoint3 &point2d) const
Given a 3-d point in space, determine the 2-d point this maps to, in the range (-1,...
This is another abstract class, for a general class of bounding volumes that actually enclose points ...
A node in the scene graph that can hold a Portal Polygon, which is a rectangle.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A container for geometry primitives.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void add_data3(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Sets the write row to a particular 3-component value, and advances the write row.
get_coordinate_system
Returns the coordinate system that all 3-d computations are performed within for this Lens.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
const NodePath & get_cull_center() const
Returns the point from which the culling operations will be performed.
void draw_to(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Draws a line segment from the pen's last position (the last call to move_to or draw_to) to the indica...
PandaNode * node() const
Returns the referenced node of the path.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Defines a series of line strips.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool extrude(const LPoint2 &point2d, LPoint3 &near_point, LPoint3 &far_point) const
Given a 2-d point in the range (-1,1) in both dimensions, where (0,0) is the center of the lens and (...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
get_point
Returns the nth vertex of the hexahedron.
get_vertex
Returns the nth vertex of the portal polygon.
TypeHandle is the identifier used to differentiate C++ class types.
const TransformState * get_transform(Thread *current_thread=Thread::get_current_thread()) const
Returns the complete transform object set on this node.
This object holds the camera position, etc., and other general setup information for rendering a part...
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
A node that holds Geom objects, renderable pieces of geometry.
This defines a bounding convex hexahedron.