Compare commits
14 Commits
cmake
...
b857996445
| Author | SHA1 | Date | |
|---|---|---|---|
| b857996445 | |||
| 00ac0d266d | |||
| 50d8f7561e | |||
| 9316f35eee | |||
|
|
b1c4939b16 | ||
| 489ddce9b2 | |||
| af0421a557 | |||
| ef4251f664 | |||
|
|
0647bb8735 | ||
| 82f103758d | |||
|
|
03ebc33ec6 | ||
|
|
3946a25f27 | ||
|
|
741958d30b | ||
| 047b913dfa |
@@ -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;
|
||||
};
|
||||
387
Simulations/MassSpringSystemSimulator.cpp
Normal file
387
Simulations/MassSpringSystemSimulator.cpp
Normal file
@@ -0,0 +1,387 @@
|
||||
#include "MassSpringSystemSimulator.h"
|
||||
#include <stdio.h>
|
||||
|
||||
MassSpringSystemSimulator::MassSpringSystemSimulator()
|
||||
{
|
||||
m_iTestCase = 0;
|
||||
m_fMass = 10;
|
||||
m_fStiffness = 40;
|
||||
m_iIntegrator = EULER;
|
||||
}
|
||||
|
||||
const char* MassSpringSystemSimulator::getTestCasesStr()
|
||||
{
|
||||
return "Demo1,Demo2,Demo3,Demo4";
|
||||
}
|
||||
|
||||
void MassSpringSystemSimulator::initUI(DrawingUtilitiesClass* DUC)
|
||||
{
|
||||
this->DUC = DUC;
|
||||
switch (m_iTestCase)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
break;
|
||||
case 2:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MassSpringSystemSimulator::reset()
|
||||
{
|
||||
m_mouse.x = m_mouse.y = 0;
|
||||
m_trackmouse.x = m_trackmouse.y = 0;
|
||||
m_oldtrackmouse.x = m_oldtrackmouse.y = 0;
|
||||
|
||||
springs.clear();
|
||||
masspoints.clear();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
m_iTestCase = testCase;
|
||||
system("cls");
|
||||
reset();
|
||||
|
||||
switch (m_iTestCase)
|
||||
{
|
||||
case 0: {
|
||||
cout << "Demo 1 !\n";
|
||||
setMass(10);
|
||||
setStiffness(40);
|
||||
|
||||
int first = addMassPoint(Vec3(0, 0, 0), Vec3(-1, 0, 0), true);
|
||||
int second = addMassPoint(Vec3(0, 2, 0), Vec3(1, 0, 0), true);
|
||||
|
||||
addSpring(first, second, 1);
|
||||
cout << "\t -- INITIAL --\n";
|
||||
printSpring(springs.at(0));
|
||||
cout << "--------------------------------------------------" << std::endl;
|
||||
|
||||
//calculate Euler for one step and print results
|
||||
setIntegrator(EULER);
|
||||
cout << "\n\n\t -- EULER RESULT --\n";
|
||||
simulateTimestep(1);
|
||||
printSpring(springs.at(0));
|
||||
|
||||
cout << "--------------------------------------------------" << std::endl;
|
||||
|
||||
reset();
|
||||
first = addMassPoint(Vec3(0, 0, 0), Vec3(-1, 0, 0), true);
|
||||
second = addMassPoint(Vec3(0, 2, 0), Vec3(1, 0, 0), true);
|
||||
|
||||
addSpring(first, second, 1);
|
||||
|
||||
//calculate Midpoint for one step and print results
|
||||
setIntegrator(MIDPOINT);
|
||||
cout << "\n\n\t -- MIDPOINT RESULT --\n";
|
||||
simulateTimestep(1);
|
||||
printSpring(springs.at(0));
|
||||
break;
|
||||
}
|
||||
|
||||
case 1: {
|
||||
cout << "Demo 2 !\n";
|
||||
reset();
|
||||
int first = addMassPoint(Vec3(0, 0, 0), Vec3(-1, 0, 0), true);
|
||||
int second = addMassPoint(Vec3(0, 2, 0), Vec3(1, 0, 0), true);
|
||||
addSpring(first, second, 1.0);
|
||||
|
||||
cout << "\t -- INITIAL --\n";
|
||||
printSpring(springs.at(0));
|
||||
|
||||
cout << "--------------------------------------------------" << std::endl;
|
||||
|
||||
//calculate Euler for a timestep of 0.005 and print results
|
||||
setIntegrator(EULER);
|
||||
cout << "\n\n\t -- EULER RESULT--\n";
|
||||
simulateTimestep(0.005);
|
||||
printSpring(springs.at(0));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 2: {
|
||||
cout << "Demo 3 !\n";
|
||||
reset();
|
||||
int first = addMassPoint(Vec3(0, 0, 0), Vec3(-1, 0, 0), true);
|
||||
int second = addMassPoint(Vec3(0, 2, 0), Vec3(1, 0, 0), true);
|
||||
addSpring(first, second, 1.0);
|
||||
|
||||
cout << "\t -- INITIAL --\n";
|
||||
printSpring(springs.at(0));
|
||||
|
||||
cout << "--------------------------------------------------" << std::endl;
|
||||
|
||||
//calculate Midpoint for a timestep of 0.005 and print results
|
||||
setIntegrator(MIDPOINT);
|
||||
cout << "\n\n\t -- MIDPOINT RESULT --\n";
|
||||
simulateTimestep(0.005);
|
||||
printSpring(springs.at(0));
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
cout << "Demo 4 !\n";
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
//update current setup for each frame
|
||||
for (size_t i = 0; i < springs.size(); i++) {
|
||||
auto sp = springs.at(i);
|
||||
if (!sp.isValid())
|
||||
{
|
||||
springs.erase(springs.begin() + i);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (m_iIntegrator == EULER) {
|
||||
|
||||
Euler(sp, timeStep);
|
||||
}
|
||||
else if (m_iIntegrator == MIDPOINT) {
|
||||
Midpoint(sp, timeStep);
|
||||
}
|
||||
else if (m_iIntegrator == LEAPFROG) {
|
||||
//TODO: Add Leapfrog
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void MassSpringSystemSimulator::onClick(int x, int y)
|
||||
{
|
||||
m_trackmouse.x = x;
|
||||
m_trackmouse.y = 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)
|
||||
{
|
||||
m_fMass = mass;
|
||||
}
|
||||
|
||||
void MassSpringSystemSimulator::setStiffness(float stiffness)
|
||||
{
|
||||
m_fStiffness = stiffness;
|
||||
}
|
||||
|
||||
void MassSpringSystemSimulator::setDampingFactor(float damping)
|
||||
{
|
||||
m_fDamping = 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)
|
||||
{
|
||||
//eine Vorstellung: for all Masspoints, update force
|
||||
}
|
||||
|
||||
float MassSpringSystemSimulator::LengthCalculator(Vec3 vector)
|
||||
{
|
||||
//wurzel aus Vektor
|
||||
float length = sqrt(vector.x * vector.x + vector.y * vector.y + vector.z * vector.z);
|
||||
return length;
|
||||
}
|
||||
|
||||
Vec3 MassSpringSystemSimulator::calculatePositionTimestepEuler(Vec3 oldPosition, float timestep, Vec3 velocity)
|
||||
{
|
||||
return oldPosition + timestep * velocity;
|
||||
}
|
||||
|
||||
Vec3 MassSpringSystemSimulator::calculateVelocityTimestepEuler(Vec3 oldVelocity, float timestep, Vec3 acceleration)
|
||||
{
|
||||
return oldVelocity + acceleration * timestep;
|
||||
}
|
||||
|
||||
Vec3 MassSpringSystemSimulator::calculateAcceleration(Vec3 force, float mass)
|
||||
{
|
||||
return force / mass;
|
||||
}
|
||||
|
||||
void MassSpringSystemSimulator::Midpoint(Spring& spring, float timestep) {
|
||||
//here some implementation about Midpoint
|
||||
auto massPoint1 = spring.mp1.lock();
|
||||
auto massPoint2 = spring.mp2.lock();
|
||||
|
||||
//old Velocity
|
||||
auto mOld_v = massPoint1->velocity;
|
||||
auto m2Old_v = massPoint2->velocity;
|
||||
|
||||
Vec3 PosVector = massPoint1->position - massPoint2->position;
|
||||
//Abstand ausrechnen
|
||||
float length = LengthCalculator(PosVector);
|
||||
//normalize
|
||||
Vec3 normal1 = PosVector / length;
|
||||
Vec3 normal2 = -1 * normal1;
|
||||
|
||||
//Midpoint calculator
|
||||
auto midpointStep1 = MidPointStep(timestep / 2, spring, massPoint1->position, massPoint1->velocity, normal1, length);
|
||||
auto midpointStep2 = MidPointStep(timestep / 2, spring, massPoint2->position, massPoint2->velocity, normal2, length);
|
||||
|
||||
auto newPosVector = std::get<0>(midpointStep1) - std::get<0>(midpointStep2);
|
||||
auto newLength = LengthCalculator(newPosVector);
|
||||
auto newNormal1 = newPosVector / newLength;
|
||||
auto newNormal2 = -1 * newNormal1;
|
||||
|
||||
auto midpoint1 = MidPointStep(timestep, spring, massPoint1->position, std::get<1>(midpointStep1), newNormal1, newLength);
|
||||
auto midpoint2 = MidPointStep(timestep, spring, massPoint2->position, std::get<1>(midpointStep2), newNormal2, newLength);
|
||||
|
||||
//cout << NewPos;
|
||||
//cout << NewVel;
|
||||
massPoint1->position = std::get<0>(midpoint1);
|
||||
massPoint1->velocity = std::get<1>(midpoint1);
|
||||
massPoint2->position = std::get<0>(midpoint2);
|
||||
massPoint2->velocity = std::get<1>(midpoint2);
|
||||
}
|
||||
|
||||
std::tuple<Vec3, Vec3> MassSpringSystemSimulator::MidPointStep(float timestep, const Spring& spring, Vec3 position, Vec3 velocity, Vec3 normal, float length)
|
||||
{
|
||||
Vec3 force = -m_fStiffness * (length - spring.initialLength) * normal;
|
||||
Vec3 acc = calculateAcceleration(force, m_fMass);
|
||||
Vec3 pos = position + timestep * velocity;
|
||||
Vec3 vel = velocity + timestep * acc;
|
||||
return std::tuple<Vec3,Vec3>(pos, vel);
|
||||
}
|
||||
|
||||
void MassSpringSystemSimulator::Euler(Spring& spring, float timestep)
|
||||
{
|
||||
auto massPoint1 = spring.mp1.lock();
|
||||
auto massPoint2 = spring.mp2.lock();
|
||||
|
||||
//take old position and send to calculatePositionTimestepEuler
|
||||
auto PosVector = massPoint1->position - massPoint2->position;
|
||||
auto lengthVector = sqrt(PosVector.x * PosVector.x + PosVector.y * PosVector.y + PosVector.z * PosVector.z);
|
||||
auto normalized = PosVector / lengthVector;
|
||||
|
||||
// Actual Calculation
|
||||
// Force of spring is -k * (l - L) * normalizedVector [for P2 we can take -F1)
|
||||
auto force = -m_fStiffness * (lengthVector - spring.initialLength) * normalized;
|
||||
auto foreP2 = -1 * force;
|
||||
auto veloc = calculateVelocityTimestepEuler(massPoint1->velocity, timestep, calculateAcceleration(force, m_fMass));
|
||||
auto pos = calculatePositionTimestepEuler(massPoint1->position, timestep, massPoint1->velocity);
|
||||
|
||||
auto veloc2 = calculateVelocityTimestepEuler(massPoint2->velocity, timestep, calculateAcceleration(foreP2, m_fMass));
|
||||
auto pos2 = calculatePositionTimestepEuler(massPoint2->position, timestep, massPoint2->velocity);
|
||||
|
||||
// Update Positions and Velocity
|
||||
massPoint1->position = pos;
|
||||
massPoint1->velocity = veloc;
|
||||
|
||||
massPoint2->position = pos2;
|
||||
massPoint2->velocity = veloc2;
|
||||
}
|
||||
|
||||
void MassSpringSystemSimulator::printSpring(const Spring& spring)
|
||||
{
|
||||
auto mp1 = spring.mp1.lock();
|
||||
auto mp2 = spring.mp2.lock();
|
||||
printf("Masspoint 1:\nPosition: %s \nVelocity: %s\n\n", mp1->position.toString().c_str(), mp1->velocity.toString().c_str());
|
||||
printf("Masspoint 2:\nPosition: %s \nVelocity: %s\n", mp2->position.toString().c_str(), mp2->velocity.toString().c_str());
|
||||
}
|
||||
@@ -1,58 +1,75 @@
|
||||
#ifndef MASSSPRINGSYSTEMSIMULATOR_h
|
||||
#define MASSSPRINGSYSTEMSIMULATOR_h
|
||||
#include "Simulator.h"
|
||||
|
||||
// Do Not Change
|
||||
#define EULER 0
|
||||
#define LEAPFROG 1
|
||||
#define MIDPOINT 2
|
||||
// Do Not Change
|
||||
|
||||
|
||||
class MassSpringSystemSimulator:public Simulator{
|
||||
public:
|
||||
// Construtors
|
||||
MassSpringSystemSimulator();
|
||||
|
||||
// UI Functions
|
||||
const char * getTestCasesStr();
|
||||
void initUI(DrawingUtilitiesClass * DUC);
|
||||
void reset();
|
||||
void drawFrame(ID3D11DeviceContext* pd3dImmediateContext);
|
||||
void notifyCaseChanged(int testCase);
|
||||
void externalForcesCalculations(float timeElapsed);
|
||||
void simulateTimestep(float timeStep);
|
||||
void onClick(int x, int y);
|
||||
void onMouse(int x, int y);
|
||||
|
||||
// Specific Functions
|
||||
void setMass(float mass);
|
||||
void setStiffness(float stiffness);
|
||||
void setDampingFactor(float damping);
|
||||
int addMassPoint(Vec3 position, Vec3 Velocity, bool isFixed);
|
||||
void addSpring(int masspoint1, int masspoint2, float initialLength);
|
||||
int getNumberOfMassPoints();
|
||||
int getNumberOfSprings();
|
||||
Vec3 getPositionOfMassPoint(int index);
|
||||
Vec3 getVelocityOfMassPoint(int index);
|
||||
#ifndef MASSSPRINGSYSTEMSIMULATOR_h
|
||||
#define MASSSPRINGSYSTEMSIMULATOR_h
|
||||
#include "Simulator.h"
|
||||
#include "MassPoint.h"
|
||||
#include "Spring.h"
|
||||
|
||||
// Do Not Change
|
||||
#define EULER 0
|
||||
#define LEAPFROG 1
|
||||
#define MIDPOINT 2
|
||||
// Do Not Change
|
||||
|
||||
|
||||
class MassSpringSystemSimulator:public Simulator{
|
||||
public:
|
||||
// Construtors
|
||||
MassSpringSystemSimulator();
|
||||
|
||||
// UI Functions
|
||||
const char * getTestCasesStr();
|
||||
void initUI(DrawingUtilitiesClass * DUC);
|
||||
void reset();
|
||||
void drawFrame(ID3D11DeviceContext* pd3dImmediateContext);
|
||||
void notifyCaseChanged(int testCase);
|
||||
void externalForcesCalculations(float timeElapsed);
|
||||
void simulateTimestep(float timeStep);
|
||||
void onClick(int x, int y);
|
||||
void onMouse(int x, int y);
|
||||
|
||||
// Specific Functions
|
||||
void setMass(float mass);
|
||||
void setStiffness(float stiffness);
|
||||
void setDampingFactor(float damping);
|
||||
int addMassPoint(Vec3 position, Vec3 Velocity, bool isFixed);
|
||||
void addSpring(int masspoint1, int masspoint2, float initialLength);
|
||||
int getNumberOfMassPoints();
|
||||
int getNumberOfSprings();
|
||||
Vec3 getPositionOfMassPoint(int index);
|
||||
Vec3 getVelocityOfMassPoint(int index);
|
||||
void applyExternalForce(Vec3 force);
|
||||
|
||||
void Midpoint(Spring& spring, float timestep);
|
||||
std::tuple<Vec3, Vec3> MidPointStep(float timestep, const Spring& spring, Vec3 position, Vec3 velocity, Vec3 normal, float length);
|
||||
float LengthCalculator(Vec3 vector);
|
||||
|
||||
Vec3 calculatePositionTimestepEuler(Vec3 oldPosition, float timestep, Vec3 veloctiy);
|
||||
Vec3 calculateVelocityTimestepEuler(Vec3 oldVelocity, float timestep, Vec3 acceleration);
|
||||
Vec3 calculateAcceleration(Vec3 acceleration, float mass);
|
||||
void Euler(Spring& spring, float timestep);
|
||||
|
||||
void printSpring(const Spring& spring);
|
||||
|
||||
// Do Not Change
|
||||
void setIntegrator(int integrator) {
|
||||
m_iIntegrator = integrator;
|
||||
}
|
||||
|
||||
private:
|
||||
// Data Attributes
|
||||
}
|
||||
|
||||
private:
|
||||
// Data Attributes
|
||||
float m_fMass;
|
||||
float m_fStiffness;
|
||||
float m_fDamping;
|
||||
int m_iIntegrator;
|
||||
|
||||
// UI Attributes
|
||||
Vec3 m_externalForce;
|
||||
Point2D m_mouse;
|
||||
Point2D m_trackmouse;
|
||||
Point2D m_oldtrackmouse;
|
||||
};
|
||||
int m_iIntegrator;
|
||||
|
||||
// UI Attributes
|
||||
Vec3 m_externalForce;
|
||||
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
|
||||
|
||||
@@ -53,9 +53,14 @@ bool firstTime = true;
|
||||
FFmpeg* g_pFFmpegVideoRecorder = nullptr;
|
||||
|
||||
|
||||
// Input Stuff
|
||||
float lastX;
|
||||
float lastY;
|
||||
|
||||
|
||||
void initTweakBar(){
|
||||
g_pDUC->g_pTweakBar = TwNewBar("TweakBar");
|
||||
TwDefine(" TweakBar color='0 128 128' alpha=128 ");
|
||||
TwDefine(" TweakBar color='128 128 128' alpha=128 ");
|
||||
TwType TW_TYPE_TESTCASE = TwDefineEnumFromString("Test Scene", g_pSimulator->getTestCasesStr());
|
||||
TwAddVarRW(g_pDUC->g_pTweakBar, "Test Scene", TW_TYPE_TESTCASE, &g_iTestCase, "");
|
||||
// HINT: For buttons you can directly pass the callback function as a lambda expression.
|
||||
@@ -202,10 +207,23 @@ void CALLBACK OnMouse( bool bLeftButtonDown, bool bRightButtonDown, bool bMiddle
|
||||
if (bLeftButtonDown)
|
||||
{
|
||||
g_pSimulator->onClick(xPos,yPos);
|
||||
|
||||
int x = xPos;
|
||||
int y = yPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_pSimulator->onMouse(xPos, yPos);
|
||||
|
||||
float deltaX = lastX - xPos;
|
||||
float deltaY = lastY - yPos;
|
||||
|
||||
lastX = xPos;
|
||||
lastY = yPos;
|
||||
|
||||
/*printf("X Delta: %f \n", deltaX);
|
||||
printf("Y Delta: %f \n", deltaY);*/
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -172,9 +172,6 @@
|
||||
<ProjectReference Include="..\DirectXTK\DirectXTK_Desktop_2022.vcxproj">
|
||||
<Project>{e0b52ae7-e160-4d32-bf3f-910b785e5a8e}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\DirectXTK\MakeSpriteFont\MakeSpriteFont.csproj">
|
||||
<Project>{7329b02d-c504-482a-a156-181d48ce493c}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\DXUT11\Core\DXUT_DirectXTK_2022.vcxproj">
|
||||
<Project>{85344b7f-5aa0-4e12-a065-d1333d11f6ca}</Project>
|
||||
</ProjectReference>
|
||||
|
||||
@@ -13,8 +13,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DXUT", "DXUT11\Core\DXUT_Di
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DXUTOpt", "DXUT11\Optional\DXUTOpt_DirectXTK_2022.vcxproj", "{61B333C2-C4F7-4CC1-A9BF-83F6D95588EB}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MakeSpriteFont22", "DirectXTK\MakeSpriteFont\MakeSpriteFont22.csproj", "{7329B02D-C504-482A-A156-181D48CE493C}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AntTweakBar", "AntTweakBar\src\AntTweakBar_2022.vcxproj", "{B99E1FA1-C30A-45F2-9D57-9E9C21B2DF42}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DirectXTK_Desktop_2022", "DirectXTK\DirectXTK_Desktop_2022.vcxproj", "{E0B52AE7-E160-4D32-BF3F-910B785E5A8E}"
|
||||
@@ -29,6 +27,22 @@ Global
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{0B7BAA5B-0753-4015-A8F3-8FA540FC8660}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{0B7BAA5B-0753-4015-A8F3-8FA540FC8660}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{0B7BAA5B-0753-4015-A8F3-8FA540FC8660}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{0B7BAA5B-0753-4015-A8F3-8FA540FC8660}.Debug|x64.Build.0 = Debug|x64
|
||||
{0B7BAA5B-0753-4015-A8F3-8FA540FC8660}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{0B7BAA5B-0753-4015-A8F3-8FA540FC8660}.Release|Win32.Build.0 = Release|Win32
|
||||
{0B7BAA5B-0753-4015-A8F3-8FA540FC8660}.Release|x64.ActiveCfg = Release|x64
|
||||
{0B7BAA5B-0753-4015-A8F3-8FA540FC8660}.Release|x64.Build.0 = Release|x64
|
||||
{3CABED2C-12F1-4408-AAAE-E2185A426F35}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{3CABED2C-12F1-4408-AAAE-E2185A426F35}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{3CABED2C-12F1-4408-AAAE-E2185A426F35}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{3CABED2C-12F1-4408-AAAE-E2185A426F35}.Debug|x64.Build.0 = Debug|x64
|
||||
{3CABED2C-12F1-4408-AAAE-E2185A426F35}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{3CABED2C-12F1-4408-AAAE-E2185A426F35}.Release|Win32.Build.0 = Release|Win32
|
||||
{3CABED2C-12F1-4408-AAAE-E2185A426F35}.Release|x64.ActiveCfg = Release|x64
|
||||
{3CABED2C-12F1-4408-AAAE-E2185A426F35}.Release|x64.Build.0 = Release|x64
|
||||
{DF460EAB-570D-4B50-9089-2E2FC801BF38}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{DF460EAB-570D-4B50-9089-2E2FC801BF38}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{DF460EAB-570D-4B50-9089-2E2FC801BF38}.Debug|x64.ActiveCfg = Debug|x64
|
||||
@@ -61,22 +75,6 @@ Global
|
||||
{B99E1FA1-C30A-45F2-9D57-9E9C21B2DF42}.Release|Win32.Build.0 = Release|Win32
|
||||
{B99E1FA1-C30A-45F2-9D57-9E9C21B2DF42}.Release|x64.ActiveCfg = Release|x64
|
||||
{B99E1FA1-C30A-45F2-9D57-9E9C21B2DF42}.Release|x64.Build.0 = Release|x64
|
||||
{3CABED2C-12F1-4408-AAAE-E2185A426F35}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{3CABED2C-12F1-4408-AAAE-E2185A426F35}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{3CABED2C-12F1-4408-AAAE-E2185A426F35}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{3CABED2C-12F1-4408-AAAE-E2185A426F35}.Debug|x64.Build.0 = Debug|x64
|
||||
{3CABED2C-12F1-4408-AAAE-E2185A426F35}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{3CABED2C-12F1-4408-AAAE-E2185A426F35}.Release|Win32.Build.0 = Release|Win32
|
||||
{3CABED2C-12F1-4408-AAAE-E2185A426F35}.Release|x64.ActiveCfg = Release|x64
|
||||
{3CABED2C-12F1-4408-AAAE-E2185A426F35}.Release|x64.Build.0 = Release|x64
|
||||
{0B7BAA5B-0753-4015-A8F3-8FA540FC8660}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{0B7BAA5B-0753-4015-A8F3-8FA540FC8660}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{0B7BAA5B-0753-4015-A8F3-8FA540FC8660}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{0B7BAA5B-0753-4015-A8F3-8FA540FC8660}.Debug|x64.Build.0 = Debug|x64
|
||||
{0B7BAA5B-0753-4015-A8F3-8FA540FC8660}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{0B7BAA5B-0753-4015-A8F3-8FA540FC8660}.Release|Win32.Build.0 = Release|Win32
|
||||
{0B7BAA5B-0753-4015-A8F3-8FA540FC8660}.Release|x64.ActiveCfg = Release|x64
|
||||
{0B7BAA5B-0753-4015-A8F3-8FA540FC8660}.Release|x64.Build.0 = Release|x64
|
||||
{E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{E0B52AE7-E160-4D32-BF3F-910B785E5A8E}.Debug|x64.ActiveCfg = Debug|x64
|
||||
|
||||
Reference in New Issue
Block a user