Browse Source

added a compose_color_scale interface

Asad M. Zaman 18 years ago
parent
commit
1d0789ecde

+ 1 - 1
panda/src/pgraph/colorScaleAttrib.h

@@ -53,10 +53,10 @@ public:
   virtual bool lower_attrib_can_override() const;
   virtual bool lower_attrib_can_override() const;
   virtual void output(ostream &out) const;
   virtual void output(ostream &out) const;
   virtual void store_into_slot(AttribSlots *slots) const;
   virtual void store_into_slot(AttribSlots *slots) const;
+  virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const;
 
 
 protected:
 protected:
   virtual int compare_to_impl(const RenderAttrib *other) const;
   virtual int compare_to_impl(const RenderAttrib *other) const;
-  virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const;
   virtual CPT(RenderAttrib) invert_compose_impl(const RenderAttrib *other) const;
   virtual CPT(RenderAttrib) invert_compose_impl(const RenderAttrib *other) const;
   virtual RenderAttrib *make_default_impl() const;
   virtual RenderAttrib *make_default_impl() const;
 
 

+ 10 - 0
panda/src/pgraph/nodePath.I

@@ -1179,6 +1179,16 @@ set_color_scale(float sr, float sg, float sb, float sa, int priority) {
   set_color_scale(LVecBase4f(sr, sg, sb, sa), priority);
   set_color_scale(LVecBase4f(sr, sg, sb, sa), priority);
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: NodePath::compose_color_scale
+//       Access: Published
+//  Description: Sets the color scale component of the transform
+////////////////////////////////////////////////////////////////////
+INLINE void NodePath::
+compose_color_scale(float sr, float sg, float sb, float sa, int priority) {
+  compose_color_scale(LVecBase4f(sr, sg, sb, sa), priority);
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: NodePath::set_sr
 //     Function: NodePath::set_sr
 //       Access: Published
 //       Access: Published

+ 33 - 0
panda/src/pgraph/nodePath.cxx

@@ -2146,6 +2146,39 @@ clear_color_scale() {
   node()->clear_attrib(ColorScaleAttrib::get_class_type());
   node()->clear_attrib(ColorScaleAttrib::get_class_type());
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: NodePath::compose_color_scale
+//       Access: Published
+//  Description: multiplies the color scale component of the transform,
+//               with previous color scale leaving translation and 
+//               rotation untouched.
+////////////////////////////////////////////////////////////////////
+void NodePath::
+compose_color_scale(const LVecBase4f &scale, int priority) {
+  nassertv_always(!is_empty());
+
+  const RenderAttrib *attrib =
+    node()->get_attrib(ColorScaleAttrib::get_class_type());
+  if (attrib != (const RenderAttrib *)NULL) {
+    priority = max(priority,
+                   node()->get_state()->get_override(ColorScaleAttrib::get_class_type()));
+    const ColorScaleAttrib *csa = DCAST(ColorScaleAttrib, attrib);
+
+    // Modify the existing ColorScaleAttrib by multiplying with the 
+    // indicated colorScale.
+    LVecBase4f prev_color_scale = csa->get_scale();
+    LVecBase4f new_color_scale(prev_color_scale[0]*scale[0],
+                               prev_color_scale[1]*scale[1],
+                               prev_color_scale[2]*scale[2],
+                               prev_color_scale[3]*scale[3]);
+    node()->set_attrib(csa->set_scale(new_color_scale), priority);
+
+  } else {
+    // Create a new ColorScaleAttrib for this node.
+    node()->set_attrib(ColorScaleAttrib::make(scale), priority);
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: NodePath::set_color_scale
 //     Function: NodePath::set_color_scale
 //       Access: Published
 //       Access: Published

+ 5 - 1
panda/src/pgraph/nodePath.h

@@ -512,8 +512,12 @@ PUBLISHED:
                        int priority = 0);
                        int priority = 0);
   INLINE void set_color_scale(float sx, float sy, float sz, float sa,
   INLINE void set_color_scale(float sx, float sy, float sz, float sa,
                               int priority = 0);
                               int priority = 0);
+  void compose_color_scale(const LVecBase4f &scale,
+                           int priority = 0);
+  INLINE void compose_color_scale(float sx, float sy, float sz, float sa,
+                                  int priority = 0);
   void set_color_scale_off(int priority = 0);
   void set_color_scale_off(int priority = 0);
-
+  
   void set_alpha_scale(float scale, int priority = 0);
   void set_alpha_scale(float scale, int priority = 0);
   void set_all_color_scale(float scale, int priority = 0);
   void set_all_color_scale(float scale, int priority = 0);
   INLINE void set_sr(float sr);
   INLINE void set_sr(float sr);

+ 24 - 0
panda/src/pgraph/nodePathCollection.cxx

@@ -470,6 +470,30 @@ set_color_scale(const Colorf &color, int priority) {
   }
   }
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: NodePathCollection::compose_color_scale
+//       Access: Published
+//  Description: Applies color scales to all NodePaths in the collection
+////////////////////////////////////////////////////////////////////
+void NodePathCollection::
+compose_color_scale(float r, float g, float b, float a, int priority) {
+  for (int i = 0; i < get_num_paths(); i++) {
+    get_path(i).compose_color_scale(Colorf(r, g, b, a), priority);
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: NodePathCollection::compose_color_scale
+//       Access: Published
+//  Description: Applies color scales to all NodePaths in the collection
+////////////////////////////////////////////////////////////////////
+void NodePathCollection::
+compose_color_scale(const Colorf &color, int priority) {
+  for (int i = 0; i < get_num_paths(); i++) {
+    get_path(i).compose_color_scale(color, priority);
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: NodePathCollection::output
 //     Function: NodePathCollection::output
 //       Access: Published
 //       Access: Published

+ 4 - 0
panda/src/pgraph/nodePathCollection.h

@@ -76,6 +76,10 @@ PUBLISHED:
                        int priority = 0);
                        int priority = 0);
   void set_color_scale(const Colorf &color, int priority = 0);
   void set_color_scale(const Colorf &color, int priority = 0);
 
 
+  void compose_color_scale(float r, float g, float b, float a = 1.0,
+                        int priority = 0);
+  void compose_color_scale(const Colorf &color, int priority = 0);
+
   void output(ostream &out) const;
   void output(ostream &out) const;
   void write(ostream &out, int indent_level = 0) const;
   void write(ostream &out, int indent_level = 0) const;