128 lines
2.6 KiB
C++
128 lines
2.6 KiB
C++
#include "MassSpringSystemSimulator.h"
|
|
|
|
MassSpringSystemSimulator::MassSpringSystemSimulator()
|
|
{
|
|
//Test only
|
|
//auto first = addMassPoint(Vec3(0, 0, 1), Vec3(0, 0, 0), true);
|
|
//auto second = addMassPoint(Vec3(0, 0, 0), Vec3(0, 0, 0), true);
|
|
//addSpring(first, second, 2.0);
|
|
}
|
|
|
|
const char* MassSpringSystemSimulator::getTestCasesStr()
|
|
{
|
|
return nullptr;
|
|
}
|
|
|
|
void MassSpringSystemSimulator::initUI(DrawingUtilitiesClass* DUC)
|
|
{
|
|
this->DUC = DUC;
|
|
}
|
|
|
|
void MassSpringSystemSimulator::reset()
|
|
{
|
|
}
|
|
|
|
void MassSpringSystemSimulator::drawFrame(ID3D11DeviceContext* pd3dImmediateContext)
|
|
{
|
|
for (size_t i = 0; i < springs.size(); i++) {
|
|
auto sp = springs.at(i);
|
|
if (!sp.isValid())
|
|
{
|
|
springs.erase(springs.begin() + i);
|
|
continue;
|
|
}
|
|
auto mp1 = sp.mp1.lock();
|
|
auto mp2 = sp.mp2.lock();
|
|
DUC->setUpLighting(Vec3(), 0.4 * Vec3(1, 1, 1), 100, 0.6 * Vec3(0.97, 0.86, 1));
|
|
|
|
DUC->drawSphere(mp1->position, Vec3(0.01));
|
|
DUC->drawSphere(mp2->position, Vec3(0.01));
|
|
|
|
DUC->beginLine();
|
|
DUC->drawLine(mp1->position, Vec3(1,0,0), mp2->position, Vec3(0,1,0));
|
|
DUC->endLine();
|
|
}
|
|
}
|
|
|
|
void MassSpringSystemSimulator::notifyCaseChanged(int testCase)
|
|
{
|
|
}
|
|
|
|
void MassSpringSystemSimulator::externalForcesCalculations(float timeElapsed)
|
|
{
|
|
}
|
|
|
|
void MassSpringSystemSimulator::simulateTimestep(float timeStep)
|
|
{
|
|
}
|
|
|
|
void MassSpringSystemSimulator::onClick(int x, int y)
|
|
{
|
|
}
|
|
|
|
void MassSpringSystemSimulator::onMouse(int x, int y)
|
|
{
|
|
}
|
|
|
|
void MassSpringSystemSimulator::setMass(float mass)
|
|
{
|
|
}
|
|
|
|
void MassSpringSystemSimulator::setStiffness(float stiffness)
|
|
{
|
|
}
|
|
|
|
void MassSpringSystemSimulator::setDampingFactor(float damping)
|
|
{
|
|
}
|
|
|
|
int MassSpringSystemSimulator::addMassPoint(Vec3 position, Vec3 Velocity, bool isFixed)
|
|
{
|
|
MassPoint masspoint;
|
|
masspoint.position = position;
|
|
masspoint.velocity = Velocity;
|
|
masspoint.isFixed = isFixed;
|
|
masspoints.push_back(std::make_shared<MassPoint>(masspoint));
|
|
|
|
return masspoints.size() - 1;
|
|
}
|
|
|
|
void MassSpringSystemSimulator::addSpring(int masspoint1, int masspoint2, float initialLength)
|
|
{
|
|
auto mp1 = masspoints.at(masspoint1);
|
|
auto mp2 = masspoints.at(masspoint2);
|
|
|
|
Spring spring;
|
|
spring.mp1 = mp1;
|
|
spring.mp2 = mp2;
|
|
spring.initialLength = initialLength;
|
|
|
|
springs.push_back(spring);
|
|
}
|
|
|
|
int MassSpringSystemSimulator::getNumberOfMassPoints()
|
|
{
|
|
return masspoints.size();
|
|
}
|
|
|
|
int MassSpringSystemSimulator::getNumberOfSprings()
|
|
{
|
|
return springs.size();
|
|
}
|
|
|
|
Vec3 MassSpringSystemSimulator::getPositionOfMassPoint(int index)
|
|
{
|
|
auto mp = masspoints.at(index);
|
|
return mp->position;
|
|
}
|
|
|
|
Vec3 MassSpringSystemSimulator::getVelocityOfMassPoint(int index)
|
|
{
|
|
auto mp = masspoints.at(index);
|
|
return mp->velocity;
|
|
}
|
|
|
|
void MassSpringSystemSimulator::applyExternalForce(Vec3 force)
|
|
{
|
|
}
|