00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef CGELMassParticleH
00015 #define CGELMassParticleH
00016
00017 #include "chai3d.h"
00018
00019 using namespace std;
00020
00021
00022
00030
00031
00032
00040
00041 class cGELMassParticle
00042 {
00043 public:
00044
00045
00046
00047
00048
00050 cGELMassParticle();
00051
00053 virtual ~cGELMassParticle();
00054
00055
00056
00057
00058
00059
00061 void setMass(double a_mass);
00062
00064 inline void addForce(cVector3d &a_force)
00065 {
00066 m_force.add(a_force);
00067 }
00068
00070 inline void setExternalForce(cVector3d &a_force)
00071 {
00072 m_externalForce = a_force;
00073 }
00074
00076 inline void computeNextPose(double a_timeInterval)
00077 {
00078 if (!m_fixed)
00079 {
00080
00081 cVector3d damping;
00082 m_vel.mulr(-m_kDampingPos * m_mass, damping);
00083 m_force.add(damping);
00084 m_acc = cDiv(m_mass, cAdd(m_force, m_externalForce));
00085 m_vel = cAdd(m_vel, cMul(a_timeInterval, m_acc));
00086 m_nextPos = cAdd(m_pos, cMul(a_timeInterval, m_vel));
00087 }
00088 else
00089 {
00090 m_nextPos = m_pos;
00091 }
00092 }
00093
00095 inline void applyNextPose()
00096 {
00097 m_pos = m_nextPos;
00098 }
00099
00101 inline void clearForces()
00102 {
00103 if (m_useGravity)
00104 {
00105 m_gravity.mulr(m_mass, m_force);
00106 }
00107 else
00108 {
00109 m_force.zero();
00110 }
00111 }
00112
00114 inline void clearExternalForces()
00115 {
00116 m_externalForce.zero();
00117 }
00118
00120 inline void render()
00121 {
00122
00123 m_color.render();
00124 glBegin(GL_POINTS);
00125 glVertex3dv( (const double *)&m_pos);
00126 glEnd();
00127
00128
00129 glColor4fv( (const float *)&m_color);
00130 cVector3d v = cAdd(m_pos, cMul(scale_force_vector_display, m_externalForce));
00131 glBegin(GL_LINES);
00132 glVertex3dv( (const double *)&m_pos);
00133 glVertex3dv( (const double *)&v);
00134 glEnd();
00135 }
00136
00137
00138
00139
00140
00141
00143 double m_mass;
00144
00146 cVector3d m_force;
00147
00149 cVector3d m_acc;
00150
00152 cVector3d m_vel;
00153
00155 double m_kDampingPos;
00156
00158 bool m_fixed;
00159
00161 bool m_useGravity;
00162
00164 cVector3d m_gravity;
00165
00166
00167
00168
00169
00170
00172 cColorf m_color;
00173
00174
00175 public:
00176
00177
00178
00179
00180
00182 cVector3d m_pos;
00183
00185 cVector3d m_nextPos;
00186
00187
00188 private:
00189
00190
00191
00192
00193
00195 cVector3d m_externalForce;
00196
00197
00198 public:
00199
00200
00201
00202
00203
00205 static double default_kDampingPos;
00206
00208 static double default_mass;
00209
00211 static cColorf default_color;
00212
00214 static bool default_useGravity;
00215
00217 static cVector3d default_gravity;
00218
00220 static bool show_forces;
00221
00223 static bool scale_force_vector_display;
00224 };
00225
00226
00227 #endif
00228
00229
00230