mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
added some more functionalities to the portal code
This commit is contained in:
parent
91b21b863a
commit
4d6434e210
@ -134,10 +134,28 @@ draw_hexahedron(BoundingHexahedron *frustum) {
|
|||||||
draw_to(frustum->get_point(2));
|
draw_to(frustum->get_point(2));
|
||||||
}
|
}
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: PortalClipper::draw the current visible portal
|
||||||
|
// Access: Public
|
||||||
|
// Description: _portal_node is the current portal, draw it.
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void PortalClipper::
|
||||||
|
draw_current_portal()
|
||||||
|
{
|
||||||
|
move_to(_portal_node->get_vertex(0));
|
||||||
|
draw_to(_portal_node->get_vertex(1));
|
||||||
|
draw_to(_portal_node->get_vertex(2));
|
||||||
|
draw_to(_portal_node->get_vertex(3));
|
||||||
|
}
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: PortalClipper::draw the lines
|
// Function: PortalClipper::draw the lines
|
||||||
// Access: Public
|
// Access: Public
|
||||||
// Description: Draw all the lines in the buffer
|
// Description: Draw all the lines in the buffer
|
||||||
//
|
// Yellow portal is the original geometry of the portal
|
||||||
|
// Cyan portal is the minmax adjusted portal
|
||||||
|
// Red portal is the clipped against frustum portal
|
||||||
|
// Blue frustum is the frustum through portal
|
||||||
|
// White frustum is the camera frustum
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void PortalClipper::
|
void PortalClipper::
|
||||||
draw_lines()
|
draw_lines()
|
||||||
@ -221,8 +239,11 @@ prepare_portal(const NodePath &node_path)
|
|||||||
// Get the Portal Node from this node_path
|
// Get the Portal Node from this node_path
|
||||||
PandaNode *node = node_path.node();
|
PandaNode *node = node_path.node();
|
||||||
_portal_node = NULL;
|
_portal_node = NULL;
|
||||||
if (node->is_of_type(PortalNode::get_class_type()))
|
if (node->is_of_type(PortalNode::get_class_type())) {
|
||||||
_portal_node = DCAST(PortalNode, node);
|
_portal_node = DCAST(PortalNode, node);
|
||||||
|
// lets draw the portal anyway
|
||||||
|
//draw_current_portal();
|
||||||
|
}
|
||||||
|
|
||||||
// walk the portal
|
// walk the portal
|
||||||
_num_vert = 0;
|
_num_vert = 0;
|
||||||
|
@ -82,6 +82,8 @@ public:
|
|||||||
INLINE void draw_to(float x, float y, float z);
|
INLINE void draw_to(float x, float y, float z);
|
||||||
void draw_to(const LVecBase3f &v);
|
void draw_to(const LVecBase3f &v);
|
||||||
|
|
||||||
|
void draw_current_portal();
|
||||||
|
|
||||||
INLINE float get_plane_depth(float x, float z, Planef *portal_plane);
|
INLINE float get_plane_depth(float x, float z, Planef *portal_plane);
|
||||||
|
|
||||||
INLINE BoundingHexahedron *get_reduced_frustum() const;
|
INLINE BoundingHexahedron *get_reduced_frustum() const;
|
||||||
|
@ -169,38 +169,38 @@ get_vertex(int n) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: PortalNode::set_zone_in
|
// Function: PortalNode::set_cell_in
|
||||||
// Access: Published
|
// Access: Published
|
||||||
// Description: Sets the zone that this portal belongs to
|
// Description: Sets the cell that this portal belongs to
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE void PortalNode::set_zone_in(const NodePath &zone) {
|
INLINE void PortalNode::set_cell_in(const NodePath &cell) {
|
||||||
_zone_in = zone;
|
_cell_in = cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: PortalNode::get_zone_in
|
// Function: PortalNode::get_cell_in
|
||||||
// Access: Published
|
// Access: Published
|
||||||
// Description: Sets the zone that this portal belongs to
|
// Description: Sets the cell that this portal belongs to
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE NodePath PortalNode::get_zone_in() const {
|
INLINE NodePath PortalNode::get_cell_in() const {
|
||||||
return _zone_in;
|
return _cell_in;
|
||||||
}
|
}
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: PortalNode::set_zone_out
|
// Function: PortalNode::set_cell_out
|
||||||
// Access: Published
|
// Access: Published
|
||||||
// Description: Sets the zone that this portal leads out to
|
// Description: Sets the cell that this portal leads out to
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE void PortalNode::set_zone_out(const NodePath &zone) {
|
INLINE void PortalNode::set_cell_out(const NodePath &cell) {
|
||||||
_zone_out = zone;
|
_cell_out = cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: PortalNode::get_zone_out
|
// Function: PortalNode::get_cell_out
|
||||||
// Access: Published
|
// Access: Published
|
||||||
// Description: Sets the zone that this portal leads out to
|
// Description: Sets the cell that this portal leads out to
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE NodePath PortalNode::get_zone_out() const {
|
INLINE NodePath PortalNode::get_cell_out() const {
|
||||||
return _zone_out;
|
return _cell_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
@ -37,7 +37,10 @@ TypeHandle PortalNode::_type_handle;
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: PortalNode::Constructor
|
// Function: PortalNode::Constructor
|
||||||
// Access: Public
|
// Access: Public
|
||||||
// Description:
|
// Description: Default constructor, just an empty node, no geo
|
||||||
|
// This is used to read portal from model. You can also
|
||||||
|
// use this from python to create an empty portal. Then
|
||||||
|
// you can set the vertices yourself, with addVertex.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
PortalNode::
|
PortalNode::
|
||||||
PortalNode(const string &name) :
|
PortalNode(const string &name) :
|
||||||
@ -46,8 +49,31 @@ PortalNode(const string &name) :
|
|||||||
_into_portal_mask(PortalMask::all_on()),
|
_into_portal_mask(PortalMask::all_on()),
|
||||||
_flags(0)
|
_flags(0)
|
||||||
{
|
{
|
||||||
_zone_in = NULL;
|
_cell_in = NULL;
|
||||||
_zone_out = NULL;
|
_cell_out = NULL;
|
||||||
|
_visible = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: PortalNode::Constructor
|
||||||
|
// Access: Public
|
||||||
|
// Description: Create a default rectangle as portal. Use this
|
||||||
|
// to create an arbitrary portal and setup from Python
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
PortalNode::
|
||||||
|
PortalNode(const string &name, LPoint3f pos, float scale) :
|
||||||
|
PandaNode(name),
|
||||||
|
_from_portal_mask(PortalMask::all_on()),
|
||||||
|
_into_portal_mask(PortalMask::all_on()),
|
||||||
|
_flags(0)
|
||||||
|
{
|
||||||
|
add_vertex(LPoint3f(pos[0]-1.0*scale, pos[1], pos[2]-1.0*scale));
|
||||||
|
add_vertex(LPoint3f(pos[0]+1.0*scale, pos[1], pos[2]-1.0*scale));
|
||||||
|
add_vertex(LPoint3f(pos[0]+1.0*scale, pos[1], pos[2]+1.0*scale));
|
||||||
|
add_vertex(LPoint3f(pos[0]-1.0*scale, pos[1], pos[2]+1.0*scale));
|
||||||
|
|
||||||
|
_cell_in = NULL;
|
||||||
|
_cell_out = NULL;
|
||||||
_visible = true;
|
_visible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,8 +89,8 @@ PortalNode(const PortalNode ©) :
|
|||||||
_into_portal_mask(copy._into_portal_mask),
|
_into_portal_mask(copy._into_portal_mask),
|
||||||
_flags(copy._flags)
|
_flags(copy._flags)
|
||||||
{
|
{
|
||||||
_zone_in = copy._zone_in;
|
_cell_in = copy._cell_in;
|
||||||
_zone_out = copy._zone_in;
|
_cell_out = copy._cell_in;
|
||||||
_visible = copy._visible;
|
_visible = copy._visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,7 +195,7 @@ has_cull_callback() const {
|
|||||||
// will be called during the cull traversal to perform
|
// will be called during the cull traversal to perform
|
||||||
// reduced frustum culling. Basically, once the scenegraph
|
// reduced frustum culling. Basically, once the scenegraph
|
||||||
// comes across a portal node, it calculates a CulltraverserData
|
// comes across a portal node, it calculates a CulltraverserData
|
||||||
// with which zone, this portal leads out to and the new frustum.
|
// with which cell, this portal leads out to and the new frustum.
|
||||||
// Then it traverses that child
|
// Then it traverses that child
|
||||||
//
|
//
|
||||||
// The return value is true if this node should be
|
// The return value is true if this node should be
|
||||||
@ -178,8 +204,8 @@ has_cull_callback() const {
|
|||||||
bool PortalNode::
|
bool PortalNode::
|
||||||
cull_callback(CullTraverser *trav, CullTraverserData &data) {
|
cull_callback(CullTraverser *trav, CullTraverserData &data) {
|
||||||
PortalClipper *portal_viewer = trav->get_portal_clipper();
|
PortalClipper *portal_viewer = trav->get_portal_clipper();
|
||||||
if (!_zone_out.is_empty() && portal_viewer) {
|
if (is_visible() && !_cell_out.is_empty() && portal_viewer) {
|
||||||
//CullTraverserData next_data(data, _zone_out);
|
//CullTraverserData next_data(data, _cell_out);
|
||||||
pgraph_cat.debug() << "checking portal node " << *this << endl;
|
pgraph_cat.debug() << "checking portal node " << *this << endl;
|
||||||
PT(GeometricBoundingVolume) vf = trav->get_view_frustum();
|
PT(GeometricBoundingVolume) vf = trav->get_view_frustum();
|
||||||
PT(BoundingVolume) reduced_frustum;
|
PT(BoundingVolume) reduced_frustum;
|
||||||
@ -197,23 +223,23 @@ cull_callback(CullTraverser *trav, CullTraverserData &data) {
|
|||||||
|
|
||||||
// trasform it to cull_center space
|
// trasform it to cull_center space
|
||||||
CPT(TransformState) cull_center_transform =
|
CPT(TransformState) cull_center_transform =
|
||||||
portal_viewer->_scene_setup->get_cull_center().get_transform(_zone_out);
|
portal_viewer->_scene_setup->get_cull_center().get_transform(_cell_out);
|
||||||
vf->xform(cull_center_transform->get_mat());
|
vf->xform(cull_center_transform->get_mat());
|
||||||
|
|
||||||
pgraph_cat.spam() << "vf is " << *vf << "\n";
|
pgraph_cat.spam() << "vf is " << *vf << "\n";
|
||||||
|
|
||||||
// Get the net trasform of the _zone_out
|
// Get the net trasform of the _cell_out
|
||||||
CPT(TransformState) zone_transform = _zone_out.get_net_transform();
|
CPT(TransformState) cell_transform = _cell_out.get_net_transform();
|
||||||
|
|
||||||
CullTraverserData next_data(_zone_out, trav->get_render_transform()->compose(zone_transform),
|
CullTraverserData next_data(_cell_out, trav->get_render_transform()->compose(cell_transform),
|
||||||
zone_transform,
|
cell_transform,
|
||||||
trav->get_initial_state(), vf,
|
trav->get_initial_state(), vf,
|
||||||
trav->get_guard_band());
|
trav->get_guard_band());
|
||||||
|
|
||||||
pgraph_cat.spam() << "cull_callback: traversing " << _zone_out.get_name() << endl;
|
pgraph_cat.spam() << "cull_callback: traversing " << _cell_out.get_name() << endl;
|
||||||
|
|
||||||
// Make this zone show with the reduced frustum
|
// Make this cell show with the reduced frustum
|
||||||
_zone_out.show();
|
_cell_out.show();
|
||||||
|
|
||||||
// all nodes visible through this portal, should have this node's frustum
|
// all nodes visible through this portal, should have this node's frustum
|
||||||
BoundingHexahedron *old_bh = portal_viewer->get_reduced_frustum();
|
BoundingHexahedron *old_bh = portal_viewer->get_reduced_frustum();
|
||||||
@ -221,7 +247,7 @@ cull_callback(CullTraverser *trav, CullTraverserData &data) {
|
|||||||
trav->traverse(next_data);
|
trav->traverse(next_data);
|
||||||
|
|
||||||
// make sure traverser is not drawing this node again
|
// make sure traverser is not drawing this node again
|
||||||
_zone_out.hide();
|
_cell_out.hide();
|
||||||
|
|
||||||
// reset portal viewer frustum for the siblings;
|
// reset portal viewer frustum for the siblings;
|
||||||
portal_viewer->set_reduced_frustum(old_bh);
|
portal_viewer->set_reduced_frustum(old_bh);
|
||||||
@ -245,6 +271,22 @@ output(ostream &out) const {
|
|||||||
PandaNode::output(out);
|
PandaNode::output(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: PortalNode::draw
|
||||||
|
// Access: Public
|
||||||
|
// Description: Draws the vertices of this portal rectangle to the
|
||||||
|
// screen with a line
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void PortalNode::
|
||||||
|
draw() const {
|
||||||
|
move_to(get_vertex(0));
|
||||||
|
draw_to(get_vertex(1));
|
||||||
|
draw_to(get_vertex(2));
|
||||||
|
draw_to(get_vertex(3));
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: PortalNode::recompute_bound
|
// Function: PortalNode::recompute_bound
|
||||||
|
@ -31,12 +31,13 @@
|
|||||||
// Description : A node in the scene graph that can hold a
|
// Description : A node in the scene graph that can hold a
|
||||||
// Portal Polygon, which is a rectangle. Other
|
// Portal Polygon, which is a rectangle. Other
|
||||||
// types of polygons are not supported for
|
// types of polygons are not supported for
|
||||||
// now. It also holds a PT(PandaNode) Zone that
|
// now. It also holds a PT(PandaNode) Cell that
|
||||||
// this portal is connected to
|
// this portal is connected to
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
class EXPCL_PANDA PortalNode : public PandaNode {
|
class EXPCL_PANDA PortalNode : public PandaNode {
|
||||||
PUBLISHED:
|
PUBLISHED:
|
||||||
PortalNode(const string &name);
|
PortalNode(const string &name);
|
||||||
|
PortalNode(const string &name, LPoint3f pos, float scale=10.0);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PortalNode(const PortalNode ©);
|
PortalNode(const PortalNode ©);
|
||||||
@ -69,15 +70,16 @@ PUBLISHED:
|
|||||||
INLINE int get_num_vertices() const;
|
INLINE int get_num_vertices() const;
|
||||||
INLINE const LPoint3f &get_vertex(int n) const;
|
INLINE const LPoint3f &get_vertex(int n) const;
|
||||||
|
|
||||||
INLINE void set_zone_in(const NodePath &zone);
|
INLINE void set_cell_in(const NodePath &cell);
|
||||||
INLINE NodePath get_zone_in() const;
|
INLINE NodePath get_cell_in() const;
|
||||||
|
|
||||||
INLINE void set_zone_out(const NodePath &zone);
|
INLINE void set_cell_out(const NodePath &cell);
|
||||||
INLINE NodePath get_zone_out() const;
|
INLINE NodePath get_cell_out() const;
|
||||||
|
|
||||||
INLINE void set_visible(bool value);
|
INLINE void set_visible(bool value);
|
||||||
INLINE bool is_visible();
|
INLINE bool is_visible();
|
||||||
|
|
||||||
|
// void draw () const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual BoundingVolume *recompute_bound();
|
virtual BoundingVolume *recompute_bound();
|
||||||
@ -101,8 +103,8 @@ private:
|
|||||||
typedef pvector<LPoint3f> Vertices;
|
typedef pvector<LPoint3f> Vertices;
|
||||||
Vertices _vertices;
|
Vertices _vertices;
|
||||||
|
|
||||||
NodePath _zone_in; // This is the zone it resides in
|
NodePath _cell_in; // This is the cell it resides in
|
||||||
NodePath _zone_out; // This is the zone it leads out to
|
NodePath _cell_out; // This is the cell it leads out to
|
||||||
|
|
||||||
bool _visible;
|
bool _visible;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user