Google

Main Page   Class Hierarchy   Compound List   File List   Compound Members  

ptmass.h

00001 /*
00002     Dynamics/Kinematics modeling and simulation library.
00003     Copyright (C) 1999 by Michael Alexander Ewert and Noah Gibbs
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019 */
00020 
00021 #ifndef __CT_PTMASS_H__
00022 #define __CT_PTMASS_H__
00023 
00024 #include "csphyzik/point.h"
00025 #include "csphyzik/entity.h"
00026 
00027 // This is an Aristotelean (i.e. F=mv) point.
00028 class ctDampedPointMass : public ctPointObj, public ctEntity
00029 {
00030 
00031  public:
00032   void set_mass (int newmass)
00033   { m = newmass; }
00034 
00035   real mass (void)
00036   { return m; }
00037 
00039   ctVector3 pos ()
00040   { return x; }
00041 
00042   ctVector3 vel ()
00043   { return v; }
00044 
00045   void apply_force (ctVector3 force)
00046   { v += force / m; }
00047 
00049   void init_state ()
00050   { v = ctVector3(0,0,0); }
00051 
00052   int get_state_size ()
00053   { return 3; }
00054 
00055   int set_state (real *sa)
00056   {
00057     printf ("Set_state!\n");
00058     sa[0] = x[0]; sa[1] = x[1]; sa[2] = x[2];
00059     return get_state_size ();
00060   }
00061 
00062   int get_state (real *sa)
00063   {
00064     printf ("Get_state!\n");
00065     x[0] = sa[0]; x[1] = sa[1]; x[2] = sa[2];
00066     return get_state_size ();
00067   }
00068   int set_delta_state (real *sa)
00069   {
00070     printf ("Set_delta_state!\n");
00071     sa[0] = v[0]; sa[1] = v[1]; sa[2] = v[2];
00072     return get_state_size ();
00073   }
00074 
00075 protected:
00076   real m;
00077   ctVector3 x;
00078 
00079   // Temp vars for dealing with derivatives & solver
00080   ctVector3 v;
00081 };
00082 
00083 // This is a Newtonian (i.e. F=ma) point.
00084 class ctPointMass : public ctPointObj, public ctEntity
00085 {
00086  public:
00087   ctPointMass (real mass)
00088     : m(mass), x(ctVector3(0.0, 0.0, 0.0)), v(ctVector3(0.0, 0.0, 0.0))  {}
00089 
00090   ctPointMass (ctVector3 pos = ctVector3(0.0, 0.0, 0.0),
00091                ctVector3 vel = ctVector3(0.0, 0.0, 0.0), real mass = 1.0)
00092     : m(mass), x(pos), v(vel) {}
00093 
00094   ~ctPointMass() {}
00095 
00096   real mass (void)
00097   { return m; }
00098 
00099   void set_mass (int newmass)
00100   { m = newmass; }
00101 
00103   ctVector3 pos ()
00104   { return x; }
00105 
00106   ctVector3 vel ()
00107   { return v; }
00108 
00109   void apply_force (ctVector3 force)
00110   { F += force / m; }
00111 
00112   void set_pos (ctVector3 pos)
00113   { x = pos; }
00114 
00115   void set_vel (ctVector3 vel)
00116   { v = vel; }
00117 
00118   void set_force (ctVector3 force)
00119   { F = force; }
00120 
00122   void init_state ()
00123   { F[0] = F[1] = F[2] = 0.0; }
00124 
00125   int  get_state_size ()
00126   { return 6; }
00127 
00128   int  set_state(real *sa)
00129   {
00130     sa[0] = x[0]; sa[1] = x[1]; sa[2] = x[2];
00131     sa[3] = v[0]; sa[4] = v[1]; sa[5] = v[2];
00132     return get_state_size();
00133   }
00134 
00135   int  get_state(const real *sa)
00136   {
00137     x[0] = sa[0]; x[1] = sa[1]; x[2] = sa[2];
00138     v[0] = sa[3]; v[1] = sa[4]; v[2] = sa[5];
00139     return get_state_size();
00140   }
00141 
00142   int set_delta_state(real *sa)
00143   {
00144     sa[0] = v[0]; sa[1] = v[1]; sa[2] = v[2];
00145     sa[3] = F[0]; sa[4] = F[1]; sa[5] = F[2];
00146     return get_state_size();
00147   }
00148 
00149 protected:
00150   real      m;
00151   ctVector3 x;
00152   ctVector3 v;
00153 
00154   // Temp vars for dealing with derivatives & solver
00155   ctVector3 F;
00156 };
00157 
00158 #endif // __CT_PTMASS_H__

Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000