Browse Source

*** empty log message ***

Dave Schuyler 20 years ago
parent
commit
9026749e4b

+ 67 - 0
panda/src/physics/linearControlForce.I

@@ -0,0 +1,67 @@
+// Filename: linearControlForce.I
+// Created by: Dave Schuyler (2006)
+//
+////////////////////////////////////////////////////////////////////
+//
+// 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_physics_object
+//      Access : Public
+// Description : encapsulating wrapper
+////////////////////////////////////////////////////////////////////
+INLINE void LinearControlForce::
+set_physics_object(const PhysicsObject *po) {
+  _physics_object = po;
+}
+
+////////////////////////////////////////////////////////////////////
+//    Function : get_physics_object
+//      Access : Public
+// Description : piecewise encapsulating wrapper
+////////////////////////////////////////////////////////////////////
+INLINE CPT(PhysicsObject) LinearControlForce::
+get_physics_object() const {
+  return _physics_object;
+}
+
+////////////////////////////////////////////////////////////////////
+//    Function : set_vector
+//      Access : Public
+// Description : encapsulating wrapper
+////////////////////////////////////////////////////////////////////
+INLINE void LinearControlForce::
+set_vector(const LVector3f& v) {
+  _fvec = v;
+}
+
+////////////////////////////////////////////////////////////////////
+//    Function : set_vector
+//      Access : Public
+// Description : piecewise encapsulating wrapper
+////////////////////////////////////////////////////////////////////
+INLINE void LinearControlForce::
+set_vector(float x, float y, float z) {
+  _fvec.set(x, y, z);
+}
+
+////////////////////////////////////////////////////////////////////
+//    Function : get_local_vector
+//      Access : Public
+// Description :
+////////////////////////////////////////////////////////////////////
+INLINE LVector3f LinearControlForce::
+get_local_vector() const {
+  return _fvec;
+}

+ 111 - 0
panda/src/physics/linearControlForce.cxx

@@ -0,0 +1,111 @@
+// Filename: linearControlForce.cxx
+// Created by: Dave Schuyler (2006)
+//
+////////////////////////////////////////////////////////////////////
+//
+// 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 "datagram.h"
+#include "datagramIterator.h"
+#include "bamReader.h"
+#include "bamWriter.h"
+
+#include "linearControlForce.h"
+
+TypeHandle LinearControlForce::_type_handle;
+
+////////////////////////////////////////////////////////////////////
+//     Function : LinearControlForce
+//       Access : Public
+//  Description : Vector Constructor
+////////////////////////////////////////////////////////////////////
+LinearControlForce::
+LinearControlForce(const PhysicsObject *po, float a, bool mass) :
+  LinearForce(a, mass),
+  _physics_object(po),
+  _fvec(0.0f, 0.0f, 0.0f) {
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function : LinearControlForce
+//       Access : Public
+//  Description : Copy Constructor
+////////////////////////////////////////////////////////////////////
+LinearControlForce::
+LinearControlForce(const LinearControlForce &copy) :
+  LinearForce(copy) {
+  _physics_object = copy._physics_object;
+  _fvec = copy._fvec;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function : LinearControlForce
+//       Access : Public
+//  Description : Destructor
+////////////////////////////////////////////////////////////////////
+LinearControlForce::
+~LinearControlForce() {
+}
+
+////////////////////////////////////////////////////////////////////
+//    Function : make_copy
+//      Access : Public, virtual
+// Description : copier
+////////////////////////////////////////////////////////////////////
+LinearForce *LinearControlForce::
+make_copy() {
+  return new LinearControlForce(*this);
+}
+
+////////////////////////////////////////////////////////////////////
+//    Function : get_child_vector
+//      Access : Public
+// Description : vector access
+////////////////////////////////////////////////////////////////////
+LVector3f LinearControlForce::
+get_child_vector(const PhysicsObject *po) {
+  if (_physics_object != 0 && po == _physics_object) {
+    return _fvec;
+  } else {
+    return LVector3f::zero();
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function : output
+//       Access : Public
+//  Description : Write a string representation of this instance to
+//                <out>.
+////////////////////////////////////////////////////////////////////
+void LinearControlForce::
+output(ostream &out) const {
+  #ifndef NDEBUG //[
+  out<<"LinearControlForce";
+  #endif //] NDEBUG
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function : write
+//       Access : Public
+//  Description : Write a string representation of this instance to
+//                <out>.
+////////////////////////////////////////////////////////////////////
+void LinearControlForce::
+write(ostream &out, unsigned int indent) const {
+  #ifndef NDEBUG //[
+  out.width(indent); out<<""; out<<"LinearControlForce:\n";
+  out.width(indent+2); out<<""; out<<"_fvec "<<_fvec<<"\n";
+  LinearForce::write(out, indent+2);
+  #endif //] NDEBUG
+}

+ 78 - 0
panda/src/physics/linearControlForce.h

@@ -0,0 +1,78 @@
+// Filename: linearControlForce.h
+// Created by: Dave Schuyler (2006)
+//
+////////////////////////////////////////////////////////////////////
+//
+// 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 LINEARCONTROLFORCE_H
+#define LINEARCONTROLFORCE_H
+
+#include "linearForce.h"
+
+////////////////////////////////////////////////////////////////
+//       Class : LinearControlForce
+// Description : Simple directed vector force.  This force is 
+//               different from the others in that it can be
+//               global and still only affect a single object.
+//               That might not make sense for a physics simulation,
+//               but it's very handy for a game.  I.e. this is
+//               the force applied by user on the selected object.
+////////////////////////////////////////////////////////////////
+class EXPCL_PANDAPHYSICS LinearControlForce : public LinearForce {
+PUBLISHED:
+  LinearControlForce(const PhysicsObject *po = 0, float a = 1.0f,
+    bool mass = false);
+  LinearControlForce(const LinearControlForce &copy);
+  virtual ~LinearControlForce();
+
+  INLINE void set_physics_object(const PhysicsObject *po);
+  INLINE CPT(PhysicsObject) get_physics_object() const;
+
+  INLINE void set_vector(const LVector3f& v);
+  INLINE void set_vector(float x, float y, float z);
+
+  INLINE LVector3f get_local_vector() const;
+  
+  virtual void output(ostream &out) const;
+  virtual void write(ostream &out, unsigned int indent=0) const;
+
+private:
+  CPT(PhysicsObject) _physics_object;
+  LVector3f _fvec;
+
+  virtual LinearForce *make_copy();
+  virtual LVector3f get_child_vector(const PhysicsObject *po);
+
+public:
+  static TypeHandle get_class_type() {
+    return _type_handle;
+  }
+  static void init_type() {
+    LinearForce::init_type();
+    register_type(_type_handle, "LinearControlForce",
+                  LinearForce::get_class_type());
+  }
+  virtual TypeHandle get_type() const {
+    return get_class_type();
+  }
+  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
+
+private:
+  static TypeHandle _type_handle;
+};
+
+#include "LinearControlForce.I"
+
+#endif // LINEARCONTROLFORCE_H