Fix Repo + add basics
This commit is contained in:
@@ -224,12 +224,14 @@
|
||||
</FxCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="MassSpringSystemSimulator.cpp" />
|
||||
<ClCompile Include="TemplateSimulator.cpp" />
|
||||
<ClCompile Include="util\FFmpeg.cpp" />
|
||||
<ClCompile Include="util\util.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="DrawingUtilitiesClass.h" />
|
||||
<ClInclude Include="MassPoint.h" />
|
||||
<ClInclude Include="MassSpringSystemSimulator.h" />
|
||||
<ClInclude Include="Simulator.h" />
|
||||
<ClInclude Include="TemplateSimulator.h" />
|
||||
|
||||
28
Simulations/Demo_2022.vcxproj.filters
Normal file
28
Simulations/Demo_2022.vcxproj.filters
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<FxCompile Include="effect.fx" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="MassSpringSystemSimulator.cpp" />
|
||||
<ClCompile Include="TemplateSimulator.cpp" />
|
||||
<ClCompile Include="util\FFmpeg.cpp" />
|
||||
<ClCompile Include="util\util.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="DrawingUtilitiesClass.h" />
|
||||
<ClInclude Include="MassSpringSystemSimulator.h" />
|
||||
<ClInclude Include="Simulator.h" />
|
||||
<ClInclude Include="TemplateSimulator.h" />
|
||||
<ClInclude Include="util\FFmpeg.h" />
|
||||
<ClInclude Include="util\matrixbase.h" />
|
||||
<ClInclude Include="util\quaternion.h" />
|
||||
<ClInclude Include="util\timer.h" />
|
||||
<ClInclude Include="util\util.h" />
|
||||
<ClInclude Include="util\vectorbase.h" />
|
||||
<ClInclude Include="MassPoint.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="..\readme.txt" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
8
Simulations/MassPoint.h
Normal file
8
Simulations/MassPoint.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#include "util/vectorbase.h"
|
||||
|
||||
struct MassPoint {
|
||||
GamePhysics::Vec3 position;
|
||||
GamePhysics::Vec3 velocity;
|
||||
bool isFixed;
|
||||
};
|
||||
127
Simulations/MassSpringSystemSimulator.cpp
Normal file
127
Simulations/MassSpringSystemSimulator.cpp
Normal file
@@ -0,0 +1,127 @@
|
||||
#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)
|
||||
{
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef MASSSPRINGSYSTEMSIMULATOR_h
|
||||
#define MASSSPRINGSYSTEMSIMULATOR_h
|
||||
#include "Simulator.h"
|
||||
#include "MassPoint.h"
|
||||
#include "Spring.h"
|
||||
|
||||
// Do Not Change
|
||||
#define EULER 0
|
||||
@@ -54,5 +56,9 @@ private:
|
||||
Point2D m_mouse;
|
||||
Point2D m_trackmouse;
|
||||
Point2D m_oldtrackmouse;
|
||||
|
||||
//Mass points and springs
|
||||
std::vector<std::shared_ptr<MassPoint>> masspoints;
|
||||
std::vector<Spring> springs;
|
||||
};
|
||||
#endif
|
||||
0
Simulations/Spring.cpp
Normal file
0
Simulations/Spring.cpp
Normal file
11
Simulations/Spring.h
Normal file
11
Simulations/Spring.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
struct Spring
|
||||
{
|
||||
std::weak_ptr<MassPoint> mp1;
|
||||
std::weak_ptr<MassPoint> mp2;
|
||||
float initialLength;
|
||||
|
||||
bool isValid() { return !mp1.expired() && !mp2.expired(); }
|
||||
};
|
||||
|
||||
@@ -20,8 +20,8 @@ using namespace GamePhysics;
|
||||
|
||||
//#define ADAPTIVESTEP
|
||||
|
||||
#define TEMPLATE_DEMO
|
||||
//#define MASS_SPRING_SYSTEM
|
||||
//#define TEMPLATE_DEMO
|
||||
#define MASS_SPRING_SYSTEM
|
||||
//#define RIGID_BODY_SYSTEM
|
||||
//#define SPH_SYSTEM
|
||||
|
||||
|
||||
Reference in New Issue
Block a user