mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-18 05:29:18 +02:00
engine revolution based cab shake configuration support, rear cab door controls animation fix
This commit is contained in:
44
Spring.cpp
44
Spring.cpp
@@ -10,48 +10,31 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "stdafx.h"
|
||||
#include "Spring.h"
|
||||
|
||||
TSpring::TSpring()
|
||||
{
|
||||
vForce1 = vForce2 = Math3D::vector3(0, 0, 0);
|
||||
Ks = 0;
|
||||
Kd = 0;
|
||||
restLen = 0;
|
||||
}
|
||||
|
||||
TSpring::~TSpring()
|
||||
{
|
||||
}
|
||||
|
||||
void TSpring::Init(double nrestLen, double nKs, double nKd)
|
||||
{
|
||||
void TSpring::Init(double nKs, double nKd) {
|
||||
Ks = nKs;
|
||||
Kd = nKd;
|
||||
restLen = nrestLen;
|
||||
}
|
||||
|
||||
Math3D::vector3 TSpring::ComputateForces( Math3D::vector3 const &pPosition1, Math3D::vector3 const &pPosition2)
|
||||
{
|
||||
Math3D::vector3 TSpring::ComputateForces( Math3D::vector3 const &pPosition1, Math3D::vector3 const &pPosition2) {
|
||||
|
||||
double dist, Hterm, Dterm;
|
||||
Math3D::vector3 springForce, deltaV;
|
||||
Math3D::vector3 springForce;
|
||||
// p1 = &system[spring->p1];
|
||||
// p2 = &system[spring->p2];
|
||||
// VectorDifference(&p1->pos,&p2->pos,&deltaP); // Vector distance
|
||||
auto deltaP = pPosition1 - pPosition2;
|
||||
// dist = VectorLength(&deltaP); // Magnitude of
|
||||
// deltaP
|
||||
dist = deltaP.Length();
|
||||
if( dist > 0.00001 ) {
|
||||
// dist = VectorLength(&deltaP); // Magnitude of deltaP
|
||||
auto dist = deltaP.Length();
|
||||
if( dist > restLen ) {
|
||||
|
||||
// Hterm = (dist - spring->restLen) * spring->Ks; // Ks * (dist - rest)
|
||||
Hterm = ( dist - restLen ) * Ks; // Ks * (dist - rest)
|
||||
auto Hterm = ( dist - restLen ) * Ks; // Ks * (dist - rest)
|
||||
|
||||
// VectorDifference(&p1->v,&p2->v,&deltaV); // Delta Velocity Vector
|
||||
deltaV = pPosition1 - pPosition2;
|
||||
auto deltaV = pPosition1 - pPosition2;
|
||||
|
||||
// Dterm = (DotProduct(&deltaV,&deltaP) * spring->Kd) / dist; // Damping Term
|
||||
// Dterm = (DotProduct(deltaV,deltaP) * Kd) / dist;
|
||||
Dterm = 0;
|
||||
auto Dterm = (DotProduct(deltaV,deltaP) * Kd) / dist;
|
||||
//Dterm = 0;
|
||||
|
||||
// ScaleVector(&deltaP,1.0f / dist, &springForce); // Normalize Distance Vector
|
||||
// ScaleVector(&springForce,-(Hterm + Dterm),&springForce); // Calc Force
|
||||
@@ -60,14 +43,7 @@ Math3D::vector3 TSpring::ComputateForces( Math3D::vector3 const &pPosition1, Mat
|
||||
// VectorDifference(&p2->f,&springForce,&p2->f); // - Force on Particle 2
|
||||
}
|
||||
|
||||
vForce1 = springForce;
|
||||
vForce2 = springForce;
|
||||
|
||||
return springForce;
|
||||
}
|
||||
|
||||
void TSpring::Render()
|
||||
{
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user