Demo 1 stuff
This commit is contained in:
@@ -2,28 +2,51 @@
|
|||||||
|
|
||||||
MassSpringSystemSimulator::MassSpringSystemSimulator()
|
MassSpringSystemSimulator::MassSpringSystemSimulator()
|
||||||
{
|
{
|
||||||
|
m_iTestCase = 0;
|
||||||
|
m_fMass = 10;
|
||||||
|
m_fStiffness = 40;
|
||||||
|
int m_iIntegrater = 0;
|
||||||
|
|
||||||
|
|
||||||
//Test only
|
//Test only
|
||||||
//auto first = addMassPoint(Vec3(0, 0, 1), Vec3(0, 0, 0), true);
|
auto first = addMassPoint(Vec3(0, 0, 1), Vec3(0, 0, 0), true);
|
||||||
//auto second = addMassPoint(Vec3(0, 0, 0), Vec3(0, 0, 0), true);
|
auto second = addMassPoint(Vec3(0, 0, 0), Vec3(0, 0, 0), true);
|
||||||
//addSpring(first, second, 2.0);
|
addSpring(first, second, 2.0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* MassSpringSystemSimulator::getTestCasesStr()
|
const char* MassSpringSystemSimulator::getTestCasesStr()
|
||||||
{
|
{
|
||||||
return nullptr;
|
return "Demo1,Demo2,Demo3,Demo4";
|
||||||
}
|
}
|
||||||
|
|
||||||
void MassSpringSystemSimulator::initUI(DrawingUtilitiesClass* DUC)
|
void MassSpringSystemSimulator::initUI(DrawingUtilitiesClass* DUC)
|
||||||
{
|
{
|
||||||
this->DUC = DUC;
|
this->DUC = DUC;
|
||||||
|
switch (m_iTestCase)
|
||||||
|
{
|
||||||
|
case 0:break;
|
||||||
|
case 1:
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
break;
|
||||||
|
default:break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MassSpringSystemSimulator::reset()
|
void MassSpringSystemSimulator::reset()
|
||||||
{
|
{
|
||||||
|
m_mouse.x = m_mouse.y = 0;
|
||||||
|
m_trackmouse.x = m_trackmouse.y = 0;
|
||||||
|
m_oldtrackmouse.x = m_oldtrackmouse.y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void MassSpringSystemSimulator::drawFrame(ID3D11DeviceContext* pd3dImmediateContext)
|
void MassSpringSystemSimulator::drawFrame(ID3D11DeviceContext* pd3dImmediateContext)
|
||||||
{
|
{
|
||||||
|
|
||||||
for (size_t i = 0; i < springs.size(); i++) {
|
for (size_t i = 0; i < springs.size(); i++) {
|
||||||
auto sp = springs.at(i);
|
auto sp = springs.at(i);
|
||||||
if (!sp.isValid())
|
if (!sp.isValid())
|
||||||
@@ -46,34 +69,103 @@ void MassSpringSystemSimulator::drawFrame(ID3D11DeviceContext* pd3dImmediateCont
|
|||||||
|
|
||||||
void MassSpringSystemSimulator::notifyCaseChanged(int testCase)
|
void MassSpringSystemSimulator::notifyCaseChanged(int testCase)
|
||||||
{
|
{
|
||||||
|
m_iTestCase = testCase;
|
||||||
|
switch (m_iTestCase)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
cout << "Demo1 !\n";
|
||||||
|
|
||||||
|
//simulateTimestep(1);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
cout << "Demo2 \n";
|
||||||
|
//m_iNumSpheres = 100;
|
||||||
|
//m_fSphereSize = 0.05f;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
cout << "Demo3 !\n";
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
cout << "Demo 4 !\n";
|
||||||
|
default:
|
||||||
|
//cout << "Demo4 !\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MassSpringSystemSimulator::externalForcesCalculations(float timeElapsed)
|
void MassSpringSystemSimulator::externalForcesCalculations(float timeElapsed)
|
||||||
{
|
{
|
||||||
|
Point2D mouseDiff;
|
||||||
|
mouseDiff.x = m_trackmouse.x - m_oldtrackmouse.x;
|
||||||
|
mouseDiff.y = m_trackmouse.y - m_oldtrackmouse.y;
|
||||||
|
if (mouseDiff.x != 0 || mouseDiff.y != 0)
|
||||||
|
{
|
||||||
|
Mat4 worldViewInv = Mat4(DUC->g_camera.GetWorldMatrix() * DUC->g_camera.GetViewMatrix());
|
||||||
|
worldViewInv = worldViewInv.inverse();
|
||||||
|
Vec3 inputView = Vec3((float)mouseDiff.x, (float)-mouseDiff.y, 0);
|
||||||
|
Vec3 inputWorld = worldViewInv.transformVectorNormal(inputView);
|
||||||
|
// find a proper scale!
|
||||||
|
float inputScale = 0.001f;
|
||||||
|
inputWorld = inputWorld * inputScale;
|
||||||
|
|
||||||
|
//m_vfMovableObjectPos = m_vfMovableObjectFinalPos + inputWorld;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//m_vfMovableObjectFinalPos = m_vfMovableObjectPos;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void MassSpringSystemSimulator::simulateTimestep(float timeStep)
|
void MassSpringSystemSimulator::simulateTimestep(float timeStep)
|
||||||
{
|
{
|
||||||
|
//update current setup for each frame
|
||||||
|
switch (m_iTestCase) {
|
||||||
|
case 0:
|
||||||
|
//update the masspoint
|
||||||
|
cout << "Euler \n";
|
||||||
|
|
||||||
|
cout << "Midpoint\n";
|
||||||
|
break;
|
||||||
|
case 1:cout << "demo 2 \n";
|
||||||
|
break;
|
||||||
|
case 2:cout << "demo 3\n";
|
||||||
|
break;
|
||||||
|
case 3: cout << "demo 4\n";
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MassSpringSystemSimulator::onClick(int x, int y)
|
void MassSpringSystemSimulator::onClick(int x, int y)
|
||||||
{
|
{
|
||||||
|
m_trackmouse.x = x;
|
||||||
|
m_trackmouse.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MassSpringSystemSimulator::onMouse(int x, int y)
|
void MassSpringSystemSimulator::onMouse(int x, int y)
|
||||||
{
|
{
|
||||||
|
m_oldtrackmouse.x = x;
|
||||||
|
m_oldtrackmouse.y = y;
|
||||||
|
m_trackmouse.x = x;
|
||||||
|
m_trackmouse.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MassSpringSystemSimulator::setMass(float mass)
|
void MassSpringSystemSimulator::setMass(float mass)
|
||||||
{
|
{
|
||||||
|
m_fMass = mass;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MassSpringSystemSimulator::setStiffness(float stiffness)
|
void MassSpringSystemSimulator::setStiffness(float stiffness)
|
||||||
{
|
{
|
||||||
|
m_fStiffness = stiffness;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MassSpringSystemSimulator::setDampingFactor(float damping)
|
void MassSpringSystemSimulator::setDampingFactor(float damping)
|
||||||
{
|
{
|
||||||
|
m_fDamping = damping;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MassSpringSystemSimulator::addMassPoint(Vec3 position, Vec3 Velocity, bool isFixed)
|
int MassSpringSystemSimulator::addMassPoint(Vec3 position, Vec3 Velocity, bool isFixed)
|
||||||
@@ -124,4 +216,5 @@ Vec3 MassSpringSystemSimulator::getVelocityOfMassPoint(int index)
|
|||||||
|
|
||||||
void MassSpringSystemSimulator::applyExternalForce(Vec3 force)
|
void MassSpringSystemSimulator::applyExternalForce(Vec3 force)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,64 +1,64 @@
|
|||||||
#ifndef MASSSPRINGSYSTEMSIMULATOR_h
|
#ifndef MASSSPRINGSYSTEMSIMULATOR_h
|
||||||
#define MASSSPRINGSYSTEMSIMULATOR_h
|
#define MASSSPRINGSYSTEMSIMULATOR_h
|
||||||
#include "Simulator.h"
|
#include "Simulator.h"
|
||||||
#include "MassPoint.h"
|
#include "MassPoint.h"
|
||||||
#include "Spring.h"
|
#include "Spring.h"
|
||||||
|
|
||||||
// Do Not Change
|
// Do Not Change
|
||||||
#define EULER 0
|
#define EULER 0
|
||||||
#define LEAPFROG 1
|
#define LEAPFROG 1
|
||||||
#define MIDPOINT 2
|
#define MIDPOINT 2
|
||||||
// Do Not Change
|
// Do Not Change
|
||||||
|
|
||||||
|
|
||||||
class MassSpringSystemSimulator:public Simulator{
|
class MassSpringSystemSimulator:public Simulator{
|
||||||
public:
|
public:
|
||||||
// Construtors
|
// Construtors
|
||||||
MassSpringSystemSimulator();
|
MassSpringSystemSimulator();
|
||||||
|
|
||||||
// UI Functions
|
// UI Functions
|
||||||
const char * getTestCasesStr();
|
const char * getTestCasesStr();
|
||||||
void initUI(DrawingUtilitiesClass * DUC);
|
void initUI(DrawingUtilitiesClass * DUC);
|
||||||
void reset();
|
void reset();
|
||||||
void drawFrame(ID3D11DeviceContext* pd3dImmediateContext);
|
void drawFrame(ID3D11DeviceContext* pd3dImmediateContext);
|
||||||
void notifyCaseChanged(int testCase);
|
void notifyCaseChanged(int testCase);
|
||||||
void externalForcesCalculations(float timeElapsed);
|
void externalForcesCalculations(float timeElapsed);
|
||||||
void simulateTimestep(float timeStep);
|
void simulateTimestep(float timeStep);
|
||||||
void onClick(int x, int y);
|
void onClick(int x, int y);
|
||||||
void onMouse(int x, int y);
|
void onMouse(int x, int y);
|
||||||
|
|
||||||
// Specific Functions
|
// Specific Functions
|
||||||
void setMass(float mass);
|
void setMass(float mass);
|
||||||
void setStiffness(float stiffness);
|
void setStiffness(float stiffness);
|
||||||
void setDampingFactor(float damping);
|
void setDampingFactor(float damping);
|
||||||
int addMassPoint(Vec3 position, Vec3 Velocity, bool isFixed);
|
int addMassPoint(Vec3 position, Vec3 Velocity, bool isFixed);
|
||||||
void addSpring(int masspoint1, int masspoint2, float initialLength);
|
void addSpring(int masspoint1, int masspoint2, float initialLength);
|
||||||
int getNumberOfMassPoints();
|
int getNumberOfMassPoints();
|
||||||
int getNumberOfSprings();
|
int getNumberOfSprings();
|
||||||
Vec3 getPositionOfMassPoint(int index);
|
Vec3 getPositionOfMassPoint(int index);
|
||||||
Vec3 getVelocityOfMassPoint(int index);
|
Vec3 getVelocityOfMassPoint(int index);
|
||||||
void applyExternalForce(Vec3 force);
|
void applyExternalForce(Vec3 force);
|
||||||
|
|
||||||
// Do Not Change
|
// Do Not Change
|
||||||
void setIntegrator(int integrator) {
|
void setIntegrator(int integrator) {
|
||||||
m_iIntegrator = integrator;
|
m_iIntegrator = integrator;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Data Attributes
|
// Data Attributes
|
||||||
float m_fMass;
|
float m_fMass;
|
||||||
float m_fStiffness;
|
float m_fStiffness;
|
||||||
float m_fDamping;
|
float m_fDamping;
|
||||||
int m_iIntegrator;
|
int m_iIntegrator;
|
||||||
|
|
||||||
// UI Attributes
|
// UI Attributes
|
||||||
Vec3 m_externalForce;
|
Vec3 m_externalForce;
|
||||||
Point2D m_mouse;
|
Point2D m_mouse;
|
||||||
Point2D m_trackmouse;
|
Point2D m_trackmouse;
|
||||||
Point2D m_oldtrackmouse;
|
Point2D m_oldtrackmouse;
|
||||||
|
|
||||||
//Mass points and springs
|
//Mass points and springs
|
||||||
std::vector<std::shared_ptr<MassPoint>> masspoints;
|
std::vector<std::shared_ptr<MassPoint>> masspoints;
|
||||||
std::vector<Spring> springs;
|
std::vector<Spring> springs;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user