Verlet intergrated cloth simulation
This commit is contained in:
56
C++/Verlet Cloth/.vscode/settings.json
vendored
Normal file
56
C++/Verlet Cloth/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"atomic": "cpp",
|
||||
"chrono": "cpp",
|
||||
"cmath": "cpp",
|
||||
"condition_variable": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cstring": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"exception": "cpp",
|
||||
"fstream": "cpp",
|
||||
"functional": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"ios": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"iostream": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"list": "cpp",
|
||||
"map": "cpp",
|
||||
"memory": "cpp",
|
||||
"mutex": "cpp",
|
||||
"new": "cpp",
|
||||
"numeric": "cpp",
|
||||
"ostream": "cpp",
|
||||
"ratio": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"string": "cpp",
|
||||
"system_error": "cpp",
|
||||
"xthread": "cpp",
|
||||
"thread": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"utility": "cpp",
|
||||
"vector": "cpp",
|
||||
"xfacet": "cpp",
|
||||
"xhash": "cpp",
|
||||
"xiosbase": "cpp",
|
||||
"xlocale": "cpp",
|
||||
"xlocinfo": "cpp",
|
||||
"xlocnum": "cpp",
|
||||
"xmemory": "cpp",
|
||||
"xmemory0": "cpp",
|
||||
"xstddef": "cpp",
|
||||
"xstring": "cpp",
|
||||
"xtr1common": "cpp",
|
||||
"xtree": "cpp",
|
||||
"xutility": "cpp"
|
||||
}
|
||||
}
|
||||
62
C++/Verlet Cloth/main.cpp
Normal file
62
C++/Verlet Cloth/main.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#define OLC_PGE_APPLICATION
|
||||
#include "olcPixelGameEngine.h"
|
||||
|
||||
struct Vec2f {
|
||||
float x, y;
|
||||
};
|
||||
|
||||
struct MassPoint {
|
||||
Vec2f sPosition;
|
||||
Vec2f sVelocity;
|
||||
|
||||
void step() {
|
||||
sPosition.x += sVelocity.x;
|
||||
sPosition.y += sVelocity.y;
|
||||
}
|
||||
};
|
||||
|
||||
class VerletCloth : public olc::PixelGameEngine {
|
||||
public:
|
||||
std::vector<MassPoint> sPoints;
|
||||
|
||||
VerletCloth() {
|
||||
sAppName = "Verlet Cloth Simulation";
|
||||
}
|
||||
|
||||
bool OnUserCreate() override {
|
||||
|
||||
sPoints.push_back({{ 100.0f, 100.0f }, { 1.0f, 4.0f }});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OnUserUpdate(float fElapsedTime) override {
|
||||
Clear(olc::WHITE);
|
||||
|
||||
m_fTimeCounter += fElapsedTime;
|
||||
|
||||
if (m_fTimeCounter >= 0.016f) {
|
||||
m_fTimeCounter = 0.0f;
|
||||
for (auto& sPoint : sPoints){
|
||||
sPoint.step();
|
||||
FillRect(sPoint.sPosition.x, sPoint.sPosition.y, 4, 4, olc::BLACK);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
float m_fTimeCounter = 0.0f;
|
||||
};
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
VerletCloth app;
|
||||
|
||||
app.Construct(1000, 600, 1, 1);
|
||||
app.Start();
|
||||
|
||||
return 0;
|
||||
}
|
||||
2069
C++/Verlet Cloth/olcPixelGameEngine.h
Normal file
2069
C++/Verlet Cloth/olcPixelGameEngine.h
Normal file
File diff suppressed because it is too large
Load Diff
BIN
C++/Verlet Cloth/output
Executable file
BIN
C++/Verlet Cloth/output
Executable file
Binary file not shown.
Reference in New Issue
Block a user