From 9026749e4b9c907cb13ef562bdce0a1c8d7c5861 Mon Sep 17 00:00:00 2001 From: Dave Schuyler Date: Fri, 3 Mar 2006 22:54:30 +0000 Subject: [PATCH] *** empty log message *** --- panda/src/physics/linearControlForce.I | 67 ++++++++++++++ panda/src/physics/linearControlForce.cxx | 111 +++++++++++++++++++++++ panda/src/physics/linearControlForce.h | 78 ++++++++++++++++ 3 files changed, 256 insertions(+) create mode 100755 panda/src/physics/linearControlForce.I create mode 100755 panda/src/physics/linearControlForce.cxx create mode 100755 panda/src/physics/linearControlForce.h diff --git a/panda/src/physics/linearControlForce.I b/panda/src/physics/linearControlForce.I new file mode 100755 index 0000000000..a908d4d099 --- /dev/null +++ b/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 +// panda3d-general@lists.sourceforge.net . +// +//////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////// +// 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; +} diff --git a/panda/src/physics/linearControlForce.cxx b/panda/src/physics/linearControlForce.cxx new file mode 100755 index 0000000000..f7321a51f6 --- /dev/null +++ b/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 +// panda3d-general@lists.sourceforge.net . +// +//////////////////////////////////////////////////////////////////// + +#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 ©) : + 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 +// . +//////////////////////////////////////////////////////////////////// +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 +// . +//////////////////////////////////////////////////////////////////// +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 +} diff --git a/panda/src/physics/linearControlForce.h b/panda/src/physics/linearControlForce.h new file mode 100755 index 0000000000..96bbf2447e --- /dev/null +++ b/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 +// panda3d-general@lists.sourceforge.net . +// +//////////////////////////////////////////////////////////////////// + +#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 ©); + 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