15 #include "scissorEffect.h" 16 #include "scissorAttrib.h" 17 #include "cullTraverser.h" 18 #include "cullTraverserData.h" 20 #include "bamReader.h" 21 #include "bamWriter.h" 23 #include "datagramIterator.h" 24 #include "boundingHexahedron.h" 36 ScissorEffect(
bool screen,
const LVecBase4 &frame,
37 const PointDef *points,
int num_points,
bool clip) :
38 _screen(screen), _frame(frame), _clip(clip)
40 _points.reserve(num_points);
41 for (
int i = 0; i < num_points; ++i) {
42 _points.push_back(points[i]);
54 _screen(copy._screen),
56 _points(copy._points),
69 make_screen(
const LVecBase4 &frame,
bool clip) {
71 return return_new(effect);
83 make_node(
bool clip) {
85 return return_new(effect);
101 points[0]._node = node;
103 points[1]._node = node;
105 return return_new(effect);
121 points[0]._node = node;
123 points[1]._node = node;
125 points[2]._node = node;
127 points[3]._node = node;
129 return return_new(effect);
151 effect->_points.push_back(point);
152 return return_new(effect);
168 for (pi = effect->_points.begin();
169 pi != effect->_points.end();
171 PointDef &point = (*pi);
172 if (point._node.is_empty()) {
173 point._p = point._p * mat;
176 return return_new(effect);
185 output(ostream &out)
const {
186 out << get_type() <<
":";
188 out <<
"screen [" << _frame <<
"]";
191 Points::const_iterator pi;
192 for (pi = _points.begin(); pi != _points.end(); ++pi) {
193 const PointDef &point = (*pi);
194 if (point._node.is_empty()) {
195 out <<
" (" << point._p <<
")";
197 out <<
" (" << point._node <<
":" << point._p <<
")";
216 has_cull_callback()
const {
239 CPT(TransformState) &node_transform,
243 CPT(TransformState) modelview_transform = data.get_modelview_transform(trav);
244 CPT(TransformState) net_transform = modelview_transform->compose(node_transform);
245 if (net_transform->is_singular()) {
254 LMatrix4 net_mat = net_transform->get_mat() * proj_mat;
256 bool any_points =
false;
258 Points::const_iterator pi;
259 for (pi = _points.begin(); pi != _points.end(); ++pi) {
260 const PointDef &point = (*pi);
261 LVecBase4 pv(point._p[0], point._p[1], point._p[2], 1.0f);
262 if (point._node.is_empty()) {
268 LMatrix4 other_mat = point._node.get_net_transform()->get_mat() * proj_mat;
275 LPoint3 pr(pv[0] / pv[3], pv[1] / pv[3], pv[2] / pv[3]);
283 frame[0] = min(frame[0], pr[0]);
284 frame[1] = max(frame[1], pr[0]);
285 frame[2] = min(frame[2], pr[1]);
286 frame[3] = max(frame[3], pr[1]);
291 frame[0] = (frame[0] + 1.0f) * 0.5f;
292 frame[1] = (frame[1] + 1.0f) * 0.5f;
293 frame[2] = (frame[2] + 1.0f) * 0.5f;
294 frame[3] = (frame[3] + 1.0f) * 0.5f;
298 frame[0] = max(min(frame[0], (PN_stdfloat)1.0), (PN_stdfloat)0.0);
299 frame[1] = max(min(frame[1], (PN_stdfloat)1.0), frame[0]);
300 frame[2] = max(min(frame[2], (PN_stdfloat)1.0), (PN_stdfloat)0.0);
301 frame[3] = max(min(frame[3], (PN_stdfloat)1.0), frame[2]);
304 CPT(
RenderAttrib) scissor_attrib = ScissorAttrib::make(frame);
305 CPT(
RenderState) state = RenderState::make(scissor_attrib);
306 node_state = node_state->compose(state);
313 frustum->xform(modelview_transform->get_inverse()->get_mat());
314 data._view_frustum = frustum;
336 DCAST_INTO_R(ta, other, 0);
338 if (_screen != ta->_screen) {
339 return (
int)_screen - (int)ta->_screen;
341 if (_clip != ta->_clip) {
342 return (
int)_clip - (int)ta->_clip;
350 int compare = (int)_points.size() - (int)ta->_points.size();
354 for (
size_t i = 0; i < _points.size(); ++i) {
355 compare = _points[i]._p.compare_to(ta->_points[i]._p);
359 compare = _points[i]._node.compare_to(ta->_points[i]._node);
375 register_with_read_factory() {
394 Points::const_iterator pi;
395 for (pi = _points.begin(); pi != _points.end(); ++pi) {
396 (*pi)._p.write_datagram(dg);
416 parse_params(params, scan, manager);
417 effect->fillin(scan, manager);
431 RenderEffect::fillin(scan, manager);
438 _points.reserve(num_points);
439 for (
int i = 0; i < num_points; ++i) {
441 point._p.read_datagram(scan);
442 _points.push_back(point);
455 make_frustum(
const Lens *lens,
const LVecBase4 &frame)
const{
458 frame[1] * 2.0f - 1.0f,
459 frame[2] * 2.0f - 1.0f,
460 frame[3] * 2.0f - 1.0f);
466 corner[0] = f2[0]; corner[1] = f2[3];
469 if (!lens->
extrude(corner, nul, ful)) {
473 corner[0] = f2[1]; corner[1] = f2[3];
476 if (!lens->
extrude(corner, nur, fur)) {
480 corner[0] = f2[1]; corner[1] = f2[2];
483 if (!lens->
extrude(corner, nlr, flr)) {
487 corner[0] = f2[0]; corner[1] = f2[2];
490 if (!lens->
extrude(corner, nll, fll)) {
This provides a higher-level wrapper around ScissorAttrib.
bool get_bool()
Extracts a boolean value.
This is the base class for a number of render attributes (other than transform) that may be set on sc...
A base class for any number of different kinds of lenses, linear and otherwise.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
bool is_screen() const
Returns true if the ScissorEffect is a screen-based effect, meaning get_frame() has a meaningful valu...
Base class for objects that can be written to and read from Bam files.
This collects together the pieces of data that are accumulated for each node while walking the scene ...
const Lens * get_lens() const
Returns the particular Lens used for rendering.
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
This is the base class for a number of special render effects that may be set on scene graph nodes to...
PN_uint16 get_uint16()
Extracts an unsigned 16-bit integer.
This is another abstract class, for a general class of bounding volumes that actually enclose points ...
void add_bool(bool value)
Adds a boolean value to the datagram.
This is a 4-by-4 transform matrix.
int compare_to(const LVecBase4f &other) const
This flavor of compare_to uses a default threshold value based on the numeric type.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
void read_datagram(DatagramIterator &source)
Reads the vector from the Datagram using get_stdfloat().
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
void add_uint16(PN_uint16 value)
Adds an unsigned 16-bit integer to the datagram.
This is the base class for all three-component vectors and points.
const LMatrix4 & get_projection_mat(StereoChannel channel=SC_mono) const
Returns the complete transformation matrix from a 3-d point in space to a point on the film...
void write_datagram(Datagram &destination) const
Writes the vector to the Datagram using add_stdfloat().
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
SceneSetup * get_scene() const
Returns the SceneSetup object.
bool get_clip() const
Returns true if this ScissorEffect actually enables scissoring, or false if it culls only...
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 (...
A class to retrieve the individual data elements previously stored in a Datagram. ...
This is a two-component point in space.
TypeHandle is the identifier used to differentiate C++ class types.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
This defines a bounding convex hexahedron.
static const LVecBase4f & zero()
Returns a zero-length vector.