35 ScissorEffect(
bool screen,
const LVecBase4 &frame,
36 const PointDef *points,
int num_points,
bool clip) :
37 _screen(screen), _frame(frame), _clip(clip)
39 _points.reserve(num_points);
40 for (
int i = 0; i < num_points; ++i) {
41 _points.push_back(points[i]);
50 _screen(copy._screen),
52 _points(copy._points),
63 make_screen(
const LVecBase4 &frame,
bool clip) {
65 return return_new(effect);
74 make_node(
bool clip) {
76 return return_new(effect);
86 make_node(
const LPoint3 &a,
const LPoint3 &b,
const NodePath &node) {
89 points[0]._node = node;
91 points[1]._node = node;
93 return return_new(effect);
103 make_node(
const LPoint3 &a,
const LPoint3 &b,
const LPoint3 &c,
const LPoint3 &d,
const NodePath &node) {
106 points[0]._node = node;
108 points[1]._node = node;
110 points[2]._node = node;
112 points[3]._node = node;
114 return return_new(effect);
126 add_point(
const LPoint3 &p,
const NodePath &node)
const {
132 effect->_points.push_back(point);
133 return return_new(effect);
140 xform(
const LMatrix4 &mat)
const {
146 for (pi = effect->_points.begin();
147 pi != effect->_points.end();
149 PointDef &point = (*pi);
150 if (point._node.is_empty()) {
151 point._p = point._p * mat;
154 return return_new(effect);
161 output(std::ostream &out)
const {
162 out << get_type() <<
":";
164 out <<
"screen [" << _frame <<
"]";
167 Points::const_iterator pi;
168 for (pi = _points.begin(); pi != _points.end(); ++pi) {
169 const PointDef &point = (*pi);
170 if (point._node.is_empty()) {
171 out <<
" (" << point._p <<
")";
173 out <<
" (" << point._node <<
":" << point._p <<
")";
188 has_cull_callback()
const {
210 CPT(
TransformState) modelview_transform = data.get_modelview_transform(trav);
211 CPT(
TransformState) net_transform = modelview_transform->compose(node_transform);
212 if (net_transform->is_singular()) {
221 LMatrix4 net_mat = net_transform->get_mat() * proj_mat;
223 bool any_points =
false;
225 Points::const_iterator pi;
226 for (pi = _points.begin(); pi != _points.end(); ++pi) {
227 const PointDef &point = (*pi);
228 LVecBase4 pv(point._p[0], point._p[1], point._p[2], 1.0f);
229 if (point._node.is_empty()) {
235 LMatrix4 other_mat = point._node.get_net_transform()->get_mat() * proj_mat;
242 LPoint3 pr(pv[0] / pv[3], pv[1] / pv[3], pv[2] / pv[3]);
250 frame[0] = min(frame[0], pr[0]);
251 frame[1] = max(frame[1], pr[0]);
252 frame[2] = min(frame[2], pr[1]);
253 frame[3] = max(frame[3], pr[1]);
258 frame[0] = (frame[0] + 1.0f) * 0.5f;
259 frame[1] = (frame[1] + 1.0f) * 0.5f;
260 frame[2] = (frame[2] + 1.0f) * 0.5f;
261 frame[3] = (frame[3] + 1.0f) * 0.5f;
265 frame[0] = max(min(frame[0], (PN_stdfloat)1.0), (PN_stdfloat)0.0);
266 frame[1] = max(min(frame[1], (PN_stdfloat)1.0), frame[0]);
267 frame[2] = max(min(frame[2], (PN_stdfloat)1.0), (PN_stdfloat)0.0);
268 frame[3] = max(min(frame[3], (PN_stdfloat)1.0), frame[2]);
271 CPT(
RenderAttrib) scissor_attrib = ScissorAttrib::make(frame);
272 CPT(
RenderState) state = RenderState::make(scissor_attrib);
273 node_state = node_state->compose(state);
279 if (frustum !=
nullptr) {
280 frustum->xform(modelview_transform->get_inverse()->get_mat());
281 data._view_frustum = frustum;
300 DCAST_INTO_R(ta, other, 0);
302 if (_screen != ta->_screen) {
303 return (
int)_screen - (int)ta->_screen;
305 if (_clip != ta->_clip) {
306 return (
int)_clip - (int)ta->_clip;
309 int compare = _frame.compare_to(ta->_frame);
314 int compare = (int)_points.size() - (int)ta->_points.size();
318 for (
size_t i = 0; i < _points.size(); ++i) {
319 compare = _points[i]._p.compare_to(ta->_points[i]._p);
323 compare = _points[i]._node.compare_to(ta->_points[i]._node);
336 register_with_read_factory() {
350 _frame.write_datagram(dg);
353 Points::const_iterator pi;
354 for (pi = _points.begin(); pi != _points.end(); ++pi) {
355 (*pi)._p.write_datagram(dg);
373 effect->fillin(scan, manager);
384 RenderEffect::fillin(scan, manager);
388 _frame.read_datagram(scan);
391 _points.reserve(num_points);
392 for (
int i = 0; i < num_points; ++i) {
394 point._p.read_datagram(scan);
395 _points.push_back(point);
406 make_frustum(
const Lens *lens,
const LVecBase4 &frame)
const{
408 LVecBase4 f2(frame[0] * 2.0f - 1.0f,
409 frame[1] * 2.0f - 1.0f,
410 frame[2] * 2.0f - 1.0f,
411 frame[3] * 2.0f - 1.0f);
413 LPoint3 fll, flr, ful, fur;
414 LPoint3 nll, nlr, nul, nur;
417 corner[0] = f2[0]; corner[1] = f2[3];
420 if (!lens->
extrude(corner, nul, ful)) {
424 corner[0] = f2[1]; corner[1] = f2[3];
427 if (!lens->
extrude(corner, nur, fur)) {
431 corner[0] = f2[1]; corner[1] = f2[2];
434 if (!lens->
extrude(corner, nlr, flr)) {
438 corner[0] = f2[0]; corner[1] = f2[2];
441 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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...
This is another abstract class, for a general class of bounding volumes that actually enclose points ...
void parse_params(const FactoryParams ¶ms, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
void add_uint16(uint16_t value)
Adds an unsigned 16-bit integer to the datagram.
void add_bool(bool value)
Adds a boolean value to the datagram.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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,...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
uint16_t get_uint16()
Extracts an unsigned 16-bit integer.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
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.
CPT(RenderEffect) ScissorEffect
Constructs a new screen-relative ScissorEffect.
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This defines a bounding convex hexahedron.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.