From 6912d2d48c2a36491e4d78441bb6674d1da290f7 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 23 Mar 2005 23:32:07 +0000 Subject: [PATCH] fix flatten in conjunction with billboards --- panda/src/pgraph/billboardEffect.cxx | 16 ++++++++++++++++ panda/src/pgraph/billboardEffect.h | 1 + panda/src/pgraph/renderEffect.cxx | 13 +++++++++++++ panda/src/pgraph/renderEffect.h | 1 + panda/src/pgraph/renderEffects.cxx | 20 ++++++++++++++++++++ panda/src/pgraph/renderEffects.h | 1 + panda/src/pgraph/sceneGraphReducer.cxx | 1 + 7 files changed, 53 insertions(+) diff --git a/panda/src/pgraph/billboardEffect.cxx b/panda/src/pgraph/billboardEffect.cxx index 8f13698886..b4602ea7fd 100644 --- a/panda/src/pgraph/billboardEffect.cxx +++ b/panda/src/pgraph/billboardEffect.cxx @@ -61,6 +61,22 @@ safe_to_transform() const { return false; } +//////////////////////////////////////////////////////////////////// +// Function: BillboardEffect::prepare_flatten_transform +// Access: Public, Virtual +// Description: Preprocesses the accumulated transform that is about +// to be applied to (or through) this node due to a +// flatten operation. The returned value will be used +// instead. +//////////////////////////////////////////////////////////////////// +CPT(TransformState) BillboardEffect:: +prepare_flatten_transform(const TransformState *net_transform) const { + // We don't want any flatten operation to rotate the billboarded + // node, since the billboard effect should eat any rotation that + // comes in from above. + return net_transform->set_hpr(LVecBase3f(0, 0, 0)); +} + //////////////////////////////////////////////////////////////////// // Function: BillboardEffect::output // Access: Public, Virtual diff --git a/panda/src/pgraph/billboardEffect.h b/panda/src/pgraph/billboardEffect.h index 5d0c6bb20f..4080d1dbba 100644 --- a/panda/src/pgraph/billboardEffect.h +++ b/panda/src/pgraph/billboardEffect.h @@ -56,6 +56,7 @@ PUBLISHED: public: virtual bool safe_to_transform() const; + virtual CPT(TransformState) prepare_flatten_transform(const TransformState *net_transform) const; virtual void output(ostream &out) const; virtual bool has_cull_callback() const; diff --git a/panda/src/pgraph/renderEffect.cxx b/panda/src/pgraph/renderEffect.cxx index 198382d522..5717b0aa65 100644 --- a/panda/src/pgraph/renderEffect.cxx +++ b/panda/src/pgraph/renderEffect.cxx @@ -102,6 +102,19 @@ safe_to_transform() const { return true; } +//////////////////////////////////////////////////////////////////// +// Function: RenderEffect::prepare_flatten_transform +// Access: Public, Virtual +// Description: Preprocesses the accumulated transform that is about +// to be applied to (or through) this node due to a +// flatten operation. The returned value will be used +// instead. +//////////////////////////////////////////////////////////////////// +CPT(TransformState) RenderEffect:: +prepare_flatten_transform(const TransformState *net_transform) const { + return net_transform; +} + //////////////////////////////////////////////////////////////////// // Function: RenderEffect::safe_to_combine // Access: Public, Virtual diff --git a/panda/src/pgraph/renderEffect.h b/panda/src/pgraph/renderEffect.h index fe95dab599..ed2b0d189f 100644 --- a/panda/src/pgraph/renderEffect.h +++ b/panda/src/pgraph/renderEffect.h @@ -67,6 +67,7 @@ public: virtual ~RenderEffect(); virtual bool safe_to_transform() const; + virtual CPT(TransformState) prepare_flatten_transform(const TransformState *net_transform) const; virtual bool safe_to_combine() const; virtual CPT(RenderEffect) xform(const LMatrix4f &mat) const; diff --git a/panda/src/pgraph/renderEffects.cxx b/panda/src/pgraph/renderEffects.cxx index 326ebfd064..3a55d1b129 100644 --- a/panda/src/pgraph/renderEffects.cxx +++ b/panda/src/pgraph/renderEffects.cxx @@ -109,6 +109,26 @@ safe_to_transform() const { return true; } +//////////////////////////////////////////////////////////////////// +// Function: RenderEffects::prepare_flatten_transform +// Access: Public, Virtual +// Description: Preprocesses the accumulated transform that is about +// to be applied to (or through) this node due to a +// flatten operation. The returned value will be used +// instead. +//////////////////////////////////////////////////////////////////// +CPT(TransformState) RenderEffects:: +prepare_flatten_transform(const TransformState *net_transform) const { + CPT(TransformState) result = net_transform; + Effects::const_iterator ai; + for (ai = _effects.begin(); ai != _effects.end(); ++ai) { + const Effect &effect = (*ai); + result = effect._effect->prepare_flatten_transform(result); + } + + return result; +} + //////////////////////////////////////////////////////////////////// // Function: RenderEffects::safe_to_combine // Access: Public diff --git a/panda/src/pgraph/renderEffects.h b/panda/src/pgraph/renderEffects.h index a34f6ee825..b5fcfa3433 100644 --- a/panda/src/pgraph/renderEffects.h +++ b/panda/src/pgraph/renderEffects.h @@ -57,6 +57,7 @@ public: virtual ~RenderEffects(); bool safe_to_transform() const; + virtual CPT(TransformState) prepare_flatten_transform(const TransformState *net_transform) const; bool safe_to_combine() const; CPT(RenderEffects) xform(const LMatrix4f &mat) const; diff --git a/panda/src/pgraph/sceneGraphReducer.cxx b/panda/src/pgraph/sceneGraphReducer.cxx index 607cb22893..68a8b267b7 100644 --- a/panda/src/pgraph/sceneGraphReducer.cxx +++ b/panda/src/pgraph/sceneGraphReducer.cxx @@ -114,6 +114,7 @@ r_apply_attribs(PandaNode *node, const AccumulatedAttribs &attribs, << "Node " << *node << " contains a non-transformable effect; leaving transform here.\n"; } + next_attribs._transform = effects->prepare_flatten_transform(next_attribs._transform); apply_types |= TT_transform; } if (!node->safe_to_transform()) {