mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-18 15:49:18 +02:00
stl-based names class replacement, re-enabled cab camera shake, enhanced parser comment support, minor bug fixes.
This commit is contained in:
40
Spring.cpp
40
Spring.cpp
@@ -29,7 +29,7 @@ void TSpring::Init(double nrestLen, double nKs, double nKd)
|
||||
restLen = nrestLen;
|
||||
}
|
||||
|
||||
bool TSpring::ComputateForces(vector3 pPosition1, vector3 pPosition2)
|
||||
Math3D::vector3 TSpring::ComputateForces(vector3 const &pPosition1, vector3 const &pPosition2)
|
||||
{
|
||||
|
||||
double dist, Hterm, Dterm;
|
||||
@@ -41,31 +41,29 @@ bool TSpring::ComputateForces(vector3 pPosition1, vector3 pPosition2)
|
||||
// dist = VectorLength(&deltaP); // Magnitude of
|
||||
// deltaP
|
||||
dist = deltaP.Length();
|
||||
if (dist == 0)
|
||||
{
|
||||
vForce1 = vForce2 = vector3(0, 0, 0);
|
||||
return false;
|
||||
if (dist != 0.0 ) {
|
||||
|
||||
// Hterm = (dist - spring->restLen) * spring->Ks; // Ks * (dist - rest)
|
||||
Hterm = ( dist - restLen ) * Ks; // Ks * (dist - rest)
|
||||
|
||||
// VectorDifference(&p1->v,&p2->v,&deltaV); // Delta Velocity Vector
|
||||
deltaV = pPosition1 - pPosition2;
|
||||
|
||||
// Dterm = (DotProduct(&deltaV,&deltaP) * spring->Kd) / dist; // Damping Term
|
||||
// Dterm = (DotProduct(deltaV,deltaP) * Kd) / dist;
|
||||
Dterm = 0;
|
||||
|
||||
// ScaleVector(&deltaP,1.0f / dist, &springForce); // Normalize Distance Vector
|
||||
// ScaleVector(&springForce,-(Hterm + Dterm),&springForce); // Calc Force
|
||||
springForce = deltaP / dist * ( -( Hterm + Dterm ) );
|
||||
// VectorSum(&p1->f,&springForce,&p1->f); // Apply to Particle 1
|
||||
// VectorDifference(&p2->f,&springForce,&p2->f); // - Force on Particle 2
|
||||
}
|
||||
|
||||
// Hterm = (dist - spring->restLen) * spring->Ks; // Ks * (dist - rest)
|
||||
Hterm = (dist - restLen) * Ks; // Ks * (dist - rest)
|
||||
|
||||
// VectorDifference(&p1->v,&p2->v,&deltaV); // Delta Velocity Vector
|
||||
deltaV = pPosition1 - pPosition2;
|
||||
|
||||
// Dterm = (DotProduct(&deltaV,&deltaP) * spring->Kd) / dist; // Damping Term
|
||||
// Dterm = (DotProduct(deltaV,deltaP) * Kd) / dist;
|
||||
Dterm = 0;
|
||||
|
||||
// ScaleVector(&deltaP,1.0f / dist, &springForce); // Normalize Distance Vector
|
||||
// ScaleVector(&springForce,-(Hterm + Dterm),&springForce); // Calc Force
|
||||
springForce = deltaP / dist * (-(Hterm + Dterm));
|
||||
// VectorSum(&p1->f,&springForce,&p1->f); // Apply to Particle 1
|
||||
// VectorDifference(&p2->f,&springForce,&p2->f); // - Force on Particle 2
|
||||
vForce1 = springForce;
|
||||
vForce2 = springForce;
|
||||
|
||||
return true;
|
||||
return springForce;
|
||||
}
|
||||
|
||||
void TSpring::Render()
|
||||
|
||||
Reference in New Issue
Block a user