35ScissorEffect(
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),
64 ScissorEffect *effect =
new ScissorEffect(
true, frame,
nullptr, 0, clip);
65 return return_new(effect);
75 ScissorEffect *effect =
new ScissorEffect(
false, LVecBase4::zero(),
nullptr, 0, clip);
76 return return_new(effect);
89 points[0]._node = node;
91 points[1]._node = node;
92 ScissorEffect *effect =
new ScissorEffect(
false, LVecBase4::zero(), points, 2,
true);
93 return return_new(effect);
103make_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;
113 ScissorEffect *effect =
new ScissorEffect(
false, LVecBase4::zero(), points, 4,
true);
114 return return_new(effect);
128 ScissorEffect *effect =
new ScissorEffect(*
this);
132 effect->_points.push_back(point);
133 return return_new(effect);
140xform(
const LMatrix4 &mat)
const {
144 ScissorEffect *effect =
new ScissorEffect(*
this);
146 for (pi = effect->_points.begin();
147 pi != effect->_points.end();
149 PointDef &point = (*pi);
151 point._p = point._p * mat;
154 return return_new(effect);
161output(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 <<
")";
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);
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);
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);
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);
406make_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)) {
445 return new BoundingHexahedron(fll, flr, fur, ful, nll, nlr, nur, nul);
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void parse_params(const FactoryParams ¶ms, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
SceneSetup * get_scene() const
Returns the SceneSetup object.
A class to retrieve the individual data elements previously stored in a Datagram.
uint16_t get_uint16()
Extracts an unsigned 16-bit integer.
bool get_bool()
Extracts a boolean value.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
void add_bool(bool value)
Adds a boolean value to the datagram.
void add_uint16(uint16_t value)
Adds an unsigned 16-bit integer to the datagram.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
This is another abstract class, for a general class of bounding volumes that actually enclose points ...
A base class for any number of different kinds of lenses, linear and otherwise.
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 (...
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,...
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
bool is_empty() const
Returns true if the NodePath contains no nodes.
This is the base class for a number of render attributes (other than transform) that may be set on sc...
This is the base class for a number of special render effects that may be set on scene graph nodes to...
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 represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
static ConstPointerTo< RenderState > make(const RenderAttrib *attrib, int override=0)
Returns a RenderState with one attribute set.
ConstPointerTo< RenderState > compose(const RenderState *other) const
Returns a new RenderState object that represents the composition of this state with the other state.
const Lens * get_lens() const
Returns the particular Lens used for rendering.
This provides a higher-level wrapper around ScissorAttrib.
virtual bool has_cull_callback() const
Should be overridden by derived classes to return true if cull_callback() has been defined.
virtual ConstPointerTo< RenderEffect > xform(const LMatrix4 &mat) const
Returns a new RenderEffect transformed by the indicated matrix.
static ConstPointerTo< RenderEffect > make_screen(const LVecBase4 &frame, bool clip=true)
Constructs a new screen-relative ScissorEffect.
bool is_screen() const
Returns true if the ScissorEffect is a screen-based effect, meaning get_frame() has a meaningful valu...
ConstPointerTo< RenderEffect > add_point(const LPoint3 &point, const NodePath &node=NodePath()) const
Returns a new ScissorEffect with the indicated point added.
bool get_clip() const
Returns true if this ScissorEffect actually enables scissoring, or false if it culls only.
static ConstPointerTo< RenderEffect > make_node(bool clip=true)
Constructs a new node-relative ScissorEffect, with no points.
static void register_with_read_factory()
Tells the BamReader how to create objects of type ScissorEffect.
virtual void cull_callback(CullTraverser *trav, CullTraverserData &data, ConstPointerTo< TransformState > &node_transform, ConstPointerTo< RenderState > &node_state) const
If has_cull_callback() returns true, this function will be called during the cull traversal to perfor...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
TypeHandle is the identifier used to differentiate C++ class types.
Base class for objects that can be written to and read from Bam files.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.