|
@@ -30,10 +30,12 @@ TypeHandle LensNode::_type_handle;
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
LensNode::
|
|
LensNode::
|
|
|
LensNode(const string &name, Lens *lens) :
|
|
LensNode(const string &name, Lens *lens) :
|
|
|
- PandaNode(name),
|
|
|
|
|
- _lens(lens)
|
|
|
|
|
|
|
+ PandaNode(name)
|
|
|
{
|
|
{
|
|
|
- _lens_is_active.push_back(true); // The default lens is on by default.
|
|
|
|
|
|
|
+ if (lens == NULL) {
|
|
|
|
|
+ lens = new PerspectiveLens;
|
|
|
|
|
+ }
|
|
|
|
|
+ set_lens(0, lens);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
@@ -44,9 +46,8 @@ LensNode(const string &name, Lens *lens) :
|
|
|
LensNode::
|
|
LensNode::
|
|
|
LensNode(const LensNode ©) :
|
|
LensNode(const LensNode ©) :
|
|
|
PandaNode(copy),
|
|
PandaNode(copy),
|
|
|
- _lens(copy._lens)
|
|
|
|
|
|
|
+ _lenses(copy._lenses)
|
|
|
{
|
|
{
|
|
|
- _lens_is_active.push_back(true); // The default lens is on by default.
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
@@ -75,6 +76,65 @@ make_copy() const {
|
|
|
return new LensNode(*this);
|
|
return new LensNode(*this);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
|
|
+// Function: LensNode::set_lens
|
|
|
|
|
+// Access: Published
|
|
|
|
|
+// Description: Sets the indicated lens. Although a LensNode
|
|
|
|
|
+// normally holds only one lens, it may optionally
|
|
|
|
|
+// include multiple lenses, each with a different index
|
|
|
|
|
+// number. The different lenses may be referenced by
|
|
|
|
|
+// index number on the DisplayRegion. Adding a new lens
|
|
|
|
|
+// automatically makes it active.
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
|
|
+void LensNode::
|
|
|
|
|
+set_lens(int index, Lens *lens) {
|
|
|
|
|
+ nassertv(index >= 0 && index < max_lenses); // Sanity check
|
|
|
|
|
+
|
|
|
|
|
+ while (index >= (int)_lenses.size()) {
|
|
|
|
|
+ LensSlot slot;
|
|
|
|
|
+ slot._is_active = false;
|
|
|
|
|
+ _lenses.push_back(slot);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ _lenses[index]._lens = lens;
|
|
|
|
|
+ _lenses[index]._is_active = true;
|
|
|
|
|
+
|
|
|
|
|
+ if (_shown_frustum != (PandaNode *)NULL) {
|
|
|
|
|
+ show_frustum();
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
|
|
+// Function: LensNode::set_lens_active
|
|
|
|
|
+// Access: Published
|
|
|
|
|
+// Description: Sets the active flag for the nth lens. When a lens
|
|
|
|
|
+// is inactive, it is not used for rendering, and any
|
|
|
|
|
+// DisplayRegions associated with it are implicitly
|
|
|
|
|
+// inactive as well. Returns true if the flag is
|
|
|
|
|
+// changed, false if it already had this value.
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
|
|
+bool LensNode::
|
|
|
|
|
+set_lens_active(int index, bool flag) {
|
|
|
|
|
+ nassertr(index >= 0 && index < max_lenses, false);
|
|
|
|
|
+
|
|
|
|
|
+ while (index >= (int)_lenses.size()) {
|
|
|
|
|
+ LensSlot slot;
|
|
|
|
|
+ slot._is_active = false;
|
|
|
|
|
+ _lenses.push_back(slot);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (_lenses[index]._is_active == flag) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ _lenses[index]._is_active = flag;
|
|
|
|
|
+
|
|
|
|
|
+ if (_shown_frustum != (PandaNode *)NULL) {
|
|
|
|
|
+ show_frustum();
|
|
|
|
|
+ }
|
|
|
|
|
+ return true;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
// Function: LensNode::is_in_view
|
|
// Function: LensNode::is_in_view
|
|
|
// Access: Published
|
|
// Access: Published
|
|
@@ -83,8 +143,10 @@ make_copy() const {
|
|
|
// see the point).
|
|
// see the point).
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
bool LensNode::
|
|
bool LensNode::
|
|
|
-is_in_view(const LPoint3f &pos) {
|
|
|
|
|
- PT(BoundingVolume) bv = _lens->make_bounds();
|
|
|
|
|
|
|
+is_in_view(int index, const LPoint3f &pos) {
|
|
|
|
|
+ Lens *lens = get_lens(index);
|
|
|
|
|
+ nassertr(lens != (Lens *)NULL, false);
|
|
|
|
|
+ PT(BoundingVolume) bv = lens->make_bounds();
|
|
|
if (bv == (BoundingVolume *)NULL) {
|
|
if (bv == (BoundingVolume *)NULL) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -109,8 +171,12 @@ show_frustum() {
|
|
|
_shown_frustum = geom_node;
|
|
_shown_frustum = geom_node;
|
|
|
add_child(_shown_frustum);
|
|
add_child(_shown_frustum);
|
|
|
|
|
|
|
|
- if (_lens != (Lens *)NULL) {
|
|
|
|
|
- geom_node->add_geom(_lens->make_geometry());
|
|
|
|
|
|
|
+ for (Lenses::const_iterator li = _lenses.begin();
|
|
|
|
|
+ li != _lenses.end();
|
|
|
|
|
+ ++li) {
|
|
|
|
|
+ if ((*li)._is_active && (*li)._lens != (Lens *)NULL) {
|
|
|
|
|
+ geom_node->add_geom((*li)._lens->make_geometry());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -136,11 +202,17 @@ hide_frustum() {
|
|
|
void LensNode::
|
|
void LensNode::
|
|
|
output(ostream &out) const {
|
|
output(ostream &out) const {
|
|
|
PandaNode::output(out);
|
|
PandaNode::output(out);
|
|
|
- if (_lens != (Lens *)NULL) {
|
|
|
|
|
- out << " (";
|
|
|
|
|
- _lens->output(out);
|
|
|
|
|
- out << ")";
|
|
|
|
|
|
|
+
|
|
|
|
|
+ out << " (";
|
|
|
|
|
+ for (Lenses::const_iterator li = _lenses.begin();
|
|
|
|
|
+ li != _lenses.end();
|
|
|
|
|
+ ++li) {
|
|
|
|
|
+ if ((*li)._is_active && (*li)._lens != (Lens *)NULL) {
|
|
|
|
|
+ out << " ";
|
|
|
|
|
+ (*li)._lens->output(out);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ out << " )";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
@@ -151,8 +223,13 @@ output(ostream &out) const {
|
|
|
void LensNode::
|
|
void LensNode::
|
|
|
write(ostream &out, int indent_level) const {
|
|
write(ostream &out, int indent_level) const {
|
|
|
PandaNode::write(out, indent_level);
|
|
PandaNode::write(out, indent_level);
|
|
|
- if (_lens != (Lens *)NULL) {
|
|
|
|
|
- _lens->write(out, indent_level + 2);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ for (Lenses::const_iterator li = _lenses.begin();
|
|
|
|
|
+ li != _lenses.end();
|
|
|
|
|
+ ++li) {
|
|
|
|
|
+ if ((*li)._is_active && (*li)._lens != (Lens *)NULL) {
|
|
|
|
|
+ (*li)._lens->write(out, indent_level + 2);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -177,7 +254,10 @@ void LensNode::
|
|
|
write_datagram(BamWriter *manager, Datagram &dg) {
|
|
write_datagram(BamWriter *manager, Datagram &dg) {
|
|
|
PandaNode::write_datagram(manager, dg);
|
|
PandaNode::write_datagram(manager, dg);
|
|
|
|
|
|
|
|
- manager->write_pointer(dg, _lens);
|
|
|
|
|
|
|
+ // For now, we only write out lens 0, simply because that's what we
|
|
|
|
|
+ // always have done. Should probably write out all lenses for the
|
|
|
|
|
+ // future.
|
|
|
|
|
+ manager->write_pointer(dg, get_lens(0));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
@@ -190,7 +270,7 @@ write_datagram(BamWriter *manager, Datagram &dg) {
|
|
|
int LensNode::
|
|
int LensNode::
|
|
|
complete_pointers(TypedWritable **p_list, BamReader *manager) {
|
|
complete_pointers(TypedWritable **p_list, BamReader *manager) {
|
|
|
int pi = PandaNode::complete_pointers(p_list, manager);
|
|
int pi = PandaNode::complete_pointers(p_list, manager);
|
|
|
- _lens = DCAST(Lens, p_list[pi++]);
|
|
|
|
|
|
|
+ set_lens(0, DCAST(Lens, p_list[pi++]));
|
|
|
return pi;
|
|
return pi;
|
|
|
}
|
|
}
|
|
|
|
|
|