15 #include "portalClipper.h"
16 #include "cullTraverser.h"
17 #include "cullTraverserData.h"
18 #include "transformState.h"
19 #include "renderState.h"
20 #include "fogAttrib.h"
21 #include "cullHandler.h"
24 #include "config_pgraph.h"
25 #include "boundingSphere.h"
26 #include "colorAttrib.h"
27 #include "renderModeAttrib.h"
28 #include "cullFaceAttrib.h"
29 #include "depthOffsetAttrib.h"
30 #include "geomVertexWriter.h"
31 #include "geomLinestrips.h"
32 #include "geomPoints.h"
43 _reduced_viewport_min(-1,-1),
44 _reduced_viewport_max(1,1),
47 _previous =
new GeomNode(
"my_frustum");
52 _scene_setup = scene_setup;
76 segs.push_back(Point(v, _color));
79 _list.push_back(segs);
103 segs.push_back(Point(v, _color));
162 if (!_list.empty()) {
163 _created_data = NULL;
166 (
"portal", GeomVertexFormat::get_v3cp(), Geom::UH_static);
174 LineList::const_iterator ll;
175 SegmentList::const_iterator sl;
177 for (ll = _list.begin(); ll != _list.end(); ll++) {
180 if (segs.size() < 2) {
182 for (sl = segs.begin(); sl != segs.end(); sl++) {
183 points->add_vertex(v);
188 points->close_primitive();
193 for (sl = segs.begin(); sl != segs.end(); sl++) {
194 lines->add_vertex(v);
199 lines->close_primitive();
203 if (lines->get_num_vertices() != 0) {
205 geom->add_primitive(lines);
206 _previous->add_geom(geom);
208 if (points->get_num_vertices() != 0) {
210 geom->add_primitive(points);
211 _previous->add_geom(geom);
227 if (node->
is_of_type(PortalNode::get_class_type())) {
232 portal_cat.spam() << *_portal_node << endl;
237 LMatrix4 cmat = ctransform->get_mat();
238 portal_cat.spam() << cmat << endl;
246 portal_cat.spam() <<
"before transformation to camera space" << endl;
247 portal_cat.spam() << temp[0] << endl;
248 portal_cat.spam() << temp[1] << endl;
249 portal_cat.spam() << temp[2] << endl;
250 portal_cat.spam() << temp[3] << endl;
252 temp[0] = temp[0]*cmat;
253 temp[1] = temp[1]*cmat;
254 temp[2] = temp[2]*cmat;
255 temp[3] = temp[3]*cmat;
257 LPlane portal_plane(temp[0], temp[1], temp[2]);
259 portal_cat.debug() <<
"portal failed 1st level test (isn't facing the camera)\n";
263 portal_cat.spam() <<
"after transformation to camera space" << endl;
264 portal_cat.spam() << temp[0] << endl;
265 portal_cat.spam() << temp[1] << endl;
266 portal_cat.spam() << temp[2] << endl;
267 portal_cat.spam() << temp[3] << endl;
278 else if (forward[2]) {
284 if ((temp[0][forward_axis] * forward[forward_axis] <= 0) ||
285 (temp[1][forward_axis] * forward[forward_axis] <= 0) ||
286 (temp[2][forward_axis] * forward[forward_axis] <= 0) ||
287 (temp[3][forward_axis] * forward[forward_axis] <= 0)) {
288 portal_cat.debug() <<
"portal intersects with center of projection.." << endl;
294 lens->
project(temp[0], projected_coords[0]);
295 lens->
project(temp[1], projected_coords[1]);
296 lens->
project(temp[2], projected_coords[2]);
297 lens->
project(temp[3], projected_coords[3]);
299 portal_cat.spam() <<
"after projection to 2d" << endl;
300 portal_cat.spam() << projected_coords[0] << endl;
301 portal_cat.spam() << projected_coords[1] << endl;
302 portal_cat.spam() << projected_coords[2] << endl;
303 portal_cat.spam() << projected_coords[3] << endl;
306 PN_stdfloat min_x, max_x, min_y, max_y;
307 min_x = min(min(min(projected_coords[0][0], projected_coords[1][0]), projected_coords[2][0]), projected_coords[3][0]);
308 max_x = max(max(max(projected_coords[0][0], projected_coords[1][0]), projected_coords[2][0]), projected_coords[3][0]);
309 min_y = min(min(min(projected_coords[0][1], projected_coords[1][1]), projected_coords[2][1]), projected_coords[3][1]);
310 max_y = max(max(max(projected_coords[0][1], projected_coords[1][1]), projected_coords[2][1]), projected_coords[3][1]);
312 portal_cat.spam() <<
"min_x " << min_x <<
";max_x " << max_x <<
";min_y " << min_y <<
";max_y " << max_y << endl;
315 min_x = max(min_x, _reduced_viewport_min[0]);
316 min_y = max(min_y, _reduced_viewport_min[1]);
317 max_x = min(max_x, _reduced_viewport_max[0]);
318 max_y = min(max_y, _reduced_viewport_max[1]);
320 portal_cat.spam() <<
"after clipping: min_x " << min_x <<
";max_x " << max_x <<
";min_y " << min_y <<
";max_y " << max_y << endl;
322 if ((min_x >= max_x) || (min_y >= max_y)) {
323 portal_cat.debug() <<
"portal got clipped away \n";
328 _reduced_viewport_min.set(min_x, min_y);
329 _reduced_viewport_max.set(max_x, max_y);
334 lens->
extrude(
LPoint2(min_x, min_y), near_point[0], far_point[0]);
335 lens->
extrude(
LPoint2(max_x, min_y), near_point[1], far_point[1]);
336 lens->
extrude(
LPoint2(max_x, max_y), near_point[2], far_point[2]);
337 lens->
extrude(
LPoint2(min_x, max_y), near_point[3], far_point[3]);
340 _reduced_frustum =
new BoundingHexahedron(far_point[0], far_point[1], far_point[2], far_point[3],
341 near_point[0], near_point[1], near_point[2], near_point[3]);
343 portal_cat.debug() << *_reduced_frustum << endl;
346 if (debug_portal_cull) {
353 move_to((near_point[0]*0.99+far_point[0]*0.01));
354 draw_to((near_point[1]*0.99+far_point[1]*0.01));
355 draw_to((near_point[2]*0.99+far_point[2]*0.01));
356 draw_to((near_point[3]*0.99+far_point[3]*0.01));
357 draw_to((near_point[0]*0.99+far_point[0]*0.01));
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...
This is the base class for all three-component vectors and points.
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.
const LPoint3 & get_vertex(int n) const
Returns the nth vertex of the portal polygon.
const TransformState * get_transform(Thread *current_thread=Thread::get_current_thread()) const
Returns the complete transform object set on this node.
void draw_lines()
Draw all the lines in the buffer Cyan portal is the original geometry of the portal Yellow portal is ...
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
bool is_facing_view(const LPlane &portal_plane)
checks if the portal plane (in camera space) is facing the camera's near plane
PandaNode * node() const
Returns the referenced node of the path.
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
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. ...
void draw_current_portal()
_portal_node is the current portal, draw it.
static LVector3f forward(CoordinateSystem cs=CS_default)
Returns the forward vector for the given coordinate system.
This is our own Panda specialization on the default STL vector.
void draw_hexahedron(BoundingHexahedron *frustum)
Given the BoundingHexahedron draw it using lines.
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 (...
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.
This is a 4-by-4 transform matrix.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
A container for geometry primitives.
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. ...
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,1) in both dimensions, where (0,0) is the center of the lens and (-1,-1) is the lower-left corner.
LPoint3 get_point(int n) const
Returns the nth vertex of the hexahedron.
const NodePath & get_cull_center() const
Returns the point from which the culling operations will be performed.
This is the base class for all three-component vectors and points.
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...
Defines a series of line strips.
This is a two-component point in space.
TypeHandle is the identifier used to differentiate C++ class types.
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...
CoordinateSystem get_coordinate_system() const
Returns the coordinate system that all 3-d computations are performed within for this Lens...
const Lens * get_lens() const
Returns the particular Lens used for rendering.
A node that holds Geom objects, renderable pieces of geometry.
This defines a bounding convex hexahedron.