Browse Source

the real uv scroll node. Not sure what happened with the commit

Zachary Pavlov 16 years ago
parent
commit
8950ddbf15
3 changed files with 108 additions and 22 deletions
  1. 32 10
      panda/src/pgraph/uvScrollNode.I
  2. 65 9
      panda/src/pgraph/uvScrollNode.cxx
  3. 11 3
      panda/src/pgraph/uvScrollNode.h

+ 32 - 10
panda/src/pgraph/uvScrollNode.I

@@ -1,5 +1,5 @@
-// Filename: modelNode.I
-// Created by:  drose (16Mar02)
+// Filename: uvScrollNode.I
+// Created by:  zpavlov (30june09)
 //
 //
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //
 //
@@ -14,20 +14,22 @@
 
 
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//     Function: ModelNode::Constructor
+//     Function: UvScrollNode::Constructor
 //       Access: Public
 //       Access: Public
 //  Description:
 //  Description:
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE UvScrollNode::
 INLINE UvScrollNode::
 UvScrollNode(const string &name, float u_speed, float v_speed) :
 UvScrollNode(const string &name, float u_speed, float v_speed) :
-  ModelNode(name)
+  PandaNode(name),
+  _u_speed(u_speed),
+  _v_speed(v_speed)
 {
 {
-  _u_speed = u_speed;
-  _v_speed = v_speed;
+  set_cull_callback();
+  _start_time = ClockObject::get_global_clock()->get_frame_time();
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//     Function: set_u_speed
+//     Function: UvSctrollNode::set_u_speed
 //       Access: Published
 //       Access: Published
 //  Description:
 //  Description:
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -37,7 +39,7 @@ set_u_speed(float u_speed) {
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//     Function: set_v_speed
+//     Function: UvSctrollNode::set_v_speed
 //       Access: Published
 //       Access: Published
 //  Description:
 //  Description:
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -48,13 +50,33 @@ set_v_speed(float v_speed) {
 
 
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//     Function: ModelNode::Copy Constructor
+//     Function: UvSctrollNode::get_u_speed
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE float UvScrollNode::
+get_u_speed() const {
+  return _u_speed;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: UvSctrollNode::get_v_speed
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE float UvScrollNode::
+get_v_speed() const {
+  return _v_speed;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: UvScrollNode::Copy Constructor
 //       Access: Protected
 //       Access: Protected
 //  Description:
 //  Description:
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE UvScrollNode::
 INLINE UvScrollNode::
 UvScrollNode(const UvScrollNode &copy) :
 UvScrollNode(const UvScrollNode &copy) :
-  ModelNode(copy),
+  PandaNode(copy),
   _u_speed(copy._u_speed),
   _u_speed(copy._u_speed),
   _v_speed(copy._v_speed)
   _v_speed(copy._v_speed)
 {
 {

+ 65 - 9
panda/src/pgraph/uvScrollNode.cxx

@@ -17,6 +17,11 @@
 #include "bamReader.h"
 #include "bamReader.h"
 #include "datagram.h"
 #include "datagram.h"
 #include "datagramIterator.h"
 #include "datagramIterator.h"
+#include "luse.h"
+#include "renderState.h"
+#include "texMatrixAttrib.h"
+#include "textureStage.h"
+#include "transformState.h"
 
 
 TypeHandle UvScrollNode::_type_handle;
 TypeHandle UvScrollNode::_type_handle;
 
 
@@ -35,10 +40,10 @@ make_copy() const {
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//     Function: ModelNode::register_with_read_factory
+//     Function: UvSctrollNode::register_with_read_factory
 //       Access: Public, Static
 //       Access: Public, Static
 //  Description: Tells the BamReader how to create objects of type
 //  Description: Tells the BamReader how to create objects of type
-//               ModelNode.
+//               UvScrollNode.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void UvScrollNode::
 void UvScrollNode::
 register_with_read_factory() {
 register_with_read_factory() {
@@ -46,16 +51,16 @@ register_with_read_factory() {
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//     Function: ModelNode::write_datagram
+//     Function: UvSctrollNode::write_datagram
 //       Access: Public, Virtual
 //       Access: Public, Virtual
 //  Description: Writes the contents of this object to the datagram
 //  Description: Writes the contents of this object to the datagram
 //               for shipping out to a Bam file.
 //               for shipping out to a Bam file.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void UvScrollNode::
 void UvScrollNode::
 write_datagram(BamWriter *manager, Datagram &dg) {
 write_datagram(BamWriter *manager, Datagram &dg) {
-  ModelNode::write_datagram(manager, dg);
-  dg.add_float64(_u_speed);
-  dg.add_float64(_v_speed);
+  PandaNode::write_datagram(manager, dg);
+  dg.add_float32(_u_speed);
+  dg.add_float32(_v_speed);
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -68,7 +73,7 @@ write_datagram(BamWriter *manager, Datagram &dg) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 TypedWritable *UvScrollNode::
 TypedWritable *UvScrollNode::
 make_from_bam(const FactoryParams &params) {
 make_from_bam(const FactoryParams &params) {
-  UvScrollNode *node = new UvScrollNode("", 0.0, 0.0);
+  UvScrollNode *node = new UvScrollNode("",0,0);
   DatagramIterator scan;
   DatagramIterator scan;
   BamReader *manager;
   BamReader *manager;
 
 
@@ -89,6 +94,57 @@ void UvScrollNode::
 fillin(DatagramIterator &scan, BamReader *manager) {
 fillin(DatagramIterator &scan, BamReader *manager) {
   PandaNode::fillin(scan, manager);
   PandaNode::fillin(scan, manager);
 
 
-  _u_speed = scan.get_float64();
-  _v_speed = scan.get_float64();
+  _u_speed = scan.get_float32();
+  _v_speed = scan.get_float32();
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: SequenceNode::cull_callback
+//       Access: Public, Virtual
+//  Description: This function will be called during the cull
+//               traversal to perform any additional operations that
+//               should be performed at cull time.  This may include
+//               additional manipulation of render state or additional
+//               visible/invisible decisions, or any other arbitrary
+//               operation.
+//
+//               Note that this function will *not* be called unless
+//               set_cull_callback() is called in the constructor of
+//               the derived class.  It is necessary to call
+//               set_cull_callback() to indicated that we require
+//               cull_callback() to be called.
+//
+//               By the time this function is called, the node has
+//               already passed the bounding-volume test for the
+//               viewing frustum, and the node's transform and state
+//               have already been applied to the indicated
+//               CullTraverserData object.
+//
+//               The return value is \true if this node should be
+//               visible, or false if it should be culled.
+////////////////////////////////////////////////////////////////////
+bool UvScrollNode::
+cull_callback(CullTraverser * trav, CullTraverserData &data) {
+  double elapsed = ClockObject::get_global_clock()->get_frame_time() - _start_time; 
+  CPT(TransformState) ts = TransformState::make_pos2d(LVecBase2f(cmod(elapsed*_u_speed,1.0)/1.0, cmod(elapsed*_v_speed,1.0)/1.0));
+  CPT(RenderAttrib) tm = TexMatrixAttrib::make(TextureStage::get_default(), ts);
+  CPT(RenderState) rs = RenderState::make_empty()->set_attrib(tm);
+  data._state = data._state->compose(rs);
+   
+  return true;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: UvScrollNode::safe_to_flatten
+//       Access: Public, Virtual
+//  Description: Returns true if it is generally safe to flatten out
+//               this particular kind of PandaNode by duplicating
+//               instances (by calling dupe_for_flatten()), false
+//               otherwise (for instance, a Camera cannot be safely
+//               flattened, because the Camera pointer itself is
+//               meaningful).
+////////////////////////////////////////////////////////////////////
+bool UvScrollNode::
+safe_to_flatten() const {
+  return false;
 }
 }

+ 11 - 3
panda/src/pgraph/uvScrollNode.h

@@ -17,14 +17,16 @@
 
 
 #include "pandabase.h"
 #include "pandabase.h"
 
 
-#include "modelNode.h"
+#include "animInterface.h"
+#include "pandaNode.h"
+
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //       Class : UvScrollNode
 //       Class : UvScrollNode
 // Description : This node is placed at key points within the scene
 // Description : This node is placed at key points within the scene
 //               graph to animate uvs. 
 //               graph to animate uvs. 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-class EXPCL_PANDA_PGRAPH UvScrollNode : public ModelNode {
+class EXPCL_PANDA_PGRAPH UvScrollNode : public PandaNode {
 PUBLISHED:
 PUBLISHED:
   INLINE UvScrollNode(const string &name, float u_speed, float v_speed);
   INLINE UvScrollNode(const string &name, float u_speed, float v_speed);
 
 
@@ -33,15 +35,21 @@ protected:
 
 
 public:
 public:
   virtual PandaNode *make_copy() const;
   virtual PandaNode *make_copy() const;
+  virtual bool safe_to_flatten() const;
+  virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
 
 
 PUBLISHED:
 PUBLISHED:
   INLINE void set_u_speed(float u_speed);
   INLINE void set_u_speed(float u_speed);
   INLINE void set_v_speed(float v_speed);
   INLINE void set_v_speed(float v_speed);
-
+  INLINE float get_u_speed() const;
+  INLINE float get_v_speed() const;
+  
 private:
 private:
   float _u_speed;
   float _u_speed;
   float _v_speed;
   float _v_speed;
 
 
+  double _start_time;
+
 public:
 public:
   static void register_with_read_factory();
   static void register_with_read_factory();
   virtual void write_datagram(BamWriter *manager, Datagram &dg);
   virtual void write_datagram(BamWriter *manager, Datagram &dg);