Initial commit.
This commit is contained in:
commit
44b5f2392f
98 changed files with 11750 additions and 0 deletions
37
physics/particle.cpp
Normal file
37
physics/particle.cpp
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
// -*- C++ -*-
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "particle.h"
|
||||
|
||||
using namespace mbostock;
|
||||
|
||||
Particle::Particle() : inverseMass(1.f) {
|
||||
}
|
||||
|
||||
Vector Particle::velocity() const {
|
||||
/* Note: ignores force * (inverseMass * timeStep / 2). */
|
||||
return (position - previousPosition) / ParticleSimulator::timeStep();
|
||||
}
|
||||
|
||||
ParticleSimulator::ParticleSimulator()
|
||||
: drag_(1.f) {
|
||||
}
|
||||
|
||||
ParticleSimulator::ParticleSimulator(float drag)
|
||||
: drag_(drag) {
|
||||
}
|
||||
|
||||
float ParticleSimulator::timeStep() {
|
||||
return .003f; // TODO .005 and interpolate
|
||||
}
|
||||
|
||||
void ParticleSimulator::step(Particle& p) const {
|
||||
static const float timeStepSquared = timeStep() * timeStep();
|
||||
|
||||
Vector p0 = p.previousPosition;
|
||||
p.previousPosition = p.position;
|
||||
p.position += (p.position - p0) * drag_
|
||||
+ p.force * (p.inverseMass * timeStepSquared);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue