formatting; adding output()

This commit is contained in:
Dave Schuyler 2003-06-14 00:51:07 +00:00
parent b2bdf47820
commit 9a480035c8
65 changed files with 986 additions and 408 deletions

View File

@ -87,3 +87,15 @@ generate(LPoint3f& pos, LVector3f& vel) {
vel *= _amplitude + SPREAD(_amplitude_spread);
vel += _offset_force;
}
////////////////////////////////////////////////////////////////////
// Function : output
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void BaseParticleEmitter::
output(ostream &out, unsigned int indent) const {
out.width(indent); out<<""; out<<"BaseParticleEmitter:\n";
//ReferenceCount::output(out, indent+2);
}

View File

@ -40,8 +40,8 @@ PUBLISHED:
ET_CUSTOM // particle launch vectors are dependent on particular derived emitter
};
virtual ~BaseParticleEmitter(void);
virtual BaseParticleEmitter *make_copy(void) = 0;
virtual ~BaseParticleEmitter();
virtual BaseParticleEmitter *make_copy() = 0;
void generate(LPoint3f& pos, LVector3f& vel);
@ -52,15 +52,17 @@ PUBLISHED:
INLINE void set_explicit_launch_vector(const LVector3f& elv);
INLINE void set_radiate_origin(const LPoint3f& ro);
INLINE emissionType get_emission_type(void) const;
INLINE float get_amplitude(void) const;
INLINE float get_amplitude_spread(void) const;
INLINE LVector3f get_offset_force(void) const;
INLINE LVector3f get_explicit_launch_vector(void) const;
INLINE LPoint3f get_radiate_origin(void) const;
INLINE emissionType get_emission_type() const;
INLINE float get_amplitude() const;
INLINE float get_amplitude_spread() const;
INLINE LVector3f get_offset_force() const;
INLINE LVector3f get_explicit_launch_vector() const;
INLINE LPoint3f get_radiate_origin() const;
virtual void output(ostream &out, unsigned int indent=0) const;
protected:
BaseParticleEmitter(void);
BaseParticleEmitter();
BaseParticleEmitter(const BaseParticleEmitter &copy);
emissionType _emission_type;

View File

@ -98,3 +98,15 @@ update_alpha_mode(ParticleRendererAlphaMode am) {
_alpha_mode = am;
}
////////////////////////////////////////////////////////////////////
// Function : output
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void BaseParticleRenderer::
output(ostream &out, unsigned int indent) const {
out.width(indent); out<<""; out<<"BaseParticleRenderer:\n";
//ReferenceCount::output(out, indent+2);
}

View File

@ -35,26 +35,6 @@
// Description : Pure virtual particle renderer base class
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAPHYSICS BaseParticleRenderer : public ReferenceCount {
private:
PT(GeomNode) _render_node;
float _user_alpha;
// birth and kill particle are for renderers that might do maintenance
// faster if it was notified on a per-event basis. An example:
// geomParticleRenderer maintains an arc for every particle. Instead
// of visiting EVERY entry in the arc array, individual arcs are
// changed on birth and death. Brings it down a little from O(N) every
// update.
virtual void birth_particle(int index) = 0;
virtual void kill_particle(int index) = 0;
virtual void init_geoms(void) = 0;
virtual void render(pvector< PT(PhysicsObject) >& po_vector,
int ttl_particles) = 0;
PUBLISHED:
enum ParticleRendererAlphaMode {
PR_ALPHA_NONE,
@ -79,6 +59,8 @@ PUBLISHED:
INLINE void set_user_alpha(float ua);
INLINE float get_user_alpha(void) const;
virtual void output(ostream &out, unsigned int indent=0) const;
protected:
ParticleRendererAlphaMode _alpha_mode;
@ -97,6 +79,26 @@ protected:
CPT(RenderState) _render_state;
private:
PT(GeomNode) _render_node;
float _user_alpha;
// birth and kill particle are for renderers that might do maintenance
// faster if it was notified on a per-event basis. An example:
// geomParticleRenderer maintains an arc for every particle. Instead
// of visiting EVERY entry in the arc array, individual arcs are
// changed on birth and death. Brings it down a little from O(N) every
// update.
virtual void birth_particle(int index) = 0;
virtual void kill_particle(int index) = 0;
virtual void init_geoms(void) = 0;
virtual void render(pvector< PT(PhysicsObject) >& po_vector,
int ttl_particles) = 0;
public:
virtual BaseParticleRenderer *make_copy(void) = 0;

View File

@ -88,3 +88,15 @@ void LineEmitter::
assign_initial_velocity(LVector3f& vel) {
vel.set(0,0,0);
}
////////////////////////////////////////////////////////////////////
// Function : output
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void LineEmitter::
output(ostream &out, unsigned int indent) const {
out.width(indent); out<<""; out<<"LineEmitter:\n";
BaseParticleEmitter::output(out, indent+2);
}

View File

@ -27,15 +27,6 @@
// particles are generated.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAPHYSICS LineEmitter : public BaseParticleEmitter {
private:
LPoint3f _endpoint1, _endpoint2;
// CUSTOM EMISSION PARAMETERS
// none
virtual void assign_initial_position(LPoint3f& pos);
virtual void assign_initial_velocity(LVector3f& vel);
PUBLISHED:
LineEmitter(void);
LineEmitter(const LineEmitter &copy);
@ -48,6 +39,17 @@ PUBLISHED:
INLINE LPoint3f get_endpoint1(void) const;
INLINE LPoint3f get_endpoint2(void) const;
virtual void output(ostream &out, unsigned int indent=0) const;
private:
LPoint3f _endpoint1, _endpoint2;
// CUSTOM EMISSION PARAMETERS
// none
virtual void assign_initial_position(LPoint3f& pos);
virtual void assign_initial_velocity(LVector3f& vel);
};
#include "lineEmitter.I"

View File

@ -241,3 +241,15 @@ render(pvector< PT(PhysicsObject) >& po_vector, int ttl_particles) {
_line_primitive->set_bound(BoundingSphere(aabb_center, radius));
get_render_node()->mark_bound_stale();
}
////////////////////////////////////////////////////////////////////
// Function : output
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void LineParticleRenderer::
output(ostream &out, unsigned int indent) const {
out.width(indent); out<<""; out<<"LineParticleRenderer:\n";
BaseParticleRenderer::output(out, indent+2);
}

View File

@ -34,8 +34,26 @@
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAPHYSICS LineParticleRenderer : public BaseParticleRenderer {
private:
PUBLISHED:
LineParticleRenderer(void);
LineParticleRenderer(const LineParticleRenderer& copy);
LineParticleRenderer(const Colorf& head,
const Colorf& tail,
ParticleRendererAlphaMode alpha_mode);
virtual ~LineParticleRenderer(void);
virtual BaseParticleRenderer *make_copy(void);
INLINE void set_head_color(const Colorf& c);
INLINE void set_tail_color(const Colorf& c);
INLINE const Colorf& get_head_color(void) const;
INLINE const Colorf& get_tail_color(void) const;
virtual void output(ostream &out, unsigned int indent=0) const;
private:
Colorf _head_color;
Colorf _tail_color;
@ -54,23 +72,6 @@ private:
virtual void render(pvector< PT(PhysicsObject) >& po_vector,
int ttl_particles);
virtual void resize_pool(int new_size);
PUBLISHED:
LineParticleRenderer(void);
LineParticleRenderer(const LineParticleRenderer& copy);
LineParticleRenderer(const Colorf& head,
const Colorf& tail,
ParticleRendererAlphaMode alpha_mode);
virtual ~LineParticleRenderer(void);
virtual BaseParticleRenderer *make_copy(void);
INLINE void set_head_color(const Colorf& c);
INLINE void set_tail_color(const Colorf& c);
INLINE const Colorf& get_head_color(void) const;
INLINE const Colorf& get_tail_color(void) const;
};
#include "lineParticleRenderer.I"

View File

@ -30,16 +30,18 @@ class EXPCL_PANDAPHYSICS OrientedParticle : public BaseParticle {
public:
OrientedParticle(int lifespan = 0, bool alive = false);
OrientedParticle(const OrientedParticle &copy);
virtual ~OrientedParticle(void);
virtual ~OrientedParticle();
virtual PhysicsObject *make_copy(void) const;
virtual PhysicsObject *make_copy() const;
INLINE void set_velocity(void);
INLINE void set_orientation(void);
INLINE void set_velocity();
INLINE void set_orientation();
virtual void init(void);
virtual void update(void);
virtual void die(void);
virtual void init();
virtual void update();
virtual void die();
virtual void output(ostream &out, unsigned int indent=0) const;
};
#include "orientedParticle.I"

View File

@ -29,13 +29,6 @@
// forces.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAPHYSICS OrientedParticleFactory : public BaseParticleFactory {
private:
virtual void populate_child_particle(BaseParticle *bp) const;
virtual BaseParticle *alloc_particle(void) const;
LOrientationf _initial_orientation;
LOrientationf _final_orientation;
PUBLISHED:
OrientedParticleFactory(void);
OrientedParticleFactory(const OrientedParticleFactory &copy);
@ -45,6 +38,15 @@ PUBLISHED:
INLINE void set_final_orientation(const LOrientationf &o);
INLINE LOrientationf get_initial_orientation(void) const;
INLINE LOrientationf get_final_orientation(void) const;
virtual void output(ostream &out, unsigned int indent=0) const;
private:
virtual void populate_child_particle(BaseParticle *bp) const;
virtual BaseParticle *alloc_particle(void) const;
LOrientationf _initial_orientation;
LOrientationf _final_orientation;
};
#include "orientedParticleFactory.I"

View File

@ -88,3 +88,15 @@ void RectangleEmitter::
assign_initial_velocity(LVector3f& vel) {
vel.set(0.0f,0.0f,0.0f);
}
////////////////////////////////////////////////////////////////////
// Function : output
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void RectangleEmitter::
output(ostream &out, unsigned int indent) const {
out.width(indent); out<<""; out<<"RectangleEmitter:\n";
BaseParticleEmitter::output(out, indent+2);
}

View File

@ -27,15 +27,6 @@
// particles are generated.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAPHYSICS RectangleEmitter : public BaseParticleEmitter {
private:
LPoint2f _vmin, _vmax;
// CUSTOM EMISSION PARAMETERS
// none
virtual void assign_initial_position(LPoint3f& pos);
virtual void assign_initial_velocity(LVector3f& vel);
PUBLISHED:
RectangleEmitter(void);
RectangleEmitter(const RectangleEmitter &copy);
@ -48,6 +39,17 @@ PUBLISHED:
INLINE LPoint2f get_min_bound(void) const;
INLINE LPoint2f get_max_bound(void) const;
virtual void output(ostream &out, unsigned int indent=0) const;
private:
LPoint2f _vmin, _vmax;
// CUSTOM EMISSION PARAMETERS
// none
virtual void assign_initial_position(LPoint3f& pos);
virtual void assign_initial_velocity(LVector3f& vel);
};
#include "rectangleEmitter.I"

View File

@ -26,7 +26,6 @@
// Access : Public
// Description : Default Constructor
////////////////////////////////////////////////////////////////////
SparkleParticleRenderer::
SparkleParticleRenderer(void) :
BaseParticleRenderer(PR_ALPHA_NONE),
@ -43,7 +42,6 @@ SparkleParticleRenderer(void) :
// Access : Public
// Description : Constructor
////////////////////////////////////////////////////////////////////
SparkleParticleRenderer::
SparkleParticleRenderer(const Colorf& center, const Colorf& edge,
float birth_radius, float death_radius,
@ -62,7 +60,6 @@ SparkleParticleRenderer(const Colorf& center, const Colorf& edge,
// Access : Public
// Description : Copy Constructor
////////////////////////////////////////////////////////////////////
SparkleParticleRenderer::
SparkleParticleRenderer(const SparkleParticleRenderer& copy) :
BaseParticleRenderer(copy) {
@ -81,7 +78,6 @@ SparkleParticleRenderer(const SparkleParticleRenderer& copy) :
// Access : Public
// Description : Destructor
////////////////////////////////////////////////////////////////////
SparkleParticleRenderer::
~SparkleParticleRenderer(void) {
}
@ -91,7 +87,6 @@ SparkleParticleRenderer::
// Access : Public
// Description : child virtual for spawning systems
////////////////////////////////////////////////////////////////////
BaseParticleRenderer *SparkleParticleRenderer::
make_copy(void) {
return new SparkleParticleRenderer(*this);
@ -102,7 +97,6 @@ make_copy(void) {
// Access : Private, virtual
// Description : child birth
////////////////////////////////////////////////////////////////////
void SparkleParticleRenderer::
birth_particle(int) {
}
@ -112,7 +106,6 @@ birth_particle(int) {
// Access : Private, virtual
// Description : child kill
////////////////////////////////////////////////////////////////////
void SparkleParticleRenderer::
kill_particle(int) {
}
@ -123,7 +116,6 @@ kill_particle(int) {
// Description : resizes the render pool. Reference counting
// makes this easy.
////////////////////////////////////////////////////////////////////
void SparkleParticleRenderer::
resize_pool(int new_size) {
_vertex_array = PTA_Vertexf::empty_array(new_size * 12);
@ -142,7 +134,6 @@ resize_pool(int new_size) {
// Access : private
// Description : initializes the geomnodes
////////////////////////////////////////////////////////////////////
void SparkleParticleRenderer::
init_geoms(void) {
_line_primitive->set_num_prims(0);
@ -157,7 +148,6 @@ init_geoms(void) {
// Access : private
// Description : populates the GeomLine
////////////////////////////////////////////////////////////////////
void SparkleParticleRenderer::
render(pvector< PT(PhysicsObject) >& po_vector, int ttl_particles) {

View File

@ -36,7 +36,6 @@ enum SparkleParticleLifeScale {
// Class : SparkleParticleRenderer
// Description : pretty sparkly things.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAPHYSICS SparkleParticleRenderer : public BaseParticleRenderer {
PUBLISHED:
enum SparkleParticleLifeScale {

View File

@ -106,3 +106,15 @@ transform_changed() {
// apply
_mass_center->set_position(pos);
}
////////////////////////////////////////////////////////////////////
// Function : output
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void ActorNode::
output(ostream &out, unsigned int indent) const {
out.width(indent); out<<""; out<<"ActorNode:\n";
PhysicalNode::output(out, indent+2);
}

View File

@ -32,6 +32,16 @@
// object's position (shoves).
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAPHYSICS ActorNode : public PhysicalNode {
public:
ActorNode(const string &name = "");
ActorNode(const ActorNode &copy);
virtual ~ActorNode();
// update the parent arc with PhysicsObject information
void update_transform();
virtual void output(ostream &out, unsigned int indent=0) const;
private:
// node hook if the client changes the node's transform.
virtual void transform_changed();
@ -41,23 +51,15 @@ private:
bool _ok_to_callback;
public:
ActorNode(const string &name = "");
ActorNode(const ActorNode &copy);
virtual ~ActorNode(void);
// update the parent arc with PhysicsObject information
void update_transform(void);
public:
static TypeHandle get_class_type(void) {
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type(void) {
static void init_type() {
PhysicalNode::init_type();
register_type(_type_handle, "ActorNode",
PhysicalNode::get_class_type());
}
virtual TypeHandle get_type(void) const {
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}

View File

@ -154,3 +154,15 @@ child_integrate(Physical *physical,
current_object->set_rotation(rot_vec);
}
}
////////////////////////////////////////////////////////////////////
// Function : output
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void AngularEulerIntegrator::
output(ostream &out, unsigned int indent) const {
out.width(indent); out<<""; out<<"AngularEulerIntegrator:\n";
AngularIntegrator::output(out, indent+2);
}

View File

@ -31,6 +31,8 @@ private:
virtual void child_integrate(Physical *physical,
pvector< PT(AngularForce) >& forces,
float dt);
virtual void output(ostream &out, unsigned int indent=0) const;
PUBLISHED:
AngularEulerIntegrator(void);

View File

@ -69,3 +69,15 @@ bool AngularForce::
is_linear(void) const {
return false;
}
////////////////////////////////////////////////////////////////////
// Function : output
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void AngularForce::
output(ostream &out, unsigned int indent) const {
out.width(indent); out<<""; out<<"AngularForce:\n";
BaseForce::output(out, indent+2);
}

View File

@ -26,30 +26,32 @@
// Description : pure virtual parent of all quat-based forces.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAPHYSICS AngularForce : public BaseForce {
PUBLISHED:
virtual ~AngularForce();
virtual AngularForce *make_copy() const = 0;
LVector3f get_vector(const PhysicsObject *po);
virtual bool is_linear() const;
virtual void output(ostream &out, unsigned int indent=0) const;
protected:
AngularForce();
AngularForce(const AngularForce &copy);
private:
virtual LVector3f get_child_vector(const PhysicsObject *po) = 0;
protected:
AngularForce(void);
AngularForce(const AngularForce &copy);
PUBLISHED:
virtual ~AngularForce(void);
virtual AngularForce *make_copy(void) const = 0;
LVector3f get_vector(const PhysicsObject *po);
virtual bool is_linear(void) const;
public:
static TypeHandle get_class_type(void) {
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type(void) {
static void init_type() {
BaseForce::init_type();
register_type(_type_handle, "AngularForce",
BaseForce::get_class_type());
}
virtual TypeHandle get_type(void) const {
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}

View File

@ -51,3 +51,15 @@ integrate(Physical *physical, pvector< PT(AngularForce) >& forces,
// this actually does the integration.
child_integrate(physical, forces, dt);
}
////////////////////////////////////////////////////////////////////
// Function : output
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void AngularIntegrator::
output(ostream &out, unsigned int indent) const {
out.width(indent); out<<""; out<<"AngularIntegrator:\n";
BaseIntegrator::output(out, indent+2);
}

View File

@ -29,6 +29,17 @@
// forces to them.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAPHYSICS AngularIntegrator : public BaseIntegrator {
public:
virtual ~AngularIntegrator(void);
void integrate(Physical *physical, pvector< PT(AngularForce) > &forces,
float dt);
virtual void output(ostream &out, unsigned int indent=0) const;
protected:
AngularIntegrator(void);
private:
static const float _max_angular_dt;
@ -36,15 +47,6 @@ private:
// actual integration function receives.
virtual void child_integrate(Physical *physical, pvector< PT(AngularForce) > &forces,
float dt) = 0;
protected:
AngularIntegrator(void);
public:
virtual ~AngularIntegrator(void);
void integrate(Physical *physical, pvector< PT(AngularForce) > &forces,
float dt);
};
#endif // ANGULARINTEGRATOR_H

View File

@ -80,3 +80,15 @@ LVector3f AngularVectorForce::
get_child_vector(const PhysicsObject *) {
return _fvec;
}
////////////////////////////////////////////////////////////////////
// Function : output
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void AngularVectorForce::
output(ostream &out, unsigned int indent) const {
out.width(indent); out<<""; out<<"AngularVectorForce:\n";
AngularForce::output(out, indent+2);
}

View File

@ -27,12 +27,6 @@
// equivalent of simple vector force.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAPHYSICS AngularVectorForce : public AngularForce {
private:
LVector3f _fvec;
virtual AngularForce *make_copy(void) const;
virtual LVector3f get_child_vector(const PhysicsObject *po);
PUBLISHED:
AngularVectorForce(const LVector3f& vec);
AngularVectorForce(float x = 0.0f, float y = 0.0f, float z = 0.0f);
@ -42,6 +36,14 @@ PUBLISHED:
INLINE void set_vector(const LVector3f& v);
INLINE void set_vector(float x, float y, float z);
INLINE LVector3f get_local_vector(void) const;
virtual void output(ostream &out, unsigned int indent=0) const;
private:
LVector3f _fvec;
virtual AngularForce *make_copy(void) const;
virtual LVector3f get_child_vector(const PhysicsObject *po);
public:
static TypeHandle get_class_type(void) {

View File

@ -48,5 +48,17 @@ BaseForce(const BaseForce &copy) :
// Description : destructor
////////////////////////////////////////////////////////////////////
BaseForce::
~BaseForce(void) {
~BaseForce() {
}
////////////////////////////////////////////////////////////////////
// Function : output
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void BaseForce::
output(ostream &out, unsigned int indent) const {
out.width(indent); out<<""; out<<"BaseForce:\n";
//TypedReferenceCount::output(out);
}

View File

@ -33,37 +33,39 @@ class ForceNode;
// POSSIBLY exist.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAPHYSICS BaseForce : public TypedReferenceCount {
PUBLISHED:
virtual ~BaseForce();
INLINE bool get_active() const;
INLINE void set_active(bool active);
virtual bool is_linear() const = 0;
INLINE ForceNode *get_force_node() const;
virtual LVector3f get_vector(const PhysicsObject *po) = 0;
virtual void output(ostream &out, unsigned int indent=0) const;
protected:
BaseForce(bool active = true);
BaseForce(const BaseForce &copy);
private:
ForceNode *_force_node;
bool _active;
virtual LVector3f get_child_vector(const PhysicsObject *po) = 0;
protected:
BaseForce(bool active = true);
BaseForce(const BaseForce &copy);
PUBLISHED:
virtual ~BaseForce(void);
INLINE bool get_active(void) const;
INLINE void set_active(bool active);
virtual bool is_linear(void) const = 0;
INLINE ForceNode *get_force_node(void) const;
virtual LVector3f get_vector(const PhysicsObject *po) = 0;
public:
static TypeHandle get_class_type(void) {
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type(void) {
static void init_type() {
TypedReferenceCount::init_type();
register_type(_type_handle, "BaseForce",
TypedReferenceCount::get_class_type());
}
virtual TypeHandle get_type(void) const {
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}

View File

@ -142,3 +142,14 @@ precompute_angular_matrices(Physical *physical,
_precomputed_angular_matrices.push_back(physical_np.get_mat(force_node));
}
}
////////////////////////////////////////////////////////////////////
// Function : output
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void BaseIntegrator::
output(ostream &out, unsigned int indent) const {
out.width(indent); out<<""; out<<"BaseIntegrator:\n";
}

View File

@ -38,27 +38,31 @@ class Physical;
// any possible child implementation.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAPHYSICS BaseIntegrator : public ReferenceCount {
private:
// since the wrt for each physicsobject between its physicalnode
// and however many forces will be the same among one physical,
// the transformation matrices can be pulled out of the inner loop
// and precomputed.
pvector< LMatrix4f > _precomputed_linear_matrices;
pvector< LMatrix4f > _precomputed_angular_matrices;
public:
typedef pvector< LMatrix4f > VectorOfMatrices;
virtual ~BaseIntegrator();
virtual void output(ostream &out, unsigned int indent=0) const;
protected:
BaseIntegrator(void);
BaseIntegrator();
INLINE const pvector< LMatrix4f > &get_precomputed_linear_matrices(void) const;
INLINE const pvector< LMatrix4f > &get_precomputed_angular_matrices(void) const;
INLINE const VectorOfMatrices &get_precomputed_linear_matrices() const;
INLINE const VectorOfMatrices &get_precomputed_angular_matrices() const;
void precompute_linear_matrices(Physical *physical,
const pvector< PT(LinearForce) > &forces);
void precompute_angular_matrices(Physical *physical,
const pvector< PT(AngularForce) > &forces);
public:
virtual ~BaseIntegrator(void);
private:
// since the wrt for each physicsobject between its physicalnode
// and however many forces will be the same among one physical,
// the transformation matrices can be pulled out of the inner loop
// and precomputed.
VectorOfMatrices _precomputed_linear_matrices;
VectorOfMatrices _precomputed_angular_matrices;
};
#include "baseIntegrator.I"

View File

@ -107,3 +107,15 @@ remove_force(int index) {
_forces.erase(remove);
}
////////////////////////////////////////////////////////////////////
// Function : output
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void ForceNode::
output(ostream &out, unsigned int indent) const {
out.width(indent); out<<""; out<<"ForceNode\n";
//PandaNode::output(out, indent+2);
}

View File

@ -32,40 +32,40 @@
// in a rotating space station. or something.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAPHYSICS ForceNode : public PandaNode {
private:
pvector< PT(BaseForce) > _forces;
PUBLISHED:
ForceNode(const string &name);
protected:
ForceNode(const ForceNode &copy);
public:
virtual ~ForceNode(void);
virtual bool safe_to_flatten(void) const { return false; }
virtual PandaNode *make_copy(void) const;
PUBLISHED:
INLINE void clear(void);
INLINE void clear();
INLINE BaseForce *get_force(int index) const;
INLINE int get_num_forces(void) const;
INLINE int get_num_forces() const;
INLINE void add_force(BaseForce *force);
void add_forces_from(const ForceNode &other);
void remove_force(BaseForce *f);
void remove_force(int index);
virtual void output(ostream &out, unsigned int indent=0) const;
public:
static TypeHandle get_class_type(void) {
virtual ~ForceNode();
virtual bool safe_to_flatten() const { return false; }
virtual PandaNode *make_copy() const;
protected:
ForceNode(const ForceNode &copy);
private:
pvector< PT(BaseForce) > _forces;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type(void) {
static void init_type() {
PandaNode::init_type();
register_type(_type_handle, "ForceNode",
PandaNode::get_class_type());
}
virtual TypeHandle get_type(void) const {
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}

View File

@ -129,3 +129,15 @@ get_child_vector(const PhysicsObject *po) {
return centripetal;
}
////////////////////////////////////////////////////////////////////
// Function : output
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void LinearCylinderVortexForce::
output(ostream &out, unsigned int indent) const {
out.width(indent); out<<""; out<<"LinearCylinderVortexForce:\n";
LinearForce::output(out, indent+2);
}

View File

@ -32,14 +32,6 @@
// let go.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAPHYSICS LinearCylinderVortexForce : public LinearForce {
private:
float _radius;
float _length;
float _coef;
virtual LinearForce *make_copy(void);
virtual LVector3f get_child_vector(const PhysicsObject *po);
PUBLISHED:
LinearCylinderVortexForce(float radius = 1.0f,
float length = 0.0f,
@ -57,6 +49,16 @@ PUBLISHED:
INLINE void set_length(float length);
INLINE float get_length(void) const;
virtual void output(ostream &out, unsigned int indent=0) const;
private:
float _radius;
float _length;
float _coef;
virtual LinearForce *make_copy(void);
virtual LVector3f get_child_vector(const PhysicsObject *po);
public:
static TypeHandle get_class_type(void) {

View File

@ -53,3 +53,15 @@ LinearDistanceForce(const LinearDistanceForce &copy) :
LinearDistanceForce::
~LinearDistanceForce(void) {
}
////////////////////////////////////////////////////////////////////
// Function : output
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void LinearDistanceForce::
output(ostream &out, unsigned int indent) const {
out.width(indent); out<<""; out<<"LinearDistanceForce:\n";
LinearForce::output(out, indent+2);
}

View File

@ -44,6 +44,8 @@ PUBLISHED:
INLINE LPoint3f get_force_center(void) const;
INLINE float get_scalar_term(void) const;
virtual void output(ostream &out, unsigned int indent=0) const;
private:
LPoint3f _force_center;

View File

@ -27,7 +27,7 @@
// Description : constructor
////////////////////////////////////////////////////////////////////
LinearEulerIntegrator::
LinearEulerIntegrator(void) {
LinearEulerIntegrator() {
}
////////////////////////////////////////////////////////////////////
@ -36,7 +36,7 @@ LinearEulerIntegrator(void) {
// Description : destructor
////////////////////////////////////////////////////////////////////
LinearEulerIntegrator::
~LinearEulerIntegrator(void) {
~LinearEulerIntegrator() {
}
////////////////////////////////////////////////////////////////////
@ -45,20 +45,27 @@ LinearEulerIntegrator::
// Description : Integrate a step of motion (based on dt) by
// applying every force in force_vec to every object
// in obj_vec.
//
// physical,
// The objects being acted upon and the
// set of local forces that are applied
// after the global forces.
// forces,
// Global forces to be applied first.
// dt,
// The delta time of this integration step.
////////////////////////////////////////////////////////////////////
void LinearEulerIntegrator::
child_integrate(Physical *physical,
pvector< PT(LinearForce) >& forces,
float dt) {
pvector< PT(PhysicsObject) >::const_iterator current_object_iter;
// perform the precomputation. Note that the vector returned by
// get_precomputed_matrices() has the matrices loaded in order of force
// type: first global, then local. If you're using this as a guide to write
// another integrator, be sure to process your forces global, then local.
// otherwise your transforms will be VERY bad.
precompute_linear_matrices(physical, forces);
const pvector< LMatrix4f > &matrices = get_precomputed_linear_matrices();
const VectorOfMatrices &matrices = get_precomputed_linear_matrices();
// Loop through each object in the set. This processing occurs in O(pf) time,
// where p is the number of physical objects and f is the number of
@ -67,14 +74,10 @@ child_integrate(Physical *physical,
// velocity of each physicsobject in the set. Accordingly, we have
// to grunt our way through each one. wrt caching of the xform matrix
// should help.
pvector< PT(PhysicsObject) >::const_iterator current_object_iter;
current_object_iter = physical->get_object_vector().begin();
for (; current_object_iter != physical->get_object_vector().end();
current_object_iter++) {
LVector3f md_accum_vec, non_md_accum_vec, accel_vec, vel_vec;
LPoint3f pos;
float mass;
PhysicsObject *current_object = *current_object_iter;
// bail out if this object doesn't exist or doesn't want to be
@ -86,6 +89,7 @@ child_integrate(Physical *physical,
continue;
// reset the accumulation vectors for this object
LVector3f md_accum_vec, non_md_accum_vec, accel_vec, vel_vec;
md_accum_vec.set(0.0f, 0.0f, 0.0f);
non_md_accum_vec.set(0.0f, 0.0f, 0.0f);
@ -140,9 +144,9 @@ child_integrate(Physical *physical,
}
// get this object's physical info
pos = current_object->get_position();
LPoint3f pos = current_object->get_position();
vel_vec = current_object->get_velocity();
mass = current_object->get_mass();
float mass = current_object->get_mass();
// we want 'a' in F = ma
// get it by computing F / m
@ -170,6 +174,19 @@ child_integrate(Physical *physical,
}
}
////////////////////////////////////////////////////////////////////
// Function : output
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void LinearEulerIntegrator::
output(ostream &out, unsigned int indent) const {
out.width(indent);
out<<""<<"LinearEulerIntegrator:\n";
LinearIntegrator::output(out, indent+2);
}

View File

@ -27,14 +27,16 @@
// physically modelable objects given a quantum dt.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAPHYSICS LinearEulerIntegrator : public LinearIntegrator {
PUBLISHED:
LinearEulerIntegrator();
virtual ~LinearEulerIntegrator();
virtual void output(ostream &out, unsigned int indent=0) const;
private:
virtual void child_integrate(Physical *physical,
pvector< PT(LinearForce) >& forces,
float dt);
PUBLISHED:
LinearEulerIntegrator();
virtual ~LinearEulerIntegrator();
};
#endif // EULERINTEGRATOR_H

View File

@ -58,7 +58,7 @@ LinearForce(const LinearForce& copy) :
// Description : Destructor
////////////////////////////////////////////////////////////////////
LinearForce::
~LinearForce(void) {
~LinearForce() {
}
////////////////////////////////////////////////////////////////////
@ -86,6 +86,24 @@ get_vector(const PhysicsObject *po) {
// Access : Public
////////////////////////////////////////////////////////////////////
bool LinearForce::
is_linear(void) const {
is_linear() const {
return true;
}
////////////////////////////////////////////////////////////////////
// Function : output
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void LinearForce::
output(ostream &out, unsigned int indent) const {
out.width(indent); out<<"";
out<<"LinearForce:";
out<<" amplitude "<<_amplitude;
out<<", mass_dependent "<<_mass_dependent;
out<<", x_mask "<<_x_mask;
out<<", y_mask "<<_y_mask;
out<<", z_mask "<<_z_mask;
BaseForce::output(out, indent+2);
}

View File

@ -27,6 +27,29 @@
// Integrator. This is a pure virtual base class.
///////////////////////////////////////////////////////////////////
class EXPCL_PANDAPHYSICS LinearForce : public BaseForce {
PUBLISHED:
~LinearForce();
INLINE void set_amplitude(const float a);
INLINE void set_mass_dependent(bool m);
INLINE float get_amplitude() const;
INLINE bool get_mass_dependent(void) const;
INLINE void set_vector_masks(bool x, bool y, bool z);
virtual LVector3f get_vector(const PhysicsObject *po);
virtual LinearForce *make_copy() = 0;
virtual bool is_linear() const;
virtual void output(ostream &out, unsigned int indent=0) const;
protected:
LinearForce(float a, bool mass);
LinearForce(const LinearForce& copy);
private:
float _amplitude;
bool _mass_dependent;
@ -37,37 +60,16 @@ private:
virtual LVector3f get_child_vector(const PhysicsObject *po) = 0;
protected:
LinearForce(float a, bool mass);
LinearForce(const LinearForce& copy);
PUBLISHED:
~LinearForce(void);
INLINE void set_amplitude(const float a);
INLINE void set_mass_dependent(bool m);
INLINE float get_amplitude(void) const;
INLINE bool get_mass_dependent(void) const;
INLINE void set_vector_masks(bool x, bool y, bool z);
virtual LVector3f get_vector(const PhysicsObject *po);
virtual LinearForce *make_copy(void) = 0;
virtual bool is_linear(void) const;
public:
static TypeHandle get_class_type(void) {
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type(void) {
static void init_type() {
BaseForce::init_type();
register_type(_type_handle, "LinearForce",
BaseForce::get_class_type());
}
virtual TypeHandle get_type(void) const {
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}

View File

@ -84,3 +84,15 @@ get_child_vector(const PhysicsObject* po) {
// that this will always be greater than or equal to zero.
return friction;
}
////////////////////////////////////////////////////////////////////
// Function : output
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void LinearFrictionForce::
output(ostream &out, unsigned int indent) const {
out.width(indent); out<<""; out<<"LinearFrictionForce:\n";
LinearForce::output(out, indent+2);
}

View File

@ -26,12 +26,6 @@
// Description : Friction-based drag force
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAPHYSICS LinearFrictionForce : public LinearForce {
private:
float _coef;
virtual LinearForce *make_copy(void);
virtual LVector3f get_child_vector(const PhysicsObject *);
PUBLISHED:
LinearFrictionForce(float coef = 1.0f, float a = 1.0f, bool m = false);
LinearFrictionForce(const LinearFrictionForce &copy);
@ -39,6 +33,14 @@ PUBLISHED:
INLINE void set_coef(float coef);
INLINE float get_coef(void) const;
virtual void output(ostream &out, unsigned int indent=0) const;
private:
float _coef;
virtual LinearForce *make_copy(void);
virtual LVector3f get_child_vector(const PhysicsObject *);
public:
static TypeHandle get_class_type(void) {

View File

@ -71,3 +71,15 @@ integrate(Physical *physical, pvector< PT(LinearForce) > &forces,
}
child_integrate(physical, forces, dt);
}
////////////////////////////////////////////////////////////////////
// Function : output
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void LinearIntegrator::
output(ostream &out, unsigned int indent) const {
out.width(indent); out<<""; out<<"LinearIntegrator:\n";
BaseIntegrator::output(out, indent+2);
}

View File

@ -30,6 +30,17 @@
// forces to them.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAPHYSICS LinearIntegrator : public BaseIntegrator {
public:
virtual ~LinearIntegrator();
void integrate(Physical *physical, pvector< PT(LinearForce) > &forces,
float dt);
virtual void output(ostream &out, unsigned int indent=0) const;
protected:
LinearIntegrator();
private:
static const float _max_linear_dt;
@ -38,15 +49,6 @@ private:
virtual void child_integrate(Physical *physical,
pvector< PT(LinearForce) > &forces,
float dt) = 0;
protected:
LinearIntegrator(void);
public:
virtual ~LinearIntegrator(void);
void integrate(Physical *physical, pvector< PT(LinearForce) > &forces,
float dt);
};
#endif // LINEARINTEGRATOR_H

View File

@ -68,3 +68,15 @@ LVector3f LinearJitterForce::
get_child_vector(const PhysicsObject *) {
return random_unit_vector();
}
////////////////////////////////////////////////////////////////////
// Function : output
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void LinearJitterForce::
output(ostream &out, unsigned int indent) const {
out.width(indent); out<<""; out<<"LinearJitterForce:\n";
LinearRandomForce::output(out, indent+2);
}

View File

@ -27,14 +27,16 @@
// repeatable, reliable, or predictable.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAPHYSICS LinearJitterForce : public LinearRandomForce {
private:
virtual LVector3f get_child_vector(const PhysicsObject *po);
virtual LinearForce *make_copy(void);
PUBLISHED:
LinearJitterForce(float a = 1.0f, bool m = false);
LinearJitterForce(const LinearJitterForce &copy);
virtual ~LinearJitterForce(void);
virtual void output(ostream &out, unsigned int indent=0) const;
private:
virtual LVector3f get_child_vector(const PhysicsObject *po);
virtual LinearForce *make_copy(void);
public:
static TypeHandle get_class_type(void) {

View File

@ -37,14 +37,12 @@ TypeHandle LinearNoiseForce::_type_handle;
////////////////////////////////////////////////////////////////////
void LinearNoiseForce::
init_noise_tables(void) {
int i;
LVector3f *gtable = _gradient_table;
// since this is a repeatable noise function, we always want
// to init with the same seed.
srand(_random_seed);
for (i = 0; i < 256; i++) {
LVector3f *gtable = _gradient_table;
for (int i = 0; i < 256; ++i) {
// fill the 1d array
_prn_table[i] = rand() & 255;
@ -83,7 +81,7 @@ LinearNoiseForce(const LinearNoiseForce &copy) :
// Description : destructor
////////////////////////////////////////////////////////////////////
LinearNoiseForce::
~LinearNoiseForce(void) {
~LinearNoiseForce() {
}
////////////////////////////////////////////////////////////////////
@ -149,3 +147,20 @@ get_child_vector(const PhysicsObject *po) {
// z direction
return vlerp(cubic_y, temp0, temp1);
}
////////////////////////////////////////////////////////////////////
// Function : output
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void LinearNoiseForce::
output(ostream &out, unsigned int indent) const {
out.width(indent);
out<<""<<"LinearNoiseForce:";
out<<", _random_seed"<<_random_seed;
out<<", _initialized"<<_initialized;
out<<", _gradient_table"<<_gradient_table<<"\n";
out.width(indent+2); out<<""; out<<"_prn_table"<<_prn_table;
out<<endl;
}

View File

@ -27,6 +27,17 @@
// Description : Repeating noise force vector.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAPHYSICS LinearNoiseForce : public LinearRandomForce {
PUBLISHED:
LinearNoiseForce(float a = 1.0f, bool m = false);
LinearNoiseForce(const LinearNoiseForce &copy);
virtual ~LinearNoiseForce();
virtual void output(ostream &out, unsigned int indent=0) const;
public:
static int _random_seed;
static void init_noise_tables();
private:
static unsigned char _prn_table[256];
static LVector3f _gradient_table[256];
@ -44,27 +55,18 @@ private:
INLINE unsigned char prn_lookup(int index) const;
virtual LVector3f get_child_vector(const PhysicsObject *po);
virtual LinearForce *make_copy(void);
virtual LinearForce *make_copy();
public:
static int _random_seed;
static void init_noise_tables(void);
PUBLISHED:
LinearNoiseForce(float a = 1.0f, bool m = false);
LinearNoiseForce(const LinearNoiseForce &copy);
virtual ~LinearNoiseForce(void);
public:
static TypeHandle get_class_type(void) {
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type(void) {
static void init_type() {
LinearRandomForce::init_type();
register_type(_type_handle, "LinearNoiseForce",
LinearRandomForce::get_class_type());
}
virtual TypeHandle get_type(void) const {
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}

View File

@ -58,3 +58,15 @@ float LinearRandomForce::
bounded_rand(void) {
return ((float)rand() / (float)RAND_MAX);
}
////////////////////////////////////////////////////////////////////
// Function : output
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void LinearRandomForce::
output(ostream &out, unsigned int indent) const {
out.width(indent); out<<""; out<<"LinearRandomForce:\n";
LinearForce::output(out, indent+2);
}

View File

@ -29,6 +29,11 @@
// Description : Pure virtual, parent to noiseForce and jitterForce
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAPHYSICS LinearRandomForce : public LinearForce {
PUBLISHED:
virtual ~LinearRandomForce(void);
virtual void output(ostream &out, unsigned int indent=0) const;
protected:
static float bounded_rand(void);
static LVector3f random_unit_vector(void);
@ -39,9 +44,6 @@ protected:
virtual LVector3f get_child_vector(const PhysicsObject *po) = 0;
virtual LinearForce *make_copy(void) = 0;
PUBLISHED:
virtual ~LinearRandomForce(void);
public:
static TypeHandle get_class_type(void) {
return _type_handle;

View File

@ -80,3 +80,15 @@ LVector3f LinearSinkForce::
get_child_vector(const PhysicsObject *po) {
return (get_force_center() - po->get_position()) * get_scalar_term();
}
////////////////////////////////////////////////////////////////////
// Function : output
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void LinearSinkForce::
output(ostream &out, unsigned int indent) const {
out.width(indent); out<<""; out<<"LinearSinkForce:\n";
LinearDistanceForce::output(out, indent+2);
}

View File

@ -26,16 +26,18 @@
// Description : Attractor force. Think black hole.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAPHYSICS LinearSinkForce : public LinearDistanceForce {
private:
virtual LVector3f get_child_vector(const PhysicsObject *po);
virtual LinearForce *make_copy(void);
PUBLISHED:
LinearSinkForce(const LPoint3f& p, FalloffType f, float r, float a = 1.0f,
bool m = true);
LinearSinkForce(void);
LinearSinkForce(const LinearSinkForce &copy);
virtual ~LinearSinkForce(void);
virtual void output(ostream &out, unsigned int indent=0) const;
private:
virtual LVector3f get_child_vector(const PhysicsObject *po);
virtual LinearForce *make_copy(void);
public:
static TypeHandle get_class_type(void) {

View File

@ -80,3 +80,15 @@ LVector3f LinearSourceForce::
get_child_vector(const PhysicsObject *po) {
return (po->get_position() - get_force_center()) * get_scalar_term();
}
////////////////////////////////////////////////////////////////////
// Function : output
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void LinearSourceForce::
output(ostream &out, unsigned int indent) const {
out.width(indent); out<<""; out<<"LinearSourceForce:\n";
LinearDistanceForce::output(out, indent+2);
}

View File

@ -26,16 +26,18 @@
// Description : Repellant force.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAPHYSICS LinearSourceForce : public LinearDistanceForce {
private:
virtual LVector3f get_child_vector(const PhysicsObject *po);
virtual LinearForce *make_copy(void);
PUBLISHED:
LinearSourceForce(const LPoint3f& p, FalloffType f, float r, float a = 1.0f,
bool mass = true);
LinearSourceForce(void);
LinearSourceForce(const LinearSourceForce &copy);
virtual ~LinearSourceForce(void);
virtual void output(ostream &out, unsigned int indent=0) const;
private:
virtual LVector3f get_child_vector(const PhysicsObject *po);
virtual LinearForce *make_copy(void);
public:
static TypeHandle get_class_type(void) {

View File

@ -72,3 +72,15 @@ LVector3f LinearUserDefinedForce::
get_child_vector(const PhysicsObject *po) {
return _proc(po);
}
////////////////////////////////////////////////////////////////////
// Function : output
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void LinearUserDefinedForce::
output(ostream &out, unsigned int indent) const {
out.width(indent); out<<""; out<<"LinearUserDefinedForce:\n";
LinearForce::output(out, indent+2);
}

View File

@ -32,12 +32,6 @@
// becomes needed...
////////////////////////////////////////////////////////////////////
class LinearUserDefinedForce : public LinearForce {
private:
LVector3f (*_proc)(const PhysicsObject *po);
virtual LVector3f get_child_vector(const PhysicsObject *po);
virtual LinearForce *make_copy(void);
PUBLISHED:
LinearUserDefinedForce(LVector3f (*proc)(const PhysicsObject *) = NULL,
float a = 1.0f,
@ -46,6 +40,14 @@ PUBLISHED:
virtual ~LinearUserDefinedForce(void);
INLINE void set_proc(LVector3f (*proc)(const PhysicsObject *));
virtual void output(ostream &out, unsigned int indent=0) const;
private:
LVector3f (*_proc)(const PhysicsObject *po);
virtual LVector3f get_child_vector(const PhysicsObject *po);
virtual LinearForce *make_copy(void);
public:
static TypeHandle get_class_type(void) {

View File

@ -88,3 +88,14 @@ get_child_vector(const PhysicsObject *) {
return _fvec;
}
////////////////////////////////////////////////////////////////////
// Function : output
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void LinearVectorForce::
output(ostream &out, unsigned int indent) const {
out.width(indent); out<<""; out<<"LinearVectorForce:\n";
LinearForce::output(out, indent+2);
}

View File

@ -27,12 +27,6 @@
// gravity, non-turbulent wind, etc...
////////////////////////////////////////////////////////////////
class EXPCL_PANDAPHYSICS LinearVectorForce : public LinearForce {
private:
LVector3f _fvec;
virtual LinearForce *make_copy(void);
virtual LVector3f get_child_vector(const PhysicsObject *po);
PUBLISHED:
LinearVectorForce(const LVector3f& vec, float a = 1.0f, bool mass = false);
LinearVectorForce(const LinearVectorForce &copy);
@ -44,6 +38,14 @@ PUBLISHED:
INLINE void set_vector(float x, float y, float z);
INLINE LVector3f get_local_vector(void) const;
virtual void output(ostream &out, unsigned int indent=0) const;
private:
LVector3f _fvec;
virtual LinearForce *make_copy(void);
virtual LVector3f get_child_vector(const PhysicsObject *po);
public:
static TypeHandle get_class_type(void) {

View File

@ -24,7 +24,7 @@
// Description : Erases the linear force list
////////////////////////////////////////////////////////////////////
INLINE void Physical::
clear_linear_forces(void) {
clear_linear_forces() {
_linear_forces.erase(_linear_forces.begin(),
_linear_forces.end());
}
@ -35,7 +35,7 @@ clear_linear_forces(void) {
// Description : Erases the angular force list
////////////////////////////////////////////////////////////////////
INLINE void Physical::
clear_angular_forces(void) {
clear_angular_forces() {
_angular_forces.erase(_angular_forces.begin(),
_angular_forces.end());
}
@ -46,7 +46,7 @@ clear_angular_forces(void) {
// Description : Erases the object list
////////////////////////////////////////////////////////////////////
INLINE void Physical::
clear_physics_objects(void) {
clear_physics_objects() {
_physics_objects.erase(_physics_objects.begin(),
_physics_objects.end());
}
@ -124,7 +124,7 @@ add_physics_object(PhysicsObject *po) {
// Access : Public
////////////////////////////////////////////////////////////////////
INLINE PhysicsManager *Physical::
get_physics_manager(void) const {
get_physics_manager() const {
return _physics_manager;
}
@ -133,7 +133,7 @@ get_physics_manager(void) const {
// Access : Public
////////////////////////////////////////////////////////////////////
INLINE PhysicsObject *Physical::
get_phys_body(void) const {
get_phys_body() const {
return _phys_body;
}
@ -142,7 +142,7 @@ get_phys_body(void) const {
// Access : Public
////////////////////////////////////////////////////////////////////
INLINE PhysicalNode *Physical::
get_physical_node(void) const {
get_physical_node() const {
return _physical_node;
}
@ -151,7 +151,7 @@ get_physical_node(void) const {
// Access : Public
////////////////////////////////////////////////////////////////////
INLINE const pvector< PT(PhysicsObject) > &Physical::
get_object_vector(void) const {
get_object_vector() const {
return _physics_objects;
}
@ -160,7 +160,7 @@ get_object_vector(void) const {
// Access : Public
////////////////////////////////////////////////////////////////////
INLINE const pvector< PT(LinearForce) > &Physical::
get_linear_forces(void) const {
get_linear_forces() const {
return _linear_forces;
}
@ -169,7 +169,7 @@ get_linear_forces(void) const {
// Access : Public
////////////////////////////////////////////////////////////////////
INLINE const pvector< PT(AngularForce) > &Physical::
get_angular_forces(void) const {
get_angular_forces() const {
return _angular_forces;
}
@ -178,7 +178,7 @@ get_angular_forces(void) const {
// Access : Public
////////////////////////////////////////////////////////////////////
INLINE int Physical::
get_num_linear_forces(void) const {
get_num_linear_forces() const {
return _linear_forces.size();
}
@ -197,7 +197,7 @@ get_linear_force(int index) const {
// Access : Public
////////////////////////////////////////////////////////////////////
INLINE int Physical::
get_num_angular_forces(void) const {
get_num_angular_forces() const {
return _angular_forces.size();
}

View File

@ -111,7 +111,7 @@ Physical(const Physical& copy) {
// Description : destructor
////////////////////////////////////////////////////////////////////
Physical::
~Physical(void) {
~Physical() {
// note that this removes a physical from a physics manager.
// this is safe because the physics manager doesn't keep PT's to
// physicals, simply *'s, and also means that we don't have to tell
@ -121,5 +121,75 @@ Physical::
}
}
////////////////////////////////////////////////////////////////////
// Function : output_physics_objects
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void Physical::
output_physics_objects(ostream &out, unsigned int indent) const {
out.width(indent);
out<<""<<"_physics_objects\n";
for (PhysicsObjectVector::const_iterator i=_physics_objects.begin();
i != _physics_objects.end();
++i) {
(*i)->output(out, indent+2);
}
}
////////////////////////////////////////////////////////////////////
// Function : output_linear_forces
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void Physical::
output_linear_forces(ostream &out, unsigned int indent) const {
out.width(indent);
out<<""<<"_linear_forces\n";
for (LinearForceVector::const_iterator i=_linear_forces.begin();
i != _linear_forces.end();
++i) {
(*i)->output(out, indent+2);
}
}
////////////////////////////////////////////////////////////////////
// Function : output_angular_forces
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void Physical::
output_angular_forces(ostream &out, unsigned int indent) const {
out.width(indent);
out<<""<<"_angular_forces\n";
for (AngularForceVector::const_iterator i=_angular_forces.begin();
i != _angular_forces.end();
++i) {
(*i)->output(out, indent+2);
}
}
////////////////////////////////////////////////////////////////////
// Function : output
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void Physical::
output(ostream &out, unsigned int indent) const {
out.width(indent); out<<""<<"Physical:\n";
output_physics_objects(out, indent+2);
output_linear_forces(out, indent+2);
output_angular_forces(out, indent+2);
if (_phys_body) {
_phys_body->output(out, indent+2);
} else {
out.width(indent+2); out<<""<<"_phys_body is null\n";
}
}

View File

@ -40,15 +40,53 @@ class PhysicsManager;
// it from this.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAPHYSICS Physical : public TypedReferenceCount {
private:
PhysicsManager *_physics_manager;
PhysicalNode *_physical_node;
PUBLISHED:
Physical(int ttl_objects = 1, bool pre_alloc = false);
Physical(const Physical& copy);
virtual ~Physical();
// helpers
INLINE PhysicsManager *get_physics_manager() const;
INLINE PhysicalNode *get_physical_node() const;
INLINE PhysicsObject *get_phys_body() const;
INLINE void clear_linear_forces();
INLINE void clear_angular_forces();
INLINE void clear_physics_objects();
INLINE void add_linear_force(LinearForce *f);
INLINE void add_angular_force(AngularForce *f);
INLINE void add_physics_object(PhysicsObject *po);
INLINE void remove_linear_force(LinearForce *f);
INLINE void remove_angular_force(AngularForce *f);
INLINE int get_num_linear_forces() const;
INLINE PT(LinearForce) get_linear_force(int index) const;
INLINE int get_num_angular_forces() const;
INLINE PT(AngularForce) get_angular_force(int index) const;
void output_physics_objects(ostream &out, unsigned int indent=0) const;
void output_linear_forces(ostream &out, unsigned int indent=0) const;
void output_angular_forces(ostream &out, unsigned int indent=0) const;
void output(ostream &out, unsigned int indent=0) const;
public:
typedef pvector< PT(PhysicsObject) > PhysicsObjectVector;
typedef pvector< PT(LinearForce) > LinearForceVector;
typedef pvector< PT(AngularForce) > AngularForceVector;
INLINE const PhysicsObjectVector &get_object_vector() const;
INLINE const LinearForceVector &get_linear_forces() const;
INLINE const AngularForceVector &get_angular_forces() const;
friend class PhysicsManager;
friend class PhysicalNode;
protected:
// containers
pvector< PT(PhysicsObject) > _physics_objects;
pvector< PT(LinearForce) > _linear_forces;
pvector< PT(AngularForce) > _angular_forces;
PhysicsObjectVector _physics_objects;
LinearForceVector _linear_forces;
AngularForceVector _angular_forces;
// this pointer exists to make life easy. If a physical exists
// with only one element (i.e. NOT a particle system or set-physical),
@ -57,49 +95,20 @@ protected:
// this is kind of a quicker way there.
PhysicsObject *_phys_body;
PUBLISHED:
Physical(int ttl_objects = 1, bool pre_alloc = false);
Physical(const Physical& copy);
virtual ~Physical(void);
// helpers
INLINE PhysicsManager *get_physics_manager(void) const;
INLINE PhysicalNode *get_physical_node(void) const;
INLINE PhysicsObject *get_phys_body(void) const;
INLINE void clear_linear_forces(void);
INLINE void clear_angular_forces(void);
INLINE void clear_physics_objects(void);
INLINE void add_linear_force(LinearForce *f);
INLINE void add_angular_force(AngularForce *f);
INLINE void add_physics_object(PhysicsObject *po);
INLINE void remove_linear_force(LinearForce *f);
INLINE void remove_angular_force(AngularForce *f);
INLINE int get_num_linear_forces(void) const;
INLINE PT(LinearForce) get_linear_force(int index) const;
INLINE int get_num_angular_forces(void) const;
INLINE PT(AngularForce) get_angular_force(int index) const;
private:
PhysicsManager *_physics_manager;
PhysicalNode *_physical_node;
public:
INLINE const pvector< PT(PhysicsObject) > &get_object_vector(void) const;
INLINE const pvector< PT(LinearForce) > &get_linear_forces(void) const;
INLINE const pvector< PT(AngularForce) > &get_angular_forces(void) const;
friend class PhysicsManager;
friend class PhysicalNode;
public:
static TypeHandle get_class_type(void) {
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type(void) {
static void init_type() {
TypedReferenceCount::init_type();
register_type(_type_handle, "Physical",
TypedReferenceCount::get_class_type());
}
virtual TypeHandle get_type(void) const {
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}

View File

@ -48,7 +48,7 @@ PhysicalNode(const PhysicalNode &copy) :
// Description : destructor
////////////////////////////////////////////////////////////////////
PhysicalNode::
~PhysicalNode(void) {
~PhysicalNode() {
}
////////////////////////////////////////////////////////////////////
@ -57,7 +57,7 @@ PhysicalNode::
// Description : dynamic child copy
////////////////////////////////////////////////////////////////////
PandaNode *PhysicalNode::
make_copy(void) const {
make_copy() const {
return new PhysicalNode(*this);
}
@ -107,3 +107,15 @@ remove_physical(int index) {
_physicals.erase(remove);
}
////////////////////////////////////////////////////////////////////
// Function : output
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void PhysicalNode::
output(ostream &out, unsigned int indent) const {
out.width(indent); out<<""; out<<"PhysicalNode:\n";
//PandaNode::output(out, indent+2);
}

View File

@ -33,40 +33,40 @@
// objects
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAPHYSICS PhysicalNode : public PandaNode {
private:
pvector< PT(Physical) > _physicals;
PUBLISHED:
PhysicalNode(const string &name);
protected:
PhysicalNode(const PhysicalNode &copy);
public:
virtual ~PhysicalNode(void);
virtual bool safe_to_flatten(void) const { return false; }
virtual PandaNode *make_copy(void) const;
PUBLISHED:
INLINE void clear(void);
INLINE void clear();
INLINE Physical *get_physical(int index) const;
INLINE int get_num_physicals(void) const;
INLINE int get_num_physicals() const;
INLINE void add_physical(Physical *physical);
void add_physicals_from(const PhysicalNode &other);
void remove_physical(Physical *physical);
void remove_physical(int index);
virtual void output(ostream &out, unsigned int indent=0) const;
public:
static TypeHandle get_class_type(void) {
virtual ~PhysicalNode();
virtual bool safe_to_flatten() const { return false; }
virtual PandaNode *make_copy() const;
protected:
PhysicalNode(const PhysicalNode &copy);
private:
pvector< PT(Physical) > _physicals;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type(void) {
static void init_type() {
PandaNode::init_type();
register_type(_type_handle, "PhysicalNode",
PandaNode::get_class_type());
}
virtual TypeHandle get_type(void) const {
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}

View File

@ -29,7 +29,7 @@
// the standard default.
////////////////////////////////////////////////////////////////////
PhysicsManager::
PhysicsManager(void) {
PhysicsManager() {
_linear_integrator.clear();
_angular_integrator.clear();
}
@ -40,7 +40,7 @@ PhysicsManager(void) {
// Description : Simple Destructor
////////////////////////////////////////////////////////////////////
PhysicsManager::
~PhysicsManager(void) {
~PhysicsManager() {
}
////////////////////////////////////////////////////////////////////
@ -89,9 +89,9 @@ remove_physical(Physical *p) {
pvector< Physical * >::iterator found;
found = find(_physicals.begin(), _physicals.end(), p);
if (found == _physicals.end())
if (found == _physicals.end()) {
return;
}
p->_physics_manager = (PhysicsManager *) NULL;
_physicals.erase(found);
}
@ -127,3 +127,94 @@ do_physics(float dt) {
}
}
}
////////////////////////////////////////////////////////////////////
// Function : output_physicals
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void PhysicsManager::
output_physicals(ostream &out, unsigned int indent) const {
if (indent>10) {
return;
}
out.width(indent);
out<<""<<"_physicals ("<<_physicals.size()<<" physicals)\n";
//out<<ios::width(indent)<<" "<<"[physicals \n";
for (pvector< Physical * >::const_iterator i=_physicals.begin();
i != _physicals.end();
++i) {
(*i)->output(out, indent+2);
}
}
////////////////////////////////////////////////////////////////////
// Function : _linear_forces
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void PhysicsManager::
output_linear_forces(ostream &out, unsigned int indent) const {
if (indent>10) {
return;
}
out.width(indent);
out<<""<<"_linear_forces ("<<_linear_forces.size()<<" forces)\n";
for (pvector< PT(LinearForce) >::const_iterator i=_linear_forces.begin();
i != _linear_forces.end();
++i) {
(*i)->output(out, indent+2);
}
}
////////////////////////////////////////////////////////////////////
// Function : output_angular_forces
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void PhysicsManager::
output_angular_forces(ostream &out, unsigned int indent) const {
if (indent>10) {
return;
}
out.width(indent);
out<<""<<"_angular_forces ("<<_angular_forces.size()<<" forces)\n";
for (pvector< PT(AngularForce) >::const_iterator i=_angular_forces.begin();
i != _angular_forces.end();
++i) {
(*i)->output(out, indent+2);
}
}
////////////////////////////////////////////////////////////////////
// Function : output
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void PhysicsManager::
output(ostream &out, unsigned int indent) const {
if (indent>10) {
return;
}
out.width(indent);
out<<""<<"PhysicsManager:\n";
output_physicals(out, indent+2);
output_linear_forces(out, indent+2);
output_angular_forces(out, indent+2);
if (_linear_integrator) {
_linear_integrator->output(out, indent+2);
} else {
out.width(indent+2);
out<<""<<"_linear_integrator is null\n";
}
if (_angular_integrator) {
_angular_integrator->output(out, indent+2);
} else {
out.width(indent+2);
out<<""<<"_angular_integrator is null\n";
}
}

View File

@ -39,6 +39,33 @@
// as you want, pick an integrator and go.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAPHYSICS PhysicsManager {
PUBLISHED:
PhysicsManager();
virtual ~PhysicsManager();
INLINE void attach_linear_integrator(LinearIntegrator *i);
INLINE void attach_angular_integrator(AngularIntegrator *i);
INLINE void attach_physical(Physical *p);
INLINE void attach_physicalnode(PhysicalNode *p);
INLINE void add_linear_force(LinearForce *f);
INLINE void add_angular_force(AngularForce *f);
INLINE void clear_linear_forces();
INLINE void clear_angular_forces();
INLINE void clear_physicals();
void remove_physical(Physical *p);
void remove_linear_force(LinearForce *f);
void remove_angular_force(AngularForce *f);
void do_physics(float dt);
virtual void output_physicals(ostream &out, unsigned int indent=0) const;
virtual void output_linear_forces(ostream &out, unsigned int indent=0) const;
virtual void output_angular_forces(ostream &out, unsigned int indent=0) const;
virtual void output(ostream &out, unsigned int indent=0) const;
public:
friend class Physical;
private:
// NOTE that the physicals container is NOT reference counted.
// this does indeed mean that you are NOT supposed to use this
@ -53,28 +80,6 @@ private:
PT(LinearIntegrator) _linear_integrator;
PT(AngularIntegrator) _angular_integrator;
PUBLISHED:
PhysicsManager(void);
virtual ~PhysicsManager(void);
INLINE void attach_linear_integrator(LinearIntegrator *i);
INLINE void attach_angular_integrator(AngularIntegrator *i);
INLINE void attach_physical(Physical *p);
INLINE void attach_physicalnode(PhysicalNode *p);
INLINE void add_linear_force(LinearForce *f);
INLINE void add_angular_force(AngularForce *f);
INLINE void clear_linear_forces(void);
INLINE void clear_angular_forces(void);
INLINE void clear_physicals(void);
void remove_physical(Physical *p);
void remove_linear_force(LinearForce *f);
void remove_angular_force(AngularForce *f);
void do_physics(float dt);
public:
friend class Physical;
};
#include "physicsManager.I"

View File

@ -55,7 +55,7 @@ PhysicsObject(const PhysicsObject& copy) {
// Description : Destructor
////////////////////////////////////////////////////////////////////
PhysicsObject::
~PhysicsObject(void) {
~PhysicsObject() {
}
////////////////////////////////////////////////////////////////////
@ -84,7 +84,7 @@ operator =(const PhysicsObject &other) {
// Description : dynamic copy.
////////////////////////////////////////////////////////////////////
PhysicsObject *PhysicsObject::
make_copy(void) const {
make_copy() const {
return new PhysicsObject(*this);
}
@ -95,7 +95,7 @@ make_copy(void) const {
// local coordinate system.
////////////////////////////////////////////////////////////////////
LMatrix4f PhysicsObject::
get_lcs(void) const {
get_lcs() const {
LMatrix4f m = LMatrix4f::translate_mat(_position);
if (_oriented == true)
@ -111,6 +111,27 @@ get_lcs(void) const {
// object's willingness to be forced.
////////////////////////////////////////////////////////////////////
LMatrix4f PhysicsObject::
get_inertial_tensor(void) const {
get_inertial_tensor() const {
return LMatrix4f::ident_mat();
}
////////////////////////////////////////////////////////////////////
// Function : output
// Access : Public
// Description : Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
void PhysicsObject::
output(ostream &out, unsigned int indent) const {
out.width(indent);
out<<""<<"PhysicsObject:\n";
out.width(indent+2); out<<""; out<<"_position "<<_position<<"\n";
out.width(indent+2); out<<""; out<<"_last_position "<<_last_position<<"\n";
out.width(indent+2); out<<""; out<<"_velocity "<<_velocity<<"\n";
out.width(indent+2); out<<""; out<<"_orientation "<<_orientation<<"\n";
out.width(indent+2); out<<""; out<<"_rotation "<<_rotation<<"\n";
out.width(indent+2); out<<""; out<<"_terminal_velocity "<<_terminal_velocity<<"\n";
out.width(indent+2); out<<""; out<<"_mass "<<_mass<<"\n";
out.width(indent+2); out<<""; out<<"_process_me "<<_process_me<<"\n";
out.width(indent+2); out<<""; out<<"_oriented "<<_oriented<<"\n";
}

View File

@ -30,22 +30,6 @@
// NOT derive from this. Derive from Physical instead.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAPHYSICS PhysicsObject : public TypedReferenceCount {
private:
// physical
LPoint3f _position;
LPoint3f _last_position;
LVector3f _velocity;
// angular
LOrientationf _orientation;
LVector3f _rotation;
float _terminal_velocity;
float _mass;
bool _process_me;
bool _oriented;
PUBLISHED:
PhysicsObject();
PhysicsObject(const PhysicsObject &copy);
@ -88,6 +72,24 @@ PUBLISHED:
virtual LMatrix4f get_inertial_tensor(void) const;
virtual LMatrix4f get_lcs() const;
virtual PhysicsObject *make_copy() const;
void output(ostream &out, unsigned int indent=0) const;
private:
// physical
LPoint3f _position;
LPoint3f _last_position;
LVector3f _velocity;
// angular
LOrientationf _orientation;
LVector3f _rotation;
float _terminal_velocity;
float _mass;
bool _process_me;
bool _oriented;
public:
static TypeHandle get_class_type() {