Explorar el Código

arcEmitter works like ringEmitter except you can constrain the particles to a an arc on the ring. usefull for splitting a single particle system into an 'in front' and 'behind' pair

Josh Wilson hace 19 años
padre
commit
409fc0d9a3

+ 114 - 0
panda/src/particlesystem/arcEmitter.cxx

@@ -0,0 +1,114 @@
+// Filename: arcEmitter.cxx
+// Created by:  charles (22Jun00)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#include "arcEmitter.h"
+
+////////////////////////////////////////////////////////////////////
+//    Function : ArcEmitter
+//      Access : Public
+// Description : constructor
+////////////////////////////////////////////////////////////////////
+ArcEmitter::
+ArcEmitter() :
+  RingEmitter(), _start_theta(0.0f), _end_theta(MathNumbers::pi_f)
+{
+}
+
+////////////////////////////////////////////////////////////////////
+//    Function : ArcEmitter
+//      Access : Public
+// Description : copy constructor
+////////////////////////////////////////////////////////////////////
+ArcEmitter::
+ArcEmitter(const ArcEmitter &copy) :
+  RingEmitter(copy) {
+  _start_theta = copy._start_theta;
+  _end_theta = copy._end_theta;
+}
+
+////////////////////////////////////////////////////////////////////
+//    Function : ~ArcEmitter
+//      Access : Public
+// Description : destructor
+////////////////////////////////////////////////////////////////////
+ArcEmitter::
+~ArcEmitter() {
+}
+
+////////////////////////////////////////////////////////////////////
+//    Function : make_copy
+//      Access : Public
+// Description : copier
+////////////////////////////////////////////////////////////////////
+BaseParticleEmitter *ArcEmitter::
+make_copy() {
+  return new ArcEmitter(*this);
+}
+
+////////////////////////////////////////////////////////////////////
+//    Function : ArcEmitter::assign_initial_position
+//      Access : Public
+// Description : Generates a location for a new particle
+////////////////////////////////////////////////////////////////////
+void ArcEmitter::
+assign_initial_position(LPoint3f& pos) {
+  float theta;
+  if ( _start_theta < _end_theta ) {
+    theta = LERP(NORMALIZED_RAND(), _start_theta, _end_theta);
+  } else {
+    theta = LERP(NORMALIZED_RAND(), _start_theta, _end_theta + 2.0f * MathNumbers::pi_f);
+  }    
+  
+  this->_cos_theta = cosf(theta);
+  this->_sin_theta = sinf(theta);
+
+  float new_radius_spread = SPREAD(_radius_spread);
+  float new_x = _cos_theta * (_radius + new_radius_spread);
+  float new_y = _sin_theta * (_radius + new_radius_spread);
+
+  pos.set(new_x, new_y, 0.0f);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function : output
+//       Access : Public
+//  Description : Write a starc representation of this instance to
+//                <out>.
+////////////////////////////////////////////////////////////////////
+void ArcEmitter::
+output(ostream &out) const {
+  #ifndef NDEBUG //[
+  out<<"ArcEmitter";
+  #endif //] NDEBUG
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function : write
+//       Access : Public
+//  Description : Write a starc representation of this instance to
+//                <out>.
+////////////////////////////////////////////////////////////////////
+void ArcEmitter::
+write(ostream &out, int indent) const {
+  #ifndef NDEBUG //[
+  out.width(indent); out<<""; out<<"ArcEmitter:\n";
+  out.width(indent+2); out<<""; out<<"_start_angle "<<rad_2_deg(_start_theta)<<"\n";
+  out.width(indent+2); out<<""; out<<"_end_angle "<<rad_2_deg(_end_theta)<<"\n";
+  RingEmitter::write(out, indent+2);
+  #endif //] NDEBUG
+}

+ 58 - 0
panda/src/particlesystem/arcEmitter.h

@@ -0,0 +1,58 @@
+// Filename: ringEmitter.h
+// Created by:  charles (22Jun00)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef ARCEMITTER_H
+#define ARCEMITTER_H
+
+#include "ringEmitter.h"
+
+////////////////////////////////////////////////////////////////////
+//       Class : ArcEmitter
+// Description : Describes a planar ring region in which
+//               particles are generated.
+////////////////////////////////////////////////////////////////////
+class EXPCL_PANDAPHYSICS ArcEmitter : public RingEmitter {
+PUBLISHED:
+  ArcEmitter();
+  ArcEmitter(const ArcEmitter &copy);
+  virtual ~ArcEmitter();
+
+  virtual BaseParticleEmitter *make_copy();
+
+  INLINE void set_start_angle(float angle);
+  INLINE void set_end_angle(float angle);
+  INLINE void set_arc(float startAngle, float endAngle);
+
+  INLINE float get_start_angle();
+  INLINE float get_end_angle();
+
+  virtual void output(ostream &out) const;
+  virtual void write(ostream &out, int indent=0) const;
+
+private:
+  // our emitter limits
+  float _start_theta;
+  float _end_theta;
+  ///////////////////////////////
+
+  virtual void assign_initial_position(LPoint3f& pos);
+};
+
+#include "arcEmitter.I"
+
+#endif // ARCEMITTER_H

+ 74 - 0
panda/src/particlesystem/arcEmitter.i

@@ -0,0 +1,74 @@
+// Filename: arcEmitter.I
+// Created by:  charles (26Jun00)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////
+//    Function : set_start_angle
+//      Access : public
+// Description : start angle set
+////////////////////////////////////////////////////////////////////
+
+INLINE void ArcEmitter::
+set_start_angle(float angle) {
+  _start_theta = deg_2_rad(angle);
+}
+
+////////////////////////////////////////////////////////////////////
+//    Function : set_end_angle
+//      Access : public
+// Description : end angle set
+////////////////////////////////////////////////////////////////////
+
+INLINE void ArcEmitter::
+set_end_angle(float angle) {
+  _end_theta = deg_2_rad(angle);
+}
+
+////////////////////////////////////////////////////////////////////
+//    Function : set_arc
+//      Access : public
+// Description : arc sweep set
+////////////////////////////////////////////////////////////////////
+
+INLINE void ArcEmitter::
+set_arc(float startAngle, float endAngle) {
+  _start_theta = deg_2_rad(startAngle);
+  _end_theta = deg_2_rad(endAngle);
+}
+
+////////////////////////////////////////////////////////////////////
+//    Function : get_start_angle
+//      Access : public
+// Description : get start angle
+////////////////////////////////////////////////////////////////////
+
+INLINE float ArcEmitter::
+get_start_angle() {
+  return rad_2_deg(_start_theta);
+}
+
+////////////////////////////////////////////////////////////////////
+//    Function : get_end_angle
+//      Access : public
+// Description : get end angle
+////////////////////////////////////////////////////////////////////
+
+INLINE float ArcEmitter::
+get_end_angle() {
+  return rad_2_deg(_end_theta);
+}
+