Lagrangian Liquid Simulation
Master Thesis project on simulation of liquids using Lagrangian approach and SPH
|
stores all rigid bodies and boundary and manages interaction among rigid bodies, fluids and the boundary More...
#include <Environment.h>
Public Member Functions | |
Environment () | |
ctor | |
~Environment () | |
dtor | |
void | loadGeometry () |
load vbo geometry | |
void | draw (ngl::TransformStack _txStack, ShaderLibrary *io_sman, const std::string _boundaryShader, const std::string _obstacleShader) |
draws the obstacles | |
void | checkAndResolveCollision (Particle &io_currentParticle, bool &o_hitBoundary, bool &o_hitRBD, const bool _fromRBD) |
detect and handles collision among particles (sphere rbd and fluid particle) | |
void | updateObstacles (Integration *_integration) |
update the rigid bodies movements and rotations at every simulation iteration | |
std::vector< std::vector < ngl::Vector > > | getBoundaryPositionList () |
return a 2d list of the faces of the boundary, used for caching | |
std::vector< std::string > | getBoundaryNameList () |
return a list of the boundary box name, used for caching | |
std::vector< std::vector < ngl::Vector > > | getSpherePositionList () |
return a 2d list of the position of spheres, used for caching | |
std::vector< std::string > | getSphereNameList () |
return a list of the spheres id, used for caching | |
std::vector< std::vector < ngl::Vector > > | getCapsulePositionList () |
return a 2d list of the position of capsules, used for caching | |
std::vector< std::string > | getCapsuleNameList () |
return a list of the capsules id, used for caching | |
std::vector< Particle > & | getSphereObstacleList () |
return the list of sphere RBD | |
std::vector< Capsule > & | getCapsuleObstacleList () |
return the list of capsule RBD | |
bool | getObstacleEnabled () const |
return whether RBD interaction is enabled | |
ngl::Vector | getBoundaryDimension () const |
return the boundary dimension | |
ngl::Vector | getBoundaryPosition () const |
return the boundary centre position | |
bool | getBoundaryBoundTop () const |
return whether the top face of the boundary is closed | |
ngl::Real | getBoundaryRestitutionCoefficientForFluid () const |
return the restitution coefficient for fluid interaction with boundary | |
ngl::Real | getBoundaryRestitutionCoefficientForRBD () const |
return the restitution coefficient for RBD interaction with boundary | |
ngl::Real | getObstacleRestitutionCoefficient () const |
return the restitution coefficient for fluid interaction with RBD | |
int | getCapsuleResolution () const |
return the resolution of the capsule drawing | |
bool | getPeriodicWallEnabled () const |
return whether the boundary periodic wall is enabled | |
ngl::Real | getPeriodicWallMaxAmplitude () const |
return the maximum amplitude of the periodic wall | |
ngl::Real | getPeriodicWallSpeed () const |
return the angle speed factor of the periodic wall | |
ngl::Real | getAngleOfPeriodicWall () const |
return the angle of the periodic wall sine function | |
ngl::Real | getPeriodicWallAngleIncrement () const |
return the angle increment of the periodic wall sine function | |
void | setObstacleEnabled (const bool _v) |
set whether RBD interaction is enabled | |
void | setBoundaryDimension (const ngl::Vector _v) |
set the boundary dimension | |
void | setBoundaryPosition (ngl::Vector _v) |
set the boundary centre position | |
void | setBoundaryBoundTop (const bool _v) |
set whether the top face of the boundary is closed | |
void | setBoundaryRestitutionCoefficientForFluid (const ngl::Real _v) |
set the restitution coefficient for fluid interaction with boundary | |
void | setBoundaryRestitutionCoefficientForRBD (const ngl::Real _v) |
set the restitution coefficient for RBD interaction with boundary | |
void | setObstacleRestitutionCoefficient (const ngl::Real _v) |
set the restitution coefficient for fluid interaction with RBD | |
void | setCapsuleResolution (const int _v) |
set the resolution of the capsule drawing | |
void | setPeriodicWallEnabled (const bool _v) |
set whether the boundary periodic wall is enabled | |
void | setPeriodicWallMaxAmplitude (const ngl::Real _v) |
set the maximum amplitude of the periodic wall | |
void | setPeriodicWallSpeed (const ngl::Real _v) |
set the angle speed factor of the periodic wall | |
void | setAngleOfPeriodicWall (const ngl::Real _v) |
set the angle of the periodic wall sine function | |
void | setPeriodicWallAngleIncrement (const ngl::Real _v) |
set the angle increment of the periodic wall sine function | |
Private Member Functions | |
bool | checkAndResolveCollisionWithObstacle (Particle &io_currentParticle, Particle &_obstacle) |
handle collision between sphere/fluid and sphere | |
bool | checkAndResolveCollisionWithObstacle (Particle &io_currentParticle, Capsule &_obstacle) |
handle collision between sphere/fluid and capsule | |
bool | checkAndResolveCollisionWithBoundary (Particle &io_currentParticle, const bool _fromRBD) |
handle collision between RBD/fluid and boundary | |
void | resolveCollision (Particle &io_currentParticle, const ngl::Vector _contactPoint, const ngl::Vector _normal, const ngl::Real _penetrationDepth, const ngl::Real _restitutionCoefficient) |
perform the actual collision handling (calculation of new position and velocity) once collision is detected | |
void | updatePeriodicBoundingBox () |
update the periodic wall position at each iteration | |
Private Attributes | |
bool | m_obstacleEnabled |
flag to determine if RBD interaction is enabled | |
ngl::Vector | m_boundaryDimension |
boundary dimension | |
ngl::Vector | m_boundaryPosition |
boundary centre position | |
ngl::BBox * | m_boundaryBBox |
boundary bounding box object used for collision handling | |
bool | m_boundaryBoundTop |
flag to determine if the top face of the boundary is closed | |
ngl::Real | m_boundaryRestitutionCoefficientForFluid |
restitution coefficient for fluid interaction with boundary | |
ngl::Real | m_boundaryRestitutionCoefficientForRBD |
restitution coefficient for RBD interaction with boundary | |
ngl::Real | m_obstacleRestitutionCoefficient |
restitution coefficient for fluid interaction with RBD | |
std::vector< Particle > | m_sphereObstacleList |
list of sphere RBD | |
std::vector< Capsule > | m_capsuleObstacleList |
list of capsule RBD | |
int | m_capsuleResolution |
resolution of the capsule drawing (the number of spheres used to draw the capsule) | |
bool | m_periodicWallEnabled |
flag to determine whether the boundary periodic wall is enabled | |
ngl::Real | m_periodicWallMaxAmplitude |
maximum amplitude of the periodic wall | |
ngl::Real | m_periodicWallSpeed |
angle speed factor of the periodic wall | |
ngl::Real | m_angleOfPeriodicWall |
angle of the periodic wall sine function | |
ngl::Real | m_periodicWallAngleIncrement |
angle increment of the periodic wall sine function |
stores all rigid bodies and boundary and manages interaction among rigid bodies, fluids and the boundary
Definition at line 26 of file Environment.h.
Environment::Environment | ( | ) |
ctor
Definition at line 12 of file Environment.cpp.
References Configuration::initialiseEnvironment(), m_angleOfPeriodicWall, m_boundaryBBox, m_boundaryBoundTop, m_boundaryDimension, m_boundaryPosition, m_boundaryRestitutionCoefficientForFluid, m_boundaryRestitutionCoefficientForRBD, m_capsuleObstacleList, m_capsuleResolution, m_obstacleEnabled, m_obstacleRestitutionCoefficient, m_periodicWallAngleIncrement, m_periodicWallEnabled, m_periodicWallMaxAmplitude, m_periodicWallSpeed, and m_sphereObstacleList.
{ //create params from config Configuration::initialiseEnvironment ( m_obstacleEnabled, m_boundaryPosition, m_boundaryDimension, m_boundaryRestitutionCoefficientForFluid, m_boundaryRestitutionCoefficientForRBD, m_boundaryBoundTop, m_sphereObstacleList, m_capsuleObstacleList, m_obstacleRestitutionCoefficient, m_periodicWallEnabled, m_periodicWallMaxAmplitude, m_periodicWallSpeed, m_periodicWallAngleIncrement, m_capsuleResolution ); //create bbox for boundary m_boundaryBBox = new ngl::BBox(m_boundaryPosition, m_boundaryDimension.m_x, m_boundaryDimension.m_y, m_boundaryDimension.m_z); //init params m_angleOfPeriodicWall = 0.0; }
Environment::~Environment | ( | ) |
dtor
Definition at line 40 of file Environment.cpp.
References m_boundaryBBox.
{ //clean up std::cout << "Environment Cleanup" << std::endl; delete m_boundaryBBox; }
void Environment::checkAndResolveCollision | ( | Particle & | io_currentParticle, |
bool & | o_hitBoundary, | ||
bool & | o_hitRBD, | ||
const bool | _fromRBD | ||
) |
detect and handles collision among particles (sphere rbd and fluid particle)
[in,out] | io_currentParticle | the particle affected by the collision resolution |
[out] | o_hitBoundary | returns whether the particle collided against the boundary |
[out] | o_hitRBD | returns whether the particle collided against a rigid body |
[in] | _fromRBD | set whether this method was called by a sphere rigid body or by a fluid particle |
Definition at line 179 of file Environment.cpp.
References Particle::getId().
{ o_hitRBD = false; if (m_obstacleEnabled) { //sphere-sphere and fluid-sphere collision handling if enabled BOOST_FOREACH(Particle& obstacle, m_sphereObstacleList) { //prevent collision check of an obstacle against itself if (obstacle.getId() != io_currentParticle.getId()) { //check collision against obstacle (sphere-sphere interaction) bool hit = checkAndResolveCollisionWithObstacle(io_currentParticle, obstacle); o_hitRBD = hit ? true : o_hitRBD; } } //sphere-capsule and fluid-capsule collision handling if enabled BOOST_FOREACH(Capsule& obstacle, m_capsuleObstacleList) { //prevent collision check of an obstacle against itself if (obstacle.getId() != io_currentParticle.getId()) { //check collision against obstacle (sphere-capsule interaction) bool hit = checkAndResolveCollisionWithObstacle(io_currentParticle, obstacle); o_hitRBD = hit ? true : o_hitRBD; } } } //collision handling against the boundary o_hitBoundary = checkAndResolveCollisionWithBoundary(io_currentParticle, _fromRBD); }
bool Environment::checkAndResolveCollisionWithBoundary | ( | Particle & | io_currentParticle, |
const bool | _fromRBD | ||
) | [private] |
handle collision between RBD/fluid and boundary
[in,out] | io_currentParticle | the particle affected by the collision resolution |
[in] | _fromRBD | flag to determine whether the affected particle is an RBD |
Definition at line 340 of file Environment.cpp.
References Particle::getPosition(), Particle::getRadius(), Particle::getVelocity(), Particle::updatePosition(), and Particle::updateVelocity().
{ //determine bounds of box ngl::Real xMax = m_boundaryBBox->center().m_x + (m_boundaryBBox->width()/2.0f); ngl::Real xMin = m_boundaryBBox->center().m_x - (m_boundaryBBox->width()/2.0f); ngl::Real yMax = m_boundaryBBox->center().m_y + (m_boundaryBBox->height()/2.0f); ngl::Real yMin = m_boundaryBBox->center().m_y - (m_boundaryBBox->height()/2.0f); ngl::Real zMax = m_boundaryBBox->center().m_z + (m_boundaryBBox->depth()/2.0f); ngl::Real zMin = m_boundaryBBox->center().m_z - (m_boundaryBBox->depth()/2.0f); //move bounds closer due to difference in particle's radius xMax -= io_currentParticle.getRadius(); xMin += io_currentParticle.getRadius(); yMax -= io_currentParticle.getRadius(); yMin += io_currentParticle.getRadius(); zMax -= io_currentParticle.getRadius(); zMin += io_currentParticle.getRadius(); //assume no collision bool hasCollisionOccured = false; //get position of particle ngl::Vector currentPosition = io_currentParticle.getPosition(); //evaluate restitution coefficient to be used based on origin ngl::Real restitutionCoefficient = _fromRBD ? m_boundaryRestitutionCoefficientForRBD : m_boundaryRestitutionCoefficientForFluid; //collision check for XMax breach if (currentPosition.m_x > xMax) { hasCollisionOccured = true; //set position to boundary edge io_currentParticle.updatePosition(ngl::Vector(xMax, io_currentParticle.getPosition().m_y, io_currentParticle.getPosition().m_z)); //calculate new velocity (reflect on face normal with restitution factor io_currentParticle.updateVelocity(ngl::Vector(-restitutionCoefficient * io_currentParticle.getVelocity().m_x, io_currentParticle.getVelocity().m_y, io_currentParticle.getVelocity().m_z)); } //collision check for XMin breach if (currentPosition.m_x < xMin) { hasCollisionOccured = true; //set position to boundary edge io_currentParticle.updatePosition(ngl::Vector(xMin, io_currentParticle.getPosition().m_y, io_currentParticle.getPosition().m_z)); //calculate new velocity (reflect on face normal with restitution factor io_currentParticle.updateVelocity(ngl::Vector(-restitutionCoefficient * io_currentParticle.getVelocity().m_x, io_currentParticle.getVelocity().m_y, io_currentParticle.getVelocity().m_z)); } //collision check for YMin breach if (currentPosition.m_y < yMin) { hasCollisionOccured = true; //set position to boundary edge io_currentParticle.updatePosition(ngl::Vector(io_currentParticle.getPosition().m_x, yMin, io_currentParticle.getPosition().m_z)); //calculate new velocity (reflect on face normal with restitution factor io_currentParticle.updateVelocity(ngl::Vector(io_currentParticle.getVelocity().m_x, -restitutionCoefficient * io_currentParticle.getVelocity().m_y, io_currentParticle.getVelocity().m_z)); } //collision check for YMax breach if top is bound if (m_boundaryBoundTop && (currentPosition.m_y > yMax)) { hasCollisionOccured = true; //set position to boundary edge io_currentParticle.updatePosition(ngl::Vector(io_currentParticle.getPosition().m_x, yMax, io_currentParticle.getPosition().m_z)); //calculate new velocity (reflect on face normal with restitution factor io_currentParticle.updateVelocity(ngl::Vector(io_currentParticle.getVelocity().m_x, -restitutionCoefficient * io_currentParticle.getVelocity().m_y, io_currentParticle.getVelocity().m_z)); } //collision check for ZMin breach if (currentPosition.m_z < zMin) { hasCollisionOccured = true; //set position to boundary edge io_currentParticle.updatePosition(ngl::Vector(io_currentParticle.getPosition().m_x, io_currentParticle.getPosition().m_y, zMin)); //calculate new velocity (reflect on face normal with restitution factor io_currentParticle.updateVelocity(ngl::Vector(io_currentParticle.getVelocity().m_x, io_currentParticle.getVelocity().m_y, -restitutionCoefficient * io_currentParticle.getVelocity().m_z)); } //collision check for ZMax breach if (currentPosition.m_z > zMax) { hasCollisionOccured = true; //set position to boundary edge io_currentParticle.updatePosition(ngl::Vector(io_currentParticle.getPosition().m_x, io_currentParticle.getPosition().m_y, zMax)); //calculate new velocity (reflect on face normal with restitution factor io_currentParticle.updateVelocity(ngl::Vector(io_currentParticle.getVelocity().m_x, io_currentParticle.getVelocity().m_y, -restitutionCoefficient * io_currentParticle.getVelocity().m_z)); } return hasCollisionOccured; }
bool Environment::checkAndResolveCollisionWithObstacle | ( | Particle & | io_currentParticle, |
Particle & | _obstacle | ||
) | [private] |
handle collision between sphere/fluid and sphere
[in,out] | io_currentParticle | the particle affected by the collision resolution |
[in] | _obstacle | the rigid body against which collision is checked |
Definition at line 220 of file Environment.cpp.
References Particle::getPosition(), and Particle::getRadius().
{ //assume no collision bool hasCollisionOccured = false; //initialise variables ngl::Vector X = io_currentParticle.getPosition(); ngl::Vector C = _obstacle.getPosition(); ngl::Vector XC = X - C; ngl::Vector CX = C - X; ngl::Real r = io_currentParticle.getRadius() + _obstacle.getRadius(); //calculate implicit function value for a sphere ngl::Real Fx = XC.lengthSquared() - (r * r); if (Fx < 0) { //collision occured hasCollisionOccured = true; //calculate contact point ngl::Vector CP = C + (r * (XC / XC.length())); //calculate penetration depth ngl::Real depth = fabs(CX.length() - r); //calculate normal ngl::Vector n = (Fx < 0 ? -1 : Fx == 0 ? 0 : 1) * (CX / CX.length()); //calculate new position and velocity for particle resolveCollision(io_currentParticle, CP, n, depth, m_obstacleRestitutionCoefficient); } return hasCollisionOccured; }
bool Environment::checkAndResolveCollisionWithObstacle | ( | Particle & | io_currentParticle, |
Capsule & | _obstacle | ||
) | [private] |
handle collision between sphere/fluid and capsule
[in,out] | io_currentParticle | the particle affected by the collision resolution |
[in] | _obstacle | the rigid body against which collision is checked |
Definition at line 261 of file Environment.cpp.
References Capsule::getHeight(), Capsule::getPoint1(), Capsule::getPoint2(), Particle::getPosition(), and Particle::getRadius().
{ //assume no collision bool hasCollisionOccured = false; //initialise variables ngl::Vector X = io_currentParticle.getPosition(); ngl::Vector C = _obstacle.getPosition(); ngl::Vector XC = X - C; ngl::Real r = io_currentParticle.getRadius() + (_obstacle.getRadius() + _obstacle.getHeight()); //calculate implicit function value for the bounding sphere ngl::Real FxSphere = XC.lengthSquared() - (r * r); if (FxSphere < 0) { //collision occured with bounding sphere -> capsule collision handling must be done //initialise capsule parameters ngl::Vector P0 = _obstacle.getPoint1(); ngl::Vector P1 = _obstacle.getPoint2(); ngl::Vector P0X = P0 - X; ngl::Vector P1P0 = P1 - P0; ngl::Real a = std::min(1.0, std::max(0.0, -1.0 * (P0X.dot(P1P0) / P1P0.lengthSquared()))); ngl::Vector Q = P0 + (a * P1P0); r = io_currentParticle.getRadius() + _obstacle.getRadius(); //calculate implicit function value for a capsule ngl::Real FxCapsule = (Q - X).length() - r; if (FxCapsule < 0) { //collision with capsule hasCollisionOccured = true; //calculate contact point ngl::Vector CP = Q + (r * ((X - Q) / (X - Q).length())); //calculate penetration depth ngl::Real depth = fabs(FxCapsule); //calculate normal ngl::Vector n = (FxCapsule < 0 ? -1 : FxCapsule == 0 ? 0 : 1) * ((Q - X) / (Q - X).length()); //calculate new position and velocity for particle resolveCollision(io_currentParticle, CP, n, depth, m_obstacleRestitutionCoefficient); } } return hasCollisionOccured; }
void Environment::draw | ( | ngl::TransformStack | _txStack, |
ShaderLibrary * | io_sman, | ||
const std::string | _boundaryShader, | ||
const std::string | _obstacleShader | ||
) |
draws the obstacles
[in] | _txStack | the transform stack, used for pushing and popping opengl states |
[in,out] | io_sman | the shader library, used for shading/rendering of the objects |
[in] | _boundaryShader | the shader used for boundary drawing |
[in] | _obstacleShader | the shader used for obstacle drawing |
Definition at line 57 of file Environment.cpp.
References Particle::getColour(), Capsule::getHeight(), Capsule::getOrientationVector(), Capsule::getPoint1(), Capsule::getPoint2(), Particle::getPosition(), Particle::getRadius(), Configuration::s_boundaryColour, ShaderLibrary::updateColor(), and ShaderLibrary::updateModel().
{ //draw boundary _txStack.pushTransform(); { //pass vertex info to shader io_sman->updateModel(_boundaryShader, _txStack.getCurrAndGlobal().getMatrix(), false); //pass color info to shader io_sman->updateColor(_boundaryShader, Configuration::s_boundaryColour, false); m_boundaryBBox->draw(); } _txStack.popTransform(); //draw obstacles if enabled if (m_obstacleEnabled) { ngl::VBOPrimitives* prim = ngl::VBOPrimitives::instance(); //draw sphere _txStack.pushTransform(); { BOOST_FOREACH(Particle& obstacle, m_sphereObstacleList) { _txStack.getCurrentTransform().setPosition(obstacle.getPosition().m_x, obstacle.getPosition().m_y, obstacle.getPosition().m_z); _txStack.getCurrentTransform().setScale(obstacle.getRadius(), obstacle.getRadius(), obstacle.getRadius()); //pass vertex info to shader io_sman->updateModel(_obstacleShader, _txStack.getCurrAndGlobal().getMatrix(), false); //pass color info to shader (dont update gradient) io_sman->updateColor(_obstacleShader, obstacle.getColour(), false); prim->draw("obstacleSphere"); } } _txStack.popTransform(); //draw capsule _txStack.pushTransform(); { BOOST_FOREACH(Capsule& obstacle, m_capsuleObstacleList) { _txStack.getCurrentTransform().setScale(obstacle.getRadius(), obstacle.getRadius(), obstacle.getRadius()); //pass color info to shader (dont update gradient) io_sman->updateColor(_obstacleShader, obstacle.getColour(), false); float step = (obstacle.getHeight() * 2.0) / m_capsuleResolution; for (float i = 0; i < obstacle.getHeight() * 2; i += step) { ngl::Vector position = obstacle.getPoint1() + (i * obstacle.getOrientationVector()); //draw sphere _txStack.getCurrentTransform().setPosition(position); //pass vertex info to shader io_sman->updateModel(_obstacleShader, _txStack.getCurrAndGlobal().getMatrix(), false); prim->draw("obstacleSphere"); } //draw sphere _txStack.getCurrentTransform().setPosition(obstacle.getPoint2()); //pass vertex info to shader io_sman->updateModel(_obstacleShader, _txStack.getCurrAndGlobal().getMatrix(), false); prim->draw("obstacleSphere"); } } _txStack.popTransform(); } }
ngl::Real Environment::getAngleOfPeriodicWall | ( | ) | const [inline] |
return the angle of the periodic wall sine function
Definition at line 126 of file Environment.h.
References m_angleOfPeriodicWall.
{ return m_angleOfPeriodicWall; }
bool Environment::getBoundaryBoundTop | ( | ) | const [inline] |
return whether the top face of the boundary is closed
Definition at line 102 of file Environment.h.
References m_boundaryBoundTop.
{ return m_boundaryBoundTop; }
ngl::Vector Environment::getBoundaryDimension | ( | ) | const [inline] |
return the boundary dimension
Definition at line 96 of file Environment.h.
References m_boundaryDimension.
{ return m_boundaryDimension; }
std::vector< std::string > Environment::getBoundaryNameList | ( | ) |
return a list of the boundary box name, used for caching
Definition at line 498 of file Environment.cpp.
{ std::vector<std::string> list; list.push_back("box"); return list; }
ngl::Vector Environment::getBoundaryPosition | ( | ) | const [inline] |
return the boundary centre position
Definition at line 99 of file Environment.h.
References m_boundaryPosition.
{ return m_boundaryPosition; }
std::vector< std::vector< ngl::Vector > > Environment::getBoundaryPositionList | ( | ) |
return a 2d list of the faces of the boundary, used for caching
Definition at line 468 of file Environment.cpp.
References m_boundaryBBox.
{ std::vector<std::vector<ngl::Vector> > positionList; std::vector<ngl::Vector> list; list.reserve(8); //determine bounds of box ngl::Real xMax = m_boundaryBBox->center().m_x + (m_boundaryBBox->width()/2.0f); ngl::Real xMin = m_boundaryBBox->center().m_x - (m_boundaryBBox->width()/2.0f); ngl::Real yMax = m_boundaryBBox->center().m_y + (m_boundaryBBox->height()/2.0f); ngl::Real yMin = m_boundaryBBox->center().m_y - (m_boundaryBBox->height()/2.0f); ngl::Real zMax = m_boundaryBBox->center().m_z + (m_boundaryBBox->depth()/2.0f); ngl::Real zMin = m_boundaryBBox->center().m_z - (m_boundaryBBox->depth()/2.0f); //add vertices anticlockwise direction (2 faces : lower, then uppper) list.push_back(ngl::Vector(xMin, yMin, zMin)); list.push_back(ngl::Vector(xMax, yMin, zMin)); list.push_back(ngl::Vector(xMax, yMin, zMax)); list.push_back(ngl::Vector(xMin, yMin, zMax)); list.push_back(ngl::Vector(xMin, yMax, zMin)); list.push_back(ngl::Vector(xMax, yMax, zMin)); list.push_back(ngl::Vector(xMax, yMax, zMax)); list.push_back(ngl::Vector(xMin, yMax, zMax)); positionList.push_back(list); return positionList; }
ngl::Real Environment::getBoundaryRestitutionCoefficientForFluid | ( | ) | const [inline] |
return the restitution coefficient for fluid interaction with boundary
Definition at line 105 of file Environment.h.
References m_boundaryRestitutionCoefficientForFluid.
{ return m_boundaryRestitutionCoefficientForFluid; }
ngl::Real Environment::getBoundaryRestitutionCoefficientForRBD | ( | ) | const [inline] |
return the restitution coefficient for RBD interaction with boundary
Definition at line 108 of file Environment.h.
References m_boundaryRestitutionCoefficientForRBD.
{ return m_boundaryRestitutionCoefficientForRBD; }
std::vector< std::string > Environment::getCapsuleNameList | ( | ) |
return a list of the capsules id, used for caching
Definition at line 569 of file Environment.cpp.
References m_capsuleObstacleList.
{ std::vector<std::string> list; //loop through capsule list for (int i = 0; i < m_capsuleObstacleList.size(); ++i) { list.push_back(boost::lexical_cast<std::string>(i)); } return list; }
std::vector<Capsule>& Environment::getCapsuleObstacleList | ( | ) | [inline] |
return the list of capsule RBD
Definition at line 89 of file Environment.h.
References m_capsuleObstacleList.
{ return m_capsuleObstacleList; }
std::vector< std::vector< ngl::Vector > > Environment::getCapsulePositionList | ( | ) |
return a 2d list of the position of capsules, used for caching
Definition at line 541 of file Environment.cpp.
References m_capsuleObstacleList, and m_capsuleResolution.
{ std::vector<std::vector<ngl::Vector> > positionList; //loop through capsule list for (int i = 0; i < m_capsuleObstacleList.size(); ++i) { std::vector<ngl::Vector> list; float step = (m_capsuleObstacleList[i].getHeight() * 2.0) / m_capsuleResolution; for (float j = 0; j < m_capsuleObstacleList[i].getHeight() * 2; j += step) { //calculate position of intermediate sphere ngl::Vector position = m_capsuleObstacleList[i].getPoint1() + (j * m_capsuleObstacleList[i].getOrientationVector()); //add position to small list list.push_back(position); } list.push_back(m_capsuleObstacleList[i].getPoint2()); //add to big list positionList.push_back(list); } return positionList; }
int Environment::getCapsuleResolution | ( | ) | const [inline] |
return the resolution of the capsule drawing
Definition at line 114 of file Environment.h.
References m_capsuleResolution.
{ return m_capsuleResolution; }
bool Environment::getObstacleEnabled | ( | ) | const [inline] |
return whether RBD interaction is enabled
Definition at line 93 of file Environment.h.
References m_obstacleEnabled.
{ return m_obstacleEnabled; }
ngl::Real Environment::getObstacleRestitutionCoefficient | ( | ) | const [inline] |
return the restitution coefficient for fluid interaction with RBD
Definition at line 111 of file Environment.h.
References m_obstacleRestitutionCoefficient.
{ return m_obstacleRestitutionCoefficient; }
ngl::Real Environment::getPeriodicWallAngleIncrement | ( | ) | const [inline] |
return the angle increment of the periodic wall sine function
Definition at line 129 of file Environment.h.
References m_periodicWallAngleIncrement.
{ return m_periodicWallAngleIncrement; }
bool Environment::getPeriodicWallEnabled | ( | ) | const [inline] |
return whether the boundary periodic wall is enabled
Definition at line 117 of file Environment.h.
References m_periodicWallEnabled.
{ return m_periodicWallEnabled; }
ngl::Real Environment::getPeriodicWallMaxAmplitude | ( | ) | const [inline] |
return the maximum amplitude of the periodic wall
Definition at line 120 of file Environment.h.
References m_periodicWallMaxAmplitude.
{ return m_periodicWallMaxAmplitude; }
ngl::Real Environment::getPeriodicWallSpeed | ( | ) | const [inline] |
return the angle speed factor of the periodic wall
Definition at line 123 of file Environment.h.
References m_periodicWallSpeed.
{ return m_periodicWallSpeed; }
std::vector< std::string > Environment::getSphereNameList | ( | ) |
return a list of the spheres id, used for caching
Definition at line 528 of file Environment.cpp.
References m_sphereObstacleList.
{ std::vector<std::string> list; //loop through sphere list for (int i = 0; i < m_sphereObstacleList.size(); ++i) { list.push_back(boost::lexical_cast<std::string>(i)); } return list; }
std::vector<Particle>& Environment::getSphereObstacleList | ( | ) | [inline] |
return the list of sphere RBD
Definition at line 86 of file Environment.h.
References m_sphereObstacleList.
{ return m_sphereObstacleList; }
std::vector< std::vector< ngl::Vector > > Environment::getSpherePositionList | ( | ) |
return a 2d list of the position of spheres, used for caching
Definition at line 506 of file Environment.cpp.
References m_sphereObstacleList.
{ std::vector<std::vector<ngl::Vector> > positionList; std::vector<ngl::Vector> list; list.reserve(m_sphereObstacleList.size()); //loop through sphere list for (int i = 0; i < m_sphereObstacleList.size(); ++i) { std::vector<ngl::Vector> list; //add sphere position to list list.push_back(m_sphereObstacleList[i].getPosition()); //add small list to big position list positionList.push_back(list); } return positionList; }
void Environment::loadGeometry | ( | ) |
load vbo geometry
Definition at line 48 of file Environment.cpp.
{ ngl::VBOPrimitives *prim=ngl::VBOPrimitives::instance(); prim->createVBOSphere("obstacleSphere", 1, 16); prim->createVBOCylinder("obstacleCylinder", 1, 1, 15, 20); }
void Environment::resolveCollision | ( | Particle & | io_currentParticle, |
const ngl::Vector | _contactPoint, | ||
const ngl::Vector | _normal, | ||
const ngl::Real | _penetrationDepth, | ||
const ngl::Real | _restitutionCoefficient | ||
) | [private] |
perform the actual collision handling (calculation of new position and velocity) once collision is detected
[in,out] | io_currentParticle | the particle affected by the collision resolution |
[in] | _contactPoint | the contact point of collision |
[in] | _normal | the unit surface normal at the point of collision |
[in] | _penetrationDepth | the penetration depth of collision |
[in] | _restitutionCoefficient | the restitution coefficient used to calculate the new velocity |
Definition at line 321 of file Environment.cpp.
References Particle::getVelocity(), Particle::updatePosition(), and Particle::updateVelocity().
{ //new position r = contact point io_currentParticle.updatePosition(_contactPoint); //calculate new velocity //u = u - (1 + Cr)(u.n)n ngl::Real dot = _normal.dot(io_currentParticle.getVelocity()); ngl::Vector vel = io_currentParticle.getVelocity() - ((1.0 + _restitutionCoefficient) * dot * _normal); io_currentParticle.updateVelocity(vel); }
void Environment::setAngleOfPeriodicWall | ( | const ngl::Real | _v | ) | [inline] |
set the angle of the periodic wall sine function
[in] | _v | the new value |
Definition at line 184 of file Environment.h.
References m_angleOfPeriodicWall.
{ m_angleOfPeriodicWall = _v; }
void Environment::setBoundaryBoundTop | ( | const bool | _v | ) | [inline] |
set whether the top face of the boundary is closed
[in] | _v | the new flag |
Definition at line 152 of file Environment.h.
References m_boundaryBoundTop.
{ m_boundaryBoundTop = _v; }
void Environment::setBoundaryDimension | ( | const ngl::Vector | _v | ) | [inline] |
set the boundary dimension
[in] | _v | the new value |
Definition at line 139 of file Environment.h.
References m_boundaryBBox, m_boundaryDimension, and m_boundaryPosition.
{ m_boundaryDimension = _v; delete m_boundaryBBox; m_boundaryBBox = new ngl::BBox(m_boundaryPosition, m_boundaryDimension.m_x, m_boundaryDimension.m_y, m_boundaryDimension.m_z); }
void Environment::setBoundaryPosition | ( | ngl::Vector | _v | ) | [inline] |
set the boundary centre position
[in] | _v | the new value |
Definition at line 148 of file Environment.h.
References m_boundaryBBox, and m_boundaryPosition.
{ m_boundaryPosition = _v; m_boundaryBBox->setCenter(_v); }
void Environment::setBoundaryRestitutionCoefficientForFluid | ( | const ngl::Real | _v | ) | [inline] |
set the restitution coefficient for fluid interaction with boundary
[in] | _v | the new value |
Definition at line 156 of file Environment.h.
References m_boundaryRestitutionCoefficientForFluid.
{ m_boundaryRestitutionCoefficientForFluid = _v; }
void Environment::setBoundaryRestitutionCoefficientForRBD | ( | const ngl::Real | _v | ) | [inline] |
set the restitution coefficient for RBD interaction with boundary
[in] | _v | the new value |
Definition at line 160 of file Environment.h.
References m_boundaryRestitutionCoefficientForRBD.
{ m_boundaryRestitutionCoefficientForRBD = _v; }
void Environment::setCapsuleResolution | ( | const int | _v | ) | [inline] |
set the resolution of the capsule drawing
[in] | _v | the new value |
Definition at line 168 of file Environment.h.
References m_capsuleResolution.
{ m_capsuleResolution = _v; }
void Environment::setObstacleEnabled | ( | const bool | _v | ) | [inline] |
set whether RBD interaction is enabled
[in] | _v | the new flag |
Definition at line 135 of file Environment.h.
References m_obstacleEnabled.
{ m_obstacleEnabled = _v; }
void Environment::setObstacleRestitutionCoefficient | ( | const ngl::Real | _v | ) | [inline] |
set the restitution coefficient for fluid interaction with RBD
[in] | _v | the new value |
Definition at line 164 of file Environment.h.
References m_obstacleRestitutionCoefficient.
{ m_obstacleRestitutionCoefficient = _v; }
void Environment::setPeriodicWallAngleIncrement | ( | const ngl::Real | _v | ) | [inline] |
set the angle increment of the periodic wall sine function
[in] | _v | the new value |
Definition at line 188 of file Environment.h.
References m_periodicWallAngleIncrement.
{ m_periodicWallAngleIncrement = _v; }
void Environment::setPeriodicWallEnabled | ( | const bool | _v | ) | [inline] |
set whether the boundary periodic wall is enabled
[in] | _v | the new flag |
Definition at line 172 of file Environment.h.
References m_periodicWallEnabled.
{ m_periodicWallEnabled = _v; }
void Environment::setPeriodicWallMaxAmplitude | ( | const ngl::Real | _v | ) | [inline] |
set the maximum amplitude of the periodic wall
[in] | _v | the new value |
Definition at line 176 of file Environment.h.
References m_periodicWallMaxAmplitude.
{ m_periodicWallMaxAmplitude = _v; }
void Environment::setPeriodicWallSpeed | ( | const ngl::Real | _v | ) | [inline] |
set the angle speed factor of the periodic wall
[in] | _v | the new value |
Definition at line 180 of file Environment.h.
References m_periodicWallSpeed.
{ m_periodicWallSpeed = _v; }
void Environment::updateObstacles | ( | Integration * | _integration | ) |
update the rigid bodies movements and rotations at every simulation iteration
Definition at line 138 of file Environment.cpp.
References checkAndResolveCollision(), Particle::getMoveable(), Integration::integrateNext(), m_capsuleObstacleList, m_obstacleEnabled, m_periodicWallEnabled, m_sphereObstacleList, Configuration::s_accelerationOfFreeFall, Particle::setAcceleration(), updatePeriodicBoundingBox(), and Capsule::updateRotation().
{ //update periodic wall if enabled if (m_periodicWallEnabled) updatePeriodicBoundingBox(); //obstacles movement and collision handling if enabled if (m_obstacleEnabled) { //update capsule obstacles BOOST_FOREACH(Capsule& obstacle, m_capsuleObstacleList) { if (obstacle.getMoveable()) { //rotate capsule obstacle.updateRotation(); //no collision check for capsule against others } } //update sphere obstacles BOOST_FOREACH(Particle& obstacle, m_sphereObstacleList) { //calculate acceleration due to gravity obstacle.setAcceleration(ngl::Vector(0, Configuration::s_accelerationOfFreeFall, 0)); if (obstacle.getMoveable()) { //determine next (position, velocity) of obstacle _integration->integrateNext(obstacle); //check and resolve collision bool hitBoundary; bool hitRBD; checkAndResolveCollision(obstacle, hitBoundary, hitRBD, true); } } } }
void Environment::updatePeriodicBoundingBox | ( | ) | [private] |
update the periodic wall position at each iteration
Definition at line 445 of file Environment.cpp.
References m_angleOfPeriodicWall, m_boundaryBBox, m_boundaryDimension, m_boundaryPosition, m_periodicWallAngleIncrement, m_periodicWallMaxAmplitude, and m_periodicWallSpeed.
{ //increment angle m_angleOfPeriodicWall += m_periodicWallAngleIncrement; //convert degrees to radians ngl::Real angle = m_angleOfPeriodicWall * (M_PI / 180.0); //get amplitude from sin function ngl::Real amplitude = sin(m_periodicWallSpeed * angle) * m_periodicWallMaxAmplitude; //determine new center ngl::Vector newCenter = m_boundaryPosition; newCenter.m_x += (amplitude / 2.0); //determine new box width ngl::Real newWidth = m_boundaryDimension.m_x + amplitude; //update bounding box (cannot resize it dynamically -> only way is to re-create it!!!!) delete m_boundaryBBox; m_boundaryBBox = new ngl::BBox(newCenter, newWidth, m_boundaryDimension.m_y, m_boundaryDimension.m_z); }
ngl::Real Environment::m_angleOfPeriodicWall [private] |
angle of the periodic wall sine function
Definition at line 235 of file Environment.h.
ngl::BBox* Environment::m_boundaryBBox [private] |
boundary bounding box object used for collision handling
Definition at line 202 of file Environment.h.
bool Environment::m_boundaryBoundTop [private] |
flag to determine if the top face of the boundary is closed
Definition at line 205 of file Environment.h.
ngl::Vector Environment::m_boundaryDimension [private] |
boundary dimension
Definition at line 196 of file Environment.h.
ngl::Vector Environment::m_boundaryPosition [private] |
boundary centre position
Definition at line 199 of file Environment.h.
ngl::Real Environment::m_boundaryRestitutionCoefficientForFluid [private] |
restitution coefficient for fluid interaction with boundary
Definition at line 208 of file Environment.h.
ngl::Real Environment::m_boundaryRestitutionCoefficientForRBD [private] |
restitution coefficient for RBD interaction with boundary
Definition at line 211 of file Environment.h.
std::vector<Capsule> Environment::m_capsuleObstacleList [private] |
list of capsule RBD
Definition at line 220 of file Environment.h.
int Environment::m_capsuleResolution [private] |
resolution of the capsule drawing (the number of spheres used to draw the capsule)
Definition at line 223 of file Environment.h.
bool Environment::m_obstacleEnabled [private] |
flag to determine if RBD interaction is enabled
Definition at line 193 of file Environment.h.
ngl::Real Environment::m_obstacleRestitutionCoefficient [private] |
restitution coefficient for fluid interaction with RBD
Definition at line 214 of file Environment.h.
ngl::Real Environment::m_periodicWallAngleIncrement [private] |
angle increment of the periodic wall sine function
Definition at line 238 of file Environment.h.
bool Environment::m_periodicWallEnabled [private] |
flag to determine whether the boundary periodic wall is enabled
Definition at line 226 of file Environment.h.
ngl::Real Environment::m_periodicWallMaxAmplitude [private] |
maximum amplitude of the periodic wall
Definition at line 229 of file Environment.h.
ngl::Real Environment::m_periodicWallSpeed [private] |
angle speed factor of the periodic wall
Definition at line 232 of file Environment.h.
std::vector<Particle> Environment::m_sphereObstacleList [private] |
list of sphere RBD
Definition at line 217 of file Environment.h.